From 77db3652f217015968c81091e6415d8545f84c7e Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 3 Feb 2024 16:39:49 +0100 Subject: [PATCH] Add info to stat panel --- CYD-Klipper/src/core/data_setup.cpp | 5 ++ CYD-Klipper/src/core/data_setup.h | 4 ++ CYD-Klipper/src/ui/panels/stats_panel.cpp | 62 +++++++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index 8686c30..d240d6d 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -121,6 +121,7 @@ void fetch_printer_data() printer.extruder_temp = status["extruder"]["temperature"]; printer.extruder_target_temp = status["extruder"]["target"]; bool can_extrude = status["extruder"]["can_extrude"]; + printer.pressure_advance = status["extruder"]["pressure_advance"]; printer.can_extrude = can_extrude == true; } @@ -148,6 +149,8 @@ void fetch_printer_data() printer.absolute_coords = absolute_coords == true; printer.speed_mult = status["gcode_move"]["speed_factor"]; printer.extrude_mult = status["gcode_move"]["extrude_factor"]; + printer.feedrate_mm_per_s = status["gcode_move"]["speed"]; + printer.feedrate_mm_per_s /= 60; // convert mm/m to mm/s } if (status.containsKey("fan")) @@ -167,6 +170,8 @@ void fetch_printer_data() printer.print_filename = filename_buff; printer.elapsed_time_s = status["print_stats"]["print_duration"]; printer.filament_used_mm = status["print_stats"]["filament_used"]; + printer.total_layers = status["print_stats"]["info"]["total_layer"]; + printer.current_layer = status["print_stats"]["info"]["current_layer"]; const char *state = status["print_stats"]["state"]; diff --git a/CYD-Klipper/src/core/data_setup.h b/CYD-Klipper/src/core/data_setup.h index 109f108..57e4e74 100644 --- a/CYD-Klipper/src/core/data_setup.h +++ b/CYD-Klipper/src/core/data_setup.h @@ -29,6 +29,10 @@ typedef struct _Printer { float gcode_offset[3]; float speed_mult; float extrude_mult; + int total_layers; + int current_layer; + float pressure_advance; + int feedrate_mm_per_s; } Printer; extern Printer printer; diff --git a/CYD-Klipper/src/ui/panels/stats_panel.cpp b/CYD-Klipper/src/ui/panels/stats_panel.cpp index 417bfad..37249e0 100644 --- a/CYD-Klipper/src/ui/panels/stats_panel.cpp +++ b/CYD-Klipper/src/ui/panels/stats_panel.cpp @@ -151,9 +151,71 @@ void create_state_button(lv_obj_t * root, lv_event_cb_t label, lv_event_cb_t but lv_obj_align(label_obj, LV_ALIGN_CENTER, 0, 0); } +static void label_pos(lv_event_t * e){ + lv_obj_t * label = lv_event_get_target(e); + char x_pos_buff[32]; + sprintf(x_pos_buff, "X%.2f Y%.2f", printer.position[0], printer.position[1]); + lv_label_set_text(label, x_pos_buff); +} + +static void label_filament_used_m(lv_event_t * e){ + lv_obj_t * label = lv_event_get_target(e); + char filament_buff[32]; + sprintf(filament_buff, "%.2f m", printer.filament_used_mm / 1000); + lv_label_set_text(label, filament_buff); +} + +static void label_total_layers(lv_event_t * e){ + lv_obj_t * label = lv_event_get_target(e); + char layers_buff[32]; + sprintf(layers_buff, "%d of %d", printer.current_layer, printer.total_layers); + lv_label_set_text(label, layers_buff); +} + +static void label_pressure_advance(lv_event_t * e){ + lv_obj_t * label = lv_event_get_target(e); + char pressure_buff[32]; + sprintf(pressure_buff, "%.3f", printer.pressure_advance); + lv_label_set_text(label, pressure_buff); +} + +static void label_feedrate(lv_event_t * e){ + lv_obj_t * label = lv_event_get_target(e); + char feedrate_buff[32]; + sprintf(feedrate_buff, "%d mm/s", printer.feedrate_mm_per_s); + lv_label_set_text(label, feedrate_buff); +} + +void create_stat_text_block(lv_obj_t * root, const char* label, lv_event_cb_t value){ + lv_obj_t * panel = lv_create_empty_panel(root); + lv_obj_set_size(panel, LV_SIZE_CONTENT, LV_SIZE_CONTENT); + lv_layout_flex_column(panel , LV_FLEX_ALIGN_START, CYD_SCREEN_GAP_PX / 2, CYD_SCREEN_GAP_PX / 2); + lv_obj_set_flex_align(panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); + + lv_obj_t * label_obj = lv_label_create(panel); + lv_label_set_text(label_obj, label); + lv_obj_set_style_text_font(label_obj, CYD_SCREEN_FONT_SMALL, 0); + + lv_obj_t * value_obj = lv_label_create(panel); + lv_obj_add_event_cb(value_obj, value, LV_EVENT_MSG_RECEIVED, NULL); + lv_msg_subscribe_obj(DATA_PRINTER_DATA, value_obj, NULL); +} + void stats_panel_init(lv_obj_t* panel) { auto panel_width = CYD_SCREEN_PANEL_WIDTH_PX / 2 - CYD_SCREEN_GAP_PX * 3; + lv_obj_t * left_panel = lv_create_empty_panel(panel); + lv_obj_set_size(left_panel, panel_width, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2); + lv_layout_flex_column(left_panel); + lv_obj_set_flex_align(left_panel, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); + lv_obj_align(left_panel, LV_ALIGN_TOP_LEFT, CYD_SCREEN_GAP_PX, CYD_SCREEN_GAP_PX); + + create_stat_text_block(left_panel, "Position:", label_pos); + create_stat_text_block(left_panel, "Filament Used:", label_filament_used_m); + create_stat_text_block(left_panel, "Layer:", label_total_layers); + create_stat_text_block(left_panel, "Pressure Advance:", label_pressure_advance); + create_stat_text_block(left_panel, "Feedrate:", label_feedrate); + lv_obj_t * right_panel = lv_create_empty_panel(panel); lv_obj_set_size(right_panel, panel_width, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2); lv_layout_flex_column(right_panel, LV_FLEX_ALIGN_CENTER);