add callbacks
This commit is contained in:
parent
ef56b5b6ae
commit
29a6be78b3
@ -5,8 +5,8 @@
|
||||
*/
|
||||
|
||||
#include "button.h"
|
||||
#include "../mcc_generated_files/pin_manager.h"
|
||||
#include "../app/factory.h"
|
||||
#include "../src/mcc_generated_files/pin_manager.h"
|
||||
#include "../src/app/factory.h"
|
||||
|
||||
/**
|
||||
* @brief Initialize the button
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "../xf/xf.h"
|
||||
#include "../src/xf/xf.h"
|
||||
|
||||
#define PB_POLL_TIME 20 // Poll time for BUTTON
|
||||
|
@ -9,6 +9,7 @@
|
||||
</logicalFolder>
|
||||
<logicalFolder name="board" displayName="board" projectFiles="true">
|
||||
<itemPath>src/board/led.h</itemPath>
|
||||
<itemPath>src/board/button.h</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="mcc_generated_files"
|
||||
displayName="mcc_generated_files"
|
||||
@ -19,6 +20,10 @@
|
||||
<itemPath>src/mcc_generated_files/interrupt_manager.h</itemPath>
|
||||
<itemPath>src/mcc_generated_files/device_config.h</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="middleware" displayName="middleware" projectFiles="true">
|
||||
<itemPath>src/middleware/clickHandler.h</itemPath>
|
||||
<itemPath>src/middleware/blinker.h</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
||||
<itemPath>src/xf/ireactive.h</itemPath>
|
||||
<itemPath>src/xf/event.h</itemPath>
|
||||
@ -38,6 +43,7 @@
|
||||
</logicalFolder>
|
||||
<logicalFolder name="board" displayName="board" projectFiles="true">
|
||||
<itemPath>src/board/led.c</itemPath>
|
||||
<itemPath>src/board/button.c</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="mcc_generated_files"
|
||||
displayName="mcc_generated_files"
|
||||
@ -48,6 +54,10 @@
|
||||
<itemPath>src/mcc_generated_files/pin_manager.c</itemPath>
|
||||
<itemPath>src/mcc_generated_files/tmr0.c</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="middleware" displayName="middleware" projectFiles="true">
|
||||
<itemPath>src/middleware/blinker.c</itemPath>
|
||||
<itemPath>src/middleware/clickHandler.c</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
||||
<itemPath>src/xf/xf.c</itemPath>
|
||||
<itemPath>src/xf/event.c</itemPath>
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
#include "../mcc_generated_files/mcc.h"
|
||||
#include "../app/factory/factory.h"
|
||||
#include "../app/factory.h"
|
||||
#include "../xf/xf.h"
|
||||
|
||||
|
||||
|
@ -1,17 +1,24 @@
|
||||
/**
|
||||
* @author Rémi Heredero (remi@heredero.ch)
|
||||
* @author R<EFBFBD>mi Heredero (remi@heredero.ch)
|
||||
* @version. 1.0.0
|
||||
* @date 2023-06-15
|
||||
*/
|
||||
|
||||
#include "clickHandler.h"
|
||||
#include "../board/led.h"
|
||||
#include "../app/factory.h"
|
||||
|
||||
typedef struct {
|
||||
CLICK_HANDLER* me;
|
||||
uint16_t t;
|
||||
} foo;
|
||||
|
||||
void CLICK_HANDLER_BUTTON_PRESS(CLICK_HANDLER* me){
|
||||
POST(me, &CLICK_HANDLER_processEvent, evCHpbPress, 0, 0);
|
||||
}
|
||||
|
||||
void CLICK_HANDLER_BUTTON_RELEASE(CLICK_HANDLER * me) {
|
||||
POST(me, &CLICK_HANDLER_processEvent, evCHpbRelease, 0, 0);
|
||||
void CLICK_HANDLER_BUTTON_RELEASE(CLICK_HANDLER* me) {
|
||||
POST(me, &CLICK_HANDLER_processEvent, evCHpbRelease,0, 0);
|
||||
}
|
||||
|
||||
void CLICK_HANDLER_init(CLICK_HANDLER* me, BUTTON* b){
|
||||
@ -21,15 +28,8 @@ void CLICK_HANDLER_init(CLICK_HANDLER* me, BUTTON* b){
|
||||
me->singleClick.fCallBack = NULL;
|
||||
me->doubleClick.fCallBack = NULL;
|
||||
|
||||
buttonCallBack pbPressCallBack;
|
||||
pbPressCallBack.fCallBack = CLICK_HANDLER_BUTTON_PRESS;
|
||||
pbPressCallBack.param = me;
|
||||
|
||||
buttonCallBack pbReleaseCallBack;
|
||||
pbReleaseCallBack.fCallBack = CLICK_HANDLER_BUTTON_RELEASE;
|
||||
pbReleaseCallBack.param = me;
|
||||
|
||||
BUTTON_setEventFunctions(b, pbPressCallBack, pbReleaseCallBack);
|
||||
BUTTON_onPress(b, CLICK_HANDLER_BUTTON_PRESS, me);
|
||||
BUTTON_onRelease(b, CLICK_HANDLER_BUTTON_RELEASE, me);
|
||||
}
|
||||
|
||||
void CLICK_HANDLER_startBehaviour(CLICK_HANDLER* me){
|
||||
@ -71,8 +71,12 @@ bool CLICK_HANDLER_processEvent(Event* ev) {
|
||||
case STCH_WAIT:
|
||||
|
||||
if(evid == evCHpbPress) {
|
||||
me->state = STCH_LONG_CLICK;
|
||||
POST(me, &CLICK_HANDLER_processEvent, evCHtimer, CH_CLICK_TIMER, 0);
|
||||
LED_on(l2());
|
||||
//me->state = STCH_LONG_CLICK;
|
||||
//POST(me, &CLICK_HANDLER_processEvent, evCHtimer, CH_CLICK_TIMER, 0);
|
||||
}
|
||||
if(evid==evCHpbRelease) {
|
||||
LED_off(l2());
|
||||
}
|
||||
|
||||
break;
|
||||
@ -86,7 +90,9 @@ bool CLICK_HANDLER_processEvent(Event* ev) {
|
||||
|
||||
if(evid == evCHtimer) {
|
||||
me->state = STCH_WAIT;
|
||||
LED_on(l4());
|
||||
if(me->longClick.fCallBack != NULL) {
|
||||
LED_on(l5());
|
||||
me->longClick.fCallBack(me->longClick.param);
|
||||
}
|
||||
}
|
||||
@ -97,10 +103,12 @@ bool CLICK_HANDLER_processEvent(Event* ev) {
|
||||
case STCH_SINGLE_CLICK:
|
||||
|
||||
if(evid == evCHpbPress) {
|
||||
LED_on(l2());
|
||||
me->state = STCH_DOUBLE_CLICK;
|
||||
}
|
||||
|
||||
if(evid == evCHtimer) {
|
||||
LED_on(l3());
|
||||
me->state = STCH_WAIT;
|
||||
if(me->singleClick.fCallBack != NULL) {
|
||||
me->singleClick.fCallBack(me->singleClick.param);
|
||||
|
Reference in New Issue
Block a user