diff --git a/CYD-Klipper/src/core/klipper/klipper_printer_integration.cpp b/CYD-Klipper/src/core/klipper/klipper_printer_integration.cpp index 017aed1..5edd7dd 100644 --- a/CYD-Klipper/src/core/klipper/klipper_printer_integration.cpp +++ b/CYD-Klipper/src/core/klipper/klipper_printer_integration.cpp @@ -696,7 +696,7 @@ bool KlipperPrinter::start_file(const char *filename) return http_code == 200; } -bool KlipperPrinter::set_target_temperature(PrinterTemperatureDevice device, float temperature) +bool KlipperPrinter::set_target_temperature(PrinterTemperatureDevice device, unsigned int temperature) { char gcode[64] = {0}; diff --git a/CYD-Klipper/src/core/klipper/klipper_printer_integration.hpp b/CYD-Klipper/src/core/klipper/klipper_printer_integration.hpp index 445c652..d758c91 100644 --- a/CYD-Klipper/src/core/klipper/klipper_printer_integration.hpp +++ b/CYD-Klipper/src/core/klipper/klipper_printer_integration.hpp @@ -48,7 +48,7 @@ class KlipperPrinter : public BasePrinter Files get_files(); bool start_file(const char* filename); unsigned char* get_32_32_png_image_thumbnail(const char* gcode_filename); - bool set_target_temperature(PrinterTemperatureDevice device, float temperature); + bool set_target_temperature(PrinterTemperatureDevice device, unsigned int temperature); bool send_gcode(const char* gcode, bool wait = true); int get_slicer_time_estimate_s(); void configure_http_client(HTTPClient &client, String url_part, bool stream, int timeout); diff --git a/CYD-Klipper/src/core/printer_integration.hpp b/CYD-Klipper/src/core/printer_integration.hpp index 06298d8..7c34875 100644 --- a/CYD-Klipper/src/core/printer_integration.hpp +++ b/CYD-Klipper/src/core/printer_integration.hpp @@ -159,7 +159,7 @@ class BasePrinter virtual Files get_files() = 0; virtual bool start_file(const char* filename) = 0; virtual unsigned char* get_32_32_png_image_thumbnail(const char* gcode_filename); - virtual bool set_target_temperature(PrinterTemperatureDevice device, float temperature) = 0; + virtual bool set_target_temperature(PrinterTemperatureDevice device, unsigned int temperature) = 0; BasePrinter(unsigned char index); PrinterData* AnnouncePrinterData(); diff --git a/CYD-Klipper/src/ui/panels/files_panel.cpp b/CYD-Klipper/src/ui/panels/files_panel.cpp index b6c29a5..e720d8e 100644 --- a/CYD-Klipper/src/ui/panels/files_panel.cpp +++ b/CYD-Klipper/src/ui/panels/files_panel.cpp @@ -78,7 +78,9 @@ static void btn_print_file_verify(lv_event_t * e){ } void files_panel_init(lv_obj_t* panel){ + freeze_request_thread(); Files files = get_current_printer()->get_files(); + unfreeze_request_thread(); if (!files.success || files.count <= 0){ lv_obj_t * label = lv_label_create(panel); diff --git a/CYD-Klipper/src/ui/panels/progress_panel.cpp b/CYD-Klipper/src/ui/panels/progress_panel.cpp index 643656a..92d1fcd 100644 --- a/CYD-Klipper/src/ui/panels/progress_panel.cpp +++ b/CYD-Klipper/src/ui/panels/progress_panel.cpp @@ -1,7 +1,7 @@ #include "panel.h" -#include "../../core/data_setup.h" #include #include "../ui_utils.h" +#include "../../core/printer_integration.hpp" char time_buffer[12]; @@ -15,35 +15,35 @@ char* time_display(unsigned long time){ static void progress_bar_update(lv_event_t* e){ lv_obj_t * bar = lv_event_get_target(e); - lv_bar_set_value(bar, printer.print_progress * 100, LV_ANIM_ON); + lv_bar_set_value(bar, get_current_printer_data()->print_progress * 100, LV_ANIM_ON); } static void update_printer_data_elapsed_time(lv_event_t * e){ lv_obj_t * label = lv_event_get_target(e); - lv_label_set_text(label, time_display(printer.elapsed_time_s)); + lv_label_set_text(label, time_display(get_current_printer_data()->elapsed_time_s)); } static void update_printer_data_remaining_time(lv_event_t * e){ lv_obj_t * label = lv_event_get_target(e); - lv_label_set_text(label, time_display(printer.remaining_time_s)); + lv_label_set_text(label, time_display(get_current_printer_data()->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) + switch (get_current_printer()->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); + sprintf(buff, "Layer %d of %d", get_current_printer_data()->current_layer, get_current_printer_data()->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); + get_current_printer_data()->position[0], get_current_printer_data()->position[1], get_current_printer_data()->feedrate_mm_per_s, get_current_printer_data()->filament_used_mm / 1000, get_current_printer_data()->current_layer, get_current_printer_data()->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); + get_current_printer_data()->pressure_advance, get_current_printer_data()->smooth_time, get_current_printer_data()->position[0], get_current_printer_data()->position[1], get_current_printer_data()->position[2], get_current_printer_data()->feedrate_mm_per_s, get_current_printer_data()->filament_used_mm / 1000, get_current_printer_data()->fan_speed * 100, get_current_printer_data()->speed_mult * 100, get_current_printer_data()->extrude_mult * 100, get_current_printer_data()->current_layer, get_current_printer_data()->total_layers); break; } @@ -53,25 +53,24 @@ static void update_printer_data_stats(lv_event_t * e){ static void update_printer_data_percentage(lv_event_t * e){ lv_obj_t * label = lv_event_get_target(e); char percentage_buffer[12]; - sprintf(percentage_buffer, "%.2f%%", printer.print_progress * 100); + sprintf(percentage_buffer, "%.2f%%", get_current_printer_data()->print_progress * 100); lv_label_set_text(label, percentage_buffer); } static void btn_click_stop(lv_event_t * e){ - send_gcode(true, "CANCEL_PRINT"); + get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureStop); } static void btn_click_pause(lv_event_t * e){ - send_gcode(true, "PAUSE"); + get_current_printer()->execute_feature(PrinterFeatures::PrinterFeaturePause); } static void btn_click_resume(lv_event_t * e){ - send_gcode(true, "RESUME"); + get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureResume); } static void btn_click_estop(lv_event_t * e){ - send_estop(); - send_gcode(false, "M112"); + get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureEmergencyStop); } void progress_panel_init(lv_obj_t* panel){ @@ -97,7 +96,7 @@ void progress_panel_init(lv_obj_t* panel){ lv_layout_flex_column(center_panel); // Only align progress bar to top mid if necessary to make room for all extras - if (get_current_printer_config()->show_stats_on_progress_panel == SHOW_STATS_ON_PROGRESS_PANEL_ALL && CYD_SCREEN_HEIGHT_PX <= 320) + if (get_current_printer()->printer_config->show_stats_on_progress_panel == SHOW_STATS_ON_PROGRESS_PANEL_ALL && CYD_SCREEN_HEIGHT_PX <= 320) { lv_obj_align(center_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX+(3 * CYD_SCREEN_GAP_PX)); } @@ -108,7 +107,7 @@ void progress_panel_init(lv_obj_t* panel){ // Filename lv_obj_t * label = lv_label_create(center_panel); - lv_label_set_text(label, printer.print_filename); + lv_label_set_text(label, get_current_printer_data()->print_filename); if (global_config.full_filenames) lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); else lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR); lv_obj_set_width(label, panel_width); @@ -155,7 +154,7 @@ void progress_panel_init(lv_obj_t* panel){ lv_obj_center(label); // Resume Button - if (printer.state == PRINTER_STATE_PAUSED){ + if (get_current_printer_data()->state == PrinterState::PrinterStatePaused){ btn = lv_btn_create(panel); lv_obj_add_event_cb(btn, btn_click_resume, LV_EVENT_CLICKED, NULL); @@ -176,7 +175,7 @@ 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_NONE) + if (get_current_printer()->printer_config->show_stats_on_progress_panel > SHOW_STATS_ON_PROGRESS_PANEL_NONE) { label = lv_label_create(panel); lv_obj_align(label, LV_ALIGN_BOTTOM_LEFT, CYD_SCREEN_GAP_PX, -1 * CYD_SCREEN_GAP_PX); diff --git a/CYD-Klipper/src/ui/panels/settings_panel.cpp b/CYD-Klipper/src/ui/panels/settings_panel.cpp index 47866c0..8e867aa 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -8,6 +8,7 @@ #include "../../core/lv_setup.h" #include "../ota_setup.h" #include "../nav_buttons.h" +#include "../../core/printer_integration.hpp" #ifndef REPO_VERSION #define REPO_VERSION "Unknown" @@ -16,7 +17,7 @@ static void invert_color_switch(lv_event_t * e){ auto state = lv_obj_get_state(lv_event_get_target(e)); bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); - get_current_printer_config()->invert_colors = checked; + get_current_printer()->printer_config->invert_colors = checked; write_global_config(); set_invert_display(); } @@ -38,8 +39,8 @@ static void reset_wifi_click(lv_event_t * e){ } static void reset_ip_click(lv_event_t * e){ - get_current_printer_config()->ip_configured = false; - get_current_printer_config()->auth_configured = false; + get_current_printer()->printer_config->ip_configured = false; + get_current_printer()->printer_config->auth_configured = false; write_global_config(); ESP.restart(); } @@ -47,7 +48,7 @@ static void reset_ip_click(lv_event_t * e){ static void light_mode_switch(lv_event_t * e){ auto state = lv_obj_get_state(lv_event_get_target(e)); bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); - get_current_printer_config()->light_mode = checked; + get_current_printer()->printer_config->light_mode = checked; write_global_config(); set_color_scheme(); } @@ -55,20 +56,20 @@ static void light_mode_switch(lv_event_t * e){ static void filament_move_mode_switch(lv_event_t * e){ auto state = lv_obj_get_state(lv_event_get_target(e)); bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); - get_current_printer_config()->custom_filament_move_macros = checked; + get_current_printer()->printer_config->custom_filament_move_macros = checked; write_global_config(); } 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; + get_current_printer()->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); - get_current_printer_config()->color_scheme = selected; + get_current_printer()->printer_config->color_scheme = selected; set_color_scheme(); write_global_config(); } @@ -171,7 +172,7 @@ const char* estimated_time_options = "Percentage\nInterpolated\nSlicer"; static void estimated_time_dropdown(lv_event_t * e){ lv_obj_t * dropdown = lv_event_get_target(e); - get_current_printer_config()->remaining_time_calc_mode = lv_dropdown_get_selected(dropdown); + get_current_printer()->printer_config->remaining_time_calc_mode = lv_dropdown_get_selected(dropdown); write_global_config(); } @@ -182,10 +183,10 @@ void settings_section_theming(lv_obj_t* panel) lv_obj_t * label = lv_label_create(panel); lv_label_set_text(label, "Theming"); - lv_create_custom_menu_dropdown("Theme", panel, theme_dropdown, "Blue\nGreen\nLime\nGrey\nYellow\nOrange\nRed\nPurple", get_current_printer_config()->color_scheme, NULL, PRINTER_SPECIFIC_SETTING); + lv_create_custom_menu_dropdown("Theme", panel, theme_dropdown, "Blue\nGreen\nLime\nGrey\nYellow\nOrange\nRed\nPurple", get_current_printer()->printer_config->color_scheme, NULL, PRINTER_SPECIFIC_SETTING); #ifndef CYD_SCREEN_DISABLE_INVERT_COLORS - lv_create_custom_menu_switch("Invert Colors", panel, invert_color_switch, get_current_printer_config()->invert_colors, NULL, (global_config.multi_printer_mode) ? "Stored per printer" + lv_create_custom_menu_switch("Invert Colors", panel, invert_color_switch, get_current_printer()->printer_config->invert_colors, NULL, (global_config.multi_printer_mode) ? "Stored per printer" #ifdef CYD_SCREEN_DRIVER_ESP32_2432S028R "\nIntended for the 2.8\" dual USB model screen" : "Intended for the 2.8\" dual USB model screen" #else @@ -194,7 +195,7 @@ void settings_section_theming(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, NULL, PRINTER_SPECIFIC_SETTING); + lv_create_custom_menu_switch("Light Mode", panel, light_mode_switch, get_current_printer()->printer_config->light_mode, NULL, PRINTER_SPECIFIC_SETTING); } void settings_section_behaviour(lv_obj_t* panel) @@ -202,8 +203,8 @@ void settings_section_behaviour(lv_obj_t* panel) lv_obj_t * label = lv_label_create(panel); lv_label_set_text(label, "\nBehaviour"); - lv_create_custom_menu_dropdown("Estimated Time", panel, estimated_time_dropdown, estimated_time_options, get_current_printer_config()->remaining_time_calc_mode, NULL, PRINTER_SPECIFIC_SETTING); - 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, NULL, PRINTER_SPECIFIC_SETTING); + lv_create_custom_menu_dropdown("Estimated Time", panel, estimated_time_dropdown, estimated_time_options, get_current_printer()->printer_config->remaining_time_calc_mode, NULL, PRINTER_SPECIFIC_SETTING); + lv_create_custom_menu_dropdown("Stats in Progress Screen", panel, show_stats_on_progress_panel_dropdown, "None\nLayers\nPartial\nAll", get_current_printer()->printer_config->show_stats_on_progress_panel, NULL, PRINTER_SPECIFIC_SETTING); #ifndef CYD_SCREEN_DISABLE_TIMEOUT int wake_timeout_settings_index = 0; @@ -225,7 +226,7 @@ void settings_section_behaviour(lv_obj_t* panel) lv_create_custom_menu_switch("Disable M117 Messaging", panel, disable_m117_messaging_switch, global_config.disable_m117_messaging); lv_create_custom_menu_button("Configure Printer IP", panel, reset_ip_click, "Restart"); - lv_create_custom_menu_switch("Custom Filament Move Macros", panel, filament_move_mode_switch, get_current_printer_config()->custom_filament_move_macros, NULL, + lv_create_custom_menu_switch("Custom Filament Move Macros", panel, filament_move_mode_switch, get_current_printer()->printer_config->custom_filament_move_macros, NULL, global_config.multi_printer_mode ? "Calls FILAMENT_RETRACT and\nFILAMENT_EXTRUDE in temperature menu\nwhen enabled. Stored per printer." : "Calls FILAMENT_RETRACT and\nFILAMENT_EXTRUDE in temperature menu\nwhen enabled"); diff --git a/CYD-Klipper/src/ui/panels/stats_panel.cpp b/CYD-Klipper/src/ui/panels/stats_panel.cpp index df19e41..22a34b5 100644 --- a/CYD-Klipper/src/ui/panels/stats_panel.cpp +++ b/CYD-Klipper/src/ui/panels/stats_panel.cpp @@ -1,173 +1,14 @@ #include "panel.h" #include "../ui_utils.h" -#include "../../core/data_setup.h" #include "../nav_buttons.h" #include #include +#include "../../core/printer_integration.hpp" static void swap_to_files_menu(lv_event_t * e) { nav_buttons_setup(PANEL_FILES); } -static void set_fan_speed_text(lv_event_t * e) { - lv_obj_t * label = lv_event_get_target(e); - char data[64]; - sprintf(data, "Fan: %.0f%%", printer.fan_speed * 100); - lv_label_set_text(label, data); -} - -static void set_fan_speed(lv_event_t * e){ - int speed = (int)lv_event_get_user_data(e); - char gcode[64]; - sprintf(gcode, "M106 S%d", speed); - send_gcode(true, gcode); -} - -const char* fan_speeds[] = { "0%", "15%", "25%", "35%" }; -const int fan_speeds_values[] = { 0, 38, 64, 90 }; - -const char* fan_speeds_2[] = { "50%", "75%", "100%"}; -const int fan_speeds_values_2[] = { 128, 192, 255 }; - -lv_button_column_t fan_speed_columns[] = { - { set_fan_speed, fan_speeds, (const void**)fan_speeds_values, 4}, - { set_fan_speed, fan_speeds_2, (const void**)fan_speeds_values_2, 3} -}; - -static void set_zoffset_text(lv_event_t * e) { - lv_obj_t * label = lv_event_get_target(e); - char data[64]; - sprintf(data, "Z Offset: %.03f", printer.gcode_offset[2]); - lv_label_set_text(label, data); -} - -static void set_zoffset_text_ex(lv_event_t * e) { - lv_obj_t * label = lv_event_get_target(e); - char data[64]; - sprintf(data, "Z Offset: %.03f, Z: %.03f", printer.gcode_offset[2], printer.position[2]); - lv_label_set_text(label, data); -} - -static void set_zoffset(lv_event_t * e){ - char* offset = (char*)lv_event_get_user_data(e); - - char gcode[64]; - sprintf(gcode, "SET_GCODE_OFFSET Z_ADJUST=%s MOVE=1", offset); - send_gcode(true, gcode); -} - -static void set_z(lv_event_t * e){ - void* ptr = lv_event_get_user_data(e); - float value = *(float *)(&ptr); - - if (value < 0) { - send_gcode(true, "SET_GCODE_OFFSET Z=0 MOVE=1"); - return; - } - - move_printer("Z", value, false); -} - -const char* zoffsets[] = { "-0.01", "-0.025", "-0.05", "-0.2" }; -const char* zoffsets_2[] = { "+0.01", "+0.025", "+0.05", "+0.2" }; -const char* zabs[] = { "Z=0", "Z=0.1", "Z=1", "Clear" }; -const float zabsvalues[] = { 0, 0.1f, 1.0f, -1.0f }; - -lv_button_column_t zoffset_columns[] = { - { set_zoffset, zoffsets, (const void**)zoffsets, 4}, - { set_zoffset, zoffsets_2, (const void**)zoffsets_2, 4}, - { set_z, zabs, (const void**)zabsvalues, 4} -}; - -static void set_speed_mult_text(lv_event_t * e){ - lv_obj_t * label = lv_event_get_target(e); - char data[64]; - sprintf(data, "Speed: %.0f%%", printer.speed_mult * 100); - lv_label_set_text(label, data); -} - -static void set_speed_mult(lv_event_t * e){ - int speed = (int)lv_event_get_user_data(e); - char gcode[64]; - sprintf(gcode, "M220 S%d", speed); - send_gcode(true, gcode); -} - -static void set_speed_mult_offset(lv_event_t * e){ - int speed = (int)lv_event_get_user_data(e); - float result = printer.speed_mult * 100 + speed; - printer.speed_mult = result / 100; - char gcode[64]; - sprintf(gcode, "M220 S%.0f", result); - send_gcode(true, gcode); -} - -const char* speed_presets[] = { "50%", "100%", "150%", "200%" }; -const int speed_presets_values[] = { 50, 100, 150, 200 }; -const char* speed_presets_minus[] = { "-1%", "-5%", "-10%", "-25%" }; -const int speed_presets_minus_values[] = { -1, -5, -10, -25 }; -const char* speed_presets_plus[] = { "+1%", "+5%", "+10%", "+25%" }; -const int speed_presets_plus_values[] = { 1, 5, 10, 25 }; - -lv_button_column_t speed_mult_columns[] = { - { set_speed_mult, speed_presets, (const void**)speed_presets_values, 4}, - { set_speed_mult_offset, speed_presets_minus, (const void**)speed_presets_minus_values, 4}, - { set_speed_mult_offset, speed_presets_plus, (const void**)speed_presets_plus_values, 4} -}; - -static void set_extrude_mult_text(lv_event_t * e){ - lv_obj_t * label = lv_event_get_target(e); - char data[64]; - sprintf(data, "Flow: %.0f%%", printer.extrude_mult * 100); - lv_label_set_text(label, data); -} - -static void set_extrude_mult(lv_event_t * e){ - int speed = (int)lv_event_get_user_data(e); - char gcode[64]; - sprintf(gcode, "M221 S%d", speed); - send_gcode(true, gcode); -} - -static void set_extrude_mult_offset(lv_event_t * e){ - int speed = (int)lv_event_get_user_data(e); - float result = printer.extrude_mult * 100 + speed; - printer.extrude_mult = result / 100; - char gcode[64]; - sprintf(gcode, "M221 S%.0f", result); - send_gcode(true, gcode); -} - -const char* extrude_presets[] = { "95%", "100%", "105%", "110%" }; -const int extrude_presets_values[] = { 95, 100, 105, 110 }; -const char* extrude_offset[] = { "+5%", "+1%", "-1%", "-5%" }; -const int extrude_offset_values[] = { 5, 1, -1, -5 }; - -lv_button_column_t extrude_mult_columns[] = { - { set_extrude_mult, extrude_presets, (const void**)extrude_presets_values, 4}, - { set_extrude_mult_offset, extrude_offset, (const void**)extrude_offset_values, 4} -}; - -static void open_fan_speed_panel(lv_event_t * e){ - lv_create_fullscreen_button_matrix_popup(lv_scr_act(), set_fan_speed_text, fan_speed_columns, 2); - lv_msg_send(DATA_PRINTER_DATA, &printer); -} - -static void open_zoffset_panel(lv_event_t * e){ - lv_create_fullscreen_button_matrix_popup(lv_scr_act(), set_zoffset_text_ex, zoffset_columns, (printer.state == PRINTER_STATE_IDLE) ? 3 : 2); - lv_msg_send(DATA_PRINTER_DATA, &printer); -} - -static void open_speed_mult_panel(lv_event_t * e){ - lv_create_fullscreen_button_matrix_popup(lv_scr_act(), set_speed_mult_text, speed_mult_columns, 3); - lv_msg_send(DATA_PRINTER_DATA, &printer); -} - -static void open_extrude_mult_panel(lv_event_t * e){ - lv_create_fullscreen_button_matrix_popup(lv_scr_act(), set_extrude_mult_text, extrude_mult_columns, 2); - lv_msg_send(DATA_PRINTER_DATA, &printer); -} - void create_state_button(lv_obj_t * root, lv_event_cb_t label, lv_event_cb_t button){ lv_obj_t * btn = lv_btn_create(root); lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH_PX / 2 - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); @@ -182,35 +23,35 @@ void create_state_button(lv_obj_t * root, lv_event_cb_t label, lv_event_cb_t but 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]); + sprintf(x_pos_buff, "X%.2f Y%.2f", get_current_printer_data()->position[0], get_current_printer_data()->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); + sprintf(filament_buff, "%.2f m", get_current_printer_data()->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); + sprintf(layers_buff, "%d of %d", get_current_printer_data()->current_layer, get_current_printer_data()->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 (%.2fs)", printer.pressure_advance, printer.smooth_time); + sprintf(pressure_buff, "%.3f (%.2fs)", get_current_printer_data()->pressure_advance, get_current_printer_data()->smooth_time); 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); + sprintf(feedrate_buff, "%d mm/s", get_current_printer_data()->feedrate_mm_per_s); lv_label_set_text(label, feedrate_buff); } @@ -241,7 +82,7 @@ void stats_panel_init(lv_obj_t* panel) { create_stat_text_block(left_panel, "Position:", label_pos); - if (printer.state != PRINTER_STATE_IDLE){ + if (get_current_printer_data()->state != PrinterState::PrinterStateIdle){ create_stat_text_block(left_panel, "Filament Used:", label_filament_used_m); create_stat_text_block(left_panel, "Layer:", label_total_layers); } @@ -254,7 +95,7 @@ void stats_panel_init(lv_obj_t* panel) { lv_layout_flex_column(right_panel, LV_FLEX_ALIGN_CENTER); lv_obj_align(right_panel, LV_ALIGN_TOP_RIGHT, -1 * CYD_SCREEN_GAP_PX, CYD_SCREEN_GAP_PX); - if (printer.state >= PRINTER_STATE_PRINTING){ + if (get_current_printer_data()->state >= PrinterState::PrinterStatePrinting){ lv_obj_t * btn = lv_btn_create(right_panel); lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH_PX / 2 - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_add_event_cb(btn, swap_to_files_menu, LV_EVENT_CLICKED, NULL); @@ -263,9 +104,10 @@ void stats_panel_init(lv_obj_t* panel) { lv_label_set_text(label, "Files"); lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); } - - create_state_button(right_panel, set_fan_speed_text, open_fan_speed_panel); - create_state_button(right_panel, set_zoffset_text, open_zoffset_panel); - create_state_button(right_panel, set_speed_mult_text, open_speed_mult_panel); - create_state_button(right_panel, set_extrude_mult_text, open_extrude_mult_panel); + + BasePrinter* printer = get_current_printer(); + for (int i = 0; i < printer->custom_menus_count; i++) + { + create_state_button(right_panel, (lv_event_cb_t)printer->custom_menus[i].set_label, (lv_event_cb_t)printer->custom_menus[i].open_panel); + } } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/temp_panel.cpp b/CYD-Klipper/src/ui/panels/temp_panel.cpp index 5880eaf..c360946 100644 --- a/CYD-Klipper/src/ui/panels/temp_panel.cpp +++ b/CYD-Klipper/src/ui/panels/temp_panel.cpp @@ -1,8 +1,8 @@ #include "lvgl.h" -#include "../../core/data_setup.h" #include "../../conf/global_config.h" #include #include "../ui_utils.h" +#include "../../core/printer_integration.hpp" enum temp_target{ TARGET_HOTEND, @@ -16,37 +16,43 @@ enum temp_target{ }; static temp_target keyboard_target; -static char hotend_buff[40]; -static char bed_buff[40]; + + static bool temp_edit_mode = false; lv_obj_t* root_panel; static void update_printer_data_hotend_temp(lv_event_t * e){ lv_obj_t * label = lv_event_get_target(e); - sprintf(hotend_buff, "Hotend: %.0f C (Target: %.0f C)", printer.extruder_temp, printer.extruder_target_temp); + char hotend_buff[40]; + sprintf(hotend_buff, "Hotend: %.0f C (Target: %.0f C)", + get_current_printer_data()->temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexNozzle1], + get_current_printer_data()->target_temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexNozzle1]); lv_label_set_text(label, hotend_buff); } static void update_printer_data_bed_temp(lv_event_t * e){ lv_obj_t * label = lv_event_get_target(e); - sprintf(bed_buff, "Bed: %.0f C (Target: %.0f C)", printer.bed_temp, printer.bed_target_temp); + char bed_buff[40]; + sprintf(bed_buff, "Bed: %.0f C (Target: %.0f C)", + get_current_printer_data()->temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexBed], + get_current_printer_data()->target_temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexBed]); lv_label_set_text(label, bed_buff); } static short get_temp_preset(int target){ switch (target){ case TARGET_HOTEND_CONFIG_1: - return get_current_printer_config()->hotend_presets[0]; + return get_current_printer()->printer_config->hotend_presets[0]; case TARGET_HOTEND_CONFIG_2: - return get_current_printer_config()->hotend_presets[1]; + return get_current_printer()->printer_config->hotend_presets[1]; case TARGET_HOTEND_CONFIG_3: - return get_current_printer_config()->hotend_presets[2]; + return get_current_printer()->printer_config->hotend_presets[2]; case TARGET_BED_CONFIG_1: - return get_current_printer_config()->bed_presets[0]; + return get_current_printer()->printer_config->bed_presets[0]; case TARGET_BED_CONFIG_2: - return get_current_printer_config()->bed_presets[1]; + return get_current_printer()->printer_config->bed_presets[1]; case TARGET_BED_CONFIG_3: - return get_current_printer_config()->bed_presets[2]; + return get_current_printer()->printer_config->bed_presets[2]; default: return -1; } @@ -63,7 +69,7 @@ static void update_temp_preset_label(lv_event_t * e){ void UpdateConfig(){ write_global_config(); - lv_msg_send(DATA_PRINTER_TEMP_PRESET, &printer); + lv_msg_send(DATA_PRINTER_TEMP_PRESET, get_current_printer()); } static void keyboard_callback(lv_event_t * e){ @@ -76,40 +82,36 @@ static void keyboard_callback(lv_event_t * e){ if (temp < 0 || temp > 500){ return; } - - char gcode[64]; switch (keyboard_target){ case TARGET_HOTEND: - sprintf(gcode, "M104 S%d", temp); - send_gcode(true, gcode); + get_current_printer()->set_target_temperature(PrinterTemperatureDevice::PrinterTemperatureDeviceNozzle1, temp); break; case TARGET_BED: - sprintf(gcode, "M140 S%d", temp); - send_gcode(true, gcode); + get_current_printer()->set_target_temperature(PrinterTemperatureDevice::PrinterTemperatureDeviceBed, temp); break; case TARGET_HOTEND_CONFIG_1: - get_current_printer_config()->hotend_presets[0] = temp; + get_current_printer()->printer_config->hotend_presets[0] = temp; UpdateConfig(); break; case TARGET_HOTEND_CONFIG_2: - get_current_printer_config()->hotend_presets[1] = temp; + get_current_printer()->printer_config->hotend_presets[1] = temp; UpdateConfig(); break; case TARGET_HOTEND_CONFIG_3: - get_current_printer_config()->hotend_presets[2] = temp; + get_current_printer()->printer_config->hotend_presets[2] = temp; UpdateConfig(); break; case TARGET_BED_CONFIG_1: - get_current_printer_config()->bed_presets[0] = temp; + get_current_printer()->printer_config->bed_presets[0] = temp; UpdateConfig(); break; case TARGET_BED_CONFIG_2: - get_current_printer_config()->bed_presets[1] = temp; + get_current_printer()->printer_config->bed_presets[1] = temp; UpdateConfig(); break; case TARGET_BED_CONFIG_3: - get_current_printer_config()->bed_presets[2] = temp; + get_current_printer()->printer_config->bed_presets[2] = temp; UpdateConfig(); break; } @@ -126,28 +128,19 @@ static void show_keyboard_with_bed(lv_event_t * e){ } static void cooldown_temp(lv_event_t * e){ - if (printer.state == PRINTER_STATE_PRINTING){ + if (get_current_printer_data()->state == PrinterState::PrinterStatePrinting){ return; } - send_gcode(true, "M104 S0"); - send_gcode(true, "M140 S0"); + get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureCooldown); } static void btn_extrude(lv_event_t * e){ - if (printer.state == PRINTER_STATE_PRINTING){ + if (get_current_printer_data()->state == PrinterState::PrinterStatePrinting){ return; } - if (get_current_printer_config()->custom_filament_move_macros) - { - send_gcode(true, "FILAMENT_EXTRUDE"); - } - else - { - send_gcode(true, "M83"); - send_gcode(true, "G1 E25 F300"); - } + get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureExtrude); } static void set_temp_via_preset(lv_event_t * e){ @@ -160,13 +153,10 @@ static void set_temp_via_preset(lv_event_t * e){ return; } - char gcode[64]; - if (target <= TARGET_HOTEND_CONFIG_3) - sprintf(gcode, "M104 S%d", value); - else - sprintf(gcode, "M140 S%d", value); - - send_gcode(true, gcode); + get_current_printer()->set_target_temperature(TARGET_HOTEND_CONFIG_3 + ? PrinterTemperatureDevice::PrinterTemperatureDeviceNozzle1 + : PrinterTemperatureDevice::PrinterTemperatureDeviceBed + , value); } static void btn_toggleable_edit(lv_event_t * e){ @@ -176,19 +166,11 @@ static void btn_toggleable_edit(lv_event_t * e){ } static void btn_retract(lv_event_t * e){ - if (printer.state == PRINTER_STATE_PRINTING){ + if (get_current_printer_data()->state == PrinterState::PrinterStatePrinting){ return; } - if (get_current_printer_config()->custom_filament_move_macros) - { - send_gcode(true, "FILAMENT_RETRACT"); - } - else - { - send_gcode(true, "M83"); - send_gcode(true, "G1 E-25 F300"); - } + get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureRetract); } static void set_chart_range(lv_event_t * e) { @@ -218,25 +200,25 @@ static void set_chart_range(lv_event_t * e) { static void set_hotend_temp_chart(lv_event_t * e){ lv_obj_t * chart = lv_event_get_target(e); lv_chart_series_t * series = (lv_chart_series_t *)lv_event_get_user_data(e); - lv_chart_set_next_value(chart, series, printer.extruder_temp); + lv_chart_set_next_value(chart, series, get_current_printer_data()->temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexNozzle1]); } static void set_hotend_target_temp_chart(lv_event_t * e){ lv_obj_t * chart = lv_event_get_target(e); lv_chart_series_t * series = (lv_chart_series_t *)lv_event_get_user_data(e); - lv_chart_set_next_value(chart, series, printer.extruder_target_temp); + lv_chart_set_next_value(chart, series, get_current_printer_data()->target_temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexNozzle1]); } static void set_bed_temp_chart(lv_event_t * e){ lv_obj_t * chart = lv_event_get_target(e); lv_chart_series_t * series = (lv_chart_series_t *)lv_event_get_user_data(e); - lv_chart_set_next_value(chart, series, printer.bed_temp); + lv_chart_set_next_value(chart, series, get_current_printer_data()->temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexBed]); } static void set_bed_target_temp_chart(lv_event_t * e){ lv_obj_t * chart = lv_event_get_target(e); lv_chart_series_t * series = (lv_chart_series_t *)lv_event_get_user_data(e); - lv_chart_set_next_value(chart, series, printer.bed_target_temp); + lv_chart_set_next_value(chart, series, get_current_printer_data()->target_temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexBed]); } void create_charts(lv_obj_t * root) @@ -251,13 +233,13 @@ void create_charts(lv_obj_t * root) lv_chart_set_update_mode(chart, LV_CHART_UPDATE_MODE_SHIFT); lv_chart_series_t * ser1 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_ORANGE), LV_CHART_AXIS_PRIMARY_Y); - lv_chart_set_all_value(chart, ser1, printer.extruder_target_temp); + lv_chart_set_all_value(chart, ser1, get_current_printer_data()->target_temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexNozzle1]); lv_chart_series_t * ser2 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y); - lv_chart_set_all_value(chart, ser2, printer.extruder_temp); + lv_chart_set_all_value(chart, ser2, get_current_printer_data()->temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexNozzle1]); lv_chart_series_t * ser3 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_TEAL), LV_CHART_AXIS_PRIMARY_Y); - lv_chart_set_all_value(chart, ser3, printer.bed_target_temp); + lv_chart_set_all_value(chart, ser3, get_current_printer_data()->temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexBed]); lv_chart_series_t * ser4 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_BLUE), LV_CHART_AXIS_PRIMARY_Y); - lv_chart_set_all_value(chart, ser4, printer.bed_temp); + lv_chart_set_all_value(chart, ser4, get_current_printer_data()->target_temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexBed]); lv_obj_add_event_cb(chart, set_hotend_target_temp_chart, LV_EVENT_MSG_RECEIVED, ser1); lv_obj_add_event_cb(chart, set_hotend_temp_chart, LV_EVENT_MSG_RECEIVED, ser2); @@ -391,5 +373,5 @@ void temp_panel_init(lv_obj_t * panel){ lv_obj_center(label); lv_obj_scroll_to_y(root_temp_panel, 9999, LV_ANIM_OFF); - lv_msg_send(DATA_PRINTER_TEMP_PRESET, &printer); + lv_msg_send(DATA_PRINTER_TEMP_PRESET, get_current_printer()); } \ No newline at end of file