Skip to content

Commit

Permalink
added stats view (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasseb committed Jun 24, 2024
2 parents 411e1d1 + b0173ce commit b20e1ef
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 53 deletions.
5 changes: 5 additions & 0 deletions node/code/modules/display_handler/display_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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();
Expand All @@ -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;
}
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 @@ -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
}
Expand Down
93 changes: 45 additions & 48 deletions node/code/modules/display_handler/init_lvgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -282,26 +277,26 @@ 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);
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,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);
Expand All @@ -316,22 +311,22 @@ 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);
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,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);
Expand All @@ -347,15 +342,15 @@ 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);
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,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);
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions node/code/modules/fsm/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
6 changes: 3 additions & 3 deletions node/code/modules/fsm/include/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef enum {
BUTTON_DOWN_RELEASED,
BUTTON_RIGHT_PRESSED,
BUTTON_RIGHT_RELEASED,
INFO_PRESSED,
PET_FEED,
PET_PLAY,
PET_CLEAN,
Expand All @@ -56,6 +57,7 @@ typedef enum {
REGISTER,
REGISTERED,
READY,
INFO,
REGISTER_CODE,
NAME,
COLOR,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b20e1ef

Please sign in to comment.