From 744051f61f9d4370ef5c2bc0c1b27bd14d140004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Thu, 15 Jun 2023 20:55:32 +0200 Subject: [PATCH] add Blinker + polish --- .../kb28/blinkerProject/app/factory/factory.c | 55 ++++--- .../kb28/blinkerProject/app/factory/factory.h | 6 +- .../ch/kb28/blinkerProject/app/lebblinker.c | 57 -------- .../ch/kb28/blinkerProject/app/ledblinker.h | 42 ------ 03-software/ch/kb28/blinkerProject/app/main.c | 2 +- .../kb28/blinkerProject/board/button/button.c | 6 +- .../kb28/blinkerProject/board/button/button.h | 61 ++++++-- .../ch/kb28/blinkerProject/board/led/led.c | 6 + .../ch/kb28/blinkerProject/board/led/led.h | 41 ++++-- .../kb28/blinkerProject/middleware/blinker.c | 135 ++++++++++++++++++ .../kb28/blinkerProject/middleware/blinker.h | 126 ++++++++++++++++ .../blinkerProject/middleware/clickHandler.c | 2 +- .../blinkerProject/middleware/clickHandler.h | 56 ++++++-- 03-software/nbproject/configurations.xml | 5 +- 14 files changed, 443 insertions(+), 157 deletions(-) delete mode 100644 03-software/ch/kb28/blinkerProject/app/lebblinker.c delete mode 100644 03-software/ch/kb28/blinkerProject/app/ledblinker.h create mode 100644 03-software/ch/kb28/blinkerProject/middleware/blinker.c create mode 100644 03-software/ch/kb28/blinkerProject/middleware/blinker.h diff --git a/03-software/ch/kb28/blinkerProject/app/factory/factory.c b/03-software/ch/kb28/blinkerProject/app/factory/factory.c index 9af49b6..7803dee 100755 --- a/03-software/ch/kb28/blinkerProject/app/factory/factory.c +++ b/03-software/ch/kb28/blinkerProject/app/factory/factory.c @@ -57,6 +57,14 @@ CLICK_HANDLER* ch3() { return &theFactory.ch3_; } +BLINKER* blA() { + return &theFactory.blA_; +} +BLINKER* blB() { + return &theFactory.blB_; +} + + LEDBlinker* lb() { return &theFactory.lb_; @@ -75,15 +83,6 @@ void Factory_init() { LED_init(l9(), 9); LED_init(l10(), 10); - BUTTON_init(b1(), 1); - BUTTON_init(b2(), 2); - BUTTON_init(b3(), 3); - - CLICK_HANDLER_init(ch1(), b1()); - CLICK_HANDLER_init(ch2(), b2()); - CLICK_HANDLER_init(ch3(), b3()); - - LED_initHW(l1()); LED_initHW(l2()); LED_initHW(l3()); @@ -95,25 +94,45 @@ void Factory_init() { LED_initHW(l9()); LED_initHW(l10()); + + BUTTON_init(b1(), 1); + BUTTON_init(b2(), 2); + BUTTON_init(b3(), 3); + BUTTON_initHW(b1()); BUTTON_initHW(b2()); BUTTON_initHW(b3()); + + CLICK_HANDLER_init(ch1(), b1()); + CLICK_HANDLER_init(ch2(), b2()); + CLICK_HANDLER_init(ch3(), b3()); + + BLINKER_init(blA()); + BLINKER_init(blB()); + } //connect objects if required void Factory_build() { - //BUTTON_setEventFunctions(b1(), BUTTON_defineCallBack(&LED_on, l1()), BUTTON_defineCallBack(NULL, NULL)); - //BUTTON_setEventFunctions(b3(), BUTTON_defineCallBack(&LED_off, l1()), BUTTON_defineCallBack(NULL, NULL)); + BLINKER_defineNblink(blA(), 3); + BLINKER_defineNblink(blB(), 5); + BLINKER_setTimeOn(blA(), 20); + BLINKER_setTimeOff(blA(), 480); - CLICK_HANDLER_setSingleClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&LED_on, l1())); - CLICK_HANDLER_setSingleClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&LED_on, l3())); + BLINKER_setTurnOn(blA(), BLINKER_defineCallBack(&LED_on, l1())); + BLINKER_setTurnOff(blA(), BLINKER_defineCallBack(&LED_off, l1())); + BLINKER_setTurnOn(blB(), BLINKER_defineCallBack(&LED_on, l10())); + BLINKER_setTurnOff(blB(), BLINKER_defineCallBack(&LED_off, l10())); - CLICK_HANDLER_setDoubleClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&LED_off, l1())); - CLICK_HANDLER_setDoubleClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&LED_off, l3())); + CLICK_HANDLER_setSingleClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&BLINKER_blink, blA())); + CLICK_HANDLER_setDoubleClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&BLINKER_endBlink, blA())); + CLICK_HANDLER_setLongClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&BLINKER_blinkN, blA())); + + CLICK_HANDLER_setSingleClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&BLINKER_blink, blB())); + CLICK_HANDLER_setDoubleClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&BLINKER_endBlink, blB())); + CLICK_HANDLER_setLongClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&BLINKER_blinkN, blB())); - CLICK_HANDLER_setLongClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&LED_on, l2())); - CLICK_HANDLER_setLongClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&LED_off, l2())); } //start all state machines @@ -125,4 +144,6 @@ void Factory_start() { CLICK_HANDLER_startBehaviour(ch1()); CLICK_HANDLER_startBehaviour(ch2()); CLICK_HANDLER_startBehaviour(ch3()); + BLINKER_starBehaviour(blA()); + BLINKER_starBehaviour(blB()); } diff --git a/03-software/ch/kb28/blinkerProject/app/factory/factory.h b/03-software/ch/kb28/blinkerProject/app/factory/factory.h index b58dbdc..0945190 100755 --- a/03-software/ch/kb28/blinkerProject/app/factory/factory.h +++ b/03-software/ch/kb28/blinkerProject/app/factory/factory.h @@ -11,6 +11,7 @@ #include "../../board/button/button.h" #include "../ledblinker.h" #include "../../middleware/clickHandler.h" +#include "../../middleware/blinker.h" typedef struct { LED l1_; @@ -29,6 +30,8 @@ typedef struct { CLICK_HANDLER ch1_; CLICK_HANDLER ch2_; CLICK_HANDLER ch3_; + BLINKER blA_; + BLINKER blB_; LEDBlinker lb_; } Factory; @@ -58,6 +61,7 @@ CLICK_HANDLER* ch1(); CLICK_HANDLER* ch2(); CLICK_HANDLER* ch3(); -LEDBlinker* lb(); +BLINKER* blA(); +BLINKER* blB(); #endif \ No newline at end of file diff --git a/03-software/ch/kb28/blinkerProject/app/lebblinker.c b/03-software/ch/kb28/blinkerProject/app/lebblinker.c deleted file mode 100644 index 01d109d..0000000 --- a/03-software/ch/kb28/blinkerProject/app/lebblinker.c +++ /dev/null @@ -1,57 +0,0 @@ -#include "ledblinker.h" -#include "factory/factory.h" -#include "../board/led/led.h" - -void LEDBlinker_init(LEDBlinker* me) { - me->state = ST_LBINIT; -} - -void LEDBlinker_startBehaviour(LEDBlinker* me) { - POST(me, &LEDBlinker_processEvent, evLBInit,0,0); -} - -bool LEDBlinker_processEvent(Event* ev) { - bool processed = false; - LEDBlinker* me = (LEDBlinker*)Event_getTarget(ev); - LBSTATES oldState = me->state; - evIDT evid = Event_getId(ev); - - switch (me->state) { - case ST_LBINIT: - if (evid == evLBInit) { - me->state = ST_LBOFF; - } - break; - case ST_LBOFF: - if (evid == evLBTMOn) { - me->state = ST_LBON; - } - break; - case ST_LBON: - if (evid == evLBTMOff) { - me->state = ST_LBOFF; - } - break; - default: - break; - } - - if (oldState != me->state) { - switch (me->state) { - case ST_LBINIT: - break; - case ST_LBOFF: - LED_off(l1()); - POST(me, &LEDBlinker_processEvent, evLBTMOn,TMOFF,0); - break; - case ST_LBON: - LED_on(l1()); - POST(me, &LEDBlinker_processEvent, evLBTMOff,TMON,0); - break; - default: - break; - } - processed = true; - } - return processed; -} \ No newline at end of file diff --git a/03-software/ch/kb28/blinkerProject/app/ledblinker.h b/03-software/ch/kb28/blinkerProject/app/ledblinker.h deleted file mode 100644 index 7512c4e..0000000 --- a/03-software/ch/kb28/blinkerProject/app/ledblinker.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * File: ledblinker.h - * Author: rim - * - * Created on May 14, 2023, 9:58 AM - */ - -#ifndef LEDBLINKER_H -#define LEDBLINKER_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "../xf/xf.h" - - enum LBSTATES_ {ST_LBINIT, ST_LBOFF, ST_LBON}; - enum LBEVENTS_ {evLBInit=200, evLBTMOff, evLBTMOn}; - typedef enum LBSTATES_ LBSTATES; - typedef enum LBEVENTS_ LBEVENTS; - - struct LEDBlinker_ { - LBSTATES state; - }; - - typedef struct LEDBlinker_ LEDBlinker; - -#define TMON 500 -#define TMOFF 1000 - - - void LEDBlinker_init(LEDBlinker* me); - - void LEDBlinker_startBehaviour(LEDBlinker* me); - bool LEDBlinker_processEvent(Event* ev); - -#ifdef __cplusplus -} -#endif - -#endif /* LEDBLINKER_H */ - diff --git a/03-software/ch/kb28/blinkerProject/app/main.c b/03-software/ch/kb28/blinkerProject/app/main.c index 23b0e52..af1013e 100644 --- a/03-software/ch/kb28/blinkerProject/app/main.c +++ b/03-software/ch/kb28/blinkerProject/app/main.c @@ -14,7 +14,7 @@ void main(void) INTERRUPT_GlobalInterruptEnable(); //INTERRUPT_GlobalInterruptDisable(); //INTERRUPT_PeripheralInterruptEnable(); - //INTERRUPT_PeripheralInterruptDisable(); + //INTERRUPT_PeripheralInterruptDisable(); XF_init(); diff --git a/03-software/ch/kb28/blinkerProject/board/button/button.c b/03-software/ch/kb28/blinkerProject/board/button/button.c index e1fef5e..a227b8c 100644 --- a/03-software/ch/kb28/blinkerProject/board/button/button.c +++ b/03-software/ch/kb28/blinkerProject/board/button/button.c @@ -1,9 +1,7 @@ /** - * @file button.c * @author Rémi Heredero (remi@heredero.ch) - * @version 1 - * @date 2023-06-13 - * + * @version. 1.0.0 + * @date 2023-06-15 */ #include "button.h" diff --git a/03-software/ch/kb28/blinkerProject/board/button/button.h b/03-software/ch/kb28/blinkerProject/board/button/button.h index 02bc92f..6bd8fe9 100644 --- a/03-software/ch/kb28/blinkerProject/board/button/button.h +++ b/03-software/ch/kb28/blinkerProject/board/button/button.h @@ -12,28 +12,37 @@ #include #include "../../xf/xf.h" -#define PB_POLL_TIME 20 +#define PB_POLL_TIME 20 // Poll time for BUTTON -typedef enum {ST_PBINIT, ST_PBRELEASED, ST_PBPRESSED} BUTTON_STATES; -typedef enum {evPBInit=100, evPBPoll} BUTTON_EVENTS; +typedef enum { + ST_PBINIT, + ST_PBRELEASED, + ST_PBPRESSED +} BUTTON_STATES; -typedef void (*fButtonCallback)(void*); +typedef enum { + evPBInit=50, + evPBPoll +} BUTTON_EVENTS; + +// Calback function +typedef void (*fButtonCallback)(void*); typedef struct { fButtonCallback fCallBack; void* param; } buttonCallBack; typedef struct { - uint8_t id; - BUTTON_STATES state; - buttonCallBack press; - buttonCallBack release; + uint8_t id; // Id of the button + BUTTON_STATES state; // Actual state + buttonCallBack press; // Callback for the rising edge of the button + buttonCallBack release; // Callback for the falling edge of the button } BUTTON; /** * @brief Initialize the button * - * @param me The object to initialize + * @param me button itself * @param id The id of the button */ void BUTTON_init(BUTTON* me, uint8_t id); @@ -41,22 +50,50 @@ void BUTTON_init(BUTTON* me, uint8_t id); /** * @brief Initialize the hardware of the button * - * @param me The object to initialize + * @param me button itself */ void BUTTON_initHW(BUTTON* me); +/** + * @brief Set both callback event functions + * + * @param me button itself + * @param fPress callback function when the button have a rising edge + * @param release callback function whent the have a falling edge + */ +void BUTTON_setEventFunctions(BUTTON* me, buttonCallBack fPress, buttonCallBack release); + /** * @brief Check if the button is pressed * The function returns true if the button is pressed, false otherwise * - * @param me The object to check + * @param me button itself * @return true if the button is pressed * @return false if the button is not pressed */ -void BUTTON_setEventFunctions(BUTTON* me, buttonCallBack fPress, buttonCallBack release); bool BUTTON_isPressed(BUTTON* me); + +/** + * @biref Start state machine of the BUTTON + * + * @param me the button itself + */ void BUTTON_startBehaviour(BUTTON* me); + +/** + * @brief State machine of the BUTTON + * + * @param ev event to process on the state machine + */ bool BUTTON_processEvent(Event* ev); + +/** + * @brief Define a callback for BUTTON + * + * @param f callback function + * @param param callback parameter for the function + * @return the callback struct + */ buttonCallBack BUTTON_defineCallBack(fButtonCallback f, void* param); #endif /* BUTTON_H */ \ No newline at end of file diff --git a/03-software/ch/kb28/blinkerProject/board/led/led.c b/03-software/ch/kb28/blinkerProject/board/led/led.c index a202097..997db02 100644 --- a/03-software/ch/kb28/blinkerProject/board/led/led.c +++ b/03-software/ch/kb28/blinkerProject/board/led/led.c @@ -1,3 +1,9 @@ +/** + * @author Rémi Heredero (remi@heredero.ch) + * @version. 1.0.0 + * @date 2023-06-15 + */ + #include "led.h" #include "../../mcc_generated_files/pin_manager.h" diff --git a/03-software/ch/kb28/blinkerProject/board/led/led.h b/03-software/ch/kb28/blinkerProject/board/led/led.h index cd7be86..e66254d 100644 --- a/03-software/ch/kb28/blinkerProject/board/led/led.h +++ b/03-software/ch/kb28/blinkerProject/board/led/led.h @@ -1,25 +1,42 @@ -/* - * File: led.h - * Author: rim - * - * Created on May 15, 2023, 7:56 AM +/** + * @file led.h + * @author Rémi Heredero (remi@heredero.ch) + * @version. 1.0.0 + * @date 2023-06-15 */ - #ifndef LED_H #define LED_H #include -struct LED_ -{ - uint8_t id; -}; - -typedef struct LED_ LED; +// LED struct +typedef struct { + uint8_t id; // The id of the LED +}LED; +/** + * Initialize the led + * @param me the led itself + * @param id the id of the led + */ void LED_init(LED* me, uint8_t id); + +/** + * Initializing the led + * @param me the led itself + */ void LED_initHW(LED* me); + +/** + * Turn On the led + * @param me the led itself + */ void LED_on(void* me); + +/** + * Turn Off the led + * @param me the led itself + */ void LED_off(void* me); #endif /* LED_H */ diff --git a/03-software/ch/kb28/blinkerProject/middleware/blinker.c b/03-software/ch/kb28/blinkerProject/middleware/blinker.c new file mode 100644 index 0000000..73d5894 --- /dev/null +++ b/03-software/ch/kb28/blinkerProject/middleware/blinker.c @@ -0,0 +1,135 @@ +/** + * @file blinker.c + * @author Rémi Heredero (remi@heredero.ch) + * @version 0 + * @date 2023-06-14 + */ + +#include "blinker.h" + + +void BLINKER_init(BLINKER* me) { + me->state = STBL_INIT; + me->tON = 500; + me->tOFF = 500; + me->nBlink = 3; + me->nBlinkIsOn = false; + me->remainBlinks = 3; + me->turnOn.fCallBack = NULL; + me->turnOff.fCallBack = NULL; +} + +blinkerCallBack BLINKER_defineCallBack(fBlinkerCallBack f, void* param) { + blinkerCallBack c; + c.fCallBack = f; + c.param = param; + return c; +} + +void BLINKER_starBehaviour(BLINKER* me) { + POST(me, &BLINKER_processEvent, evBLinit, 0, 0); +} + +void BLINKER_setTurnOn(BLINKER* me, blinkerCallBack callBack) { + me->turnOn = callBack; +} + +void BLINKER_setTurnOff(BLINKER* me, blinkerCallBack callBack) { + me->turnOff = callBack; +} + +void BLINKER_defineNblink(BLINKER* me, uint8_t n){ + me->nBlink = n; +} + +void BLINKER_setTimeOn(BLINKER*me, uint16_t t) { + me->tON = t; +} + +void BLINKER_setTimeOff(BLINKER*me, uint16_t t) { + me->tOFF = t; +} + +void BLINKER_blinkN(BLINKER* me){ + POST(me, &BLINKER_processEvent, evBLblinkN, 0, 0); +} + +void BLINKER_blink(BLINKER* me){ + POST(me, &BLINKER_processEvent, evBLblink, 0, 0); +} + +bool BLINKER_processEvent(Event* ev) { + bool processed = false; + BLINKER* me = (BLINKER*) Event_getTarget(ev); + BLINKER_STATES oldState = me->state; + evIDT evid = Event_getId(ev); + + switch(me->state) { + case STBL_INIT: + if(evid == evBLinit) { + me->state = STBL_WAIT; + } + break; + + case STBL_WAIT: + me->remainBlinks = me->nBlink; + + if(evid == evBLblinkN) { + me->state = STBL_ON; + me->nBlinkIsOn = true; + POST(me, &BLINKER_processEvent, evBLtimer, me->tON, 0); + } + + if(evid==evBLblink) { + me->state = STBL_ON; + me->nBlinkIsOn = false; + POST(me, &BLINKER_processEvent, evBLtimer, me->tON, 0); + } + break; + + case STBL_ON: + if(me->nBlinkIsOn) me->remainBlinks--; + + if(evid == evBLtimer) { + me->state = STBL_OFF; + POST(me, &BLINKER_processEvent, evBLtimer, me->tOFF, 0); + } + + break; + + case STBL_OFF: + + if(evid == evBLtimer) { + if(me->remainBlinks == 0) { + me->state = STBL_WAIT; + } else { + me->state = STBL_ON; + POST(me, &BLINKER_processEvent, evBLtimer, me->tON, 0); + } + } + + break; + } + + if(oldState != me->state) { + switch(me->state) { + case STBL_INIT: + break; + + case STBL_WAIT: + break; + + case STBL_ON: + if(me->turnOn.fCallBack != NULL) me->turnOn.fCallBack(me->turnOn.param); + break; + + case STBL_OFF: + if(me->turnOff.fCallBack != NULL) me->turnOff.fCallBack(me->turnOff.param); + break; + } + } +} + +void BLINKER_endBlink(BLINKER* me) { + me->remainBlinks = 0; +} diff --git a/03-software/ch/kb28/blinkerProject/middleware/blinker.h b/03-software/ch/kb28/blinkerProject/middleware/blinker.h new file mode 100644 index 0000000..565ec63 --- /dev/null +++ b/03-software/ch/kb28/blinkerProject/middleware/blinker.h @@ -0,0 +1,126 @@ +/** + * @file blinker.h + * @author Rémi Heredero (remi@heredero.ch) + * @version 0 + * @date 2023-06-14 + */ + +#ifndef BLINKER_H +#define BLINKER_H + +#include "../xf/xf.h" + +typedef enum { + STBL_INIT, + STBL_WAIT, + STBL_ON, + STBL_OFF +} BLINKER_STATES; + +typedef enum { + evBLinit = 200, + evBLblink, + evBLblinkN, + evBLtimer, + evEndBlink +} BLINKER_EVENTS; + +typedef void (*fBlinkerCallBack)(void*); +typedef struct { + fBlinkerCallBack fCallBack; + void* param; +} blinkerCallBack; + +typedef struct { + BLINKER_STATES state; + uint16_t tON; // Time on + uint16_t tOFF; // Time off + uint8_t nBlink; // Number of blink for this blinker when start with blinkN + bool nBlinkIsOn; // If the nBlink way is enable + uint8_t remainBlinks; // Actual remain blink + blinkerCallBack turnOn; // Callback for turnOn + blinkerCallBack turnOff; // Calbback for turnOff +}BLINKER; + +/** + * Initialize the blinker + * @param me blinker itself + */ +void BLINKER_init(BLINKER* me); + +/** + * Define a callback for BLINKER + * @param f callback for BLINKER + * @param param callback paramater for ther function + * @return the callback struct + */ +blinkerCallBack BLINKER_defineCallBack(fBlinkerCallBack f, void* param); + +/** + * Start state machine of the BLINKER + * @param me the blinker itself + */ +void BLINKER_starBehaviour(BLINKER* me); + +/** + * Set callback event functions for turn on + * @param me the blinker itself + * @param callBack function when the blinker is on + */ +void BLINKER_setTurnOn(BLINKER* me, blinkerCallBack callBack); + +/** + * Set callback event functions for turn off + * @param me the blinker itself + * @param callBack function when the blinker is off + */ +void BLINKER_setTurnOff(BLINKER* me, blinkerCallBack callBack); + +/** + * define number of time the Blinker have to blink + * @param me the blinker itself + * @param n number of blink + */ +void BLINKER_defineNblink(BLINKER* me, uint8_t n); + +/** + * define time to stay ON + * @param me the blinker itself + * @param t the time to stay ON + */ +void BLINKER_setTimeOn(BLINKER*me, uint16_t t); + +/** + * define time to stay OFF + * @param me the blinker itself + * @param t the time to stay OFF + */ +void BLINKER_setTimeOff(BLINKER*me, uint16_t t); + +/** + * Start to blink n time + * @param me the blinker itself + */ +void BLINKER_blinkN(BLINKER* me); + +/** + * Start to blink indefinitely + * @param me the blinker itself + */ +void BLINKER_blink(BLINKER* me); + +/** + * State machine of the BUTTON + * @param ev event to process on the state machine + */ +bool BLINKER_processEvent(Event* ev); + +/** + * Stop to blink if it was indefinitely blinking + * @param me the blinker itself + */ +void BLINKER_endBlink(BLINKER* me); + + +#endif /* BLINKER_H */ + diff --git a/03-software/ch/kb28/blinkerProject/middleware/clickHandler.c b/03-software/ch/kb28/blinkerProject/middleware/clickHandler.c index 63542db..5c7632d 100644 --- a/03-software/ch/kb28/blinkerProject/middleware/clickHandler.c +++ b/03-software/ch/kb28/blinkerProject/middleware/clickHandler.c @@ -1,7 +1,7 @@ /** * @file clickHandler.c * @author Rémi Heredero (remi@heredero.ch) - * @version 0.1 + * @version 0 * @date 2023-06-13 */ diff --git a/03-software/ch/kb28/blinkerProject/middleware/clickHandler.h b/03-software/ch/kb28/blinkerProject/middleware/clickHandler.h index 4f219db..5d8598d 100644 --- a/03-software/ch/kb28/blinkerProject/middleware/clickHandler.h +++ b/03-software/ch/kb28/blinkerProject/middleware/clickHandler.h @@ -1,8 +1,8 @@ /** * @file clickHandler.h * @author Rémi Heredero (remi@heredero.ch) - * @version 0.1 - * @date 2023-06-13 + * @version 1 + * @date 2023-06-14 */ #ifndef CLICKHANDLER_H @@ -22,7 +22,7 @@ typedef enum { } CLICK_HANDLER_STATES; typedef enum { - evCHinit = 150, + evCHinit = 100, evCHtimer, evCHpbPress, evCHpbRelease @@ -35,19 +35,59 @@ typedef struct { } clickHandlerCallBack; typedef struct { - BUTTON* button; - CLICK_HANDLER_STATES state; - clickHandlerCallBack longClick; - clickHandlerCallBack singleClick; - clickHandlerCallBack doubleClick; + 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); diff --git a/03-software/nbproject/configurations.xml b/03-software/nbproject/configurations.xml index 571e132..196fb3a 100644 --- a/03-software/nbproject/configurations.xml +++ b/03-software/nbproject/configurations.xml @@ -8,7 +8,6 @@ ch/kb28/blinkerProject/app/factory/factory.h - ch/kb28/blinkerProject/app/ledblinker.h @@ -29,6 +28,7 @@ ch/kb28/blinkerProject/middleware/clickHandler.h + ch/kb28/blinkerProject/middleware/blinker.c ch/kb28/blinkerProject/xf/ireactive.h @@ -47,7 +47,6 @@ ch/kb28/blinkerProject/app/factory/factory.c - ch/kb28/blinkerProject/app/lebblinker.c ch/kb28/blinkerProject/app/main.c @@ -69,6 +68,7 @@ ch/kb28/blinkerProject/middleware/clickHandler.c + ch/kb28/blinkerProject/middleware/blinker.h ch/kb28/blinkerProject/xf/xf.c @@ -262,6 +262,7 @@ +