mirror of
https://github.com/suchmememanyskill/CYD-Klipper.git
synced 2026-03-21 05:33:24 +00:00
Improve printer menu
This commit is contained in:
@@ -10,8 +10,8 @@ COLOR_DEF color_defs[] = {
|
|||||||
{LV_PALETTE_GREY, 0, LV_PALETTE_CYAN},
|
{LV_PALETTE_GREY, 0, LV_PALETTE_CYAN},
|
||||||
{LV_PALETTE_YELLOW, -2, LV_PALETTE_PINK},
|
{LV_PALETTE_YELLOW, -2, LV_PALETTE_PINK},
|
||||||
{LV_PALETTE_ORANGE, -2, LV_PALETTE_BLUE},
|
{LV_PALETTE_ORANGE, -2, LV_PALETTE_BLUE},
|
||||||
{LV_PALETTE_RED, 0, LV_PALETTE_GREEN},
|
{LV_PALETTE_RED, 0, LV_PALETTE_BLUE},
|
||||||
{LV_PALETTE_PURPLE, 0, LV_PALETTE_GREY},
|
{LV_PALETTE_PURPLE, 0, LV_PALETTE_CYAN},
|
||||||
};
|
};
|
||||||
|
|
||||||
void write_global_config()
|
void write_global_config()
|
||||||
|
|||||||
@@ -340,7 +340,7 @@ void fetch_printer_data_minimal()
|
|||||||
data[i].state = PRINTER_STATE_ERROR;
|
data[i].state = PRINTER_STATE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
data[i].power_devices = 0;
|
data[i].power_devices = power_devices_count(config);
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
deserializeJson(doc, client.getStream());
|
deserializeJson(doc, client.getStream());
|
||||||
auto status = doc["result"]["status"];
|
auto status = doc["result"]["status"];
|
||||||
|
|||||||
@@ -51,6 +51,21 @@ static void update_printer_status_text(lv_event_t * e)
|
|||||||
lv_label_set_text(label, printer_status[printer->state]);
|
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)
|
static void update_printer_percentage_bar(lv_event_t * e)
|
||||||
{
|
{
|
||||||
lv_obj_t * percentage = lv_event_get_target(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;
|
int index = config - global_config.printer_config;
|
||||||
PrinterMinimal * printer = &printer_minimal[index];
|
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");
|
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);
|
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
|
||||||
|
|
||||||
if (config == get_current_printer_config())
|
if (config == get_current_printer_config())
|
||||||
{
|
{
|
||||||
// Disable
|
lv_label_set_text(label, LV_SYMBOL_SETTINGS);
|
||||||
lv_obj_add_state(btn, LV_STATE_DISABLED);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Enable
|
lv_label_set_text(label, LV_SYMBOL_TRASH);
|
||||||
lv_obj_clear_state(btn, LV_STATE_DISABLED);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +139,7 @@ static void btn_enable_control(lv_event_t * e)
|
|||||||
int index = config - global_config.printer_config;
|
int index = config - global_config.printer_config;
|
||||||
PrinterMinimal * printer = &printer_minimal[index];
|
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
|
// Disable
|
||||||
lv_obj_add_state(btn, LV_STATE_DISABLED);
|
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);
|
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);
|
lv_obj_t * btn = lv_event_get_target(e);
|
||||||
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
|
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
|
||||||
|
|
||||||
if (config == get_current_printer_config())
|
if (config == get_current_printer_config())
|
||||||
{
|
{
|
||||||
|
nav_buttons_setup(PANEL_SETTINGS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +181,6 @@ static void btn_printer_delete(lv_event_t * e)
|
|||||||
nav_buttons_setup(PANEL_PRINTER);
|
nav_buttons_setup(PANEL_PRINTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Extract this from temp/print panel and combine
|
|
||||||
static void btn_printer_rename(lv_event_t * e)
|
static void btn_printer_rename(lv_event_t * e)
|
||||||
{
|
{
|
||||||
keyboard_config = (PRINTER_CONFIG*)lv_event_get_user_data(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;
|
int index = config - global_config.printer_config;
|
||||||
PrinterMinimal * printer = &printer_minimal[index];
|
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);
|
macros_draw_power_fullscreen(config);
|
||||||
return;
|
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_t * btn = lv_btn_create(button_row);
|
||||||
lv_obj_set_flex_grow(btn, 1);
|
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_printer_secondary, LV_EVENT_CLICKED, config);
|
||||||
lv_obj_add_event_cb(btn, btn_enable_delete, 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);
|
lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, btn, config);
|
||||||
|
|
||||||
label = lv_label_create(btn);
|
label = lv_label_create(btn);
|
||||||
lv_label_set_text(label, LV_SYMBOL_TRASH);
|
|
||||||
lv_obj_center(label);
|
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);
|
btn = lv_btn_create(button_row);
|
||||||
lv_obj_set_flex_grow(btn, 2);
|
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, 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);
|
label = lv_label_create(btn);
|
||||||
lv_label_set_text(label, "Rename");
|
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_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_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, 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);
|
lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, btn, config);
|
||||||
|
|
||||||
label = lv_label_create(btn);
|
label = lv_label_create(btn);
|
||||||
|
|||||||
Reference in New Issue
Block a user