Skip to content

Commit

Permalink
Improve printer menu
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Mar 22, 2024
1 parent 0f472ae commit 713e04b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
4 changes: 2 additions & 2 deletions CYD-Klipper/src/conf/global_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion CYD-Klipper/src/core/data_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
45 changes: 31 additions & 14 deletions CYD-Klipper/src/ui/panels/printer_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}
Expand All @@ -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);
}
}

Expand All @@ -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);
Expand All @@ -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;
}

Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand Down

0 comments on commit 713e04b

Please sign in to comment.