Archived
Template
1
0

update blinker with XFTGenerator

This commit is contained in:
Rémi Heredero 2023-07-13 14:38:28 +02:00
parent 01d096e886
commit defd961017
6 changed files with 279 additions and 319 deletions

View File

@ -46,8 +46,8 @@ void APP_init(APP* me){
CLICK_HANDLER_onLong_click(ch1(), &longClick, me);
CLICK_HANDLER_onLong_click(ch3(), &longClick, me);
BLINKER_setFinished(blL(), BLINKER_defineCallBack(&endL, me));
BLINKER_setFinished(blR(), BLINKER_defineCallBack(&endR, me));
BLINKER_onFinished(blL(), &endL, me);
BLINKER_onFinished(blR(), &endR, me);
}
@ -71,34 +71,34 @@ bool APP_processEvent(Event* ev){
case STAP_WAIT:
if(evid == evAPclickL) {
me->state = STAP_BLINKER_L;
BLINKER_blink(blL());
BLINKER_emitBlink(blL(), 0);
}
if(evid == evAPclickLn) {
me->state = STAP_BLINKER_L;
BLINKER_blinkN(blL());
BLINKER_emitBlinkN(blL(), 0);
}
if(evid == evAPclickR) {
me->state = STAP_BLINKER_R;
BLINKER_blink(blR());
BLINKER_emitBlink(blR(), 0);
}
if(evid == evAPclickRn) {
me->state = STAP_BLINKER_R;
BLINKER_blinkN(blR());
BLINKER_emitBlinkN(blR(), 0);
}
if(evid == evAPlongClick) {
me->state = STAP_BLINKER_W;
BLINKER_blink(blB());
BLINKER_emitBlink(blB(), 0);
}
break;
case STAP_BLINKER_L:
if(evid == evAPclickR){
me->state = STAP_BLINKER_LR;
BLINKER_blink(blR());
BLINKER_emitBlink(blR(), 0);
}
if(evid == evAPclickRn){
me->state = STAP_BLINKER_LR;
BLINKER_blinkN(blR());
BLINKER_emitBlinkN(blR(), 0);
}
if(evid == evAPclickL) {
me->state = STAP_WAIT;
@ -110,18 +110,18 @@ bool APP_processEvent(Event* ev){
if(evid == evAPlongClick) {
me->state = STAP_BLINKER_W;
BLINKER_endBlink(blL());
BLINKER_blink(blB());
BLINKER_emitBlink(blB(), 0);
}
break;
case STAP_BLINKER_R:
if(evid == evAPclickL){
me->state = STAP_BLINKER_LR;
BLINKER_blink(blL());
BLINKER_emitBlink(blL(), 0);
}
if(evid == evAPclickLn){
me->state = STAP_BLINKER_LR;
BLINKER_blinkN(blL());
BLINKER_emitBlinkN(blL(), 0);
}
if(evid == evAPclickR) {
me->state = STAP_WAIT;
@ -133,7 +133,7 @@ bool APP_processEvent(Event* ev){
if(evid == evAPlongClick) {
me->state = STAP_BLINKER_W;
BLINKER_endBlink(blR());
BLINKER_blink(blB());
BLINKER_emitBlink(blB(), 0);
}
break;
@ -156,7 +156,8 @@ bool APP_processEvent(Event* ev){
me->state = STAP_BLINKER_W;
BLINKER_endBlink(blL());
BLINKER_endBlink(blR());
BLINKER_blink(blB());
BLINKER_emitBlink(blB(), 0);
}
break;

View File

@ -145,12 +145,12 @@ void Factory_build() {
BUTTON_onReleased(b2(), &CLICK_HANDLER_emitPbrelease, ch2());
BUTTON_onReleased(b3(), &CLICK_HANDLER_emitPbrelease, ch3());
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_onOn(blL(), &LED_on, l1());
BLINKER_onOff(blL(), &LED_off, l1());
BLINKER_onOn(blR(), &LED_on, l10());
BLINKER_onOff(blR(), &LED_off, l10());
BLINKER_onOn(blB(), &warningBlink, true);
BLINKER_onOff(blB(), &warningBlink, false);
}
@ -162,8 +162,8 @@ void Factory_start() {
CLICK_HANDLER_startBehaviour(ch1());
CLICK_HANDLER_startBehaviour(ch2());
CLICK_HANDLER_startBehaviour(ch3());
BLINKER_starBehaviour(blL());
BLINKER_starBehaviour(blR());
BLINKER_starBehaviour(blB());
BLINKER_startBehaviour(blL());
BLINKER_startBehaviour(blR());
BLINKER_startBehaviour(blB());
APP_startBehaviour(app());
}

View File

@ -1,122 +1,83 @@
/**
* @author Rémi Heredero (remi@heredero.ch)
* @version. 1.0.0
* @date 2023-06-15
* @author Rémi Heredero
* @version 1.0.0
* @date July 2023
* @file blinker.c
*/
#include "blinker.h"
void BLINKER_init(BLINKER* me) {
void BLINKER_init(BLINKER* me){
me->state = STBL_INIT;
me->tON = 500;
me->tOFF = 500;
me->nBlink = 3;
me->timeOn = 500;
me->timeOff = 500;
me->numberOfBlink = 3;
me->nBlinkIsOn = false;
me->remainBlinks = 3;
me->turnOn.fCallBack = NULL;
me->turnOff.fCallBack = NULL;
me->wait.f = NULL;
me->on.f = NULL;
me->off.f = NULL;
me->finished.f = NULL;
}
blinkerCallBack BLINKER_defineCallBack(fBlinkerCallBack f, void* param) {
blinkerCallBack c;
c.fCallBack = f;
c.param = param;
return c;
}
void BLINKER_starBehaviour(BLINKER* me) {
void BLINKER_startBehaviour(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* me = (BLINKER*)Event_getTarget(ev);
BLINKER_STATES oldState = me->state;
evIDT evid = Event_getId(ev);
switch(me->state) {
switch (me->state) { // onState
case STBL_INIT:
if(evid == evBLinit) {
if (ev->id == evBLinit) {
me->state = STBL_WAIT;
}
break;
case STBL_WAIT:
me->remainBlinks = me->nBlink;
me->remainBlinks = me->numberOfBlink;
if(evid == evBLblinkN) {
me->state = STBL_ON;
me->nBlinkIsOn = true;
POST(me, &BLINKER_processEvent, evBLtimer, me->tON, 0);
BLINKER_emitTimer(me, me->timeOn);
}
if(evid==evBLblink) {
if(evid == evBLblink) {
me->state = STBL_ON;
me->nBlinkIsOn = false;
POST(me, &BLINKER_processEvent, evBLtimer, me->tON, 0);
BLINKER_emitTimer(me, me->timeOn);
}
break;
case STBL_ON:
if(me->nBlinkIsOn) me->remainBlinks--;
if(evid == evBLtimer) {
me->state = STBL_OFF;
POST(me, &BLINKER_processEvent, evBLtimer, me->tOFF, 0);
if (me->nBlinkIsOn) {
me->remainBlinks--;
}
if (evid == evBLtimer) {
me->state = STBL_OFF;
BLINKER_emitTimer(me, me->timeOff);
}
break;
case STBL_OFF:
if(evid == evBLtimer) {
if(me->remainBlinks == 0) {
if (evid == evBLtimer) {
if (me->remainBlinks == 0) {
me->state = STBL_WAIT;
if(me->finished.fCallBack != NULL) me->finished.fCallBack(me->finished.param);
if (me->finished.f != NULL) {
me->finished.f(me->finished.p);
}
} else {
me->state = STBL_ON;
POST(me, &BLINKER_processEvent, evBLtimer, me->tON, 0);
BLINKER_emitTimer(me, me->timeOn);
}
}
break;
}
if(oldState != me->state) {
switch(me->state) { // on entry
if(oldState != me->state){
switch (oldState) { // onExit
case STBL_INIT:
break;
@ -124,32 +85,105 @@ bool BLINKER_processEvent(Event* ev) {
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;
}
switch (me->state) { // onEntry
case STBL_INIT:
break;
case STBL_WAIT:
if (me->wait.f != NULL) {
me->wait.f(me->wait.p);
}
break;
case STBL_ON:
if (me->on.f != NULL) {
me->on.f(me->on.p);
}
break;
case STBL_OFF:
if (me->off.f != NULL) {
me->off.f(me->off.p);
}
break;
}
processed = true;
}
return processed;
}
/*************
* Callbacks *
*************/
void BLINKER_onWait(BLINKER* me, BLINKER_CALLBACK_FUNCTION f, void* p) {
me->wait.f = f;
me->wait.p = p;
}
void BLINKER_onOn(BLINKER* me, BLINKER_CALLBACK_FUNCTION f, void* p) {
me->on.f = f;
me->on.p = p;
}
void BLINKER_onOff(BLINKER* me, BLINKER_CALLBACK_FUNCTION f, void* p) {
me->off.f = f;
me->off.p = p;
}
void BLINKER_onFinished(BLINKER* me, BLINKER_CALLBACK_FUNCTION f, void* p) {
me->finished.f = f;
me->finished.p = p;
}
/************
* EMITTERS *
************/
void BLINKER_emitBlink(BLINKER* me, uint16_t t) {
POST(me, &BLINKER_processEvent, evBLblink, t, 0);
}
void BLINKER_emitBlinkN(BLINKER* me, uint16_t t) {
POST(me, &BLINKER_processEvent, evBLblinkN, t, 0);
}
void BLINKER_emitTimer(BLINKER* me, uint16_t t) {
POST(me, &BLINKER_processEvent, evBLtimer, t, 0);
}
/***********
* SETTERS *
***********/
void BLINKER_setTimeOn(BLINKER* me, uint16_t v) {
me->timeOn = v;
}
void BLINKER_setTimeOff(BLINKER* me, uint16_t v) {
me->timeOff = v;
}
void BLINKER_setNumberOfBlink(BLINKER* me, uint8_t v) {
me->numberOfBlink = v;
}
void BLINKER_setNBlinkIsOn(BLINKER* me, bool v) {
me->nBlinkIsOn = v;
}
void BLINKER_setRemainBlinks(BLINKER* me, uint8_t v) {
me->remainBlinks = v;
}
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;
}
}

View File

@ -1,9 +1,9 @@
/**
* @author Rémi Heredero (remi@heredero.ch)
* @author Rémi Heredero
* @version 1.0.0
* @date 2023-06-15
* @date July 2023
* @file blinker.h
*/
#ifndef BLINKER_H
#define BLINKER_H
@ -20,116 +20,148 @@ typedef enum {
evBLinit = 200,
evBLblink,
evBLblinkN,
evBLtimer,
evEndBlink
evBLtimer
} BLINKER_EVENTS;
typedef void (*fBlinkerCallBack)(void*);
typedef void (*BLINKER_CALLBACK_FUNCTION)(void*);
typedef struct {
fBlinkerCallBack fCallBack;
void* param;
} blinkerCallBack;
BLINKER_CALLBACK_FUNCTION f; // function
void* p; // param(s)
} BLINKER_CALLBACK;
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
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
blinkerCallBack turnOn; // Callback for turnOn
blinkerCallBack turnOff; // Calbback for turnOff
blinkerCallBack finished; // Callback for finish n blink
}BLINKER;
BLINKER_CALLBACK wait;
BLINKER_CALLBACK on;
BLINKER_CALLBACK off;
BLINKER_CALLBACK finished;
} BLINKER;
/**
* Initialize the blinker
* @param me blinker itself
* Initialize the BLINKER
* @param me the 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
* Start the BLINKER state machine
* @param me the BLINKER itself
*/
blinkerCallBack BLINKER_defineCallBack(fBlinkerCallBack f, void* param);
void BLINKER_startBehaviour(BLINKER* me);
/**
* 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
* 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);
void BLINKER_toggle(BLINKER* me);
#endif /* BLINKER_H */
#endif

View File

@ -1,52 +0,0 @@
/**
* @author Rémi Heredero
* @version 1.0.0
* @date July 2023
* @file ${FILENAME}.c
*/
#include "${FILENAME}.h"
void ${FILENAME}_init(${FILENAME}* me){
me->state = ST${FN}_INIT;
}
void ${FILENAME}_startBehaviour(${FILENAME}* me){
POST(me, &${FILENAME}_processEvent, ev${FN}init, 0, 0);
}
bool ${FILENAME}_processEvent(Event* ev) {
bool processed = false;
${FILENAME}* me = (${FILENAME}*)Event_getTarget(ev);
switch (me->state) { // onState
case ST${FN}_INIT:
if (ev->id == ev${FN}init) {}
break;
{STATES}
}
if(oldState != me->state){
switch (oldState) { // onExit
case ST${FN}_INIT:
break;
{STATES}
}
switch (me->state) { // onEntry
case ST${FN}_INIT:
break;
{STATES}
}
processed = true;
}
return processed;
}
void ${FILENAME}_set{VAR}(${FILENAME}*me, uint16_t t) {
me->tON = t;
}
void ${FILENAME}_emit${EVENT}(${FILENAME}*me, uint16_t t) {
POST(me, &${FILENAME}_processEvent, ev${FN}${EVENT}, t, 0);
}

View File

@ -1,55 +0,0 @@
/**
* @author Rémi Heredero
* @version 1.0.0
* @date July 2023
* @file ${FILENAME}.h
*/
#ifndef ${FILENAME}_H
#define ${FILENAME}_H
#include "../xf/xf.h"
typedef enum{
ST${FN}_INIT,
{STATES}
} ${FILENAME}_STATES;
typedef enum{
ev${FN}init = 100, // TODO change this number
{EVENTS}
} ${FILENAME}_EVENTS;
typedef struct{
${FILENAME}_STATES state;
} ${FILENAME};
/**
* Initialize the ${FILENAME}
* @param me the ${FILENAME} itself
*/
void ${FILENAME}_init(${FILENAME}* me);
/**
* Start the ${FILENAME} state machine
* @param me the ${FILENAME} itself
*/
void ${FILENAME}_startBehaviour(${FILENAME}* me);
/**
* Process the event
* @param ev the event to process
* @return true if the event is processed
*/
bool ${FILENAME}_processEvent(Event* ev);
void ${FILENAME}_set{TIMEON}(${FILENAME}*me, uint16_t t);
/**
* Emit the ${EVENT} event
* @param me the ${FILENAME} itself
* @param t Time to wait before trig the event
*/
void ${FILENAME}_emit${EVENT}(${FILENAME}*me, uint16_t t);
#endif