Skip to content

Commit

Permalink
Show extra stats on progress panel
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Mar 17, 2024
1 parent ae3348d commit 56301d3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CYD-Klipper/src/conf/global_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
};
};

Expand Down
51 changes: 50 additions & 1 deletion CYD-Klipper/src/ui/panels/progress_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}
7 changes: 7 additions & 0 deletions CYD-Klipper/src/ui/panels/settings_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 56301d3

Please sign in to comment.