Archived
Template
1
0

update clickHandler with XFTGenerator

This commit is contained in:
Rémi Heredero 2023-07-12 19:07:00 +02:00
parent 2dd13a3621
commit 33834416f3
5 changed files with 19 additions and 258 deletions

View File

@ -7,7 +7,7 @@
#include "app.h"
#include "factory.h"
#include "../middleware/blinker.h"
#include "../middleware/clickHandler.h"
#include "../middleware/click_handler.h"
void clickL(APP* me){
POST(me, &APP_processEvent, evAPclickL, 0, 0);
@ -37,14 +37,14 @@ 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_onSingle_click(ch1(), &clickL, me);
CLICK_HANDLER_onSingle_click(ch3(), &clickR, me);
CLICK_HANDLER_setDoubleClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&clickLn, me));
CLICK_HANDLER_setDoubleClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&clickRn, me));
CLICK_HANDLER_onDouble_click(ch1(), &clickLn, me);
CLICK_HANDLER_onDouble_click(ch3(), &clickRn, me);
CLICK_HANDLER_setLongClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&longClick, me));
CLICK_HANDLER_setLongClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&longClick, 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));

View File

@ -109,9 +109,9 @@ void Factory_init() {
BUTTON_initHW(b2());
BUTTON_initHW(b3());
CLICK_HANDLER_init(ch1(), b1());
CLICK_HANDLER_init(ch2(), b2());
CLICK_HANDLER_init(ch3(), b3());
CLICK_HANDLER_init(ch1());
CLICK_HANDLER_init(ch2());
CLICK_HANDLER_init(ch3());
BLINKER_init(blL());
BLINKER_init(blR());
@ -137,6 +137,14 @@ void warningBlink(void* on_){
//connect objects if required
void Factory_build() {
BUTTON_onPressed(b1(), &CLICK_HANDLER_emitPbpress, ch1());
BUTTON_onPressed(b2(), &CLICK_HANDLER_emitPbpress, ch2());
BUTTON_onPressed(b3(), &CLICK_HANDLER_emitPbpress, ch3());
BUTTON_onReleased(b1(), &CLICK_HANDLER_emitPbrelease, ch1());
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()));

View File

@ -12,7 +12,7 @@
#include "../board/led.h"
#include "../board/button.h"
#include "../middleware/clickHandler.h"
#include "../middleware/click_handler.h"
#include "../middleware/blinker.h"
#include "app.h"

View File

@ -1,153 +0,0 @@
/**
* @author R<EFBFBD>mi Heredero (remi@heredero.ch)
* @version. 1.0.0
* @date 2023-06-15
*/
#include "clickHandler.h"
#include "../board/led.h"
#include "../app/factory.h"
typedef struct {
CLICK_HANDLER* me;
uint16_t t;
} foo;
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;
BUTTON_onPressed(b, CLICK_HANDLER_BUTTON_PRESS, me);
BUTTON_onReleased(b, CLICK_HANDLER_BUTTON_RELEASE, me);
}
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;
}

View File

@ -1,94 +0,0 @@
/**
* @author R<EFBFBD>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 */