add callbacks
This commit is contained in:
parent
ef56b5b6ae
commit
29a6be78b3
@ -5,8 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
#include "../mcc_generated_files/pin_manager.h"
|
#include "../src/mcc_generated_files/pin_manager.h"
|
||||||
#include "../app/factory.h"
|
#include "../src/app/factory.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize the button
|
* @brief Initialize the button
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "../xf/xf.h"
|
#include "../src/xf/xf.h"
|
||||||
|
|
||||||
#define PB_POLL_TIME 20 // Poll time for BUTTON
|
#define PB_POLL_TIME 20 // Poll time for BUTTON
|
||||||
|
|
@ -9,6 +9,7 @@
|
|||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="board" displayName="board" projectFiles="true">
|
<logicalFolder name="board" displayName="board" projectFiles="true">
|
||||||
<itemPath>src/board/led.h</itemPath>
|
<itemPath>src/board/led.h</itemPath>
|
||||||
|
<itemPath>src/board/button.h</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="mcc_generated_files"
|
<logicalFolder name="mcc_generated_files"
|
||||||
displayName="mcc_generated_files"
|
displayName="mcc_generated_files"
|
||||||
@ -19,6 +20,10 @@
|
|||||||
<itemPath>src/mcc_generated_files/interrupt_manager.h</itemPath>
|
<itemPath>src/mcc_generated_files/interrupt_manager.h</itemPath>
|
||||||
<itemPath>src/mcc_generated_files/device_config.h</itemPath>
|
<itemPath>src/mcc_generated_files/device_config.h</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
|
<logicalFolder name="middleware" displayName="middleware" projectFiles="true">
|
||||||
|
<itemPath>src/middleware/clickHandler.h</itemPath>
|
||||||
|
<itemPath>src/middleware/blinker.h</itemPath>
|
||||||
|
</logicalFolder>
|
||||||
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
||||||
<itemPath>src/xf/ireactive.h</itemPath>
|
<itemPath>src/xf/ireactive.h</itemPath>
|
||||||
<itemPath>src/xf/event.h</itemPath>
|
<itemPath>src/xf/event.h</itemPath>
|
||||||
@ -38,6 +43,7 @@
|
|||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="board" displayName="board" projectFiles="true">
|
<logicalFolder name="board" displayName="board" projectFiles="true">
|
||||||
<itemPath>src/board/led.c</itemPath>
|
<itemPath>src/board/led.c</itemPath>
|
||||||
|
<itemPath>src/board/button.c</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="mcc_generated_files"
|
<logicalFolder name="mcc_generated_files"
|
||||||
displayName="mcc_generated_files"
|
displayName="mcc_generated_files"
|
||||||
@ -48,6 +54,10 @@
|
|||||||
<itemPath>src/mcc_generated_files/pin_manager.c</itemPath>
|
<itemPath>src/mcc_generated_files/pin_manager.c</itemPath>
|
||||||
<itemPath>src/mcc_generated_files/tmr0.c</itemPath>
|
<itemPath>src/mcc_generated_files/tmr0.c</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
|
<logicalFolder name="middleware" displayName="middleware" projectFiles="true">
|
||||||
|
<itemPath>src/middleware/blinker.c</itemPath>
|
||||||
|
<itemPath>src/middleware/clickHandler.c</itemPath>
|
||||||
|
</logicalFolder>
|
||||||
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
||||||
<itemPath>src/xf/xf.c</itemPath>
|
<itemPath>src/xf/xf.c</itemPath>
|
||||||
<itemPath>src/xf/event.c</itemPath>
|
<itemPath>src/xf/event.c</itemPath>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
#include "../mcc_generated_files/mcc.h"
|
#include "../mcc_generated_files/mcc.h"
|
||||||
#include "../app/factory/factory.h"
|
#include "../app/factory.h"
|
||||||
#include "../xf/xf.h"
|
#include "../xf/xf.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
* @author Rémi Heredero (remi@heredero.ch)
|
* @author R<EFBFBD>mi Heredero (remi@heredero.ch)
|
||||||
* @version. 1.0.0
|
* @version. 1.0.0
|
||||||
* @date 2023-06-15
|
* @date 2023-06-15
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "clickHandler.h"
|
#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){
|
void CLICK_HANDLER_BUTTON_PRESS(CLICK_HANDLER* me){
|
||||||
POST(me, &CLICK_HANDLER_processEvent, evCHpbPress, 0, 0);
|
POST(me, &CLICK_HANDLER_processEvent, evCHpbPress, 0, 0);
|
||||||
@ -21,15 +28,8 @@ void CLICK_HANDLER_init(CLICK_HANDLER* me, BUTTON* b){
|
|||||||
me->singleClick.fCallBack = NULL;
|
me->singleClick.fCallBack = NULL;
|
||||||
me->doubleClick.fCallBack = NULL;
|
me->doubleClick.fCallBack = NULL;
|
||||||
|
|
||||||
buttonCallBack pbPressCallBack;
|
BUTTON_onPress(b, CLICK_HANDLER_BUTTON_PRESS, me);
|
||||||
pbPressCallBack.fCallBack = CLICK_HANDLER_BUTTON_PRESS;
|
BUTTON_onRelease(b, CLICK_HANDLER_BUTTON_RELEASE, me);
|
||||||
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){
|
void CLICK_HANDLER_startBehaviour(CLICK_HANDLER* me){
|
||||||
@ -71,8 +71,12 @@ bool CLICK_HANDLER_processEvent(Event* ev) {
|
|||||||
case STCH_WAIT:
|
case STCH_WAIT:
|
||||||
|
|
||||||
if(evid == evCHpbPress) {
|
if(evid == evCHpbPress) {
|
||||||
me->state = STCH_LONG_CLICK;
|
LED_on(l2());
|
||||||
POST(me, &CLICK_HANDLER_processEvent, evCHtimer, CH_CLICK_TIMER, 0);
|
//me->state = STCH_LONG_CLICK;
|
||||||
|
//POST(me, &CLICK_HANDLER_processEvent, evCHtimer, CH_CLICK_TIMER, 0);
|
||||||
|
}
|
||||||
|
if(evid==evCHpbRelease) {
|
||||||
|
LED_off(l2());
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -86,7 +90,9 @@ bool CLICK_HANDLER_processEvent(Event* ev) {
|
|||||||
|
|
||||||
if(evid == evCHtimer) {
|
if(evid == evCHtimer) {
|
||||||
me->state = STCH_WAIT;
|
me->state = STCH_WAIT;
|
||||||
|
LED_on(l4());
|
||||||
if(me->longClick.fCallBack != NULL) {
|
if(me->longClick.fCallBack != NULL) {
|
||||||
|
LED_on(l5());
|
||||||
me->longClick.fCallBack(me->longClick.param);
|
me->longClick.fCallBack(me->longClick.param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,10 +103,12 @@ bool CLICK_HANDLER_processEvent(Event* ev) {
|
|||||||
case STCH_SINGLE_CLICK:
|
case STCH_SINGLE_CLICK:
|
||||||
|
|
||||||
if(evid == evCHpbPress) {
|
if(evid == evCHpbPress) {
|
||||||
|
LED_on(l2());
|
||||||
me->state = STCH_DOUBLE_CLICK;
|
me->state = STCH_DOUBLE_CLICK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(evid == evCHtimer) {
|
if(evid == evCHtimer) {
|
||||||
|
LED_on(l3());
|
||||||
me->state = STCH_WAIT;
|
me->state = STCH_WAIT;
|
||||||
if(me->singleClick.fCallBack != NULL) {
|
if(me->singleClick.fCallBack != NULL) {
|
||||||
me->singleClick.fCallBack(me->singleClick.param);
|
me->singleClick.fCallBack(me->singleClick.param);
|
||||||
|
Reference in New Issue
Block a user