diff --git a/node/code/modules/display_handler/display_handler.c b/node/code/modules/display_handler/display_handler.c index 71e606b7..98655863 100644 --- a/node/code/modules/display_handler/display_handler.c +++ b/node/code/modules/display_handler/display_handler.c @@ -29,6 +29,7 @@ char display_thread_stack [DISPLAY_STACKSIZE]; handler_result_t displayHandler_handleEvent(EVENT_T event){ + char buf[100]; DEBUG("[DisplayHandler:handleEvent]\n"); switch(event){ case BUTTON_OK_PRESSED: @@ -48,6 +49,7 @@ handler_result_t displayHandler_handleEvent(EVENT_T event){ break; case BUTTON_DOWN_RELEASED: down_released(); + init_registered_pet(); break; case BUTTON_LEFT_PRESSED: left_pressed(); @@ -67,6 +69,9 @@ handler_result_t displayHandler_handleEvent(EVENT_T event){ case REGISTERED: init_registered_pet(); break; + case INFO: + get_pet_stats((char*)&buf); + init_pet_stats((char*)&buf); default: break; } diff --git a/node/code/modules/display_handler/include/init_lvgl.h b/node/code/modules/display_handler/include/init_lvgl.h index 801b5c7c..65879745 100644 --- a/node/code/modules/display_handler/include/init_lvgl.h +++ b/node/code/modules/display_handler/include/init_lvgl.h @@ -22,6 +22,7 @@ void right_pressed(void); void right_released(void); void init_not_registered_code(char* code); void init_registered_pet(void); +void init_pet_stats(char* stats); #ifdef __cplusplus } diff --git a/node/code/modules/display_handler/init_lvgl.c b/node/code/modules/display_handler/init_lvgl.c index c67eba50..708f16da 100644 --- a/node/code/modules/display_handler/init_lvgl.c +++ b/node/code/modules/display_handler/init_lvgl.c @@ -107,13 +107,8 @@ 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 && (img_index_pairs[current_img_index].event == PET_FEED || - img_index_pairs[current_img_index].event == PET_PLAY || - img_index_pairs[current_img_index].event == PET_MEDICATE || - img_index_pairs[current_img_index].event == PET_CLEAN)){ - // msg_t message; - // message.type = img_index_pairs[current_img_index].event ; - // msg_try_send(&message, dispatcher_pid_lvgl); + }else if (key == LV_KEY_ENTER){ + trigger_event(img_index_pairs[current_img_index].event); } } } @@ -282,7 +277,7 @@ static void timer_cb(lv_timer_t *param){ void init_not_registered(void){ - // /* Style of the align bar*/ + /* Style of the align bar*/ static lv_style_t style_align; lv_style_init(&style_align); lv_style_set_border_width(&style_align,0); @@ -290,18 +285,18 @@ void init_not_registered(void){ lv_style_set_bg_opa(&style_align,LV_OPA_TRANSP); lv_style_set_width(&style_align,240); lv_style_set_height(&style_align,70); - // // /*Create a container for align*/ + /*Create a container for align*/ lv_obj_t *align = lv_obj_create(center); lv_obj_center(align); lv_obj_clear_flag(align,LV_OBJ_FLAG_SCROLLABLE); lv_obj_add_style(align,&style_align,LV_PART_MAIN); lv_obj_align(align, LV_ALIGN_CENTER,0,0); - // // // // /*Create a spinner*/ + /*Create a spinner*/ lv_obj_t * spinner = lv_spinner_create(align,10000,100); lv_obj_set_size(spinner, 50, 50); lv_obj_align(spinner, LV_ALIGN_RIGHT_MID,0,0); - // // /* Create registering label*/ + /* Create registering label*/ lv_obj_t * registering_label = lv_label_create(align); lv_label_set_text(registering_label,"connecting"); lv_obj_set_style_text_color(registering_label, lv_color_hex(0x000000), LV_PART_MAIN); @@ -316,7 +311,7 @@ void init_not_registered(void){ void init_not_registered_code(char *code){ // timer_deactivate(); lv_obj_clean(center); - // /* Style of the align bar*/ + /* Style of the align bar*/ static lv_style_t style_align; lv_style_init(&style_align); lv_style_set_border_width(&style_align,0); @@ -324,14 +319,14 @@ void init_not_registered_code(char *code){ lv_style_set_bg_opa(&style_align,LV_OPA_TRANSP); lv_style_set_width(&style_align,240); lv_style_set_height(&style_align,70); - // // /*Create a container for align*/ + /*Create a container for align*/ lv_obj_t *align = lv_obj_create(center); lv_obj_center(align); lv_obj_clear_flag(align,LV_OBJ_FLAG_SCROLLABLE); lv_obj_add_style(align,&style_align,LV_PART_MAIN); lv_obj_align(align, LV_ALIGN_CENTER,0,0); - // // /* Create registering label*/ + /* Create registering label*/ lv_obj_t * registering_label = lv_label_create(align); lv_label_set_text(registering_label,code); lv_obj_set_style_text_color(registering_label, lv_color_hex(0x000000), LV_PART_MAIN); @@ -347,7 +342,7 @@ void init_registered_pet(void){ // timer_deactivate(); lv_obj_clean(center); - // /* Style of the align */ + /* Style of the align */ static lv_style_t style_align; lv_style_init(&style_align); lv_style_set_border_width(&style_align,0); @@ -355,7 +350,7 @@ void init_registered_pet(void){ lv_style_set_bg_opa(&style_align,LV_OPA_TRANSP); lv_style_set_width(&style_align,240); lv_style_set_height(&style_align,160); - // // /*Create a container for align*/ + /*Create a container for align*/ lv_obj_t *align = lv_obj_create(center); lv_obj_center(align); lv_obj_clear_flag(align,LV_OBJ_FLAG_SCROLLABLE); @@ -369,6 +364,39 @@ void init_registered_pet(void){ lv_obj_align(pet, LV_ALIGN_CENTER, 0, 0); } +void init_pet_stats(char* stats){ + // timer_deactivate(); + lv_obj_clean(center); + + /* Style of the align */ + static lv_style_t style_align; + lv_style_init(&style_align); + lv_style_set_border_width(&style_align,0); + lv_style_set_radius(&style_align,0); + lv_style_set_bg_opa(&style_align,LV_OPA_TRANSP); + lv_style_set_width(&style_align,240); + lv_style_set_height(&style_align,120); + /*Create a container for align*/ + lv_obj_t *align = lv_obj_create(center); + lv_obj_center(align); + lv_obj_clear_flag(align,LV_OBJ_FLAG_SCROLLABLE); + lv_obj_add_style(align,&style_align,LV_PART_MAIN); + lv_obj_align(align, LV_ALIGN_CENTER,0,0); + + static lv_style_t style; + lv_style_init(&style); + lv_style_set_bg_opa(&style,LV_OPA_50); + lv_style_set_bg_color(&style,lv_color_hex(0x0)); + lv_obj_add_style(align,&style,LV_PART_MAIN); + /* Pet stats*/ + lv_obj_t * stats_label = lv_label_create(align); + lv_label_set_text(stats_label,stats); + + lv_obj_set_style_text_color(stats_label, lv_color_hex(0xFFFFFF), LV_PART_MAIN); + lv_obj_set_style_text_font(stats_label,&lv_font_montserrat_12, LV_PART_MAIN); + lv_obj_align(stats_label, LV_ALIGN_LEFT_MID,0,8); +} + void init_menu(void){ static lv_style_t style; lv_style_init(&style); @@ -410,41 +438,10 @@ 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 = 0; + img_index_pairs[4].event = INFO; lv_obj_add_event_cb(bottom_bar,menu_cb,LV_EVENT_ALL,NULL); lv_group_add_obj(group1,bottom_bar); - // // /* Style of the align */ - // static lv_style_t style_align; - // lv_style_init(&style_align); - // lv_style_set_border_width(&style_align,0); - // // lv_style_set_radius(&style_align,0); - // lv_style_set_bg_opa(&style_align,LV_OPA_TRANSP);; - // // // /*Create a container for align*/ - // lv_obj_t *align = lv_obj_create(center); - // lv_obj_center(align); - // lv_obj_clear_flag(align,LV_OBJ_FLAG_SCROLLABLE); - // lv_obj_add_style(align,&style_align,LV_PART_MAIN); - // lv_obj_align(align, LV_ALIGN_LEFT_MID,-12,0); - // lv_obj_set_size(align,80,140); - - // roller1 = lv_roller_create(align); - // lv_roller_set_options(roller1, - // "Exit\n" - // "Feed\n" - // "Medicate\n" - // "Play\n" - // "Pet\n" - // "Wash", - // LV_ROLLER_MODE_INFINITE); - - // lv_roller_set_visible_row_count(roller1, 4); - // lv_obj_set_size(roller1,79,139); - // lv_obj_align(roller1, LV_ALIGN_CENTER, 0, 0); - // lv_obj_add_event_cb(roller1,menu_cb,LV_EVENT_ALL,NULL); - // lv_group_add_obj(group1,roller1); - // //lv_obj_add_event_cb(roller1, event_handler, LV_EVENT_KEY, NULL); - } int init_lvgl(void) diff --git a/node/code/modules/fsm/events.c b/node/code/modules/fsm/events.c index 7c9b8181..cf4a0d06 100644 --- a/node/code/modules/fsm/events.c +++ b/node/code/modules/fsm/events.c @@ -13,8 +13,9 @@ static msg_t rcv_queue[RCV_QUEUE_SIZE]; pet_stats_t pet_stats; device_register_code register_code; -pet_stats_t* get_pet_stats(void){ - return &pet_stats; +void get_pet_stats(char *buf){ + sprintf(buf,"Happiness: %ld%%\n Wellbeing: %ld%%\n Health: %ld%%\n XP: %ld%%\n Hunger: %ld%%\n Cleanliness: %ld%%\n Fun: %ld%%\n", + pet_stats.happiness, pet_stats.wellbeing, pet_stats.health, pet_stats.xp,pet_stats.hunger, pet_stats.cleanliness, pet_stats.fun); } char* get_register_code(void){ diff --git a/node/code/modules/fsm/include/events.h b/node/code/modules/fsm/include/events.h index 31f1f30e..8764ebb9 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, + INFO_PRESSED, PET_FEED, PET_PLAY, PET_CLEAN, @@ -56,6 +57,7 @@ typedef enum { REGISTER, REGISTERED, READY, + INFO, REGISTER_CODE, NAME, COLOR, @@ -104,10 +106,8 @@ typedef enum /** * @brief Writes the actual pet stats into the parameter pointer * - * - * @param[in] stats The pointer to an pet_stats_t object in which the that gets copied. */ -pet_stats_t* get_pet_stats(void); +void get_pet_stats(char *buf); /** * @brief Writes the register code into the parameter pointer