From 56301d3d72ab57392d4838cfd4fe83b82312e6ca Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 17 Mar 2024 14:59:43 +0100 Subject: [PATCH] Show extra stats on progress panel --- CYD-Klipper/src/conf/global_config.h | 8 +++ CYD-Klipper/src/ui/panels/progress_panel.cpp | 51 +++++++++++++++++++- CYD-Klipper/src/ui/panels/settings_panel.cpp | 7 +++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/CYD-Klipper/src/conf/global_config.h b/CYD-Klipper/src/conf/global_config.h index c7e2c1b..8c080f7 100644 --- a/CYD-Klipper/src/conf/global_config.h +++ b/CYD-Klipper/src/conf/global_config.h @@ -12,6 +12,13 @@ enum { REMAINING_TIME_CALC_SLICER = 2, }; +enum { + SHOW_STATS_ON_PROGRESS_PANEL_NONE = 0, + SHOW_STATS_ON_PROGRESS_PANEL_LAYER = 1, + SHOW_STATS_ON_PROGRESS_PANEL_PARTIAL = 2, + SHOW_STATS_ON_PROGRESS_PANEL_ALL = 3, +}; + typedef struct _PRINTER_CONFIG { union { unsigned int raw; @@ -24,6 +31,7 @@ typedef struct _PRINTER_CONFIG { bool light_mode : 1; bool invert_colors : 1; unsigned char remaining_time_calc_mode : 2; + unsigned char show_stats_on_progress_panel : 2; }; }; diff --git a/CYD-Klipper/src/ui/panels/progress_panel.cpp b/CYD-Klipper/src/ui/panels/progress_panel.cpp index 7aa84ef..93825e7 100644 --- a/CYD-Klipper/src/ui/panels/progress_panel.cpp +++ b/CYD-Klipper/src/ui/panels/progress_panel.cpp @@ -28,6 +28,28 @@ static void update_printer_data_remaining_time(lv_event_t * e){ lv_label_set_text(label, time_display(printer.remaining_time_s)); } +static void update_printer_data_stats(lv_event_t * e){ + lv_obj_t * label = lv_event_get_target(e); + char buff[256] = {0}; + + switch (get_current_printer_config()->show_stats_on_progress_panel) + { + case SHOW_STATS_ON_PROGRESS_PANEL_LAYER: + sprintf(buff, "Layer %d of %d", printer.current_layer, printer.total_layers); + break; + case SHOW_STATS_ON_PROGRESS_PANEL_PARTIAL: + sprintf(buff, "Position: X%.2f Y%.2f\nFeedrate: %d mm/s\nFilament Used: %.2f m\nLayer %d of %d", + printer.position[0], printer.position[1], printer.feedrate_mm_per_s, printer.filament_used_mm / 1000, printer.current_layer, printer.total_layers); + break; + case SHOW_STATS_ON_PROGRESS_PANEL_ALL: + sprintf(buff, "Pressure Advance: %.3f (%.2fs)\nPosition: X%.2f Y%.2f Z%.2f\nFeedrate: %d mm/s\nFilament Used: %.2f m\nFan: %.0f%%\nSpeed: %.0f%%\nFlow: %.0f%%\nLayer %d of %d", + printer.pressure_advance, printer.smooth_time, printer.position[0], printer.position[1], printer.position[2], printer.feedrate_mm_per_s, printer.filament_used_mm / 1000, printer.fan_speed * 100, printer.speed_mult * 100, printer.extrude_mult * 100, printer.current_layer, printer.total_layers); + break; + } + + lv_label_set_text(label, buff); +} + static void update_printer_data_percentage(lv_event_t * e){ lv_obj_t * label = lv_event_get_target(e); char percentage_buffer[12]; @@ -52,10 +74,28 @@ void progress_panel_init(lv_obj_t* panel){ const auto button_size_mult = 1.3f; lv_obj_t * center_panel = lv_create_empty_panel(panel); - lv_obj_align(center_panel, LV_ALIGN_CENTER, 0, 0); lv_obj_set_size(center_panel, panel_width, LV_SIZE_CONTENT); lv_layout_flex_column(center_panel); + if (get_current_printer_config()->show_stats_on_progress_panel == SHOW_STATS_ON_PROGRESS_PANEL_ALL) + { + lv_obj_align(center_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_GAP_PX); + } + else + { + lv_obj_align(center_panel, LV_ALIGN_CENTER, 0, 0); + } + + + if (get_current_printer_config()->show_stats_on_progress_panel == SHOW_STATS_ON_PROGRESS_PANEL_LAYER) + { + lv_obj_t * label = lv_label_create(panel); + lv_obj_align(label, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_GAP_PX); + lv_obj_set_style_text_font(label, &CYD_SCREEN_FONT_SMALL, 0); + lv_obj_add_event_cb(label, update_printer_data_stats, LV_EVENT_MSG_RECEIVED, NULL); + lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL); + } + // Filename lv_obj_t * label = lv_label_create(center_panel); lv_label_set_text(label, printer.print_filename); @@ -124,4 +164,13 @@ void progress_panel_init(lv_obj_t* panel){ lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -2 * CYD_SCREEN_GAP_PX - CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, -1 * CYD_SCREEN_GAP_PX); lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * button_size_mult); + + if (get_current_printer_config()->show_stats_on_progress_panel >= SHOW_STATS_ON_PROGRESS_PANEL_PARTIAL) + { + label = lv_label_create(panel); + lv_obj_align(label, LV_ALIGN_BOTTOM_LEFT, CYD_SCREEN_GAP_PX, -1 * CYD_SCREEN_GAP_PX); + lv_obj_set_style_text_font(label, &CYD_SCREEN_FONT_SMALL, 0); + lv_obj_add_event_cb(label, update_printer_data_stats, LV_EVENT_MSG_RECEIVED, NULL); + lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL); + } } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/settings_panel.cpp b/CYD-Klipper/src/ui/panels/settings_panel.cpp index ecc124d..137e249 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -48,6 +48,12 @@ static void light_mode_switch(lv_event_t * e){ set_color_scheme(); } +static void show_stats_on_progress_panel_dropdown(lv_event_t * e){ + auto selected = lv_dropdown_get_selected(lv_event_get_target(e)); + get_current_printer_config()->show_stats_on_progress_panel = selected; + write_global_config(); +} + static void theme_dropdown(lv_event_t * e){ lv_obj_t * dropdown = lv_event_get_target(e); auto selected = lv_dropdown_get_selected(dropdown); @@ -141,6 +147,7 @@ void settings_panel_init(lv_obj_t* panel){ #endif // CYD_SCREEN_DISABLE_INVERT_COLORS lv_create_custom_menu_switch("Light Mode", panel, light_mode_switch, get_current_printer_config()->light_mode); + lv_create_custom_menu_dropdown("Stats in Progress Screen", panel, show_stats_on_progress_panel_dropdown, "None\nLayers\nPartial\nAll", get_current_printer_config()->show_stats_on_progress_panel); lv_create_custom_menu_button("Configure IP", panel, reset_ip_click, "Restart"); if (global_config.multi_printer_mode)