add files from blinker project
This commit is contained in:
		
							
								
								
									
										193
									
								
								src/app/factory.c
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										193
									
								
								src/app/factory.c
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,60 +1,155 @@ | |||||||
| /*$file${.::app::factory.c} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ | /** | ||||||
| /* |  * @author R<>mi Heredero (remi@heredero.ch) | ||||||
| * Model: XFT.qm |  * @version. 0.0.6 | ||||||
| * File:  ${.::app::factory.c} |  * @date 2023-06-15 | ||||||
| * |  | ||||||
| * This code has been generated by QM 5.2.5 <www.state-machine.com/qm>. |  | ||||||
| * DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost. |  | ||||||
| * |  | ||||||
| * SPDX-License-Identifier: GPL-3.0-or-later |  | ||||||
| * |  | ||||||
| * This generated code is open source software: you can redistribute it under |  | ||||||
| * the terms of the GNU General Public License as published by the Free |  | ||||||
| * Software Foundation. |  | ||||||
| * |  | ||||||
| * This code is distributed in the hope that it will be useful, but WITHOUT |  | ||||||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |  | ||||||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |  | ||||||
| * more details. |  | ||||||
| * |  | ||||||
| * NOTE: |  | ||||||
| * Alternatively, this generated code may be distributed under the terms |  | ||||||
| * of Quantum Leaps commercial licenses, which expressly supersede the GNU |  | ||||||
| * General Public License and are specifically designed for licensees |  | ||||||
| * interested in retaining the proprietary status of their code. |  | ||||||
| * |  | ||||||
| * Contact information: |  | ||||||
| * <www.state-machine.com/licensing> |  | ||||||
| * <info@state-machine.com> |  | ||||||
| */ |  | ||||||
| /*$endhead${.::app::factory.c} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ |  | ||||||
| /* |  | ||||||
|  * @author Rémi Heredero |  | ||||||
|  * @date July 2023 |  | ||||||
|  * @version 1.0.0 |  | ||||||
|  * @see work of Medar Rieder & Pascal Sartoretti about femto XF |  | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| #include "factory.h" | #include "factory.h" | ||||||
| Factory Factory_theFactory; |  | ||||||
|  |  | ||||||
| /*${app::Factory::init} ....................................................*/ |  | ||||||
| void Factory_init(void) { | //the factory object containing all objects of our system | ||||||
|     LED_init(Factory_l1(), 1); | static Factory theFactory; | ||||||
|     LED_initHW(Factory_l1()); |  | ||||||
|  |  | ||||||
|  | //all the getters | ||||||
|  | LED* l1() { | ||||||
|  |     return &theFactory.l1_; | ||||||
|  | } | ||||||
|  | LED* l2()  { | ||||||
|  |     return &theFactory.l2_; | ||||||
|  | } | ||||||
|  | LED* l3()  { | ||||||
|  |     return &theFactory.l3_; | ||||||
|  | } | ||||||
|  | LED* l4()  { | ||||||
|  |     return &theFactory.l4_; | ||||||
|  | } | ||||||
|  | LED* l5()  { | ||||||
|  |     return &theFactory.l5_; | ||||||
|  | } | ||||||
|  | LED* l6()  { | ||||||
|  |     return &theFactory.l6_; | ||||||
|  | } | ||||||
|  | LED* l7()  { | ||||||
|  |     return &theFactory.l7_; | ||||||
|  | } | ||||||
|  | LED* l8()  { | ||||||
|  |     return &theFactory.l8_; | ||||||
|  | } | ||||||
|  | LED* l9()  { | ||||||
|  |     return &theFactory.l9_; | ||||||
|  | } | ||||||
|  | LED* l10()  { | ||||||
|  |     return &theFactory.l10_; | ||||||
| } | } | ||||||
|  |  | ||||||
| void Factory_build(){ | BUTTON* b1() { | ||||||
|  |     return &theFactory.b1_; | ||||||
|  | } | ||||||
|  | BUTTON* b2() { | ||||||
|  |     return &theFactory.b2_; | ||||||
|  | } | ||||||
|  | BUTTON* b3() { | ||||||
|  |     return &theFactory.b3_; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | CLICK_HANDLER* ch1() { | ||||||
|  |     return &theFactory.ch1_; | ||||||
|  | } | ||||||
|  | CLICK_HANDLER* ch2() { | ||||||
|  |     return &theFactory.ch2_; | ||||||
|  | } | ||||||
|  | CLICK_HANDLER* ch3() { | ||||||
|  |     return &theFactory.ch3_; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | BLINKER* blL() { | ||||||
|  |     return &theFactory.blL_; | ||||||
|  | } | ||||||
|  | BLINKER* blR() { | ||||||
|  |     return &theFactory.blR_; | ||||||
|  | } | ||||||
|  | BLINKER* blB() { | ||||||
|  |     return &theFactory.blB_; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //initialize all objects | ||||||
|  | void Factory_init() { | ||||||
|  |     LED_init(l1(), 1); | ||||||
|  |     LED_init(l2(), 2); | ||||||
|  |     LED_init(l3(), 3); | ||||||
|  |     LED_init(l4(), 4); | ||||||
|  |     LED_init(l5(), 5); | ||||||
|  |     LED_init(l6(), 6); | ||||||
|  |     LED_init(l7(), 7); | ||||||
|  |     LED_init(l8(), 8); | ||||||
|  |     LED_init(l9(), 9); | ||||||
|  |     LED_init(l10(), 10); | ||||||
|  |      | ||||||
|  |     LED_initHW(l1()); | ||||||
|  |     LED_initHW(l2()); | ||||||
|  |     LED_initHW(l3()); | ||||||
|  |     LED_initHW(l4()); | ||||||
|  |     LED_initHW(l5()); | ||||||
|  |     LED_initHW(l6()); | ||||||
|  |     LED_initHW(l7()); | ||||||
|  |     LED_initHW(l8()); | ||||||
|  |     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(blL()); | ||||||
|  |     BLINKER_init(blR()); | ||||||
|  |     BLINKER_init(blB()); | ||||||
|  |  | ||||||
|      |      | ||||||
| } | } | ||||||
|  |  | ||||||
| /*${app::Factory::start} ...................................................*/ | void warningBlink(void* on_){ | ||||||
| void Factory_start(void) { |     bool on = (bool)on_; | ||||||
|     LED_on(Factory_l1()); |     BLINKER_endBlink(blL()); | ||||||
|  |     BLINKER_endBlink(blR()); | ||||||
|  |     if(on) { | ||||||
|  |         LED_on(l1()); | ||||||
|  |         LED_on(l10()); | ||||||
|  |     } else { | ||||||
|  |         LED_off(l1()); | ||||||
|  |         LED_off(l10()); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| /*${app::Factory::l1} ......................................................*/ | //connect objects if required | ||||||
| LED* Factory_l1(void) { | void Factory_build() { | ||||||
|     return &Factory_theFactory.l1_; |      | ||||||
|  |     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)); | ||||||
|  |      | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //start all state machines | ||||||
|  | void Factory_start() { | ||||||
|  |     BUTTON_startBehaviour(b1()); | ||||||
|  |     BUTTON_startBehaviour(b2()); | ||||||
|  |     BUTTON_startBehaviour(b3()); | ||||||
|  |     CLICK_HANDLER_startBehaviour(ch1()); | ||||||
|  |     CLICK_HANDLER_startBehaviour(ch2()); | ||||||
|  |     CLICK_HANDLER_startBehaviour(ch3()); | ||||||
|  |     BLINKER_starBehaviour(blL()); | ||||||
|  |     BLINKER_starBehaviour(blR()); | ||||||
|  |     BLINKER_starBehaviour(blB()); | ||||||
| } | } | ||||||
| /*$enddef${app::Factory} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ |  | ||||||
|   | |||||||
							
								
								
									
										102
									
								
								src/app/factory.h
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										102
									
								
								src/app/factory.h
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,38 +1,7 @@ | |||||||
| /*$file${.::app::factory.h} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ | /** | ||||||
| /* |  * @author R<>mi Heredero (remi@heredero.ch) | ||||||
| * Model: XFT.qm |  * @version. 0.0.6 | ||||||
| * File:  ${.::app::factory.h} |  * @date 2023-06-15 | ||||||
| * |  | ||||||
| * This code has been generated by QM 5.2.5 <www.state-machine.com/qm>. |  | ||||||
| * DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost. |  | ||||||
| * |  | ||||||
| * SPDX-License-Identifier: GPL-3.0-or-later |  | ||||||
| * |  | ||||||
| * This generated code is open source software: you can redistribute it under |  | ||||||
| * the terms of the GNU General Public License as published by the Free |  | ||||||
| * Software Foundation. |  | ||||||
| * |  | ||||||
| * This code is distributed in the hope that it will be useful, but WITHOUT |  | ||||||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |  | ||||||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |  | ||||||
| * more details. |  | ||||||
| * |  | ||||||
| * NOTE: |  | ||||||
| * Alternatively, this generated code may be distributed under the terms |  | ||||||
| * of Quantum Leaps commercial licenses, which expressly supersede the GNU |  | ||||||
| * General Public License and are specifically designed for licensees |  | ||||||
| * interested in retaining the proprietary status of their code. |  | ||||||
| * |  | ||||||
| * Contact information: |  | ||||||
| * <www.state-machine.com/licensing> |  | ||||||
| * <info@state-machine.com> |  | ||||||
| */ |  | ||||||
| /*$endhead${.::app::factory.h} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ |  | ||||||
| /* |  | ||||||
|  * @author Rémi Heredero |  | ||||||
|  * @date July 2023 |  | ||||||
|  * @version 1.0.0 |  | ||||||
|  * @see work of Medar Rieder & Pascal Sartoretti about femto XF |  | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| #ifndef FACTORY_H | #ifndef FACTORY_H | ||||||
| @@ -42,21 +11,60 @@ | |||||||
| #include <stdbool.h> | #include <stdbool.h> | ||||||
|  |  | ||||||
| #include "../board/led.h" | #include "../board/led.h" | ||||||
|  | #include "../board/button.h" | ||||||
|  | #include "../middleware/clickHandler.h" | ||||||
|  | #include "../middleware/blinker.h" | ||||||
|  |  | ||||||
| /*$declare${app::Factory} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ | typedef struct { | ||||||
|  |  | ||||||
| /*${app::Factory} ..........................................................*/ |  | ||||||
| typedef struct Factory { |  | ||||||
| /* public: */ |  | ||||||
|     LED l1_; |     LED l1_; | ||||||
|  |     LED l2_; | ||||||
|  |     LED l3_; | ||||||
|  |     LED l4_; | ||||||
|  |     LED l5_; | ||||||
|  |     LED l6_; | ||||||
|  |     LED l7_; | ||||||
|  |     LED l8_; | ||||||
|  |     LED l9_; | ||||||
|  |     LED l10_; | ||||||
|  |     BUTTON b1_; | ||||||
|  |     BUTTON b2_; | ||||||
|  |     BUTTON b3_; | ||||||
|  |     CLICK_HANDLER ch1_; | ||||||
|  |     CLICK_HANDLER ch2_; | ||||||
|  |     CLICK_HANDLER ch3_; | ||||||
|  |     BLINKER blL_; | ||||||
|  |     BLINKER blR_; | ||||||
|  |     BLINKER blB_; | ||||||
| } Factory; | } Factory; | ||||||
|  |  | ||||||
| /* public: */ |  | ||||||
| void Factory_init(void); | void Factory_init(); | ||||||
| void Factory_build(void); | void Factory_build(); | ||||||
| void Factory_start(void); | void Factory_start(); | ||||||
| LED* Factory_l1(void); |  | ||||||
| extern Factory Factory_theFactory; | //these are global getters for our objects | ||||||
| /*$enddecl${app::Factory} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ | LED* l1(); | ||||||
|  | LED* l2(); | ||||||
|  | LED* l3(); | ||||||
|  | LED* l4(); | ||||||
|  | LED* l5(); | ||||||
|  | LED* l6(); | ||||||
|  | LED* l7(); | ||||||
|  | LED* l8(); | ||||||
|  | LED* l9(); | ||||||
|  | LED* l10(); | ||||||
|  |  | ||||||
|  | BUTTON* b1(); | ||||||
|  | BUTTON* b2(); | ||||||
|  | BUTTON* b3(); | ||||||
|  |  | ||||||
|  | CLICK_HANDLER* ch1(); | ||||||
|  | CLICK_HANDLER* ch2(); | ||||||
|  | CLICK_HANDLER* ch3(); | ||||||
|  |  | ||||||
|  | BLINKER* blL(); | ||||||
|  | BLINKER* blR(); | ||||||
|  | BLINKER* blB(); | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
| @@ -1,37 +1,12 @@ | |||||||
|  |  | ||||||
| /* |  | ||||||
| * Model: XFT.qm |  | ||||||
| * File:  ${.::app::main.c} |  | ||||||
| * |  | ||||||
| * This code has been generated by QM 5.2.5 <www.state-machine.com/qm>. |  | ||||||
| * DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost. |  | ||||||
| * |  | ||||||
| * SPDX-License-Identifier: GPL-3.0-or-later |  | ||||||
| * |  | ||||||
| * This generated code is open source software: you can redistribute it under |  | ||||||
| * the terms of the GNU General Public License as published by the Free |  | ||||||
| * Software Foundation. |  | ||||||
| * |  | ||||||
| * This code is distributed in the hope that it will be useful, but WITHOUT |  | ||||||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |  | ||||||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |  | ||||||
| * more details. |  | ||||||
| * |  | ||||||
| * NOTE: |  | ||||||
| * Alternatively, this generated code may be distributed under the terms |  | ||||||
| * of Quantum Leaps commercial licenses, which expressly supersede the GNU |  | ||||||
| * General Public License and are specifically designed for licensees |  | ||||||
| * interested in retaining the proprietary status of their code. |  | ||||||
| * |  | ||||||
| * Contact information: |  | ||||||
| * <www.state-machine.com/licensing> |  | ||||||
| * <info@state-machine.com> |  | ||||||
| */ |  | ||||||
| #include "../mcc_generated_files/mcc.h" | #include "../mcc_generated_files/mcc.h" | ||||||
| #include "../app/factory.h" | #include "../app/factory/factory.h" | ||||||
| #include "../xf/xf.h" | #include "../xf/xf.h" | ||||||
|  |  | ||||||
| void main(void) { |  | ||||||
|  |  | ||||||
|  | void main(void) | ||||||
|  | { | ||||||
|     // Initialize the device |     // Initialize the device | ||||||
|     SYSTEM_Initialize(); |     SYSTEM_Initialize(); | ||||||
|      |      | ||||||
|   | |||||||
| @@ -1,62 +1,137 @@ | |||||||
| /*$file${.::board::button.c} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ | /** | ||||||
| /* |  * @author R<>mi Heredero (remi@heredero.ch) | ||||||
| * Model: XFT.qm |  * @version. 1.0.0 | ||||||
| * File:  ${.::board::button.c} |  * @date 2023-06-15 | ||||||
| * |  */ | ||||||
| * This code has been generated by QM 5.2.5 <www.state-machine.com/qm>. |  | ||||||
| * DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost. |  | ||||||
| * |  | ||||||
| * SPDX-License-Identifier: GPL-3.0-or-later |  | ||||||
| * |  | ||||||
| * This generated code is open source software: you can redistribute it under |  | ||||||
| * the terms of the GNU General Public License as published by the Free |  | ||||||
| * Software Foundation. |  | ||||||
| * |  | ||||||
| * This code is distributed in the hope that it will be useful, but WITHOUT |  | ||||||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |  | ||||||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |  | ||||||
| * more details. |  | ||||||
| * |  | ||||||
| * NOTE: |  | ||||||
| * Alternatively, this generated code may be distributed under the terms |  | ||||||
| * of Quantum Leaps commercial licenses, which expressly supersede the GNU |  | ||||||
| * General Public License and are specifically designed for licensees |  | ||||||
| * interested in retaining the proprietary status of their code. |  | ||||||
| * |  | ||||||
| * Contact information: |  | ||||||
| * <www.state-machine.com/licensing> |  | ||||||
| * <info@state-machine.com> |  | ||||||
| */ |  | ||||||
| /*$endhead${.::board::button.c} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ |  | ||||||
| #include "button.h" | #include "button.h" | ||||||
| #include "../mcc_generated_files/pin_manager.h" | #include "../mcc_generated_files/pin_manager.h" | ||||||
|  | #include "../app/factory.h" | ||||||
|  |  | ||||||
| /*$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ | /** | ||||||
| /* Check for the minimum required QP version */ |  * @brief Initialize the button | ||||||
| #if (QP_VERSION < 700U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U)) |  *  | ||||||
| #error qpc version 7.0.0 or higher required |  * @param me The object to initialize | ||||||
| #endif |  * @param id The id of the button | ||||||
| /*$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ |  */ | ||||||
|  | void BUTTON_init(BUTTON* me, uint8_t id) { | ||||||
| /*$define${board::Button} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ |     me->id = id; | ||||||
|  |     me->state = ST_PBINIT; | ||||||
| /*${board::Button} .........................................................*/ |     me->press.fCallBack = NULL; | ||||||
|  |     me->release.fCallBack = NULL; | ||||||
| /*${board::Button::SM} .....................................................*/ |  | ||||||
| QState Button_initial(Button * const me, void const * const par) { |  | ||||||
|     /*${board::Button::SM::initial} */ |  | ||||||
|     return Q_TRAN(&Button_INIT); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /*${board::Button::SM::INIT} ...............................................*/ | /** | ||||||
| QState Button_INIT(Button * const me, QEvt const * const e) { |  * @brief Initialize the hardware of the button | ||||||
|     QState status_; |  *  | ||||||
|     switch (e->sig) { |  * @param me The object to initialize | ||||||
|         default: { |  */ | ||||||
|             status_ = Q_SUPER(&QHsm_top); | void BUTTON_initHW(BUTTON* me) { | ||||||
|  |     switch (me->id) { | ||||||
|  |         case 1: | ||||||
|  |             INPUT1_SetDigitalInput(); | ||||||
|  |             break; | ||||||
|  |         case 2: | ||||||
|  |             INPUT2_SetDigitalInput(); | ||||||
|  |             break; | ||||||
|  |         case 3: | ||||||
|  |             INPUT3_SetDigitalInput(); | ||||||
|  |             break; | ||||||
|  |         default: | ||||||
|             break; |             break; | ||||||
|     } |     } | ||||||
|     } |  | ||||||
|     return status_; |  | ||||||
| } | } | ||||||
| /*$enddef${board::Button} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ |  | ||||||
|  | /** | ||||||
|  |  * @brief Check if the button is pressed | ||||||
|  |  * The function returns true if the button is pressed, false otherwise | ||||||
|  |  *  | ||||||
|  |  * @param me The object to check | ||||||
|  |  * @return true if the button is pressed | ||||||
|  |  * @return false if the button is not pressed | ||||||
|  |  */ | ||||||
|  | bool BUTTON_isPressed(BUTTON* me) { | ||||||
|  |     switch (me->id) { | ||||||
|  |         case 1: | ||||||
|  |             return INPUT1_GetValue(); | ||||||
|  |             break; | ||||||
|  |         case 2: | ||||||
|  |             return INPUT2_GetValue(); | ||||||
|  |             break; | ||||||
|  |         case 3: | ||||||
|  |             return INPUT3_GetValue(); | ||||||
|  |             break; | ||||||
|  |         default: | ||||||
|  |             return false; | ||||||
|  |             break; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void BUTTON_startBehaviour(BUTTON* me) { | ||||||
|  |     POST(me, &BUTTON_processEvent, evPBInit, 0, 0); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | bool BUTTON_processEvent(Event * ev) { | ||||||
|  |     bool processed = false; | ||||||
|  |     BUTTON* me = (BUTTON*)Event_getTarget(ev); | ||||||
|  |     BUTTON_STATES oldState = me->state; | ||||||
|  |     evIDT evid = Event_getId(ev); | ||||||
|  |      | ||||||
|  |     switch(me->state){ | ||||||
|  |         case ST_PBINIT: | ||||||
|  |             if (evid == evPBInit) { | ||||||
|  |                 POST(me, &BUTTON_processEvent, evPBPoll, 0, 0); | ||||||
|  |                 if(BUTTON_isPressed(me)) { | ||||||
|  |                     me->state = ST_PBPRESSED; | ||||||
|  |                 } else { | ||||||
|  |                     me->state = ST_PBRELEASED; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             break; | ||||||
|  |         case ST_PBRELEASED: | ||||||
|  |             if(evid == evPBPoll) { | ||||||
|  |                 POST(me, &BUTTON_processEvent, evPBPoll, PB_POLL_TIME, 0); | ||||||
|  |                 if(BUTTON_isPressed(me)) { | ||||||
|  |                     me->state = ST_PBPRESSED; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |              | ||||||
|  |             break; | ||||||
|  |         case ST_PBPRESSED: | ||||||
|  |             if(evid == evPBPoll) { | ||||||
|  |                 POST(me, &BUTTON_processEvent, evPBPoll, PB_POLL_TIME, 0);                 | ||||||
|  |                 if(!BUTTON_isPressed(me)){ | ||||||
|  |                     me->state = ST_PBRELEASED; | ||||||
|  |                 } | ||||||
|  |                      | ||||||
|  |             } | ||||||
|  |             break; | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     if(oldState != me->state) { | ||||||
|  |         switch(me->state){ | ||||||
|  |             case ST_PBINIT: | ||||||
|  |                 break; | ||||||
|  |             case ST_PBRELEASED: | ||||||
|  |                 if(me->release.fCallBack != NULL) me->release.fCallBack(me->release.param); | ||||||
|  |                 break; | ||||||
|  |             case ST_PBPRESSED: | ||||||
|  |                 if(me->press.fCallBack != NULL) me->press.fCallBack(me->press.param); | ||||||
|  |                 break; | ||||||
|  |         } | ||||||
|  |         processed = true; | ||||||
|  |     } | ||||||
|  |     return processed; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | 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; | ||||||
|  | } | ||||||
| @@ -1,53 +1,97 @@ | |||||||
| /*$file${.::board::button.h} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ | /** | ||||||
| /* |  * @author R<>mi Heredero (remi@heredero.ch) | ||||||
| * Model: XFT.qm |  * @version. 1.0.0 | ||||||
| * File:  ${.::board::button.h} |  * @date 2023-06-15 | ||||||
| * |  */ | ||||||
| * This code has been generated by QM 5.2.5 <www.state-machine.com/qm>. |  | ||||||
| * DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost. |  | ||||||
| * |  | ||||||
| * SPDX-License-Identifier: GPL-3.0-or-later |  | ||||||
| * |  | ||||||
| * This generated code is open source software: you can redistribute it under |  | ||||||
| * the terms of the GNU General Public License as published by the Free |  | ||||||
| * Software Foundation. |  | ||||||
| * |  | ||||||
| * This code is distributed in the hope that it will be useful, but WITHOUT |  | ||||||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |  | ||||||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |  | ||||||
| * more details. |  | ||||||
| * |  | ||||||
| * NOTE: |  | ||||||
| * Alternatively, this generated code may be distributed under the terms |  | ||||||
| * of Quantum Leaps commercial licenses, which expressly supersede the GNU |  | ||||||
| * General Public License and are specifically designed for licensees |  | ||||||
| * interested in retaining the proprietary status of their code. |  | ||||||
| * |  | ||||||
| * Contact information: |  | ||||||
| * <www.state-machine.com/licensing> |  | ||||||
| * <info@state-machine.com> |  | ||||||
| */ |  | ||||||
| /*$endhead${.::board::button.h} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ |  | ||||||
| #ifndef BUTTON_H | #ifndef BUTTON_H | ||||||
| #define BUTTON_H | #define BUTTON_H | ||||||
|  |  | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
|  | #include <stdbool.h> | ||||||
|  | #include "../xf/xf.h" | ||||||
|  |  | ||||||
| /*$declare${board::Button} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ | #define PB_POLL_TIME 20 // Poll time for BUTTON | ||||||
|  |  | ||||||
| /*${board::Button} .........................................................*/ | typedef enum { | ||||||
|  |     ST_PBINIT, | ||||||
|  |     ST_PBRELEASED, | ||||||
|  |     ST_PBPRESSED | ||||||
|  | }  BUTTON_STATES; | ||||||
|  |  | ||||||
|  | typedef enum { | ||||||
|  |     evPBInit=50, | ||||||
|  |     evPBPoll | ||||||
|  | } BUTTON_EVENTS; | ||||||
|  |  | ||||||
|  | // Calback function | ||||||
|  | typedef void (*fButtonCallback)(void*);  | ||||||
| typedef struct { | typedef struct { | ||||||
| /* protected: */ |     fButtonCallback fCallBack; | ||||||
|     QActive super; |     void* param; | ||||||
|  | } buttonCallBack; | ||||||
|  |  | ||||||
| /* public: */ | typedef struct { | ||||||
|     uint8_t id; |     uint8_t id; // Id of the button | ||||||
|     BUTTON_STATES state; |     BUTTON_STATES state; // Actual state  | ||||||
| } Button; |     buttonCallBack press; // Callback for the rising edge of the button | ||||||
|  |     buttonCallBack release;  // Callback for the falling edge of the button | ||||||
|  | } BUTTON; | ||||||
|  |  | ||||||
| /* protected: */ | /** | ||||||
| QState Button_initial(Button * const me, void const * const par); |  * @brief Initialize the button | ||||||
| QState Button_INIT(Button * const me, QEvt const * const e); |  *  | ||||||
| /*$enddecl${board::Button} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ |  * @param me button itself | ||||||
|  |  * @param id The id of the button | ||||||
|  |  */ | ||||||
|  | void BUTTON_init(BUTTON* me, uint8_t id); | ||||||
|  |  | ||||||
| #endif | /** | ||||||
|  |  * @brief Initialize the hardware of the button | ||||||
|  |  *  | ||||||
|  |  * @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 button itself | ||||||
|  |  * @return true if the button is pressed | ||||||
|  |  * @return false if the button is not pressed | ||||||
|  |  */ | ||||||
|  | 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 */ | ||||||
| @@ -1,44 +1,25 @@ | |||||||
|  | /** | ||||||
|  |  * @author R<>mi Heredero (remi@heredero.ch) | ||||||
|  |  * @version. 1.0.0 | ||||||
|  |  * @date 2023-06-15 | ||||||
|  |  */ | ||||||
|  |  | ||||||
| /* |  | ||||||
| * Model: XFT.qm |  | ||||||
| * File:  ${.::board::led.c} |  | ||||||
| * |  | ||||||
| * This code has been generated by QM 5.2.5 <www.state-machine.com/qm>. |  | ||||||
| * DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost. |  | ||||||
| * |  | ||||||
| * SPDX-License-Identifier: GPL-3.0-or-later |  | ||||||
| * |  | ||||||
| * This generated code is open source software: you can redistribute it under |  | ||||||
| * the terms of the GNU General Public License as published by the Free |  | ||||||
| * Software Foundation. |  | ||||||
| * |  | ||||||
| * This code is distributed in the hope that it will be useful, but WITHOUT |  | ||||||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |  | ||||||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |  | ||||||
| * more details. |  | ||||||
| * |  | ||||||
| * NOTE: |  | ||||||
| * Alternatively, this generated code may be distributed under the terms |  | ||||||
| * of Quantum Leaps commercial licenses, which expressly supersede the GNU |  | ||||||
| * General Public License and are specifically designed for licensees |  | ||||||
| * interested in retaining the proprietary status of their code. |  | ||||||
| * |  | ||||||
| * Contact information: |  | ||||||
| * <www.state-machine.com/licensing> |  | ||||||
| * <info@state-machine.com> |  | ||||||
| */ |  | ||||||
| #include "led.h" | #include "led.h" | ||||||
| #include "../mcc_generated_files/pin_manager.h" | #include "../mcc_generated_files/pin_manager.h" | ||||||
|  |  | ||||||
| void LED_init(LED * const me, | void LED_init(LED* me, uint8_t id) { | ||||||
|     uint8_t id) |  | ||||||
| { |  | ||||||
|     me->id = id; |     me->id = id; | ||||||
| } | } | ||||||
| void LED_initHW(LED * const me) { |  | ||||||
|  | /** | ||||||
|  |  * @brief Initialize the Driver | ||||||
|  |  *  | ||||||
|  |  */ | ||||||
|  | void LED_initHW(LED* me) { | ||||||
|     LED_off(me); |     LED_off(me); | ||||||
| } | } | ||||||
| void LED_on(LED * const me) { |  | ||||||
|  | void LED_on(void* me) { | ||||||
|     LED* l = (LED*) me; |     LED* l = (LED*) me; | ||||||
|     switch (l->id) { |     switch (l->id) { | ||||||
|         case 1: |         case 1: | ||||||
| @@ -72,8 +53,10 @@ void LED_on(LED * const me) { | |||||||
|             OUTPUT10_SetHigh(); |             OUTPUT10_SetHigh(); | ||||||
|         break;     |         break;     | ||||||
|     } |     } | ||||||
|  |        | ||||||
| } | } | ||||||
| void LED_off(LED * const me) { |  | ||||||
|  | void LED_off(void* me) { | ||||||
|     LED* l = (LED*) me; |     LED* l = (LED*) me; | ||||||
|     switch (l->id) { |     switch (l->id) { | ||||||
|         case 1: |         case 1: | ||||||
| @@ -108,3 +91,4 @@ void LED_off(LED * const me) { | |||||||
|         break;     |         break;     | ||||||
|     }             |     }             | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,73 +1,43 @@ | |||||||
|  | /** | ||||||
|  |  * @author R<>mi Heredero (remi@heredero.ch) | ||||||
|  |  * @version. 1.0.0 | ||||||
|  |  * @date 2023-06-15 | ||||||
|  |  */ | ||||||
|  |  | ||||||
| /* |  | ||||||
| * Model: XFT.qm |  | ||||||
| * File:  ${.::board::led.h} |  | ||||||
| * |  | ||||||
| * This code has been generated by QM 5.2.5 <www.state-machine.com/qm>. |  | ||||||
| * DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost. |  | ||||||
| * |  | ||||||
| * SPDX-License-Identifier: GPL-3.0-or-later |  | ||||||
| * |  | ||||||
| * This generated code is open source software: you can redistribute it under |  | ||||||
| * the terms of the GNU General Public License as published by the Free |  | ||||||
| * Software Foundation. |  | ||||||
| * |  | ||||||
| * This code is distributed in the hope that it will be useful, but WITHOUT |  | ||||||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |  | ||||||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |  | ||||||
| * more details. |  | ||||||
| * |  | ||||||
| * NOTE: |  | ||||||
| * Alternatively, this generated code may be distributed under the terms |  | ||||||
| * of Quantum Leaps commercial licenses, which expressly supersede the GNU |  | ||||||
| * General Public License and are specifically designed for licensees |  | ||||||
| * interested in retaining the proprietary status of their code. |  | ||||||
| * |  | ||||||
| * Contact information: |  | ||||||
| * <www.state-machine.com/licensing> |  | ||||||
| * <info@state-machine.com> |  | ||||||
| */ |  | ||||||
| #ifndef LED_H | #ifndef LED_H | ||||||
| #define LED_H | #define LED_H | ||||||
|  |  | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
| /* |  | ||||||
|  * @author Rémi Heredero |  | ||||||
|  * @date July 2023 |  | ||||||
|  * @version 1.0.0 |  | ||||||
|  * @see work of Medar Rieder & Pascal Sartoretti about femto XF |  | ||||||
|  */ |  | ||||||
| typedef struct { |  | ||||||
| /* public: */ |  | ||||||
|     uint8_t id; |  | ||||||
| } LED; |  | ||||||
|  |  | ||||||
| /* public: */ | // LED struct | ||||||
|  | typedef struct { | ||||||
|  |     uint8_t id; // The id of the LED | ||||||
|  | }LED; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Initialize the led |  * Initialize the led | ||||||
|  * @param me the led itself |  * @param me the led itself | ||||||
|  * @param id the id of the led |  * @param id the id of the led | ||||||
|  */ |  */ | ||||||
| void LED_init(LED * const me, | void LED_init(LED* me, uint8_t id); | ||||||
|     uint8_t id); |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Initializing the led |  * Initializing the led | ||||||
|  * @param me the led itself |  * @param me the led itself | ||||||
|  */ |  */ | ||||||
| void LED_initHW(LED * const me); | void LED_initHW(LED* me); | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Turn On the led  |  * Turn On the led  | ||||||
|  * @param me the led itself |  * @param me the led itself | ||||||
|  */ |  */ | ||||||
| void LED_on(LED * const me); | void LED_on(void* me); | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Turn Off the led  |  * Turn Off the led  | ||||||
|  * @param me the led itself |  * @param me the led itself | ||||||
|  */ |  */ | ||||||
| void LED_off(LED * const me); | void LED_off(void* me); | ||||||
|  |  | ||||||
|  | #endif	/* LED_H */ | ||||||
|  |  | ||||||
| #endif |  | ||||||
|   | |||||||
							
								
								
									
										155
									
								
								src/middleware/blinker.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										155
									
								
								src/middleware/blinker.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,155 @@ | |||||||
|  | /** | ||||||
|  |  * @author R<>mi Heredero (remi@heredero.ch) | ||||||
|  |  * @version. 1.0.0 | ||||||
|  |  * @date 2023-06-15 | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | #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_setFinished(BLINKER* me, blinkerCallBack callBack){ | ||||||
|  |     me->finished = 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; | ||||||
|  |                     if(me->finished.fCallBack != NULL) me->finished.fCallBack(me->finished.param); | ||||||
|  |                 } else { | ||||||
|  |                     me->state = STBL_ON; | ||||||
|  |                     POST(me, &BLINKER_processEvent, evBLtimer, me->tON, 0); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |              | ||||||
|  |             break; | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     if(oldState != me->state) { | ||||||
|  |         switch(me->state) { // on entry | ||||||
|  |             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; | ||||||
|  |         } | ||||||
|  |         processed = true; | ||||||
|  |     } | ||||||
|  |     return processed; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | 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; | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										135
									
								
								src/middleware/blinker.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										135
									
								
								src/middleware/blinker.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,135 @@ | |||||||
|  | /** | ||||||
|  |  * @author R<>mi Heredero (remi@heredero.ch) | ||||||
|  |  * @version 1.0.0 | ||||||
|  |  * @date 2023-06-15 | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | #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; // Actual 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 | ||||||
|  |     blinkerCallBack finished; // Callback for finish n blink | ||||||
|  | }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); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * 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 | ||||||
|  |  * @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); | ||||||
|  |  | ||||||
|  | void BLINKER_toggle(BLINKER* me); | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #endif	/* BLINKER_H */ | ||||||
|  |  | ||||||
							
								
								
									
										153
									
								
								src/middleware/clickHandler.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										153
									
								
								src/middleware/clickHandler.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,153 @@ | |||||||
|  | /** | ||||||
|  |  * @author R<>mi Heredero (remi@heredero.ch) | ||||||
|  |  * @version. 1.0.0 | ||||||
|  |  * @date 2023-06-15 | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | #include "clickHandler.h" | ||||||
|  |  | ||||||
|  | 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; | ||||||
|  |      | ||||||
|  |     buttonCallBack pbPressCallBack; | ||||||
|  |     pbPressCallBack.fCallBack = CLICK_HANDLER_BUTTON_PRESS; | ||||||
|  |     pbPressCallBack.param = me; | ||||||
|  |      | ||||||
|  |     buttonCallBack pbReleaseCallBack; | ||||||
|  |     pbReleaseCallBack.fCallBack = CLICK_HANDLER_BUTTON_RELEASE; | ||||||
|  |     pbReleaseCallBack.param = me; | ||||||
|  |      | ||||||
|  |     BUTTON_setEventFunctions(b, pbPressCallBack, pbReleaseCallBack); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | 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; | ||||||
|  | } | ||||||
							
								
								
									
										94
									
								
								src/middleware/clickHandler.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								src/middleware/clickHandler.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,94 @@ | |||||||
|  | /** | ||||||
|  |  * @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 */ | ||||||
|  |  | ||||||
		Reference in New Issue
	
	Block a user