firmware: Add menu and idle states
This commit is contained in:
		@@ -1,3 +1,6 @@
 | 
			
		||||
idf_component_register(
 | 
			
		||||
  SRCS "valconomy.c" "ui.c" "lcd.c" "usb.c" "font/tungsten_40.c" "font/tungsten_180.c" "img/bg.c" "img/moon.c" "img/star.c"
 | 
			
		||||
  SRCS
 | 
			
		||||
    "font/tungsten_40.c" "font/tungsten_180.c"
 | 
			
		||||
    "img/bg.c" "img/moon.c" "img/star.c" "img/sleep.c"
 | 
			
		||||
    "valconomy.c" "ui.c" "lcd.c" "usb.c"
 | 
			
		||||
  INCLUDE_DIRS ".")
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,7 @@ static lv_obj_t *o_container = NULL;
 | 
			
		||||
 | 
			
		||||
static lv_anim_timeline_t *at_active = NULL;
 | 
			
		||||
static lv_obj_t *o_active = NULL;
 | 
			
		||||
static bool state_ready = true;
 | 
			
		||||
 | 
			
		||||
static const void* imgfont_get_path(
 | 
			
		||||
    const lv_font_t *font, uint32_t unicode, uint32_t unicode_next, int32_t *offset_y, void *user_data) {
 | 
			
		||||
@@ -28,6 +29,8 @@ static const void* imgfont_get_path(
 | 
			
		||||
    return &ui_img_moon;
 | 
			
		||||
  case 0x2B50:
 | 
			
		||||
    return &ui_img_star;
 | 
			
		||||
  case 0x1F634:
 | 
			
		||||
    return &ui_img_sleep;
 | 
			
		||||
  default:
 | 
			
		||||
    return NULL;
 | 
			
		||||
  }
 | 
			
		||||
@@ -41,6 +44,9 @@ static void b_cfg_cb(lv_event_t *e) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void setup_next_state() {
 | 
			
		||||
  assert(state_ready);
 | 
			
		||||
  state_ready = false;
 | 
			
		||||
 | 
			
		||||
  if (at_active) {
 | 
			
		||||
    lv_anim_timeline_delete(at_active);
 | 
			
		||||
    at_active = NULL;
 | 
			
		||||
@@ -59,6 +65,13 @@ static void setup_next_state() {
 | 
			
		||||
  at_active = lv_anim_timeline_create();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool val_ui_state_ready() {
 | 
			
		||||
  return state_ready;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void anim_state_ready_cb(lv_anim_t *anim) {
 | 
			
		||||
  state_ready = true;
 | 
			
		||||
}
 | 
			
		||||
static void anim_x_cb(void *var, int32_t v) {
 | 
			
		||||
  lv_obj_set_x(var, v);
 | 
			
		||||
}
 | 
			
		||||
@@ -75,6 +88,7 @@ static void anim_val_time_text(lv_anim_t *anim) {
 | 
			
		||||
void val_ui_none() {
 | 
			
		||||
  setup_next_state();
 | 
			
		||||
 | 
			
		||||
  // Widgets
 | 
			
		||||
  lv_obj_t *l_main = lv_label_create(o_active);
 | 
			
		||||
  lv_obj_add_style(l_main, &s_hero, 0);
 | 
			
		||||
  lv_obj_center(l_main);
 | 
			
		||||
@@ -105,14 +119,6 @@ void val_ui_none() {
 | 
			
		||||
  lv_anim_set_path_cb(&a_hello_in, lv_anim_path_ease_in);
 | 
			
		||||
  lv_anim_set_duration(&a_hello_in, 500);
 | 
			
		||||
 | 
			
		||||
  lv_anim_t a_sub;
 | 
			
		||||
  lv_anim_init(&a_sub);
 | 
			
		||||
  lv_anim_set_var(&a_sub, l_subtitle);
 | 
			
		||||
  lv_anim_set_values(&a_sub, 0, 255);
 | 
			
		||||
  lv_anim_set_exec_cb(&a_sub, anim_opa_cb);
 | 
			
		||||
  lv_anim_set_path_cb(&a_sub, lv_anim_path_linear);
 | 
			
		||||
  lv_anim_set_duration(&a_sub, 750);
 | 
			
		||||
 | 
			
		||||
  lv_anim_t a_hello_out;
 | 
			
		||||
  lv_anim_init(&a_hello_out);
 | 
			
		||||
  lv_anim_set_var(&a_hello_out, l_main);
 | 
			
		||||
@@ -131,6 +137,15 @@ void val_ui_none() {
 | 
			
		||||
  lv_anim_set_path_cb(&a_val, lv_anim_path_linear);
 | 
			
		||||
  lv_anim_set_duration(&a_val, 500);
 | 
			
		||||
 | 
			
		||||
  lv_anim_t a_sub;
 | 
			
		||||
  lv_anim_init(&a_sub);
 | 
			
		||||
  lv_anim_set_var(&a_sub, l_subtitle);
 | 
			
		||||
  lv_anim_set_values(&a_sub, 0, 255);
 | 
			
		||||
  lv_anim_set_exec_cb(&a_sub, anim_opa_cb);
 | 
			
		||||
  lv_anim_set_path_cb(&a_sub, lv_anim_path_linear);
 | 
			
		||||
  lv_anim_set_completed_cb(&a_sub, anim_state_ready_cb);
 | 
			
		||||
  lv_anim_set_duration(&a_sub, 750);
 | 
			
		||||
 | 
			
		||||
  lv_anim_timeline_add(at_active, 0, &a_hello_in);
 | 
			
		||||
  lv_anim_timeline_add(at_active, 3000, &a_hello_out);
 | 
			
		||||
  lv_anim_timeline_add(at_active, 3250, &a_val);
 | 
			
		||||
@@ -138,6 +153,87 @@ void val_ui_none() {
 | 
			
		||||
  lv_anim_timeline_start(at_active);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void val_ui_menu(bool was_idle) {
 | 
			
		||||
  setup_next_state();
 | 
			
		||||
 | 
			
		||||
  // Widgets
 | 
			
		||||
  lv_obj_t *l_main = lv_label_create(o_active);
 | 
			
		||||
  lv_obj_add_style(l_main, &s_hero, 0);
 | 
			
		||||
  lv_obj_center(l_main);
 | 
			
		||||
  lv_label_set_text_static(l_main, "LET'S GO");
 | 
			
		||||
 | 
			
		||||
  lv_obj_t *l_subtitle = lv_label_create(o_active);
 | 
			
		||||
  lv_obj_add_style(l_subtitle, &s_subtitle, 0);
 | 
			
		||||
  lv_obj_center(l_subtitle);
 | 
			
		||||
  lv_label_set_text_static(l_subtitle, was_idle ? "WELCOME BACK!" : "GET QUEUEING!");
 | 
			
		||||
 | 
			
		||||
  lv_obj_update_layout(o_active);
 | 
			
		||||
 | 
			
		||||
  // Animations
 | 
			
		||||
  lv_anim_t a_title;
 | 
			
		||||
  lv_anim_init(&a_title);
 | 
			
		||||
  lv_anim_set_var(&a_title, l_main);
 | 
			
		||||
  lv_anim_set_values(
 | 
			
		||||
    &a_title,
 | 
			
		||||
    -(lv_obj_get_height(o_container) - lv_obj_get_height(l_main)) / 2, 0);
 | 
			
		||||
  lv_anim_set_exec_cb(&a_title, anim_y_cb);
 | 
			
		||||
  lv_anim_set_path_cb(&a_title, lv_anim_path_ease_in);
 | 
			
		||||
  lv_anim_set_duration(&a_title, 500);
 | 
			
		||||
 | 
			
		||||
  lv_anim_t a_sub;
 | 
			
		||||
  lv_anim_init(&a_sub);
 | 
			
		||||
  lv_anim_set_var(&a_sub, l_subtitle);
 | 
			
		||||
  lv_anim_set_values(
 | 
			
		||||
    &a_sub,
 | 
			
		||||
    (lv_obj_get_height(o_container) - lv_obj_get_height(l_main)) / 2,
 | 
			
		||||
    (lv_obj_get_height(l_main) + lv_obj_get_height(l_subtitle)) / 2 + 5);
 | 
			
		||||
  lv_anim_set_exec_cb(&a_sub, anim_y_cb);
 | 
			
		||||
  lv_anim_set_path_cb(&a_sub, lv_anim_path_ease_in);
 | 
			
		||||
  lv_anim_set_completed_cb(&a_sub, anim_state_ready_cb);
 | 
			
		||||
  lv_anim_set_duration(&a_sub, 500);
 | 
			
		||||
 | 
			
		||||
  lv_anim_timeline_add(at_active, 0, &a_title);
 | 
			
		||||
  lv_anim_timeline_add(at_active, 0, &a_sub);
 | 
			
		||||
  lv_anim_timeline_start(at_active);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void val_ui_idle() {
 | 
			
		||||
  setup_next_state();
 | 
			
		||||
 | 
			
		||||
  // Widgets
 | 
			
		||||
  lv_obj_t *l_main = lv_label_create(o_active);
 | 
			
		||||
  lv_obj_add_style(l_main, &s_hero, 0);
 | 
			
		||||
  lv_obj_center(l_main);
 | 
			
		||||
  lv_label_set_text_static(l_main, "\U0001F634");
 | 
			
		||||
 | 
			
		||||
  lv_obj_t *l_subtitle = lv_label_create(o_active);
 | 
			
		||||
  lv_obj_add_style(l_subtitle, &s_subtitle, 0);
 | 
			
		||||
  lv_obj_center(l_subtitle);
 | 
			
		||||
  lv_label_set_text_static(l_subtitle, "COME BACK SOON...");
 | 
			
		||||
 | 
			
		||||
  lv_obj_update_layout(o_active);
 | 
			
		||||
  lv_obj_set_y(
 | 
			
		||||
    l_subtitle,
 | 
			
		||||
    (lv_obj_get_height(l_main) + lv_obj_get_height(l_subtitle)) / 2 + 5);
 | 
			
		||||
 | 
			
		||||
  // Animations
 | 
			
		||||
  lv_anim_t a_fade_in;
 | 
			
		||||
  lv_anim_init(&a_fade_in);
 | 
			
		||||
  lv_anim_set_values(&a_fade_in, 0, 255);
 | 
			
		||||
  lv_anim_set_exec_cb(&a_fade_in, anim_opa_cb);
 | 
			
		||||
  lv_anim_set_path_cb(&a_fade_in, lv_anim_path_ease_in);
 | 
			
		||||
  lv_anim_set_duration(&a_fade_in, 1000);
 | 
			
		||||
 | 
			
		||||
  lv_anim_set_var(&a_fade_in, l_main);
 | 
			
		||||
  lv_anim_timeline_add(at_active, 0, &a_fade_in);
 | 
			
		||||
 | 
			
		||||
  lv_anim_set_var(&a_fade_in, l_subtitle);
 | 
			
		||||
  lv_anim_set_completed_cb(&a_fade_in, anim_state_ready_cb);
 | 
			
		||||
  lv_anim_timeline_add(at_active, 0, &a_fade_in);
 | 
			
		||||
 | 
			
		||||
  lv_anim_timeline_start(at_active);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void val_lvgl_ui(lv_display_t *disp) {
 | 
			
		||||
  color_primary = lv_color_hex(0xff4655);
 | 
			
		||||
  color_secondary = lv_color_hex(0xf7518f);
 | 
			
		||||
@@ -184,5 +280,7 @@ void val_lvgl_ui(lv_display_t *disp) {
 | 
			
		||||
  lv_label_set_text(l_cfg, LV_SYMBOL_SETTINGS);
 | 
			
		||||
  lv_obj_center(l_cfg);
 | 
			
		||||
 | 
			
		||||
  val_ui_none();
 | 
			
		||||
  // val_ui_none();
 | 
			
		||||
  // val_ui_menu(true);
 | 
			
		||||
  val_ui_idle();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,5 +8,12 @@ LV_FONT_DECLARE(lv_font_tungsten_180)
 | 
			
		||||
LV_IMAGE_DECLARE(ui_img_bg);
 | 
			
		||||
LV_IMAGE_DECLARE(ui_img_moon);
 | 
			
		||||
LV_IMAGE_DECLARE(ui_img_star);
 | 
			
		||||
LV_IMAGE_DECLARE(ui_img_sleep);
 | 
			
		||||
 | 
			
		||||
bool val_ui_state_ready();
 | 
			
		||||
 | 
			
		||||
void val_ui_none();
 | 
			
		||||
void val_ui_menu(bool was_idle);
 | 
			
		||||
void val_ui_idle();
 | 
			
		||||
 | 
			
		||||
void val_lvgl_ui(lv_display_t *disp);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user