diff --git a/node/code/inc/shell_commands.h b/node/code/inc/shell_commands.h index 592c50b4..b8208377 100644 --- a/node/code/inc/shell_commands.h +++ b/node/code/inc/shell_commands.h @@ -2,6 +2,8 @@ #include "shell.h" #include +#include "events.h" +#include static int echo_command(int argc, char **argv) { @@ -18,27 +20,27 @@ static int echo_command(int argc, char **argv) return 0; } -// /** -// * @brief Sends an event to the dispatcher. -// * @example send_event 1 -// */ -// static int send_event(int argc, char **argv) { -// if (argc != 2) { -// puts("usage: send_event "); -// return 1; -// } +static int send_event(int argc, char **argv) { + if (argc != 2) { + puts("usage: send_event "); + return 1; + } + + int event_id = atoi(argv[1]); + if (event_id < 0) { + puts("usage: send_event "); + return 1; + } -// msg_t message; -// message.type = atoi(argv[1]); + trigger_event(event_id); -// msg_try_send(&message, DISPATCHER_THREAD_ID); + return 0; -// return 0; -// } +} const shell_command_t SHELL_COMMANDS[] = { { "echo", "Prints the message to the console", echo_command }, - // { "send_event", "Sends an event to the dispatcher. send_event 1", send_event }, + { "send_event", "Sends an event to the dispatcher. send_event 1", send_event }, { NULL, NULL, NULL } }; diff --git a/node/code/main.c b/node/code/main.c index 1bc08041..6da47561 100644 --- a/node/code/main.c +++ b/node/code/main.c @@ -8,9 +8,8 @@ #define SHELL_QUEUE_SIZE (8) static msg_t _shell_queue[SHELL_QUEUE_SIZE]; - int main(void) -{ +{ fsm_start_thread(); msg_init_queue(_shell_queue, SHELL_QUEUE_SIZE); shell_loop(); diff --git a/node/code/modules/display_handler/display_handler.c b/node/code/modules/display_handler/display_handler.c index 98655863..4c16e762 100644 --- a/node/code/modules/display_handler/display_handler.c +++ b/node/code/modules/display_handler/display_handler.c @@ -64,19 +64,23 @@ handler_result_t displayHandler_handleEvent(EVENT_T event){ right_released(); break; case REGISTER_CODE: - init_not_registered_code(get_register_code()); + //init_not_registered_code(get_register_code()); + init_not_registered_code("Hallo Tom"); break; case REGISTERED: + init_registered_no_pet(); + break; + case READY: init_registered_pet(); break; - case INFO: + case INFO_PRESSED: get_pet_stats((char*)&buf); init_pet_stats((char*)&buf); default: break; } lvgl_wakeup(); - return EVENT_HANDLED; + return HANDLED; } void *display_run(void * arg){ diff --git a/node/code/modules/display_handler/include/init_lvgl.h b/node/code/modules/display_handler/include/init_lvgl.h index 65879745..ed231642 100644 --- a/node/code/modules/display_handler/include/init_lvgl.h +++ b/node/code/modules/display_handler/include/init_lvgl.h @@ -21,6 +21,7 @@ void left_released(void); void right_pressed(void); void right_released(void); void init_not_registered_code(char* code); +void init_registered_no_pet(void); void init_registered_pet(void); void init_pet_stats(char* stats); diff --git a/node/code/modules/display_handler/init_lvgl.c b/node/code/modules/display_handler/init_lvgl.c index 708f16da..4cff4783 100644 --- a/node/code/modules/display_handler/init_lvgl.c +++ b/node/code/modules/display_handler/init_lvgl.c @@ -32,6 +32,7 @@ #include "disp_dev.h" #include "init_lvgl.h" #include "events.h" +#include "debug.h" #define CPU_LABEL_COLOR "FF0000" #define MEM_LABEL_COLOR "0000FF" @@ -94,6 +95,7 @@ void init_menu(void); static void menu_cb(lv_event_t * e){ lv_event_code_t code = lv_event_get_code(e); if(code == LV_EVENT_KEY) { + uint32_t key = lv_event_get_key(e); if(key == LV_KEY_LEFT || key == LV_KEY_RIGHT) { lv_obj_set_style_bg_opa(img_index_pairs[current_img_index].img,LV_OPA_TRANSP,LV_PART_MAIN); @@ -108,6 +110,7 @@ static void menu_cb(lv_event_t * e){ // Zeige das neue aktuelle Bild an lv_obj_set_style_bg_opa(img_index_pairs[current_img_index].img,LV_OPA_70,LV_PART_MAIN); }else if (key == LV_KEY_ENTER){ + DEBUG("Enter pressed\n"); trigger_event(img_index_pairs[current_img_index].event); } } @@ -438,7 +441,7 @@ void init_menu(void){ img_index_pairs[3].event = PET_MEDICATE; img_index_pairs[4].img = info_ico; img_index_pairs[4].index = 4; - img_index_pairs[4].event = INFO; + img_index_pairs[4].event = INFO_PRESSED; lv_obj_add_event_cb(bottom_bar,menu_cb,LV_EVENT_ALL,NULL); lv_group_add_obj(group1,bottom_bar); diff --git a/node/code/modules/fsm/events.c b/node/code/modules/fsm/events.c index cf4a0d06..5429015d 100644 --- a/node/code/modules/fsm/events.c +++ b/node/code/modules/fsm/events.c @@ -28,6 +28,7 @@ void set_t_events_pid(kernel_pid_t pid){ } void trigger_event(EVENT_T _event){ + //DEBUG("event input \n"); msg_t msg; msg.type = _event; if (msg_try_send(&msg, t_events_pid) == 0) { diff --git a/node/code/modules/fsm/fsm.c b/node/code/modules/fsm/fsm.c index c478e8d3..126ec5dd 100644 --- a/node/code/modules/fsm/fsm.c +++ b/node/code/modules/fsm/fsm.c @@ -1,4 +1,3 @@ - #include "fsm.h" #include @@ -13,142 +12,122 @@ char fsm_thread_stack[THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF]; -typedef struct hierarchical_state state_t; +void *fsm_thread(void * arg); +void fsm_handle(EVENT_T event); + +handler_result_t on_handler(EVENT_T event); +void on_entry(void); +void on_exit(void); +handler_result_t off_handler(EVENT_T event); +void off_entry(void); +void off_exit(void); +handler_result_t unregistered_handler(EVENT_T event); +void unregistered_entry(void); +void unregistered_exit(void); +handler_result_t userLinked_handler(EVENT_T event); +void userLinked_entry(void); +void userLinked_exit(void); +handler_result_t pet_handler(EVENT_T event); +void pet_entry(void); +void pet_exit(void); +handler_result_t mainView_handler(EVENT_T event); +void mainView_entry(void); +void mainView_exit(void); +handler_result_t gameView_handler(EVENT_T event); +void gameView_entry(void); +void gameView_exit(void); + +typedef struct hierarchical_state state_t; struct hierarchical_state { fsm_handler Handler; //!< State handler function void (*Entry)(void); //!< Entry action for state void (*Exit)(void); //!< Exit action for state. const state_t *const Parent; //!< Parent state of the current state. - const state_t *const Node; //!< Child states of the current state. + const state_t *const Child; //!< Child states of the current state. uint32_t Level; //!< Hierarchy level from the top state. }; -handler_result_t testHandler(EVENT_T event); -void main_state_init_entry_handler(void); -handler_result_t main_state_init_handler(EVENT_T event); -void fsm_handle(EVENT_T event); -void *fsm_thread(void * arg); -// // This is an array of root (top most) states . -// static const state_t Top_Level[] = {{ -// top_level_awake_handler, // state handler -// top_level_awake_entry_handler, // Entry action handler -// top_level_awake_exit_handler, // Exit action handler -// NULL, // Parent state -// RunningState, // Child state -// 0 // Hierarchical state level -// }}; - -// // This is an array of root (top most) states . -// static const state_t RunningState[] = {{ -// running_state_init_handler, // state handler -// running_state_init_entry_handler, // Entry action handler -// running_state_init_exit_handler, // Exit action handler -// MainState, // Parent state -// NULL, // Child state -// 1 // Hierarchical state level -// }}; - -// // This is an array of root (top most) states . -// static const state_t MainState[] = { -// { -// main_state_init_handler, // state handler -// main_state_init_entry_handler, // Entry action handler -// main_state_init_exit_handler, // Exit action handler -// RunningState, // Parent state -// NULL, // Child state -// 2 // Hierarchical state level -// }, -// { -// main_state_notregistered_handler, // state handler -// main_state_notregistered_entry_handler, // Entry action handler -// main_state_notregistered_exit_handler, // Exit action handler -// RunningState, // Parent state -// NULL, // Child state -// 2 // Hierarchical state level -// }, -// { -// main_state_linkednopet_handler, // state handler -// main_state_linkednopet_entry_handler, // Entry action handler -// main_state_linkednopet_exit_handler, // Exit action handler -// RunningState, // Parent state -// NULL, // Child state -// 2 // Hierarchical state level -// }, -// { -// main_state_pet_handler, // state handler -// main_state_pet_entry_handler, // Entry action handler -// main_state_pet_exit_handler, // Exit action handler -// RunningState, // Parent state -// NULL, // Child state -// 2 // Hierarchical state level -// }}; - -static const state_t MainState[4]; -static const state_t RunningState[1]; - -// This is an array of root (top most) states . -static const state_t MainState[] = { - { - main_state_init_handler, // state handler - main_state_init_entry_handler, // Entry action handler - NULL, // Exit action handler - &RunningState[0], // Parent state - NULL, // Child state - 2 // Hierarchical state level +static bool firstStart = true; +static bool registered = false; +static bool userLinked = false; + +static const state_t Top_Level[2]; +static const state_t On_Level[3]; +static const state_t Pet_Level[2]; + +static const state_t Top_Level[] = { + {//on + on_handler, // state handler + on_entry, // Entry action handler + on_exit, // Exit action handler + NULL, // Parent state + &On_Level[0], // Child state + 1 // Hierarchical state level }, - { - NULL, // state handler - NULL, // Entry action handler - NULL, // Exit action handler - &RunningState[0], // Parent state - NULL, // Child state - 2 // Hierarchical state level + {//off + off_handler, // state handler + off_entry, // Entry action handler + off_exit, // Exit action handler + NULL, // Parent state + NULL, // Child state + 1 // Hierarchical state level + } +}; + +static const state_t On_Level[] = { + {//unregistered + unregistered_handler, // state handler + unregistered_entry, // Entry action handler + unregistered_exit, // Exit action handler + &Top_Level[0], // Parent state + NULL, // Child state + 2 // Hierarchical state level }, - { - NULL, // state handler - NULL, // Entry action handler - NULL, // Exit action handler - &RunningState[0], // Parent state - NULL, // Child state - 2 // Hierarchical state level + {//user_linked + userLinked_handler, // state handler + userLinked_entry, // Entry action handler + userLinked_exit, // Exit action handler + &Top_Level[0], // Parent state + NULL, // Child state + 2 // Hierarchical state level + }, + {//pet + pet_handler, // state handler + pet_entry, // Entry action handler + pet_exit, // Exit action handler + &Top_Level[0], // Parent state + &Pet_Level[0], // Child state + 2 // Hierarchical state level + } +}; + +static const state_t Pet_Level[] = { + {//Main_View + mainView_handler, // state handler + mainView_entry, // Entry action handler + mainView_exit, // Exit action handler + &On_Level[2], // Parent state + NULL, // Child state + 3 // Hierarchical state level }, - { - NULL, // state handler - NULL, // Entry action handler - NULL, // Exit action handler - &RunningState[0], // Parent state - NULL, // Child state - 2 // Hierarchical state level - }}; - -// This is an array of root (top most) states . -static const state_t RunningState[] = {{ - NULL, // state handler - NULL, // Entry action handler - NULL, // Exit action handler - NULL, // Parent state - &MainState[0], // Child state - 1 // Hierarchical state level -}}; - -// // This is an array of root (top most) states . -// static const state_t Top_Level[] = {{ -// NULL, // state handler -// NULL, // Entry action handler -// NULL, // Exit action handler -// NULL, // Parent state -// &RunningState[0], // Child state -// 0 // Hierarchical state level -// }}; - -static const state_t *currentState = &MainState[0]; + {//Game_View + gameView_handler, // state handler + gameView_entry, // Entry action handler + gameView_exit, // Exit action handler + &On_Level[2], // Parent state + NULL, // Child state + 3 // Hierarchical state level + } +}; + +static const state_t *currentState = &Top_Level[1]; void fsm_start_thread(void){ set_t_events_pid(thread_create(fsm_thread_stack, sizeof(fsm_thread_stack), THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST, - fsm_thread, NULL, "fsm_thread")); + fsm_thread, NULL, "fsm_thread")); } void *fsm_thread(void *arg) { @@ -160,59 +139,230 @@ void *fsm_thread(void *arg) { } void fsm_handle(EVENT_T event) { - DEBUG("[FSM:fsm_handle]: handle\n"); + if (!currentState->Handler) puts("no handler \n"); handler_result_t result = currentState->Handler(event); - if (result != EVENT_HANDLED) { + if (result != HANDLED) { + DEBUG("[FSM:fsm_handle]: UNHANDLED\n"); const state_t *pState = currentState; do { - // check if state has parent state. - if (pState->Parent == NULL) // Is Node reached top - { - DEBUG("[FSM:fsm_handle]: Fatal error, terminating.\n"); - // This is a fatal error. terminate state machine. - return; + //check if state has parent state. + if (pState->Parent == NULL) { //Is Node reached top + DEBUG("[FSM:fsm_handle]: Fatal error, terminating.\n"); + //This is a fatal error. terminate state machine. + return; + } + DEBUG("[FSM:fsm_handle]: Traverse to parent state\n"); + pState = pState->Parent; // traverse to parent state + result = pState->Handler(event); + DEBUG("[FSM:fsm_handle]: result: %d\n", result); } - - pState = pState->Parent; // traverse to parent state - } while (pState->Handler == - NULL); // repeat again if parent state doesn't have handler - pState->Handler(event); - }else{ - DEBUG("[FSM:fsm_handle]: Event handled\n"); + while (pState->Handler == + NULL || result == UNHANDLED); // repeat again if parent state doesn't have handler + DEBUG("[FSM:fsm_handle]: State machine traversed to parent state\n"); } + } -void traverse_state(state_t target_state) { - while (target_state.Level > currentState->Level) { - if (currentState->Exit) currentState->Exit(); - currentState = currentState->Parent; - if (currentState->Entry) currentState->Entry(); - } - while (target_state.Level < currentState->Level) { - currentState = currentState->Node; +void traverse_state(const state_t *target_state) { + while (target_state->Level < currentState->Level) { + if (currentState->Exit) currentState->Exit(); + currentState = currentState->Parent; + //if (currentState->Entry) currentState->Entry(); + } + while (target_state->Level > currentState->Level) { + currentState = currentState->Child; + if (currentState->Entry) currentState->Entry(); + } + if (currentState->Level == target_state->Level) { + if (currentState->Exit) currentState->Exit(); + } + currentState = target_state; if (currentState->Entry) currentState->Entry(); - } - if (currentState->Level == target_state.Level) { - if (currentState->Exit) currentState->Exit(); - } - currentState = &target_state; - if (currentState->Entry) currentState->Entry(); -} - -void main_state_init_entry_handler(void) { - DEBUG("[FSM:init_entry]\n"); - lwm2m_handler_init(); - lwm2m_handler_start(); - io_init(); - display_init(); - startDisplayThread(); -} - -handler_result_t main_state_init_handler(EVENT_T event) { - DEBUG("[FSM:main_state_init_handler]: lwm2m handle\n"); - lwm2m_handleEvent(event); - ioHandler_handleEvent(event); - displayHandler_handleEvent(event); - - return EVENT_HANDLED; } + +handler_result_t on_handler(EVENT_T event) { + switch (event) { + case BUTTON_OK_LONG: + DEBUG("[FSM:on_handler]: BUTTON_OK_LONG\n"); + traverse_state(&Top_Level[1]); //transition to off + DEBUG("[FSM:on_handler]: transition to off\n"); + return HANDLED; + default: + DEBUG("[FSM:on_handler]: UNHANDLED\n"); + return HANDLED; //TODO Error detection + } +} + +void on_entry(void) { + DEBUG("[FSM:on_entry_handler]: called\n"); + ioHandler_handleEvent(VIBRATE); + traverse_state(&On_Level[0]); //wie gehe ich in den Child State +} + +void on_exit(void) { + +} + +handler_result_t off_handler(EVENT_T event) { + switch (event) { + case BUTTON_OK_LONG: + DEBUG("[FSM:off_handler]: BUTTON_OK_LONG\n"); + traverse_state(&Top_Level[0]); //transition to on + return HANDLED; + break; + default: + DEBUG("[FSM:off_handler]: UNHANDLED\n"); + return HANDLED; //TODO Error detection + break; + } +} + +void off_entry(void) { + if (firstStart) { + firstStart = false; + lwm2m_handler_init(); + lwm2m_handler_start(); + io_init(); + display_init(); + startDisplayThread(); + } +} + +void off_exit(void) { + +} + +handler_result_t unregistered_handler(EVENT_T event) { + switch (event) { + case REGISTERED: + displayHandler_handleEvent(REGISTERED); + traverse_state(&On_Level[1]); + return HANDLED; + default: + DEBUG("[FSM:unregistered_state_handler]: UNHANDLED\n"); + return UNHANDLED; + break; + } +} + +void unregistered_entry(void) { + DEBUG("[FSM:unregistered_entry]: called\n"); + displayHandler_handleEvent(REGISTER_CODE); +} + +void unregistered_exit(void) { + +} + +handler_result_t userLinked_handler(EVENT_T event) { + switch (event) { + case READY: + displayHandler_handleEvent(READY); + traverse_state(&On_Level[2]); + return HANDLED; + default: + DEBUG("[FSM:userLinked_handler]: UNHANDLED\n"); + return UNHANDLED; + } +} + +void userLinked_entry(void) { + registered = true; +} + +void userLinked_exit(void) { + +} + +handler_result_t pet_handler(EVENT_T event) { + switch (event) { + default: + DEBUG("[FSM:pet_handler]: UNHANDLED\n"); + return UNHANDLED; + } +} + +void pet_entry(void) { + userLinked = true; + traverse_state(&Pet_Level[0]); +} + +void pet_exit(void) { + +} + +handler_result_t mainView_handler(EVENT_T event) { + switch (event) { + case BUTTON_OK_LONG: + DEBUG("[FSM:mainView_handler]: langer Button nach oben\n"); + return UNHANDLED; + case BUTTON_OK_PRESSED: + DEBUG("[FSM:mainView_handler]: BUTTON_OK_PRESSED\n"); + displayHandler_handleEvent(event); + return HANDLED; + case BUTTON_OK_RELEASED: + DEBUG("[FSM:mainView_handler]: BUTTON_OK_RELEASED\n"); + displayHandler_handleEvent(event); + return HANDLED; + case BUTTON_UP_PRESSED: + case BUTTON_UP_RELEASED: + case BUTTON_DOWN_PRESSED: + case BUTTON_DOWN_RELEASED: + case BUTTON_LEFT_PRESSED: + case BUTTON_LEFT_RELEASED: + case BUTTON_RIGHT_PRESSED: + case BUTTON_RIGHT_RELEASED: + DEBUG("[FSM:mainView_handler]: BUTTON_PRESSED or BUTTON_RELEASED\n"); + displayHandler_handleEvent(event); + return HANDLED; + case PET_FEED: + DEBUG("[FSM:mainView_handler]: PET_FEED\n"); + lwm2m_handleEvent(PET_FEED); + return HANDLED; + case PET_PLAY: + DEBUG("[FSM:mainView_handler]: PET_PLAY\n"); + lwm2m_handleEvent(PET_PLAY); + return HANDLED; + case PET_MEDICATE: + DEBUG("[FSM:mainView_handler]: PET_MEDICATE\n"); + lwm2m_handleEvent(PET_MEDICATE); + return HANDLED; + case PET_CLEAN: + DEBUG("[FSM:mainView_handler]: PET_CLEAN\n"); + lwm2m_handleEvent(PET_CLEAN); + return HANDLED; + case INFO_PRESSED: + DEBUG("[FSM:mainView_handler]: INFO_PRESSED\n"); + displayHandler_handleEvent(INFO_PRESSED); + return HANDLED; + default: + DEBUG("[FSM:mainView_handler]: UNHANDLED\n"); + return UNHANDLED; + } +} + +void mainView_entry(void) { + //displayHandler_handleEvent(MAIN_VIEW); +} + +void mainView_exit(void) { + +} + +handler_result_t gameView_handler(EVENT_T event) { + switch (event) { + default: + DEBUG("[FSM:gameView_handler]: UNHANDLED\n"); + return UNHANDLED; + break; + } +} + +void gameView_entry(void) { + //displayHandler_handleEvent(GAME_VIEW); +} + +void gameView_exit(void) { + +} +//EOF diff --git a/node/code/modules/fsm/include/events.h b/node/code/modules/fsm/include/events.h index 8764ebb9..a7364505 100644 --- a/node/code/modules/fsm/include/events.h +++ b/node/code/modules/fsm/include/events.h @@ -43,6 +43,7 @@ typedef enum { BUTTON_DOWN_RELEASED, BUTTON_RIGHT_PRESSED, BUTTON_RIGHT_RELEASED, + BUTTON_OK_LONG, INFO_PRESSED, PET_FEED, PET_PLAY, @@ -57,7 +58,6 @@ typedef enum { REGISTER, REGISTERED, READY, - INFO, REGISTER_CODE, NAME, COLOR, @@ -96,11 +96,11 @@ typedef struct{ /* Enum of the fsm handler return values*/ typedef enum { - EVENT_HANDLED, //!< Event handled successfully. - EVENT_UN_HANDLED, //!< Event could not be handled. + HANDLED, //!< Event handled successfully. + UNHANDLED, //!< Event could not be handled. //!< Handler handled the Event successfully and posted new event to itself. TRIGGERED_TO_SELF, -}handler_result_t; +} handler_result_t; /** diff --git a/node/code/modules/io_handler/include/init_buttons.h b/node/code/modules/io_handler/include/init_buttons.h index e4a1bc03..bdb599ff 100644 --- a/node/code/modules/io_handler/include/init_buttons.h +++ b/node/code/modules/io_handler/include/init_buttons.h @@ -27,6 +27,8 @@ void button_down_callback (void *arg); void button_right_callback (void *arg); void button_ok_callback (void *arg); +void timer_long_pressed_cb(void *arg); + //Vibration functions prototypes: void vibrate(uint16_t msec); diff --git a/node/code/modules/io_handler/init_buttons.c b/node/code/modules/io_handler/init_buttons.c index a29b3d2b..71dca78d 100644 --- a/node/code/modules/io_handler/init_buttons.c +++ b/node/code/modules/io_handler/init_buttons.c @@ -17,6 +17,7 @@ */ #include "init_buttons.h" +#include "ztimer.h" #define ENABLE_DEBUG 1 #include "debug.h" @@ -32,6 +33,10 @@ gpio_t button_left = GPIO_PIN(0, 3); //PIN A5 gpio_t vibr_gpio = GPIO_PIN(1, 9); gpio_mode_t vibr_gpio_mode = GPIO_OUT; //Define the vibr. GPIO as Output GPIO +bool long_pressed = false; +ztimer_t timeout = { .callback=timer_long_pressed_cb }; + + int init_buttons(void) { puts("Buttons initialization..."); @@ -51,6 +56,11 @@ int init_buttons(void) return 0; } +void timer_long_pressed_cb(void *arg) { + (void) arg; + long_pressed = true; +} + //Vibrate for msec milliseconds: void vibrate(uint16_t msec) { @@ -63,11 +73,9 @@ void button_up_callback (void *arg) { (void) arg; /* the argument is not used */ if (!gpio_read(button_up)) { - DEBUG("Button up pressed!\n"); trigger_event(BUTTON_UP_PRESSED); } else { - DEBUG("Button up released!\n"); trigger_event(BUTTON_UP_RELEASED); } } @@ -76,11 +84,9 @@ void button_left_callback (void *arg) { (void) arg; /* the argument is not used */ if (!gpio_read(button_left)) { - DEBUG("Button left pressed!\n"); trigger_event(BUTTON_LEFT_PRESSED); } else { - DEBUG("Button left released!\n"); trigger_event(BUTTON_LEFT_RELEASED); } } @@ -89,11 +95,9 @@ void button_down_callback (void *arg) { (void) arg; /* the argument is not used */ if (!gpio_read(button_down)) { - DEBUG("Button down pressed!\n"); trigger_event(BUTTON_DOWN_PRESSED); } else { - DEBUG("Button down released!\n"); trigger_event(BUTTON_DOWN_RELEASED); } } @@ -102,11 +106,9 @@ void button_right_callback (void *arg) { (void) arg; /* the argument is not used */ if (!gpio_read(button_right)) { - DEBUG("Button right pressed!\n"); trigger_event(BUTTON_RIGHT_PRESSED); } else { - DEBUG("Button right released!\n"); trigger_event(BUTTON_RIGHT_RELEASED); } } @@ -115,11 +117,19 @@ void button_ok_callback (void *arg) { (void) arg; /* the argument is not used */ if (!gpio_read(button_ok)) { - DEBUG("Button ok pressed!\n"); + long_pressed = false; + //ztimer_t timeout = { .callback=timer_long_pressed_cb }; + ztimer_set(ZTIMER_SEC, &timeout, 1); trigger_event(BUTTON_OK_PRESSED); } else { - DEBUG("Button ok released!\n"); + if (long_pressed) { + long_pressed = false; + trigger_event(BUTTON_OK_LONG); + } + trigger_event(BUTTON_OK_RELEASED); + ztimer_remove(ZTIMER_SEC, &timeout); } } +//EOF diff --git a/node/code/modules/io_handler/io_handler.c b/node/code/modules/io_handler/io_handler.c index a94f4e8a..a5b3582d 100644 --- a/node/code/modules/io_handler/io_handler.c +++ b/node/code/modules/io_handler/io_handler.c @@ -30,7 +30,6 @@ void io_init(void){ } handler_result_t ioHandler_handleEvent(EVENT_T event){ - DEBUG("[IoHandler:handleEvent]\n"); switch(event){ case VIBRATE: DEBUG("[IoHandler:handleEvent]: vibrate\n"); @@ -39,5 +38,5 @@ handler_result_t ioHandler_handleEvent(EVENT_T event){ default: break; } - return EVENT_HANDLED; + return HANDLED; } diff --git a/node/code/modules/lwm2m_handler/lwm2m_handler.c b/node/code/modules/lwm2m_handler/lwm2m_handler.c index 17c4a4a8..0b8707d6 100644 --- a/node/code/modules/lwm2m_handler/lwm2m_handler.c +++ b/node/code/modules/lwm2m_handler/lwm2m_handler.c @@ -197,6 +197,6 @@ handler_result_t lwm2m_handleEvent(EVENT_T event){ default: break; } - return EVENT_HANDLED; + return HANDLED; }