diff --git a/03-software/ch/kb28/blinkerProject/app/factory/factory.c b/03-software/ch/kb28/blinkerProject/app/factory/factory.c index 3133334..2e9fefb 100755 --- a/03-software/ch/kb28/blinkerProject/app/factory/factory.c +++ b/03-software/ch/kb28/blinkerProject/app/factory/factory.c @@ -62,8 +62,11 @@ CLICK_HANDLER* ch3() { return &theFactory.ch3_; } -BLINKER* blA() { - return &theFactory.blA_; +BLINKER* blL() { + return &theFactory.blL_; +} +BLINKER* blR() { + return &theFactory.blR_; } BLINKER* blB() { return &theFactory.blB_; @@ -106,31 +109,44 @@ void Factory_init() { CLICK_HANDLER_init(ch2(), b2()); CLICK_HANDLER_init(ch3(), b3()); - BLINKER_init(blA()); + BLINKER_init(blL()); + BLINKER_init(blR()); BLINKER_init(blB()); } +void warningBlink(void* on_){ + bool on = (bool)on_; + BLINKER_endBlink(blL()); + BLINKER_endBlink(blR()); + if(on) { + LED_on(l1()); + LED_on(l10()); + } else { + LED_off(l1()); + LED_off(l10()); + } +} + //connect objects if required void Factory_build() { - BLINKER_defineNblink(blA(), 3); - BLINKER_defineNblink(blB(), 5); + - BLINKER_setTimeOn(blA(), 20); - BLINKER_setTimeOff(blA(), 480); + BLINKER_setTurnOn(blL(), BLINKER_defineCallBack(&LED_on, l1())); + BLINKER_setTurnOff(blL(), BLINKER_defineCallBack(&LED_off, l1())); + BLINKER_setTurnOn(blR(), BLINKER_defineCallBack(&LED_on, l10())); + BLINKER_setTurnOff(blR(), BLINKER_defineCallBack(&LED_off, l10())); + BLINKER_setTurnOn(blB(), BLINKER_defineCallBack(&warningBlink, true)); + BLINKER_setTurnOff(blB(), BLINKER_defineCallBack(&warningBlink, false)); - 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_setSingleClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&BLINKER_toggle, blL())); + CLICK_HANDLER_setSingleClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&BLINKER_toggle, blR())); - 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_setDoubleClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&BLINKER_blinkN, blL())); + CLICK_HANDLER_setDoubleClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&BLINKER_blinkN, blR())); - 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(&BLINKER_toggle, blB())); + CLICK_HANDLER_setLongClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&BLINKER_toggle, blB())); } @@ -142,6 +158,7 @@ void Factory_start() { CLICK_HANDLER_startBehaviour(ch1()); CLICK_HANDLER_startBehaviour(ch2()); CLICK_HANDLER_startBehaviour(ch3()); - BLINKER_starBehaviour(blA()); + BLINKER_starBehaviour(blL()); + BLINKER_starBehaviour(blR()); 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 4db7530..7040c0a 100755 --- a/03-software/ch/kb28/blinkerProject/app/factory/factory.h +++ b/03-software/ch/kb28/blinkerProject/app/factory/factory.h @@ -32,7 +32,8 @@ typedef struct { CLICK_HANDLER ch1_; CLICK_HANDLER ch2_; CLICK_HANDLER ch3_; - BLINKER blA_; + BLINKER blL_; + BLINKER blR_; BLINKER blB_; } Factory; @@ -61,7 +62,8 @@ CLICK_HANDLER* ch1(); CLICK_HANDLER* ch2(); CLICK_HANDLER* ch3(); -BLINKER* blA(); +BLINKER* blL(); +BLINKER* blR(); BLINKER* blB(); #endif \ No newline at end of file diff --git a/03-software/ch/kb28/blinkerProject/middleware/blinker.c b/03-software/ch/kb28/blinkerProject/middleware/blinker.c index 4ae1419..e42c1ab 100644 --- a/03-software/ch/kb28/blinkerProject/middleware/blinker.c +++ b/03-software/ch/kb28/blinkerProject/middleware/blinker.c @@ -132,3 +132,18 @@ bool BLINKER_processEvent(Event* ev) { void BLINKER_endBlink(BLINKER* me) { me->remainBlinks = 0; } + +void BLINKER_toggle(BLINKER* me){ + switch(me->state) { + case STBL_WAIT: + BLINKER_blink(me); + break; + case STBL_OFF: + BLINKER_endBlink(me); + break; + case STBL_ON: + BLINKER_endBlink(me); + break; + } + me->toggleRemainBlinks = me->remainBlinks; +} diff --git a/03-software/ch/kb28/blinkerProject/middleware/blinker.h b/03-software/ch/kb28/blinkerProject/middleware/blinker.h index 4c12fbb..35b1f8f 100644 --- a/03-software/ch/kb28/blinkerProject/middleware/blinker.h +++ b/03-software/ch/kb28/blinkerProject/middleware/blinker.h @@ -120,6 +120,8 @@ bool BLINKER_processEvent(Event* ev); */ void BLINKER_endBlink(BLINKER* me); +void BLINKER_toggle(BLINKER* me); + #endif /* BLINKER_H */