diff --git a/CYD-Klipper/src/conf/global_config.cpp b/CYD-Klipper/src/conf/global_config.cpp index cff6515..d282551 100644 --- a/CYD-Klipper/src/conf/global_config.cpp +++ b/CYD-Klipper/src/conf/global_config.cpp @@ -10,8 +10,8 @@ COLOR_DEF color_defs[] = { {LV_PALETTE_GREY, 0, LV_PALETTE_CYAN}, {LV_PALETTE_YELLOW, -2, LV_PALETTE_PINK}, {LV_PALETTE_ORANGE, -2, LV_PALETTE_BLUE}, - {LV_PALETTE_RED, 0, LV_PALETTE_GREEN}, - {LV_PALETTE_PURPLE, 0, LV_PALETTE_GREY}, + {LV_PALETTE_RED, 0, LV_PALETTE_BLUE}, + {LV_PALETTE_PURPLE, 0, LV_PALETTE_CYAN}, }; void write_global_config() diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index dd5ca4e..28ff021 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -340,7 +340,7 @@ void fetch_printer_data_minimal() data[i].state = PRINTER_STATE_ERROR; } - data[i].power_devices = 0; + data[i].power_devices = power_devices_count(config); JsonDocument doc; deserializeJson(doc, client.getStream()); auto status = doc["result"]["status"]; diff --git a/CYD-Klipper/src/ui/panels/printer_panel.cpp b/CYD-Klipper/src/ui/panels/printer_panel.cpp index 1816ade..f2628eb 100644 --- a/CYD-Klipper/src/ui/panels/printer_panel.cpp +++ b/CYD-Klipper/src/ui/panels/printer_panel.cpp @@ -51,6 +51,21 @@ static void update_printer_status_text(lv_event_t * e) lv_label_set_text(label, printer_status[printer->state]); } +static void update_printer_button_active_printer(lv_event_t * e) +{ + lv_obj_t * btn = lv_event_get_target(e); + PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); + + if (config == get_current_printer_config()) + { + lv_obj_add_state(btn, LV_STATE_CHECKED); + } + else + { + lv_obj_clear_state(btn, LV_STATE_CHECKED); + } +} + static void update_printer_percentage_bar(lv_event_t * e) { lv_obj_t * percentage = lv_event_get_target(e); @@ -92,7 +107,7 @@ static void update_printer_control_button_text(lv_event_t * e) int index = config - global_config.printer_config; PrinterMinimal * printer = &printer_minimal[index]; - if (printer->state == PRINTER_STATE_OFFLINE && printer->power_devices > 0) + if (printer->power_devices > 0 && (config == get_current_printer_config() || printer->state == PRINTER_STATE_OFFLINE)) { lv_label_set_text(label, "Power"); } @@ -102,20 +117,18 @@ static void update_printer_control_button_text(lv_event_t * e) } } -static void btn_enable_delete(lv_event_t * e) +static void btn_set_secondary_button_text(lv_event_t * e) { - lv_obj_t * btn = lv_event_get_target(e); + lv_obj_t * label = lv_event_get_target(e); PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); if (config == get_current_printer_config()) { - // Disable - lv_obj_add_state(btn, LV_STATE_DISABLED); + lv_label_set_text(label, LV_SYMBOL_SETTINGS); } else { - // Enable - lv_obj_clear_state(btn, LV_STATE_DISABLED); + lv_label_set_text(label, LV_SYMBOL_TRASH); } } @@ -126,7 +139,7 @@ static void btn_enable_control(lv_event_t * e) int index = config - global_config.printer_config; PrinterMinimal * printer = &printer_minimal[index]; - if (config == get_current_printer_config() || (printer->state == PRINTER_STATE_OFFLINE && printer->power_devices <= 0)) + if ((config == get_current_printer_config() || printer->state == PRINTER_STATE_OFFLINE) && printer->power_devices <= 0) { // Disable lv_obj_add_state(btn, LV_STATE_DISABLED); @@ -151,13 +164,14 @@ static void keyboard_callback(lv_event_t * e){ lv_msg_send(DATA_PRINTER_MINIMAL, NULL); } -static void btn_printer_delete(lv_event_t * e) +static void btn_printer_secondary(lv_event_t * e) { lv_obj_t * btn = lv_event_get_target(e); PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); if (config == get_current_printer_config()) { + nav_buttons_setup(PANEL_SETTINGS); return; } @@ -167,7 +181,6 @@ static void btn_printer_delete(lv_event_t * e) nav_buttons_setup(PANEL_PRINTER); } -// TODO: Extract this from temp/print panel and combine static void btn_printer_rename(lv_event_t * e) { keyboard_config = (PRINTER_CONFIG*)lv_event_get_user_data(e); @@ -181,7 +194,7 @@ static void btn_printer_activate(lv_event_t * e) int index = config - global_config.printer_config; PrinterMinimal * printer = &printer_minimal[index]; - if (printer->state == PRINTER_STATE_OFFLINE) + if (printer->power_devices > 0 && (config == get_current_printer_config() || printer->state == PRINTER_STATE_OFFLINE)) { macros_draw_power_fullscreen(config); return; @@ -233,17 +246,20 @@ void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root) lv_obj_t * btn = lv_btn_create(button_row); lv_obj_set_flex_grow(btn, 1); - lv_obj_add_event_cb(btn, btn_printer_delete, LV_EVENT_CLICKED, config); - lv_obj_add_event_cb(btn, btn_enable_delete, LV_EVENT_MSG_RECEIVED, config); + lv_obj_add_event_cb(btn, btn_printer_secondary, LV_EVENT_CLICKED, config); + lv_obj_add_event_cb(btn, update_printer_button_active_printer, LV_EVENT_MSG_RECEIVED, config); lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, btn, config); label = lv_label_create(btn); - lv_label_set_text(label, LV_SYMBOL_TRASH); lv_obj_center(label); + lv_obj_add_event_cb(label, btn_set_secondary_button_text, LV_EVENT_MSG_RECEIVED, config); + lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, config); btn = lv_btn_create(button_row); lv_obj_set_flex_grow(btn, 2); lv_obj_add_event_cb(btn, btn_printer_rename, LV_EVENT_CLICKED, config); + lv_obj_add_event_cb(btn, update_printer_button_active_printer, LV_EVENT_MSG_RECEIVED, config); + lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, btn, config); label = lv_label_create(btn); lv_label_set_text(label, "Rename"); @@ -253,6 +269,7 @@ void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root) lv_obj_set_flex_grow(btn, 2); lv_obj_add_event_cb(btn, btn_printer_activate, LV_EVENT_CLICKED, config); lv_obj_add_event_cb(btn, btn_enable_control, LV_EVENT_MSG_RECEIVED, config); + lv_obj_add_event_cb(btn, update_printer_button_active_printer, LV_EVENT_MSG_RECEIVED, config); lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, btn, config); label = lv_label_create(btn);