diff --git a/03-software/ch/kb28/blinkerProject/app/factory/factory.c b/03-software/ch/kb28/blinkerProject/app/factory/factory.c index 76a2065..6980348 100755 --- a/03-software/ch/kb28/blinkerProject/app/factory/factory.c +++ b/03-software/ch/kb28/blinkerProject/app/factory/factory.c @@ -86,20 +86,30 @@ void Factory_init() { BUTTON_initHW(b3()); } -void lON(){ - LED_on(l9()); +//typedef void (*fButtonCallback)(void*); +buttonCallBack myFunction; + +void lON(void * l){ + LED* l_ = (LED*)l; + LED_on(l_); } -void lOFF() { - LED_off(l9()); + + +void lOFF(void* l) { + LED* l_ = (LED*)l; + LED_off(l_); } + //connect objects if required void Factory_build() { - BUTTON_setEventFunctions(b1(), &lON, &lOFF); + BUTTON_setEventFunctions(b1(), BUTTON_defineCallBack(&lON, l1()), BUTTON_defineCallBack(NULL, NULL)); + BUTTON_setEventFunctions(b3(), BUTTON_defineCallBack(&lOFF, l1()), BUTTON_defineCallBack(NULL, NULL)); } //start all state machines void Factory_start() { - LEDBlinker_startBehaviour(lb()); + //LEDBlinker_startBehaviour(lb()); BUTTON_startBehaviour(b1()); + BUTTON_startBehaviour(b3()); } diff --git a/03-software/ch/kb28/blinkerProject/board/button/button.c b/03-software/ch/kb28/blinkerProject/board/button/button.c index 0c08cde..d9a4d59 100644 --- a/03-software/ch/kb28/blinkerProject/board/button/button.c +++ b/03-software/ch/kb28/blinkerProject/board/button/button.c @@ -19,7 +19,8 @@ void BUTTON_init(BUTTON* me, uint8_t id) { me->id = id; me->state = ST_PBINIT; - + me->press.fCallBack = NULL; + me->release.fCallBack = NULL; } /** @@ -114,10 +115,10 @@ bool BUTTON_processEvent(Event * ev) { case ST_PBINIT: break; case ST_PBRELEASED: - if(me->fButtonRelease != NULL) me->fButtonRelease(); + if(me->release.fCallBack != NULL) me->release.fCallBack(me->release.param); break; case ST_PBPRESSED: - if(me->fButtonPress != NULL) me->fButtonPress(); + if(me->press.fCallBack != NULL) me->press.fCallBack(me->press.param); break; } processed = true; @@ -125,7 +126,14 @@ bool BUTTON_processEvent(Event * ev) { return processed; } -void BUTTON_setEventFunctions(BUTTON* me, void (*fPress)(void), void (*fRelease)(void)) { - me->fButtonPress = fPress; - me->fButtonRelease = fRelease; +void BUTTON_setEventFunctions(BUTTON* me, buttonCallBack fPress, buttonCallBack fRelease) { + me->press = fPress; + me->release = fRelease; +} + +buttonCallBack BUTTON_defineCallBack(fButtonCallback f, void* param){ + buttonCallBack c; + c.fCallBack = f; + c.param = param; + return c; } \ No newline at end of file diff --git a/03-software/ch/kb28/blinkerProject/board/button/button.h b/03-software/ch/kb28/blinkerProject/board/button/button.h index 0db6698..3061c36 100644 --- a/03-software/ch/kb28/blinkerProject/board/button/button.h +++ b/03-software/ch/kb28/blinkerProject/board/button/button.h @@ -17,18 +17,26 @@ typedef enum {ST_PBINIT, ST_PBRELEASED, ST_PBPRESSED} BUTTON_STATES; typedef enum {evPBInit=100, evPBPoll} BUTTON_EVENTS; +typedef void (*fButtonCallback)(void*); +typedef struct { + fButtonCallback fCallBack; + void* param; +} buttonCallBack; + typedef struct { uint8_t id; BUTTON_STATES state; - void (*fButtonPress)(void); - void (*fButtonRelease)(void); + buttonCallBack press; + buttonCallBack release; } BUTTON; + void BUTTON_init(BUTTON* me, uint8_t id); void BUTTON_initHW(BUTTON* me); bool BUTTON_isPressed(BUTTON* me); void BUTTON_startBehaviour(BUTTON* me); bool BUTTON_processEvent(Event* ev); -void BUTTON_setEventFunctions(BUTTON* me, void (*fPress)(void), void (*fRelease)(void)); +void BUTTON_setEventFunctions(BUTTON* me, buttonCallBack fPress, buttonCallBack release); +buttonCallBack BUTTON_defineCallBack(fButtonCallback f, void* param); #endif /* BUTTON_H */ \ No newline at end of file