diff --git a/CYD-Klipper/src/ui/main_ui.cpp b/CYD-Klipper/src/ui/main_ui.cpp index 8b33ae9..4ac8492 100644 --- a/CYD-Klipper/src/ui/main_ui.cpp +++ b/CYD-Klipper/src/ui/main_ui.cpp @@ -11,77 +11,6 @@ #include "switch_printer.h" #include "macros.h" -char extruder_temp_buff[20]; -char bed_temp_buff[20]; -char position_buff[20]; - -static void btn_click_restart(lv_event_t * e){ - send_gcode(false, "RESTART"); -} - -static void btn_click_firmware_restart(lv_event_t * e){ - send_gcode(false, "FIRMWARE_RESTART"); -} - -void error_ui_macros_open(lv_event_t * e){ - macros_draw_power_fullscreen(); -} - -void error_ui(){ - lv_obj_clean(lv_scr_act()); - - lv_obj_t * panel = lv_create_empty_panel(lv_scr_act()); - lv_layout_flex_column(panel); - lv_obj_set_size(panel, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); - lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0); - lv_obj_set_flex_align(panel, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); - - lv_obj_t * label; - label = lv_label_create(panel); - lv_label_set_text(label, LV_SYMBOL_WARNING " Printer is not ready"); - - label = lv_label_create(panel); - lv_label_set_text(label, printer.state_message); - lv_obj_set_width(label, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2); - lv_obj_clear_flag(label, LV_OBJ_FLAG_SCROLLABLE); - lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); - - lv_obj_t * button_row = lv_create_empty_panel(panel); - lv_obj_set_size(button_row, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_layout_flex_row(button_row); - - lv_obj_t * btn = lv_btn_create(button_row); - lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_obj_add_event_cb(btn, btn_click_restart, LV_EVENT_CLICKED, NULL); - lv_obj_set_flex_grow(btn, 1); - - label = lv_label_create(btn); - lv_label_set_text(label, "Restart"); - lv_obj_center(label); - - btn = lv_btn_create(button_row); - lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_obj_add_event_cb(btn, btn_click_firmware_restart, LV_EVENT_CLICKED, NULL); - lv_obj_set_flex_grow(btn, 1); - - label = lv_label_create(btn); - lv_label_set_text(label, "FW Restart"); - lv_obj_center(label); - - if (power_devices_count() >= 1){ - btn = lv_btn_create(button_row); - lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_obj_add_event_cb(btn, error_ui_macros_open, LV_EVENT_CLICKED, NULL); - lv_obj_set_flex_grow(btn, 1); - - label = lv_label_create(btn); - lv_label_set_text(label, "Devices"); - lv_obj_center(label); - } - - draw_switch_printer_button(); -} - void check_if_screen_needs_to_be_disabled(){ if (global_config.on_during_print && printer.state == PRINTER_STATE_PRINTING){ screen_timer_wake(); @@ -96,10 +25,10 @@ static void on_state_change(void * s, lv_msg_t * m){ check_if_screen_needs_to_be_disabled(); if (printer.state == PRINTER_STATE_ERROR){ - error_ui(); + nav_buttons_setup(PANEL_ERROR); } else { - nav_buttons_setup(0); + nav_buttons_setup(PANEL_PRINT); } } diff --git a/CYD-Klipper/src/ui/nav_buttons.cpp b/CYD-Klipper/src/ui/nav_buttons.cpp index cf6a29f..aa2d0d2 100644 --- a/CYD-Klipper/src/ui/nav_buttons.cpp +++ b/CYD-Klipper/src/ui/nav_buttons.cpp @@ -58,27 +58,31 @@ static void update_printer_data_time(lv_event_t * e){ } static void btn_click_files(lv_event_t * e){ - nav_buttons_setup(0); + nav_buttons_setup(PANEL_PRINT); } static void btn_click_move(lv_event_t * e){ - nav_buttons_setup(1); + nav_buttons_setup(PANEL_MOVE); } static void btn_click_extrude(lv_event_t * e){ - nav_buttons_setup(2); + nav_buttons_setup(PANEL_TEMP); } static void btn_click_settings(lv_event_t * e){ - nav_buttons_setup(3); + nav_buttons_setup(PANEL_SETTINGS); } static void btn_click_macros(lv_event_t * e){ - nav_buttons_setup(4); + nav_buttons_setup(PANEL_MACROS); } static void btn_click_printer(lv_event_t * e){ - nav_buttons_setup(6); + nav_buttons_setup(PANEL_PRINTER); +} + +static void btn_click_err(lv_event_t * e){ + nav_buttons_setup(PANEL_ERROR); } void create_button(const char* icon, const char* name, lv_event_cb_t button_click, lv_event_cb_t label_update, lv_obj_t * root){ @@ -124,20 +128,27 @@ void nav_buttons_setup(unsigned char active_panel){ #endif - // Files/Print - create_button(LV_SYMBOL_COPY, "Idle", btn_click_files, update_printer_data_time, root_panel); + if (printer.state != PRINTER_STATE_ERROR){ + // Files/Print + create_button(LV_SYMBOL_COPY, "Idle", btn_click_files, update_printer_data_time, root_panel); - // Move - create_button(printer.state == PRINTER_STATE_PRINTING ? LV_SYMBOL_EDIT : LV_SYMBOL_CHARGE, "Z?", btn_click_move, update_printer_data_z_pos, root_panel); + // Move + create_button(printer.state == PRINTER_STATE_PRINTING ? LV_SYMBOL_EDIT : LV_SYMBOL_CHARGE, "Z?", btn_click_move, update_printer_data_z_pos, root_panel); - // Extrude/Temp - create_button(LV_SYMBOL_WARNING, "?/?", btn_click_extrude, update_printer_data_temp, root_panel); + // Extrude/Temp + create_button(LV_SYMBOL_WARNING, "?/?", btn_click_extrude, update_printer_data_temp, root_panel); + } + else { + // Error UI + create_button(LV_SYMBOL_WARNING, "Error", btn_click_err, NULL, root_panel); + } // Macros create_button(LV_SYMBOL_GPS, "Macro", btn_click_macros, NULL, root_panel); if (global_config.multi_printer_mode) { + // Printers create_button(LV_SYMBOL_HOME, "Printer", btn_click_printer, NULL, root_panel); } @@ -146,27 +157,30 @@ void nav_buttons_setup(unsigned char active_panel){ lv_obj_align(panel, LV_ALIGN_TOP_RIGHT, 0, 0); switch (active_panel){ - case 0: + case PANEL_PRINT: print_panel_init(panel); break; - case 1: + case PANEL_MOVE: move_panel_init(panel); break; - case 2: + case PANEL_TEMP: temp_panel_init(panel); break; - case 3: + case PANEL_SETTINGS: settings_panel_init(panel); break; - case 4: + case PANEL_MACROS: macros_panel_init(panel); break; - case 5: + case PANEL_STATS: stats_panel_init(panel); break; - case 6: + case PANEL_PRINTER: printer_panel_init(panel); break; + case PANEL_ERROR: + error_panel_init(panel); + break; } lv_msg_send(DATA_PRINTER_DATA, &printer); diff --git a/CYD-Klipper/src/ui/nav_buttons.h b/CYD-Klipper/src/ui/nav_buttons.h index 5ba07de..b1c6c10 100644 --- a/CYD-Klipper/src/ui/nav_buttons.h +++ b/CYD-Klipper/src/ui/nav_buttons.h @@ -1,2 +1,13 @@ +#pragma once + +#define PANEL_PRINT 0 +#define PANEL_MOVE 1 +#define PANEL_TEMP 2 +#define PANEL_SETTINGS 3 +#define PANEL_MACROS 4 +#define PANEL_STATS 5 +#define PANEL_PRINTER 6 +#define PANEL_ERROR 7 + void nav_buttons_setup(unsigned char active_panel); void nav_style_setup(); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/error_panel.cpp b/CYD-Klipper/src/ui/panels/error_panel.cpp new file mode 100644 index 0000000..10a28ba --- /dev/null +++ b/CYD-Klipper/src/ui/panels/error_panel.cpp @@ -0,0 +1,53 @@ +#include "panel.h" +#include "../../core/data_setup.h" +#include "../ui_utils.h" + +static void btn_click_restart(lv_event_t * e){ + send_gcode(false, "RESTART"); +} + +static void btn_click_firmware_restart(lv_event_t * e){ + send_gcode(false, "FIRMWARE_RESTART"); +} + +void error_panel_init(lv_obj_t* panel) +{ + lv_layout_flex_column(panel, LV_FLEX_ALIGN_SPACE_BETWEEN); + lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0); + + lv_obj_t * label; + label = lv_label_create(panel); + lv_label_set_text(label, LV_SYMBOL_WARNING " Printer is not ready"); + + lv_obj_t * panel_with_text = lv_create_empty_panel(panel); + lv_layout_flex_column(panel_with_text, LV_FLEX_ALIGN_START); + lv_obj_set_flex_grow(panel_with_text, 1); + lv_obj_set_width(panel_with_text, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2); + + label = lv_label_create(panel_with_text); + lv_label_set_text(label, printer.state_message); + lv_obj_set_width(label, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2); + lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); + + lv_obj_t * button_row = lv_create_empty_panel(panel); + lv_obj_set_size(button_row, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_layout_flex_row(button_row); + + lv_obj_t * btn = lv_btn_create(button_row); + lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_add_event_cb(btn, btn_click_restart, LV_EVENT_CLICKED, NULL); + lv_obj_set_flex_grow(btn, 1); + + label = lv_label_create(btn); + lv_label_set_text(label, "Restart"); + lv_obj_center(label); + + btn = lv_btn_create(button_row); + lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_add_event_cb(btn, btn_click_firmware_restart, LV_EVENT_CLICKED, NULL); + lv_obj_set_flex_grow(btn, 1); + + label = lv_label_create(btn); + lv_label_set_text(label, "FW Restart"); + lv_obj_center(label); +} \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/macros_panel.cpp b/CYD-Klipper/src/ui/panels/macros_panel.cpp index 6245f97..295eaca 100644 --- a/CYD-Klipper/src/ui/panels/macros_panel.cpp +++ b/CYD-Klipper/src/ui/panels/macros_panel.cpp @@ -7,7 +7,7 @@ #include static void btn_goto_settings(lv_event_t * e){ - nav_buttons_setup(3); + nav_buttons_setup(PANEL_SETTINGS); } void macros_panel_init(lv_obj_t* panel) { diff --git a/CYD-Klipper/src/ui/panels/move_panel.cpp b/CYD-Klipper/src/ui/panels/move_panel.cpp index 2ffc264..913339d 100644 --- a/CYD-Klipper/src/ui/panels/move_panel.cpp +++ b/CYD-Klipper/src/ui/panels/move_panel.cpp @@ -85,7 +85,7 @@ static void disable_steppers_click(lv_event_t * e) { static void switch_to_stat_panel(lv_event_t * e) { lv_obj_t * panel = lv_event_get_target(e); - nav_buttons_setup(5); + nav_buttons_setup(PANEL_STATS); } inline void root_panel_steppers_locked(lv_obj_t * root_panel){ diff --git a/CYD-Klipper/src/ui/panels/panel.h b/CYD-Klipper/src/ui/panels/panel.h index a6c1aa8..70223ad 100644 --- a/CYD-Klipper/src/ui/panels/panel.h +++ b/CYD-Klipper/src/ui/panels/panel.h @@ -10,4 +10,5 @@ void move_panel_init(lv_obj_t* panel); void progress_panel_init(lv_obj_t* panel); void macros_panel_init(lv_obj_t* panel); void stats_panel_init(lv_obj_t* panel); -void printer_panel_init(lv_obj_t* panel); \ No newline at end of file +void printer_panel_init(lv_obj_t* panel); +void error_panel_init(lv_obj_t* panel); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/printer_panel.cpp b/CYD-Klipper/src/ui/panels/printer_panel.cpp index bc2ef52..6e8dfd6 100644 --- a/CYD-Klipper/src/ui/panels/printer_panel.cpp +++ b/CYD-Klipper/src/ui/panels/printer_panel.cpp @@ -163,7 +163,7 @@ static void btn_printer_delete(lv_event_t * e) config->ip_configured = false; write_global_config(); - nav_buttons_setup(6); + nav_buttons_setup(PANEL_PRINTER); } // TODO: Extract this from temp/print panel and combine diff --git a/CYD-Klipper/src/ui/panels/settings_panel.cpp b/CYD-Klipper/src/ui/panels/settings_panel.cpp index 12fdad9..ecc124d 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -111,7 +111,7 @@ static void multi_printer_switch(lv_event_t* e){ bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); global_config.multi_printer_mode = checked; write_global_config(); - nav_buttons_setup(3); + nav_buttons_setup(PANEL_SETTINGS); } const char* estimated_time_options = "Percentage\nInterpolated\nSlicer";