Skip to content

Commit

Permalink
State Machine, Registration, Buttons & Friends (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnsAnns authored Jun 24, 2024
2 parents 95ff62f + a24b831 commit db614b1
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 205 deletions.
32 changes: 17 additions & 15 deletions node/code/inc/shell_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "shell.h"
#include <stdio.h>
#include "events.h"
#include <stdlib.h>

static int echo_command(int argc, char **argv)
{
Expand All @@ -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 <event>");
// return 1;
// }
static int send_event(int argc, char **argv) {
if (argc != 2) {
puts("usage: send_event <event_id>");
return 1;
}

int event_id = atoi(argv[1]);
if (event_id < 0) {
puts("usage: send_event <event_id>");
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 }
};

Expand Down
3 changes: 1 addition & 2 deletions node/code/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 7 additions & 3 deletions node/code/modules/display_handler/display_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
1 change: 1 addition & 0 deletions node/code/modules/display_handler/include/init_lvgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion node/code/modules/display_handler/init_lvgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions node/code/modules/fsm/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit db614b1

Please sign in to comment.