add blinker
This commit is contained in:
		
							
								
								
									
										167
									
								
								306-controller_interface.X/middleware/blinker.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										167
									
								
								306-controller_interface.X/middleware/blinker.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,167 @@ | ||||
| /** | ||||
|  * @author Rémi Heredero | ||||
|  * @version 1.0.0 | ||||
|  * @date July 2023 | ||||
|  * @file blinker.h | ||||
|  */ | ||||
| #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 | ||||
| } BLINKER_EVENTS; | ||||
|  | ||||
| typedef void (*BLINKER_CALLBACK_FUNCTION)(void*); | ||||
| typedef struct { | ||||
|     BLINKER_CALLBACK_FUNCTION f; // function | ||||
|     void* p; // param(s) | ||||
| } BLINKER_CALLBACK; | ||||
|  | ||||
| typedef struct { | ||||
|     BLINKER_STATES state; //Actual state | ||||
|     uint16_t timeOn; // Time on | ||||
|     uint16_t timeOff; // Time off | ||||
|     uint8_t numberOfBlink; // Number of blink for this blinker when start with blinkN | ||||
|     bool nBlinkIsOn; // If the nBlink way is enable | ||||
|     uint8_t remainBlinks; // Actual remain blink | ||||
|     BLINKER_CALLBACK wait; | ||||
|     BLINKER_CALLBACK on; | ||||
|     BLINKER_CALLBACK off; | ||||
|     BLINKER_CALLBACK finished; | ||||
| } BLINKER; | ||||
|  | ||||
| /** | ||||
|  * Initialize the BLINKER | ||||
|  * @param me the BLINKER itself | ||||
|  */ | ||||
| void BLINKER_init(BLINKER* me); | ||||
|  | ||||
| /** | ||||
|  * Start the BLINKER state machine | ||||
|  * @param me the BLINKER itself | ||||
|  */ | ||||
| void BLINKER_startBehaviour(BLINKER* me); | ||||
|  | ||||
| /** | ||||
|  * Process the event | ||||
|  * @param ev the event to process | ||||
|  * @return true if the event is processed | ||||
|  */ | ||||
| bool BLINKER_processEvent(Event* ev); | ||||
|  | ||||
| /************* | ||||
|  * Callbacks * | ||||
|  *************/ | ||||
|  | ||||
| /** | ||||
|  * Set the callback function to call when the BLINKER is entering state wait | ||||
|  * @param me the BLINKER itself | ||||
|  * @param f the function to call | ||||
|  * @param p the param(s) to pass to the function | ||||
|  */ | ||||
| void BLINKER_onWait(BLINKER* me, BLINKER_CALLBACK_FUNCTION f, void* p); | ||||
|  | ||||
| /** | ||||
|  * Set the callback function to call when the BLINKER is entering state on | ||||
|  * @param me the BLINKER itself | ||||
|  * @param f the function to call | ||||
|  * @param p the param(s) to pass to the function | ||||
|  */ | ||||
| void BLINKER_onOn(BLINKER* me, BLINKER_CALLBACK_FUNCTION f, void* p); | ||||
|  | ||||
| /** | ||||
|  * Set the callback function to call when the BLINKER is entering state off | ||||
|  * @param me the BLINKER itself | ||||
|  * @param f the function to call | ||||
|  * @param p the param(s) to pass to the function | ||||
|  */ | ||||
| void BLINKER_onOff(BLINKER* me, BLINKER_CALLBACK_FUNCTION f, void* p); | ||||
|  | ||||
| /** | ||||
|  * Set the callabck function to call when the BLINKER is entering state finished | ||||
|  * @param me the BLINKER itself | ||||
|  * @param f the function to call | ||||
|  * @param t the param(s) to pass to the function | ||||
|  */ | ||||
| void BLINKER_onFinished(BLINKER* me, BLINKER_CALLBACK_FUNCTION f, void* p); | ||||
|  | ||||
| /************ | ||||
|  * EMITTERS * | ||||
|  ************/ | ||||
|  | ||||
| /** | ||||
|  * Emit the blink event | ||||
|  * @param me the BLINKER itself | ||||
|  * @param t time to wait in ms before triggering event | ||||
|  */void BLINKER_emitBlink(BLINKER* me, uint16_t t); | ||||
|  | ||||
| /** | ||||
|  * Emit the blinkn event | ||||
|  * @param me the BLINKER itself | ||||
|  * @param t time to wait in ms before triggering event | ||||
|  */void BLINKER_emitBlinkN(BLINKER* me, uint16_t t); | ||||
|  | ||||
| /** | ||||
|  * Emit the timer event | ||||
|  * @param me the BLINKER itself | ||||
|  * @param t time to wait in ms before triggering event | ||||
|  */void BLINKER_emitTimer(BLINKER* me, uint16_t t); | ||||
|  | ||||
| /*********** | ||||
|  * SETTERS * | ||||
|  ***********/ | ||||
|  | ||||
| /** | ||||
|  * Set the time on | ||||
|  * @param me the BLINKER itself | ||||
|  * @param v the value to set | ||||
|  */ | ||||
| void BLINKER_setTimeOn(BLINKER* me, uint16_t v); | ||||
|  | ||||
| /** | ||||
|  * Set the time off | ||||
|  * @param me the BLINKER itself | ||||
|  * @param v the value to set | ||||
|  */ | ||||
| void BLINKER_setTimeOff(BLINKER* me, uint16_t v); | ||||
|  | ||||
| /** | ||||
|  * Set the number of blink | ||||
|  * @param me the BLINKER itself | ||||
|  * @param v the value to set | ||||
|  */ | ||||
| void BLINKER_setNumberOfBlink(BLINKER* me, uint8_t v); | ||||
|  | ||||
| /** | ||||
|  * Set the nBlinkIsOn | ||||
|  * @param me the BLINKER itself | ||||
|  * @param v the value to set | ||||
|  */ | ||||
| void BLINKER_setNBlinkIsOn(BLINKER* me, bool v); | ||||
|  | ||||
| /** | ||||
|  * Set the remain blink(s) | ||||
|  * @param me the BLINKER itself | ||||
|  * @param v the value to set | ||||
|  */ | ||||
| void BLINKER_setRemainBlinks(BLINKER* me, uint8_t v); | ||||
|  | ||||
| /** | ||||
|  * Stop to blink if it was indefinitely blinking | ||||
|  * @param me the blinker itself | ||||
|  */ | ||||
| void BLINKER_endBlink(BLINKER* me); | ||||
|  | ||||
| #endif | ||||
		Reference in New Issue
	
	Block a user