From 33834416f337f300c24cbb9c8fcce1078d176659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Wed, 12 Jul 2023 19:07:00 +0200 Subject: [PATCH] update clickHandler with XFTGenerator --- src/app/app.c | 14 ++-- src/app/factory.c | 14 +++- src/app/factory.h | 2 +- src/middleware/clickHandler.c | 153 ---------------------------------- src/middleware/clickHandler.h | 94 --------------------- 5 files changed, 19 insertions(+), 258 deletions(-) delete mode 100644 src/middleware/clickHandler.c delete mode 100644 src/middleware/clickHandler.h diff --git a/src/app/app.c b/src/app/app.c index 9bb99ad..372b0bd 100644 --- a/src/app/app.c +++ b/src/app/app.c @@ -7,7 +7,7 @@ #include "app.h" #include "factory.h" #include "../middleware/blinker.h" -#include "../middleware/clickHandler.h" +#include "../middleware/click_handler.h" void clickL(APP* me){ POST(me, &APP_processEvent, evAPclickL, 0, 0); @@ -37,14 +37,14 @@ void APP_init(APP* me){ me->state = STAP_INIT; - CLICK_HANDLER_setSingleClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&clickL, me)); - CLICK_HANDLER_setSingleClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&clickR, me)); + CLICK_HANDLER_onSingle_click(ch1(), &clickL, me); + CLICK_HANDLER_onSingle_click(ch3(), &clickR, me); - CLICK_HANDLER_setDoubleClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&clickLn, me)); - CLICK_HANDLER_setDoubleClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&clickRn, me)); + CLICK_HANDLER_onDouble_click(ch1(), &clickLn, me); + CLICK_HANDLER_onDouble_click(ch3(), &clickRn, me); - CLICK_HANDLER_setLongClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&longClick, me)); - CLICK_HANDLER_setLongClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&longClick, me)); + CLICK_HANDLER_onLong_click(ch1(), &longClick, me); + CLICK_HANDLER_onLong_click(ch3(), &longClick, me); BLINKER_setFinished(blL(), BLINKER_defineCallBack(&endL, me)); BLINKER_setFinished(blR(), BLINKER_defineCallBack(&endR, me)); diff --git a/src/app/factory.c b/src/app/factory.c index 86301f9..81e3cbd 100755 --- a/src/app/factory.c +++ b/src/app/factory.c @@ -109,9 +109,9 @@ void Factory_init() { BUTTON_initHW(b2()); BUTTON_initHW(b3()); - CLICK_HANDLER_init(ch1(), b1()); - CLICK_HANDLER_init(ch2(), b2()); - CLICK_HANDLER_init(ch3(), b3()); + CLICK_HANDLER_init(ch1()); + CLICK_HANDLER_init(ch2()); + CLICK_HANDLER_init(ch3()); BLINKER_init(blL()); BLINKER_init(blR()); @@ -137,6 +137,14 @@ void warningBlink(void* on_){ //connect objects if required void Factory_build() { + BUTTON_onPressed(b1(), &CLICK_HANDLER_emitPbpress, ch1()); + BUTTON_onPressed(b2(), &CLICK_HANDLER_emitPbpress, ch2()); + BUTTON_onPressed(b3(), &CLICK_HANDLER_emitPbpress, ch3()); + + BUTTON_onReleased(b1(), &CLICK_HANDLER_emitPbrelease, ch1()); + BUTTON_onReleased(b2(), &CLICK_HANDLER_emitPbrelease, ch2()); + BUTTON_onReleased(b3(), &CLICK_HANDLER_emitPbrelease, ch3()); + BLINKER_setTurnOn(blL(), BLINKER_defineCallBack(&LED_on, l1())); BLINKER_setTurnOff(blL(), BLINKER_defineCallBack(&LED_off, l1())); BLINKER_setTurnOn(blR(), BLINKER_defineCallBack(&LED_on, l10())); diff --git a/src/app/factory.h b/src/app/factory.h index f65928f..b1895f6 100755 --- a/src/app/factory.h +++ b/src/app/factory.h @@ -12,7 +12,7 @@ #include "../board/led.h" #include "../board/button.h" -#include "../middleware/clickHandler.h" +#include "../middleware/click_handler.h" #include "../middleware/blinker.h" #include "app.h" diff --git a/src/middleware/clickHandler.c b/src/middleware/clickHandler.c deleted file mode 100644 index 88178d6..0000000 --- a/src/middleware/clickHandler.c +++ /dev/null @@ -1,153 +0,0 @@ -/** - * @author R�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_init(CLICK_HANDLER* me, BUTTON* b){ - me->button = b; - me->state = STCH_INIT; - me->longClick.fCallBack = NULL; - me->singleClick.fCallBack = NULL; - me->doubleClick.fCallBack = NULL; - - BUTTON_onPressed(b, CLICK_HANDLER_BUTTON_PRESS, me); - BUTTON_onReleased(b, CLICK_HANDLER_BUTTON_RELEASE, me); -} - -void CLICK_HANDLER_startBehaviour(CLICK_HANDLER* me){ - POST(me, &CLICK_HANDLER_processEvent, evCHinit, 0, 0); -} - -clickHandlerCallBack CLICK_HANDLER_defineCallBack(fClickHandlerCallBack f, void* param) { - clickHandlerCallBack c; - c.fCallBack = f; - c.param = param; - return c; -} - -void CLICK_HANDLER_setLongClickCallback(CLICK_HANDLER* me, clickHandlerCallBack callBack) { - me->longClick = callBack; -} - -void CLICK_HANDLER_setSingleClickCallback(CLICK_HANDLER* me, clickHandlerCallBack callBack) { - me->singleClick = callBack; -} - -void CLICK_HANDLER_setDoubleClickCallback(CLICK_HANDLER* me, clickHandlerCallBack callBack) { - me->doubleClick = callBack; -} - -bool CLICK_HANDLER_processEvent(Event* ev) { - bool processed = false; - CLICK_HANDLER* me = (CLICK_HANDLER*)Event_getTarget(ev); - CLICK_HANDLER_STATES oldState = me->state; - evIDT evid = Event_getId(ev); - - switch(me->state) { - case STCH_INIT: - if(evid == evCHinit) { - me->state = STCH_WAIT; - } - break; - - case STCH_WAIT: - - if(evid == evCHpbPress) { - me->state = STCH_LONG_CLICK; - POST(me, &CLICK_HANDLER_processEvent, evCHtimer, CH_CLICK_TIMER, 0); - } - - break; - - - case STCH_LONG_CLICK: - - if(evid == evCHpbRelease) { - me->state = STCH_SINGLE_CLICK; - } - - if(evid == evCHtimer) { - me->state = STCH_WAIT; - if(me->longClick.fCallBack != NULL) { - me->longClick.fCallBack(me->longClick.param); - } - } - - break; - - - case STCH_SINGLE_CLICK: - - if(evid == evCHpbPress) { - me->state = STCH_DOUBLE_CLICK; - } - - if(evid == evCHtimer) { - me->state = STCH_WAIT; - if(me->singleClick.fCallBack != NULL) { - me->singleClick.fCallBack(me->singleClick.param); - } - } - - break; - - - case STCH_DOUBLE_CLICK: - - if(evid == evCHpbRelease){ - me->state = STCH_WAIT; - if(me->doubleClick.fCallBack != NULL){ - me->doubleClick.fCallBack(me->doubleClick.param); - } - } - - if(evid == evCHtimer) { - me->state = STCH_WAIT; - if(me->doubleClick.fCallBack != NULL) { - me->doubleClick.fCallBack(me->doubleClick.param); - } - } - - break; - - } - - if(oldState != me->state) { - switch(oldState) { - case STCH_INIT: - break; - - case STCH_WAIT: - break; - - case STCH_LONG_CLICK: - break; - - case STCH_SINGLE_CLICK: - break; - - case STCH_DOUBLE_CLICK: - break; - } - processed = true; - } - return processed; -} diff --git a/src/middleware/clickHandler.h b/src/middleware/clickHandler.h deleted file mode 100644 index 3842d37..0000000 --- a/src/middleware/clickHandler.h +++ /dev/null @@ -1,94 +0,0 @@ -/** - * @author R�mi Heredero (remi@heredero.ch) - * @version. 1.0.0 - * @date 2023-06-15 - */ - -#ifndef CLICKHANDLER_H -#define CLICKHANDLER_H - -#include "../xf/xf.h" -#include "../board/button.h" - -#define CH_CLICK_TIMER 250 - -typedef enum { - STCH_INIT, - STCH_WAIT, - STCH_LONG_CLICK, - STCH_SINGLE_CLICK, - STCH_DOUBLE_CLICK -} CLICK_HANDLER_STATES; - -typedef enum { - evCHinit = 100, - evCHtimer, - evCHpbPress, - evCHpbRelease -} CLICK_HANDLER_EVENTS; - -typedef void (*fClickHandlerCallBack)(void*); -typedef struct { - fClickHandlerCallBack fCallBack; - void* param; -} clickHandlerCallBack; - -typedef struct { - BUTTON* button; // The button connected to the clickHandler - CLICK_HANDLER_STATES state; // The actual state - clickHandlerCallBack longClick; // Callback for longClick - clickHandlerCallBack singleClick; // Callback for singleClick - clickHandlerCallBack doubleClick; // Callback for doubleClick -}CLICK_HANDLER; - -/** - * Initialize the clickHandler - * @param me the clickHandler itself - * @param b the button to connect on the clickHandler - */ -void CLICK_HANDLER_init(CLICK_HANDLER* me, BUTTON* b); - -/** - * Define a callback for CLICKHANDLER - * @param f callback function for CLICKHANDLER - * @param param callback parameter for the function - * @return the callback struct - */ -clickHandlerCallBack CLICK_HANDLER_defineCallBack(fClickHandlerCallBack f, void* param); - -/** - * Start state machine of the CLICKHANDLER - * @param me the clickHandler itself - */ -void CLICK_HANDLER_startBehaviour(CLICK_HANDLER* me); - -/** - * Set Callback eventfunction for long click - * @param me the clickHandler itself - * @param callBack callback function when the click handler have a long click - */ -void CLICK_HANDLER_setLongClickCallback(CLICK_HANDLER* me, clickHandlerCallBack callBack); - -/** - * Set Callback event function for single click - * @param me the clickHandler itself - * @param callBack callback function when the click handler have a single click - */ -void CLICK_HANDLER_setSingleClickCallback(CLICK_HANDLER* me, clickHandlerCallBack callBack); - -/** - * Set Callback evenet function for double click - * @param me the clickHandler itself - * @param callBack callback function when the click handler have a double click - */ -void CLICK_HANDLER_setDoubleClickCallback(CLICK_HANDLER* me, clickHandlerCallBack callBack); - -/** - * State machine of the CLICKHANDLER - * @param ev event to process on the state machine - */ -bool CLICK_HANDLER_processEvent(Event* ev); - - -#endif /* CLICKHANDLER_H */ -