From 70f80452fcfa20a0e5c383ec2c1c1be9a2c71709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= <63239207+Klagarge@users.noreply.github.com> Date: Sun, 18 Jun 2023 11:34:59 +0200 Subject: [PATCH] add APP --- 02-UML/ST_APP.uxf | 217 +++++++++++++++--- 03-software/ch/kb28/blinkerProject/app/app.c | 216 +++++++++++++++++ 03-software/ch/kb28/blinkerProject/app/app.h | 40 ++++ .../kb28/blinkerProject/app/factory/factory.c | 17 +- .../kb28/blinkerProject/app/factory/factory.h | 4 + .../kb28/blinkerProject/middleware/blinker.c | 10 +- .../kb28/blinkerProject/middleware/blinker.h | 10 +- .../blinkerProject/middleware/clickHandler.c | 2 + 03-software/nbproject/configurations.xml | 8 +- 9 files changed, 472 insertions(+), 52 deletions(-) create mode 100644 03-software/ch/kb28/blinkerProject/app/app.c create mode 100644 03-software/ch/kb28/blinkerProject/app/app.h diff --git a/02-UML/ST_APP.uxf b/02-UML/ST_APP.uxf index 8fe0b31..62e727a 100644 --- a/02-UML/ST_APP.uxf +++ b/02-UML/ST_APP.uxf @@ -1,13 +1,13 @@ - 20 + 15 UMLSpecialState - 640 - 60 - 40 - 40 + 600 + 150 + 30 + 30 type=initial @@ -15,10 +15,10 @@ UMLState - 560 - 220 - 200 - 80 + 135 + 225 + 960 + 60 WAIT @@ -26,21 +26,66 @@ Relation - 640 - 80 - 60 - 180 + 600 + 165 + 45 + 90 lt=-> - 10.0;10.0;10.0;70.0 + 10.0;10.0;10.0;40.0 UMLState - 320 + 135 420 - 240 - 80 + 210 + 60 + + ST_BLINKER_L + + + + UMLState + + 915 + 420 + 180 + 360 + + ST_BLINKER_W + + + + UMLState + + 495 + 570 + 210 + 60 + + ST_BLINKER_R + + + + Relation + + 990 + 270 + 150 + 180 + + lt=<-> +evLongClick + 10.0;100.0;10.0;10.0 + + + UMLState + + 135 + 720 + 570 + 60 ST_BLINKER_LR @@ -48,34 +93,134 @@ Relation - 420 - 280 - 280 - 180 + 690 + 735 + 255 + 60 - lt=-> - 120.0;10.0;10.0;70.0 + lt=-> +m1=evLongClick + 10.0;10.0;150.0;10.0 Relation - 640 - 280 - 280 - 180 + 690 + 585 + 255 + 60 - lt=-> - 10.0;10.0;120.0;70.0 + lt=-> +m1=evLongClick + 10.0;10.0;150.0;10.0 - UMLState + Relation - 760 - 420 - 240 - 80 + 330 + 435 + 615 + 60 - ST_BLINKER_W - + lt=-> +m1=evLongClick + 10.0;10.0;390.0;10.0 + + + Relation + + 150 + 270 + 120 + 180 + + lt=-> +m1=evClickL + 10.0;10.0;10.0;100.0 + + + Relation + + 300 + 270 + 210 + 180 + + lt=-> +m1=evClickL / evEndL + + 10.0;100.0;10.0;10.0 + + + Relation + + 150 + 465 + 120 + 285 + + lt=-> +m1=evClickR + 10.0;10.0;10.0;170.0 + + + Relation + + 300 + 465 + 225 + 285 + + lt=-> +m1=evClickR / evEndR + 10.0;170.0;10.0;10.0 + + + Relation + + 510 + 270 + 120 + 330 + + lt=-> +m1=evClickR + 10.0;10.0;10.0;200.0 + + + Relation + + 660 + 270 + 225 + 330 + + lt=-> +m1=evClickR / evEndR + 10.0;200.0;10.0;10.0 + + + Relation + + 510 + 615 + 120 + 135 + + lt=-> +m1=evClickL + 10.0;10.0;10.0;70.0 + + + Relation + + 660 + 615 + 210 + 135 + + lt=-> +m1=evClickL / evEndL + 10.0;70.0;10.0;10.0 diff --git a/03-software/ch/kb28/blinkerProject/app/app.c b/03-software/ch/kb28/blinkerProject/app/app.c new file mode 100644 index 0000000..d8c8626 --- /dev/null +++ b/03-software/ch/kb28/blinkerProject/app/app.c @@ -0,0 +1,216 @@ +/** + * @author Rémi Heredero (remi@heredero.ch) + * @version 1.0.0 + * @date 2023-06-15 + */ + +#include "app.h" +#include "factory/factory.h" +#include "../middleware/blinker.h" +#include "../middleware/clickHandler.h" + +void clickL(APP* me){ + POST(me, &APP_processEvent, evAPclickL, 0, 0); +} +void clickLn(APP* me){ + POST(me, &APP_processEvent, evAPclickLn, 0, 0); +} +void clickR(APP* me){ + POST(me, &APP_processEvent, evAPclickR, 0, 0); +} +void clickRn(APP* me){ + POST(me, &APP_processEvent, evAPclickRn, 0, 0); +} +void endL(APP* me){ + POST(me, &APP_processEvent, evAPendL, 0, 0); +} +void endR(APP* me){ + POST(me, &APP_processEvent, evAPendR, 0, 0); +} +void longClick(APP* me){ + POST(me, &APP_processEvent, evAPlongClick, 0, 0); +} + + + +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_setDoubleClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&clickLn, me)); + CLICK_HANDLER_setDoubleClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&clickRn, me)); + + CLICK_HANDLER_setLongClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&longClick, me)); + CLICK_HANDLER_setLongClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&longClick, me)); + + BLINKER_setFinished(blL(), BLINKER_defineCallBack(&endL, me)); + BLINKER_setFinished(blR(), BLINKER_defineCallBack(&endR, me)); + +} + +void APP_startBehaviour(APP* me){ + POST(me, &APP_processEvent, evAPinit, 0, 0); +} + +bool APP_processEvent(Event* ev){ + bool processed = false; + APP* me = (APP*) Event_getTarget(ev); + APP_STATES oldState = me->state; + evIDT evid = Event_getId(ev); + + switch(me->state) { // In state + case STAP_INIT: + if(evid == evAPinit) { + me->state = STAP_WAIT; + } + break; + + case STAP_WAIT: + if(evid == evAPclickL) { + me->state = STAP_BLINKER_L; + BLINKER_blink(blL()); + } + if(evid == evAPclickLn) { + me->state = STAP_BLINKER_L; + BLINKER_blinkN(blL()); + } + if(evid == evAPclickR) { + me->state = STAP_BLINKER_R; + BLINKER_blink(blR()); + } + if(evid == evAPclickRn) { + me->state = STAP_BLINKER_R; + BLINKER_blinkN(blR()); + } + if(evid == evAPlongClick) { + me->state = STAP_BLINKER_W; + BLINKER_blink(blB()); + } + break; + + case STAP_BLINKER_L: + if(evid == evAPclickR){ + me->state = STAP_BLINKER_LR; + BLINKER_blink(blR()); + } + if(evid == evAPclickRn){ + me->state = STAP_BLINKER_LR; + BLINKER_blinkN(blR()); + } + if(evid == evAPclickL) { + me->state = STAP_WAIT; + BLINKER_endBlink(blL()); + } + if(evid == evAPendL) { + me->state = STAP_WAIT; + } + if(evid == evAPlongClick) { + me->state = STAP_BLINKER_W; + BLINKER_endBlink(blL()); + BLINKER_blink(blB()); + } + break; + + case STAP_BLINKER_R: + if(evid == evAPclickL){ + me->state = STAP_BLINKER_LR; + BLINKER_blink(blL()); + } + if(evid == evAPclickLn){ + me->state = STAP_BLINKER_LR; + BLINKER_blinkN(blL()); + } + if(evid == evAPclickR) { + me->state = STAP_WAIT; + BLINKER_endBlink(blR()); + } + if(evid == evAPendR) { + me->state = STAP_WAIT; + } + if(evid == evAPlongClick) { + me->state = STAP_BLINKER_W; + BLINKER_endBlink(blR()); + BLINKER_blink(blB()); + } + break; + + case STAP_BLINKER_LR: + if(evid == evAPclickR) { + me->state = STAP_BLINKER_L; + BLINKER_endBlink(blR()); + } + if(evid == evAPendR) { + me->state = STAP_BLINKER_L; + } + if(evid == evAPclickL) { + me->state = STAP_BLINKER_R; + BLINKER_endBlink(blL()); + } + if(evid == evAPendL) { + me->state = STAP_BLINKER_R; + } + if(evid == evAPlongClick) { + me->state = STAP_BLINKER_W; + BLINKER_endBlink(blL()); + BLINKER_endBlink(blR()); + BLINKER_blink(blB()); + } + break; + + case STAP_BLINKER_W: + if(evid == evAPlongClick){ + me->state = STAP_WAIT; + BLINKER_endBlink(blB()); + } + break; + + } + + if(oldState != me->state) { + switch(oldState) { // on exit + case STAP_INIT: + break; + + case STAP_WAIT: + break; + + case STAP_BLINKER_L: + break; + + case STAP_BLINKER_R: + break; + + case STAP_BLINKER_LR: + break; + + case STAP_BLINKER_W: + break; + } + + switch(me->state) { // on entry + case STAP_INIT: + break; + + case STAP_WAIT: + break; + + case STAP_BLINKER_L: + break; + + case STAP_BLINKER_R: + break; + + case STAP_BLINKER_LR: + break; + + case STAP_BLINKER_W: + break; + + } + processed = true; + } + return processed; +} diff --git a/03-software/ch/kb28/blinkerProject/app/app.h b/03-software/ch/kb28/blinkerProject/app/app.h new file mode 100644 index 0000000..90b8dec --- /dev/null +++ b/03-software/ch/kb28/blinkerProject/app/app.h @@ -0,0 +1,40 @@ +/** + * @author Rémi Heredero (remi@heredero.ch) + * @version 1.0.0 + * @date 2023-06-17 + */ +#ifndef APP_H +#define APP_H + +#include "../xf/xf.h" + +typedef enum { + STAP_INIT, + STAP_WAIT, + STAP_BLINKER_L, + STAP_BLINKER_R, + STAP_BLINKER_LR, + STAP_BLINKER_W +} APP_STATES; + +typedef enum { + evAPinit = 150, + evAPclickL, + evAPclickLn, + evAPclickR, + evAPclickRn, + evAPendL, + evAPendR, + evAPlongClick +} APP_EVENTS; + +typedef struct { + APP_STATES state; // Actual state +} APP; + +void APP_init(APP* me); +void APP_startBehaviour(APP* me); +bool APP_processEvent(Event* ev); + +#endif /* APP_H */ + diff --git a/03-software/ch/kb28/blinkerProject/app/factory/factory.c b/03-software/ch/kb28/blinkerProject/app/factory/factory.c index 2e9fefb..98071ca 100755 --- a/03-software/ch/kb28/blinkerProject/app/factory/factory.c +++ b/03-software/ch/kb28/blinkerProject/app/factory/factory.c @@ -72,6 +72,10 @@ BLINKER* blB() { return &theFactory.blB_; } +APP* app() { + return &theFactory.app_; +} + //initialize all objects void Factory_init() { LED_init(l1(), 1); @@ -113,6 +117,8 @@ void Factory_init() { BLINKER_init(blR()); BLINKER_init(blB()); + APP_init(app()); + } void warningBlink(void* on_){ @@ -130,7 +136,6 @@ void warningBlink(void* on_){ //connect objects if required void Factory_build() { - BLINKER_setTurnOn(blL(), BLINKER_defineCallBack(&LED_on, l1())); BLINKER_setTurnOff(blL(), BLINKER_defineCallBack(&LED_off, l1())); @@ -139,15 +144,6 @@ void Factory_build() { BLINKER_setTurnOn(blB(), BLINKER_defineCallBack(&warningBlink, true)); BLINKER_setTurnOff(blB(), BLINKER_defineCallBack(&warningBlink, false)); - CLICK_HANDLER_setSingleClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&BLINKER_toggle, blL())); - CLICK_HANDLER_setSingleClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&BLINKER_toggle, blR())); - - CLICK_HANDLER_setDoubleClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&BLINKER_blinkN, blL())); - CLICK_HANDLER_setDoubleClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&BLINKER_blinkN, blR())); - - CLICK_HANDLER_setLongClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&BLINKER_toggle, blB())); - CLICK_HANDLER_setLongClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&BLINKER_toggle, blB())); - } //start all state machines @@ -161,4 +157,5 @@ void Factory_start() { BLINKER_starBehaviour(blL()); BLINKER_starBehaviour(blR()); BLINKER_starBehaviour(blB()); + APP_startBehaviour(app()); } diff --git a/03-software/ch/kb28/blinkerProject/app/factory/factory.h b/03-software/ch/kb28/blinkerProject/app/factory/factory.h index 7040c0a..8b37d30 100755 --- a/03-software/ch/kb28/blinkerProject/app/factory/factory.h +++ b/03-software/ch/kb28/blinkerProject/app/factory/factory.h @@ -14,6 +14,7 @@ #include "../../board/button/button.h" #include "../../middleware/clickHandler.h" #include "../../middleware/blinker.h" +#include "../app.h" typedef struct { LED l1_; @@ -35,6 +36,7 @@ typedef struct { BLINKER blL_; BLINKER blR_; BLINKER blB_; + APP app_; } Factory; @@ -66,4 +68,6 @@ BLINKER* blL(); BLINKER* blR(); BLINKER* blB(); +APP* app(); + #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 e42c1ab..ed1d5ab 100644 --- a/03-software/ch/kb28/blinkerProject/middleware/blinker.c +++ b/03-software/ch/kb28/blinkerProject/middleware/blinker.c @@ -37,6 +37,10 @@ void BLINKER_setTurnOff(BLINKER* me, blinkerCallBack callBack) { me->turnOff = callBack; } +void BLINKER_setFinished(BLINKER* me, blinkerCallBack callBack){ + me->finished = callBack; +} + void BLINKER_defineNblink(BLINKER* me, uint8_t n){ me->nBlink = n; } @@ -101,6 +105,7 @@ bool BLINKER_processEvent(Event* ev) { if(evid == evBLtimer) { if(me->remainBlinks == 0) { me->state = STBL_WAIT; + if(me->finished.fCallBack != NULL) me->finished.fCallBack(me->finished.param); } else { me->state = STBL_ON; POST(me, &BLINKER_processEvent, evBLtimer, me->tON, 0); @@ -111,7 +116,7 @@ bool BLINKER_processEvent(Event* ev) { } if(oldState != me->state) { - switch(me->state) { + switch(me->state) { // on entry case STBL_INIT: break; @@ -126,7 +131,9 @@ bool BLINKER_processEvent(Event* ev) { if(me->turnOff.fCallBack != NULL) me->turnOff.fCallBack(me->turnOff.param); break; } + processed = true; } + return processed; } void BLINKER_endBlink(BLINKER* me) { @@ -145,5 +152,4 @@ void BLINKER_toggle(BLINKER* me){ 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 35b1f8f..3c82721 100644 --- a/03-software/ch/kb28/blinkerProject/middleware/blinker.h +++ b/03-software/ch/kb28/blinkerProject/middleware/blinker.h @@ -1,6 +1,6 @@ /** * @author Rémi Heredero (remi@heredero.ch) - * @version. 1.0.0 + * @version 1.0.0 * @date 2023-06-15 */ @@ -39,6 +39,7 @@ typedef struct { uint8_t remainBlinks; // Actual remain blink blinkerCallBack turnOn; // Callback for turnOn blinkerCallBack turnOff; // Calbback for turnOff + blinkerCallBack finished; // Callback for finish n blink }BLINKER; /** @@ -75,6 +76,13 @@ void BLINKER_setTurnOn(BLINKER* me, blinkerCallBack callBack); */ void BLINKER_setTurnOff(BLINKER* me, blinkerCallBack callBack); +/** + * Set callback event functions for when the blinker has blink n times + * @param me the blinker itseld + * @param callBack callBack function when the blinker has blink n times + */ +void BLINKER_setFinished(BLINKER* me, blinkerCallBack callBack); + /** * define number of time the Blinker have to blink * @param me the blinker itself diff --git a/03-software/ch/kb28/blinkerProject/middleware/clickHandler.c b/03-software/ch/kb28/blinkerProject/middleware/clickHandler.c index 4068de8..7379f8f 100644 --- a/03-software/ch/kb28/blinkerProject/middleware/clickHandler.c +++ b/03-software/ch/kb28/blinkerProject/middleware/clickHandler.c @@ -147,5 +147,7 @@ bool CLICK_HANDLER_processEvent(Event* ev) { case STCH_DOUBLE_CLICK: break; } + processed = true; } + return processed; } diff --git a/03-software/nbproject/configurations.xml b/03-software/nbproject/configurations.xml index 196fb3a..f58fb30 100644 --- a/03-software/nbproject/configurations.xml +++ b/03-software/nbproject/configurations.xml @@ -8,6 +8,7 @@ ch/kb28/blinkerProject/app/factory/factory.h + ch/kb28/blinkerProject/app/app.h @@ -28,7 +29,7 @@ ch/kb28/blinkerProject/middleware/clickHandler.h - ch/kb28/blinkerProject/middleware/blinker.c + ch/kb28/blinkerProject/middleware/blinker.h ch/kb28/blinkerProject/xf/ireactive.h @@ -48,6 +49,7 @@ ch/kb28/blinkerProject/app/factory/factory.c ch/kb28/blinkerProject/app/main.c + ch/kb28/blinkerProject/app/app.c @@ -68,7 +70,7 @@ ch/kb28/blinkerProject/middleware/clickHandler.c - ch/kb28/blinkerProject/middleware/blinker.h + ch/kb28/blinkerProject/middleware/blinker.c ch/kb28/blinkerProject/xf/xf.c @@ -95,7 +97,7 @@ PICkit3PlatformTool XC8 2.41 - 2 + 3