From 9630c2683c39468bf885c560a1768d8b377d9462 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Sat, 24 Oct 2020 01:37:45 -0300 Subject: [PATCH] More MKS UI cleanup, optimization (#19869) Co-authored-by: Scott Lahteine --- Marlin/src/feature/tmc_util.h | 24 +- .../lcd/extui/lib/mks_ui/SPIFlashStorage.cpp | 3 +- .../src/lcd/extui/lib/mks_ui/draw_about.cpp | 32 +- .../lib/mks_ui/draw_acceleration_settings.cpp | 347 +++-------- .../lib/mks_ui/draw_advance_settings.cpp | 237 +------ .../draw_auto_level_offset_settings.cpp | 133 +--- .../extui/lib/mks_ui/draw_baby_stepping.cpp | 200 ++---- .../extui/lib/mks_ui/draw_change_speed.cpp | 242 +++---- .../src/lcd/extui/lib/mks_ui/draw_dialog.cpp | 588 +++++++----------- Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.h | 77 +-- .../extui/lib/mks_ui/draw_eeprom_settings.cpp | 159 +---- .../lib/mks_ui/draw_encoder_settings.cpp | 74 +-- .../extui/lib/mks_ui/draw_error_message.cpp | 16 +- .../lcd/extui/lib/mks_ui/draw_extrusion.cpp | 226 +++---- Marlin/src/lcd/extui/lib/mks_ui/draw_fan.cpp | 146 ++--- .../extui/lib/mks_ui/draw_filament_change.cpp | 170 ++--- .../lib/mks_ui/draw_filament_settings.cpp | 239 ++----- Marlin/src/lcd/extui/lib/mks_ui/draw_home.cpp | 144 +---- .../draw_homing_sensitivity_settings.cpp | 179 ++---- .../extui/lib/mks_ui/draw_jerk_settings.cpp | 164 ++--- .../lcd/extui/lib/mks_ui/draw_keyboard.cpp | 36 +- .../lcd/extui/lib/mks_ui/draw_language.cpp | 249 +++----- .../extui/lib/mks_ui/draw_level_settings.cpp | 183 +----- .../extui/lib/mks_ui/draw_machine_para.cpp | 207 +----- .../lib/mks_ui/draw_machine_settings.cpp | 185 +----- .../lcd/extui/lib/mks_ui/draw_manuaLevel.cpp | 216 ++----- .../mks_ui/draw_manual_level_pos_settings.cpp | 377 +++-------- .../lib/mks_ui/draw_max_feedrate_settings.cpp | 262 ++------ .../extui/lib/mks_ui/draw_motor_settings.cpp | 260 ++------ .../lcd/extui/lib/mks_ui/draw_move_motor.cpp | 219 ++----- .../lcd/extui/lib/mks_ui/draw_number_key.cpp | 473 +++++--------- .../lcd/extui/lib/mks_ui/draw_operation.cpp | 178 ++---- .../extui/lib/mks_ui/draw_pause_position.cpp | 132 +--- .../src/lcd/extui/lib/mks_ui/draw_preHeat.cpp | 261 +++----- .../lcd/extui/lib/mks_ui/draw_print_file.cpp | 249 +++----- .../lcd/extui/lib/mks_ui/draw_print_file.h | 4 +- .../lcd/extui/lib/mks_ui/draw_printing.cpp | 140 ++--- .../src/lcd/extui/lib/mks_ui/draw_printing.h | 18 +- .../lcd/extui/lib/mks_ui/draw_ready_print.cpp | 88 +-- Marlin/src/lcd/extui/lib/mks_ui/draw_set.cpp | 219 ++----- .../extui/lib/mks_ui/draw_step_settings.cpp | 251 ++------ .../lib/mks_ui/draw_tmc_current_settings.cpp | 324 +++------- .../mks_ui/draw_tmc_step_mode_settings.cpp | 336 ++-------- Marlin/src/lcd/extui/lib/mks_ui/draw_tool.cpp | 190 ++---- Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp | 254 ++++++-- Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h | 124 ++-- Marlin/src/lcd/extui/lib/mks_ui/draw_wifi.cpp | 113 ++-- .../lcd/extui/lib/mks_ui/draw_wifi_list.cpp | 97 ++- .../extui/lib/mks_ui/draw_wifi_settings.cpp | 206 +++--- .../lcd/extui/lib/mks_ui/draw_wifi_tips.cpp | 18 +- .../lcd/extui/lib/mks_ui/gb2312_puhui16.cpp | 6 +- .../extui/lib/mks_ui/mks_hardware_test.cpp | 2 +- .../extui/lib/mks_ui/printer_operation.cpp | 7 - .../lib/mks_ui/tft_lvgl_configuration.cpp | 30 +- .../src/lcd/extui/lib/mks_ui/wifi_upload.cpp | 4 +- buildroot/tests/mks_robin_nano35-tests | 12 + 56 files changed, 2726 insertions(+), 6604 deletions(-) diff --git a/Marlin/src/feature/tmc_util.h b/Marlin/src/feature/tmc_util.h index abde342307..b21b89f68b 100644 --- a/Marlin/src/feature/tmc_util.h +++ b/Marlin/src/feature/tmc_util.h @@ -103,9 +103,11 @@ class TMCMarlin : public TMC, public TMCStorage { inline uint16_t get_microstep_counter() { return TMC::MSCNT(); } #if HAS_STEALTHCHOP - inline void refresh_stepping_mode() { this->en_pwm_mode(this->stored.stealthChop_enabled); } - inline bool get_stealthChop() { return this->en_pwm_mode(); } - inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; } + inline bool get_stealthChop() { return this->en_pwm_mode(); } + inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; } + inline void refresh_stepping_mode() { this->en_pwm_mode(this->stored.stealthChop_enabled); } + inline void set_stealthChop(const bool stch) { this->stored.stealthChop_enabled = stch; refresh_stepping_mode(); } + inline bool toggle_stepping_mode() { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); } #endif #if ENABLED(HYBRID_THRESHOLD) @@ -170,9 +172,11 @@ class TMCMarlin : public TMC220 inline uint16_t get_microstep_counter() { return TMC2208Stepper::MSCNT(); } #if HAS_STEALTHCHOP - inline void refresh_stepping_mode() { en_spreadCycle(!this->stored.stealthChop_enabled); } - inline bool get_stealthChop() { return !this->en_spreadCycle(); } - inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; } + inline bool get_stealthChop() { return !this->en_spreadCycle(); } + inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; } + inline void refresh_stepping_mode() { this->en_spreadCycle(!this->stored.stealthChop_enabled); } + inline void set_stealthChop(const bool stch) { this->stored.stealthChop_enabled = stch; refresh_stepping_mode(); } + inline bool toggle_stepping_mode() { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); } #endif #if ENABLED(HYBRID_THRESHOLD) @@ -216,9 +220,11 @@ class TMCMarlin : public TMC220 inline uint16_t get_microstep_counter() { return TMC2209Stepper::MSCNT(); } #if HAS_STEALTHCHOP - inline void refresh_stepping_mode() { en_spreadCycle(!this->stored.stealthChop_enabled); } - inline bool get_stealthChop() { return !this->en_spreadCycle(); } - inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; } + inline bool get_stealthChop() { return !this->en_spreadCycle(); } + inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; } + inline void refresh_stepping_mode() { this->en_spreadCycle(!this->stored.stealthChop_enabled); } + inline void set_stealthChop(const bool stch) { this->stored.stealthChop_enabled = stch; refresh_stepping_mode(); } + inline bool toggle_stepping_mode() { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); } #endif #if ENABLED(HYBRID_THRESHOLD) diff --git a/Marlin/src/lcd/extui/lib/mks_ui/SPIFlashStorage.cpp b/Marlin/src/lcd/extui/lib/mks_ui/SPIFlashStorage.cpp index 3f57124451..e028b3e6ec 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/SPIFlashStorage.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/SPIFlashStorage.cpp @@ -183,10 +183,9 @@ void SPIFlashStorage::loadPage(uint8_t* buffer) { // Test env // char fname[256]; - // memset(buffer, 0, SPI_FLASH_PageSize); // snprintf(fname, sizeof(fname), "./pages/page-%03d.data", m_currentPage); // FILE *fp = fopen(fname, "rb"); - // if (fp != NULL) { + // if (fp != nullptr) { // fread(buffer, 1, SPI_FLASH_PageSize, fp); // fclose(fp); // } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_about.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_about.cpp index 48a2cb1362..b5e59692fd 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_about.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_about.cpp @@ -32,22 +32,18 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; -static lv_obj_t * fw_type, *board; //*fw_version; +extern lv_group_t *g; +static lv_obj_t *scr; +static lv_obj_t *fw_type, *board; //*fw_version; -#define ID_A_RETURN 1 +enum { ID_A_RETURN = 1 }; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_A_RETURN: - if (event == LV_EVENT_CLICKED) { - // do nothing - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - draw_return_ui(); - } + clear_cur_ui(); + draw_return_ui(); break; } } @@ -59,11 +55,7 @@ void lv_draw_about(void) { } disp_state = ABOUT_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); @@ -84,13 +76,13 @@ void lv_draw_about(void) { } //fw_version = lv_label_create(scr, SHORT_BUILD_VERSION); - //lv_obj_align(fw_version, NULL, LV_ALIGN_CENTER, 0, -60); + //lv_obj_align(fw_version, nullptr, LV_ALIGN_CENTER, 0, -60); fw_type = lv_label_create(scr, "Firmware: Marlin " SHORT_BUILD_VERSION); - lv_obj_align(fw_type, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(fw_type, nullptr, LV_ALIGN_CENTER, 0, -20); board = lv_label_create(scr, "Board: " BOARD_INFO_NAME); - lv_obj_align(board, NULL, LV_ALIGN_CENTER, 0, -60); + lv_obj_align(board, nullptr, LV_ALIGN_CENTER, 0, -60); } void lv_clear_about() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_acceleration_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_acceleration_settings.cpp index 95bba3b549..9b86929bca 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_acceleration_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_acceleration_settings.cpp @@ -29,331 +29,128 @@ #include "../../../../module/planner.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_ACCE_RETURN 1 -#define ID_ACCE_PRINT 2 -#define ID_ACCE_RETRA 3 -#define ID_ACCE_TRAVEL 4 -#define ID_ACCE_X 5 -#define ID_ACCE_Y 6 -#define ID_ACCE_Z 7 -#define ID_ACCE_E0 8 -#define ID_ACCE_E1 9 -#define ID_ACCE_UP 10 -#define ID_ACCE_DOWN 11 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_ACCE_RETURN = 1, + ID_ACCE_PRINT, + ID_ACCE_RETRA, + ID_ACCE_TRAVEL, + ID_ACCE_X, + ID_ACCE_Y, + ID_ACCE_Z, + ID_ACCE_E0, + ID_ACCE_E1, + ID_ACCE_UP, + ID_ACCE_DOWN +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_ACCE_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_acceleration_settings(); - draw_return_ui(); - } + uiCfg.para_ui_page = 0; + lv_clear_acceleration_settings(); + draw_return_ui(); break; case ID_ACCE_PRINT: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = PrintAcceleration; - lv_clear_acceleration_settings(); - lv_draw_number_key(); - } + value = PrintAcceleration; + lv_clear_acceleration_settings(); + lv_draw_number_key(); break; case ID_ACCE_RETRA: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = RetractAcceleration; - lv_clear_acceleration_settings(); - lv_draw_number_key(); - } + value = RetractAcceleration; + lv_clear_acceleration_settings(); + lv_draw_number_key(); break; case ID_ACCE_TRAVEL: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = TravelAcceleration; - lv_clear_acceleration_settings(); - lv_draw_number_key(); - } + value = TravelAcceleration; + lv_clear_acceleration_settings(); + lv_draw_number_key(); break; case ID_ACCE_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = XAcceleration; - lv_clear_acceleration_settings(); - lv_draw_number_key(); - } + value = XAcceleration; + lv_clear_acceleration_settings(); + lv_draw_number_key(); break; case ID_ACCE_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = YAcceleration; - lv_clear_acceleration_settings(); - lv_draw_number_key(); - } + value = YAcceleration; + lv_clear_acceleration_settings(); + lv_draw_number_key(); break; case ID_ACCE_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = ZAcceleration; - lv_clear_acceleration_settings(); - lv_draw_number_key(); - } + value = ZAcceleration; + lv_clear_acceleration_settings(); + lv_draw_number_key(); break; case ID_ACCE_E0: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = E0Acceleration; - lv_clear_acceleration_settings(); - lv_draw_number_key(); - } + value = E0Acceleration; + lv_clear_acceleration_settings(); + lv_draw_number_key(); break; case ID_ACCE_E1: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = E1Acceleration; - lv_clear_acceleration_settings(); - lv_draw_number_key(); - } + value = E1Acceleration; + lv_clear_acceleration_settings(); + lv_draw_number_key(); break; case ID_ACCE_UP: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_acceleration_settings(); - lv_draw_acceleration_settings(); - } + uiCfg.para_ui_page = 0; + lv_clear_acceleration_settings(); + lv_draw_acceleration_settings(); break; case ID_ACCE_DOWN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 1; - lv_clear_acceleration_settings(); - lv_draw_acceleration_settings(); - } + uiCfg.para_ui_page = 1; + lv_clear_acceleration_settings(); + lv_draw_acceleration_settings(); break; } } void lv_draw_acceleration_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL, *buttonTurnPage = NULL, *labelTurnPage = NULL; - lv_obj_t *buttonPrintValue = NULL, *labelPrintValue = NULL; - lv_obj_t *buttonRetraValue = NULL, *labelRetraValue = NULL; - lv_obj_t *buttonTravelValue = NULL, *labelTravelValue = NULL; - lv_obj_t *buttonXValue = NULL, *labelXValue = NULL; - lv_obj_t *buttonYValue = NULL, *labelYValue = NULL; - lv_obj_t *buttonZValue = NULL, *labelZValue = NULL; - lv_obj_t *buttonE0Value = NULL, *labelE0Value = NULL; - lv_obj_t *buttonE1Value = NULL, *labelE1Value = NULL; - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL, * line4 = NULL; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != ACCELERATION_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = ACCELERATION_UI; } disp_state = ACCELERATION_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, machine_menu.AccelerationConfTitle); - lv_refr_now(lv_refr_get_disp_refreshing()); if (uiCfg.para_ui_page != 1) { + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.acceleration); + lv_screen_menu_item_1_edit(scr, machine_menu.PrintAcceleration, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_ACCE_PRINT, 0, public_buf_l); - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.PrintAcceleration); - - buttonPrintValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_ACCE_PRINT); - labelPrintValue = lv_label_create_empty(buttonPrintValue); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10, machine_menu.RetractAcceleration); - - buttonRetraValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_ACCE_RETRA); - labelRetraValue = lv_label_create_empty(buttonRetraValue); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.retract_acceleration); + lv_screen_menu_item_1_edit(scr, machine_menu.RetractAcceleration, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_ACCE_RETRA, 1, public_buf_l); - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10, machine_menu.TravelAcceleration); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.travel_acceleration); + lv_screen_menu_item_1_edit(scr, machine_menu.TravelAcceleration, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_ACCE_TRAVEL, 2, public_buf_l); - buttonTravelValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_ACCE_TRAVEL); - labelTravelValue = lv_label_create_empty(buttonTravelValue); + sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[X_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.X_Acceleration, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_ACCE_X, 3, public_buf_l); - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10, machine_menu.X_Acceleration); - - buttonXValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_ACCE_X); - labelXValue = lv_label_create_empty(buttonXValue); - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - buttonTurnPage = lv_btn_create_back(scr, event_handler, ID_ACCE_DOWN); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonPrintValue); - lv_group_add_obj(g, buttonRetraValue); - lv_group_add_obj(g, buttonTravelValue); - lv_group_add_obj(g, buttonXValue); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.next, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_ACCE_DOWN, true); } else { - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.Y_Acceleration); - - buttonYValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_ACCE_Y); - labelYValue = lv_label_create_empty(buttonYValue); + sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[Y_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.Y_Acceleration, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_ACCE_Y, 0, public_buf_l); - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); + sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[Z_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.Z_Acceleration, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_ACCE_Z, 1, public_buf_l); - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10, machine_menu.Z_Acceleration); + sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[E_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.E0_Acceleration, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_ACCE_E0, 2, public_buf_l); - buttonZValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_ACCE_Z); - labelZValue = lv_label_create_empty(buttonZValue); + sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(1)]); + lv_screen_menu_item_1_edit(scr, machine_menu.E1_Acceleration, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_ACCE_E1, 3, public_buf_l); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10, machine_menu.E0_Acceleration); - - buttonE0Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_ACCE_E0); - labelE0Value = lv_label_create_empty(buttonE0Value); - - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10, machine_menu.E1_Acceleration); - - buttonE1Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_ACCE_E1); - labelE1Value = lv_label_create_empty(buttonE1Value); - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - buttonTurnPage = lv_btn_create_back(scr, event_handler, ID_ACCE_UP); - //lv_imgbtn_set_src_both(buttonTurnPage, "F:/bmp_back70x40.bin"); - //lv_imgbtn_use_label_style(buttonTurnPage); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonYValue); - lv_group_add_obj(g, buttonZValue); - lv_group_add_obj(g, buttonE0Value); - lv_group_add_obj(g, buttonE1Value); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.previous, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_ACCE_UP, true); } - //lv_obj_set_pos(buttonTurnPage, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y); - //lv_btn_set_layout(buttonTurnPage, LV_LAYOUT_OFF); - //labelTurnPage = lv_label_create_empty(buttonTurnPage); - lv_obj_set_pos(buttonTurnPage, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y); - lv_obj_set_size(buttonTurnPage, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - labelTurnPage = lv_label_create_empty(buttonTurnPage); - - buttonBack = lv_btn_create_back(scr, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE, event_handler, ID_ACCE_RETURN); - //lv_imgbtn_set_src_both(buttonBack, "F:/bmp_back70x40.bin"); - //lv_imgbtn_use_label_style(buttonBack); - label_Back = lv_label_create_empty(buttonBack); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - //lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - //lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - - if (gCfgItems.multiple_language) { - if (uiCfg.para_ui_page != 1) { - - lv_label_set_text(labelTurnPage, machine_menu.next); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.acceleration); - lv_label_set_text(labelPrintValue, public_buf_l); - lv_obj_align(labelPrintValue, buttonPrintValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.retract_acceleration); - lv_label_set_text(labelRetraValue, public_buf_l); - lv_obj_align(labelRetraValue, buttonRetraValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.travel_acceleration); - lv_label_set_text(labelTravelValue, public_buf_l); - lv_obj_align(labelTravelValue, buttonTravelValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[X_AXIS]); - lv_label_set_text(labelXValue, public_buf_l); - lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0); - } - else { - - lv_label_set_text(labelTurnPage, machine_menu.previous); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[Y_AXIS]); - lv_label_set_text(labelYValue, public_buf_l); - lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[Z_AXIS]); - lv_label_set_text(labelZValue, public_buf_l); - lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[E_AXIS]); - lv_label_set_text(labelE0Value, public_buf_l); - lv_obj_align(labelE0Value, buttonE0Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(1)]); - lv_label_set_text(labelE1Value, public_buf_l); - lv_obj_align(labelE1Value, buttonE1Value, LV_ALIGN_CENTER, 0, 0); - } - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_ACCE_RETURN, true); } void lv_clear_acceleration_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_advance_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_advance_settings.cpp index 99de179a9c..5c3b067682 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_advance_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_advance_settings.cpp @@ -28,248 +28,71 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_ADVANCE_RETURN 1 -#define ID_PAUSE_POS 2 -#define ID_PAUSE_POS_ARROW 3 -#define ID_WIFI_PARA 4 -#define ID_WIFI_PARA_ARROW 5 -#define ID_FILAMENT_SETTINGS 6 -#define ID_FILAMENT_SETTINGS_ARROW 7 -#define ID_ENCODER_SETTINGS 8 -#define ID_ENCODER_SETTINGS_ARROW 9 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_ADVANCE_RETURN = 1, + ID_PAUSE_POS, + ID_WIFI_PARA, + ID_FILAMENT_SETTINGS, + ID_ENCODER_SETTINGS +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { switch (obj->mks_obj_id) { case ID_ADVANCE_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - draw_return_ui(); - } + lv_clear_advance_settings(); + draw_return_ui(); break; case ID_PAUSE_POS: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - lv_draw_pause_position(); - } - break; - case ID_PAUSE_POS_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - lv_draw_pause_position(); - } + lv_clear_advance_settings(); + lv_draw_pause_position(); break; case ID_FILAMENT_SETTINGS: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - lv_draw_filament_settings(); - } - break; - case ID_FILAMENT_SETTINGS_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - lv_draw_filament_settings(); - } + lv_clear_advance_settings(); + lv_draw_filament_settings(); break; #if ENABLED(USE_WIFI_FUNCTION) case ID_WIFI_PARA: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - lv_draw_wifi_settings(); - } - break; - case ID_WIFI_PARA_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - lv_draw_wifi_settings(); - } + lv_clear_advance_settings(); + lv_draw_wifi_settings(); break; #endif #if HAS_ROTARY_ENCODER case ID_ENCODER_SETTINGS: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - lv_draw_encoder_settings(); - } - break; - case ID_ENCODER_SETTINGS_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - lv_draw_encoder_settings(); - } + lv_clear_advance_settings(); + lv_draw_encoder_settings(); break; #endif } } void lv_draw_advance_settings(void) { - lv_obj_t *buttonBack, *label_Back; - lv_obj_t *buttonPausePos, *labelPausePos; - lv_obj_t *buttonFilamentSettings, *labelFilamentSettings; - lv_obj_t * line1,* line2; - #if ENABLED(USE_WIFI_FUNCTION) - lv_obj_t *buttonWifiSet, *labelWifiSet, *buttonWifiSetNarrow; - #endif - #if HAS_ROTARY_ENCODER - lv_obj_t *buttonEncoder, *labelEncoder, *buttonEncoderNarrow; - #endif - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != ADVANCED_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = ADVANCED_UI; } disp_state = ADVANCED_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, machine_menu.AdvancedConfTitle); lv_refr_now(lv_refr_get_disp_refreshing()); - buttonPausePos = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonPausePos, PARA_UI_POS_X, PARA_UI_POS_Y); - lv_obj_set_size(buttonPausePos, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); - //lv_obj_set_event_cb(buttonMachine, event_handler); - lv_obj_set_event_cb_mks(buttonPausePos, event_handler, ID_PAUSE_POS, NULL, 0); - lv_btn_use_label_style(buttonPausePos); - lv_btn_set_layout(buttonPausePos, LV_LAYOUT_OFF); - labelPausePos = lv_label_create_empty(buttonPausePos); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonPausePos); - #endif - - (void)lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y + PARA_UI_ARROW_V, event_handler, ID_PAUSE_POS_ARROW); - - line1 = lv_line_create(lv_scr_act(), NULL); - lv_ex_line(line1, line_points[0]); - - buttonFilamentSettings = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonFilamentSettings, PARA_UI_POS_X, PARA_UI_POS_Y*2); - lv_obj_set_size(buttonFilamentSettings, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); - lv_obj_set_event_cb_mks(buttonFilamentSettings, event_handler, ID_FILAMENT_SETTINGS, NULL, 0); - lv_btn_use_label_style(buttonFilamentSettings); - lv_btn_set_layout(buttonFilamentSettings, LV_LAYOUT_OFF); - labelFilamentSettings = lv_label_create_empty(buttonFilamentSettings); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonFilamentSettings); - #endif - - (void)lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y*2 + PARA_UI_ARROW_V, event_handler, ID_FILAMENT_SETTINGS_ARROW); - - line2 = lv_line_create(lv_scr_act(), NULL); - lv_ex_line(line2, line_points[1]); - + int index = 0; + lv_screen_menu_item(scr, machine_menu.PausePosition, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_PAUSE_POS, index++); + lv_screen_menu_item(scr, machine_menu.FilamentConf, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_FILAMENT_SETTINGS, index++); #if ENABLED(USE_WIFI_FUNCTION) - - buttonWifiSet = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonWifiSet, PARA_UI_POS_X,PARA_UI_POS_Y*3); - lv_obj_set_size(buttonWifiSet, PARA_UI_SIZE_X,PARA_UI_SIZE_Y); - lv_obj_set_event_cb_mks(buttonWifiSet, event_handler,ID_WIFI_PARA,NULL, 0); - lv_btn_use_label_style(buttonWifiSet); - lv_btn_set_layout(buttonWifiSet, LV_LAYOUT_OFF); - labelWifiSet = lv_label_create_empty(buttonWifiSet); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonWifiSet); - #endif - - buttonWifiSetNarrow = lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 3 + PARA_UI_ARROW_V, event_handler, ID_WIFI_PARA_ARROW); - - lv_obj_t * line3 = lv_line_create(scr, NULL); - lv_ex_line(line3,line_points[2]); - - #if HAS_ROTARY_ENCODER - buttonEncoder = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonEncoder, PARA_UI_POS_X,PARA_UI_POS_Y*4); - lv_obj_set_size(buttonEncoder, PARA_UI_SIZE_X,PARA_UI_SIZE_Y); - lv_obj_set_event_cb_mks(buttonEncoder, event_handler,ID_ENCODER_SETTINGS,NULL, 0); - lv_btn_use_label_style(buttonEncoder); - lv_btn_set_layout(buttonEncoder, LV_LAYOUT_OFF); - labelEncoder = lv_label_create_empty(buttonEncoder); - - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonEncoder); - - buttonEncoderNarrow = lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 4 + PARA_UI_ARROW_V, event_handler, ID_ENCODER_SETTINGS_ARROW); - - lv_obj_t * line4 = lv_line_create(scr, NULL); - lv_ex_line(line4,line_points[3]); - #endif - - #elif HAS_ROTARY_ENCODER - buttonEncoder = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonEncoder, PARA_UI_POS_X,PARA_UI_POS_Y*3); - lv_obj_set_size(buttonEncoder, PARA_UI_SIZE_X,PARA_UI_SIZE_Y); - lv_obj_set_event_cb_mks(buttonEncoder, event_handler,ID_ENCODER_SETTINGS,NULL, 0); - lv_btn_use_label_style(buttonEncoder); - lv_btn_set_layout(buttonEncoder, LV_LAYOUT_OFF); - labelEncoder = lv_label_create_empty(buttonEncoder); - - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonEncoder); - - buttonEncoderNarrow = lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 3 + PARA_UI_ARROW_V, event_handler, ID_ENCODER_SETTINGS_ARROW); - - lv_obj_t * line3 = lv_line_create(scr, NULL); - lv_ex_line(line3,line_points[2]); + lv_screen_menu_item(scr, machine_menu.WifiSettings, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_WIFI_PARA, index++); #endif - - buttonBack = lv_imgbtn_create(scr, "F:/bmp_back70x40.bin", PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_ADVANCE_RETURN); #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); + lv_screen_menu_item(scr, machine_menu.EncoderSettings, PARA_UI_POS_X, PARA_UI_POS_Y * (index + 1), event_handler, ID_ENCODER_SETTINGS, index); + index++; #endif - label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelPausePos, machine_menu.PausePosition); - lv_obj_align(labelPausePos, buttonPausePos, LV_ALIGN_IN_LEFT_MID, 0, 0); - - lv_label_set_text(labelFilamentSettings, machine_menu.FilamentConf); - lv_obj_align(labelFilamentSettings, buttonFilamentSettings, LV_ALIGN_IN_LEFT_MID, 0, 0); - - #if ENABLED(USE_WIFI_FUNCTION) - lv_label_set_text(labelWifiSet, machine_menu.WifiSettings); - lv_obj_align(labelWifiSet, buttonWifiSet, LV_ALIGN_IN_LEFT_MID,0, 0); - #endif - #if HAS_ROTARY_ENCODER - lv_label_set_text(labelEncoder, machine_menu.EncoderSettings); - lv_obj_align(labelEncoder, buttonEncoder, LV_ALIGN_IN_LEFT_MID,0, 0); - #endif - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X + 10, PARA_UI_BACL_POS_Y, event_handler, ID_ADVANCE_RETURN, true); } void lv_clear_advance_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_auto_level_offset_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_auto_level_offset_settings.cpp index 87632a27c9..8e40956c0f 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_auto_level_offset_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_auto_level_offset_settings.cpp @@ -29,135 +29,64 @@ #include "../../../../module/probe.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_OFFSET_RETURN 1 -#define ID_OFFSET_X 2 -#define ID_OFFSET_Y 3 -#define ID_OFFSET_Z 4 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_OFFSET_RETURN = 1, + ID_OFFSET_X, + ID_OFFSET_Y, + ID_OFFSET_Z +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_OFFSET_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_auto_level_offset_settings(); - draw_return_ui(); - } + lv_clear_auto_level_offset_settings(); + draw_return_ui(); break; case ID_OFFSET_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = x_offset; - lv_clear_auto_level_offset_settings(); - lv_draw_number_key(); - } + value = x_offset; + lv_clear_auto_level_offset_settings(); + lv_draw_number_key(); break; case ID_OFFSET_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = y_offset; - lv_clear_auto_level_offset_settings(); - lv_draw_number_key(); - } + value = y_offset; + lv_clear_auto_level_offset_settings(); + lv_draw_number_key(); break; case ID_OFFSET_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = z_offset; - lv_clear_auto_level_offset_settings(); - lv_draw_number_key(); - } + value = z_offset; + lv_clear_auto_level_offset_settings(); + lv_draw_number_key(); break; } } void lv_draw_auto_level_offset_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL; - lv_obj_t *buttonXValue = NULL, *labelXValue = NULL; - lv_obj_t *buttonYValue = NULL, *labelYValue = NULL; - lv_obj_t *buttonZValue = NULL, *labelZValue = NULL; - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != NOZZLE_PROBE_OFFSET_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = NOZZLE_PROBE_OFFSET_UI; } disp_state = NOZZLE_PROBE_OFFSET_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, machine_menu.OffsetConfTitle); lv_refr_now(lv_refr_get_disp_refreshing()); - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.Xoffset); - - buttonXValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_OFFSET_X); - labelXValue = lv_label_create_empty(buttonXValue); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10, machine_menu.Yoffset); - - buttonYValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_OFFSET_Y); - labelYValue = lv_label_create_empty(buttonYValue); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); + sprintf_P(public_buf_l, PSTR("%.1f"), TERN(HAS_PROBE_XY_OFFSET, probe.offset.x, 0)); + lv_screen_menu_item_1_edit(scr, machine_menu.Xoffset, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_OFFSET_X, 0, public_buf_l); - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10, machine_menu.Zoffset); + sprintf_P(public_buf_l, PSTR("%.1f"), TERN(HAS_PROBE_XY_OFFSET, probe.offset.y, 0)); + lv_screen_menu_item_1_edit(scr, machine_menu.Yoffset, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_OFFSET_Y, 1, public_buf_l); - buttonZValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_OFFSET_Z); - labelZValue = lv_label_create_empty(buttonZValue); + sprintf_P(public_buf_l, PSTR("%.1f"), probe.offset.z); + lv_screen_menu_item_1_edit(scr, machine_menu.Zoffset, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_OFFSET_Z, 2, public_buf_l); - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - buttonBack = lv_btn_create_back(scr, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE, event_handler, ID_OFFSET_RETURN); - label_Back = lv_label_create_empty(buttonBack); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonXValue); - lv_group_add_obj(g, buttonYValue); - lv_group_add_obj(g, buttonZValue); - lv_group_add_obj(g, buttonBack); - } - #endif - - if (gCfgItems.multiple_language) { - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), TERN(HAS_PROBE_XY_OFFSET, probe.offset.x, 0)); - lv_label_set_text(labelXValue, public_buf_l); - lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), TERN(HAS_PROBE_XY_OFFSET, probe.offset.y, 0)); - lv_label_set_text(labelYValue, public_buf_l); - lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), probe.offset.z); - lv_label_set_text(labelZValue, public_buf_l); - lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_OFFSET_RETURN, true); } void lv_clear_auto_level_offset_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_baby_stepping.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_baby_stepping.cpp index adf69719cd..b0a004ed9e 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_baby_stepping.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_baby_stepping.cpp @@ -38,113 +38,75 @@ #include "../../../../module/probe.h" #endif -extern lv_group_t * g; -static lv_obj_t * scr; - -static lv_obj_t *labelV, *buttonV, * zOffsetText; - -#define ID_BABY_STEP_X_P 1 -#define ID_BABY_STEP_X_N 2 -#define ID_BABY_STEP_Y_P 3 -#define ID_BABY_STEP_Y_N 4 -#define ID_BABY_STEP_Z_P 5 -#define ID_BABY_STEP_Z_N 6 -#define ID_BABY_STEP_DIST 7 -#define ID_BABY_STEP_RETURN 8 +extern lv_group_t *g; +static lv_obj_t *scr; + +static lv_obj_t *labelV, *buttonV, *zOffsetText; + +enum { + ID_BABY_STEP_X_P = 1, + ID_BABY_STEP_X_N, + ID_BABY_STEP_Y_P, + ID_BABY_STEP_Y_N, + ID_BABY_STEP_Z_P, + ID_BABY_STEP_Z_N, + ID_BABY_STEP_DIST, + ID_BABY_STEP_RETURN +}; static float babystep_dist=0.01; static uint8_t has_adjust_z = 0; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; char baby_buf[30] = { 0 }; switch (obj->mks_obj_id) { case ID_BABY_STEP_X_P: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - sprintf_P(baby_buf, PSTR("M290 X%.3f"),babystep_dist); - gcode.process_subcommands_now_P(PSTR(baby_buf)); - has_adjust_z = 1; - } + sprintf_P(baby_buf, PSTR("M290 X%.3f"), babystep_dist); + gcode.process_subcommands_now_P(PSTR(baby_buf)); + has_adjust_z = 1; break; case ID_BABY_STEP_X_N: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - sprintf_P(baby_buf, PSTR("M290 X%.3f"),((float)0 - babystep_dist)); - gcode.process_subcommands_now_P(PSTR(baby_buf)); - has_adjust_z = 1; - } + sprintf_P(baby_buf, PSTR("M290 X%.3f"), -babystep_dist); + gcode.process_subcommands_now_P(PSTR(baby_buf)); + has_adjust_z = 1; break; case ID_BABY_STEP_Y_P: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - sprintf_P(baby_buf, PSTR("M290 Y%.3f"), babystep_dist); - gcode.process_subcommands_now_P(PSTR(baby_buf)); - has_adjust_z = 1; - } + sprintf_P(baby_buf, PSTR("M290 Y%.3f"), babystep_dist); + gcode.process_subcommands_now_P(PSTR(baby_buf)); + has_adjust_z = 1; break; case ID_BABY_STEP_Y_N: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - sprintf_P(baby_buf, PSTR("M290 Y%.3f"),((float)0 - babystep_dist)); - gcode.process_subcommands_now_P(PSTR(baby_buf)); - has_adjust_z = 1; - } + sprintf_P(baby_buf, PSTR("M290 Y%.3f"), -babystep_dist); + gcode.process_subcommands_now_P(PSTR(baby_buf)); + has_adjust_z = 1; break; case ID_BABY_STEP_Z_P: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - sprintf_P(baby_buf, PSTR("M290 Z%.3f"), babystep_dist); - gcode.process_subcommands_now_P(PSTR(baby_buf)); - has_adjust_z = 1; - } + sprintf_P(baby_buf, PSTR("M290 Z%.3f"), babystep_dist); + gcode.process_subcommands_now_P(PSTR(baby_buf)); + has_adjust_z = 1; break; case ID_BABY_STEP_Z_N: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - sprintf_P(baby_buf, PSTR("M290 Z%.3f"),((float)0 - babystep_dist)); - gcode.process_subcommands_now_P(PSTR(baby_buf)); - has_adjust_z = 1; - } + sprintf_P(baby_buf, PSTR("M290 Z%.3f"), babystep_dist); + gcode.process_subcommands_now_P(PSTR(baby_buf)); + has_adjust_z = 1; break; case ID_BABY_STEP_DIST: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (abs((int)(100 * babystep_dist)) == 1) - babystep_dist = 0.05; - else if (abs((int)(100 * babystep_dist)) == 5) - babystep_dist = 0.1; - else - babystep_dist = 0.01; - disp_baby_step_dist(); - } - + if (abs((int)(100 * babystep_dist)) == 1) + babystep_dist = 0.05; + else if (abs((int)(100 * babystep_dist)) == 5) + babystep_dist = 0.1; + else + babystep_dist = 0.01; + disp_baby_step_dist(); break; case ID_BABY_STEP_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (has_adjust_z == 1) { - TERN_(EEPROM_SETTINGS, (void)settings.save()); - has_adjust_z = 0; - } - clear_cur_ui(); - draw_return_ui(); + if (has_adjust_z == 1) { + TERN_(EEPROM_SETTINGS, (void)settings.save()); + has_adjust_z = 0; } + clear_cur_ui(); + draw_return_ui(); break; } } @@ -156,75 +118,31 @@ void lv_draw_baby_stepping(void) { } disp_state = BABY_STEP_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); - // Create an Image button - lv_obj_t *buttonXI = lv_imgbtn_create(scr, "F:/bmp_xAdd.bin", INTERVAL_V, titleHeight, event_handler, ID_BABY_STEP_X_P); - lv_obj_t *buttonXD = lv_imgbtn_create(scr, "F:/bmp_xDec.bin", INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_BABY_STEP_X_N); - lv_obj_t *buttonYI = lv_imgbtn_create(scr, "F:/bmp_yAdd.bin", BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_BABY_STEP_Y_P); - lv_obj_t *buttonYD = lv_imgbtn_create(scr, "F:/bmp_yDec.bin", BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_BABY_STEP_Y_N); - lv_obj_t *buttonZI = lv_imgbtn_create(scr, "F:/bmp_zAdd.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_BABY_STEP_Z_P); - lv_obj_t *buttonZD = lv_imgbtn_create(scr, "F:/bmp_zDec.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_BABY_STEP_Z_N); - buttonV = lv_imgbtn_create(scr, NULL, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_BABY_STEP_DIST); - lv_obj_t *buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_BABY_STEP_RETURN); - - // Create labels on the image buttons - lv_obj_t *labelXI = lv_label_create_empty(buttonXI); - lv_obj_t *labelXD = lv_label_create_empty(buttonXD); - lv_obj_t *labelYI = lv_label_create_empty(buttonYI); - lv_obj_t *labelYD = lv_label_create_empty(buttonYD); - lv_obj_t *labelZI = lv_label_create_empty(buttonZI); - lv_obj_t *labelZD = lv_label_create_empty(buttonZD); + lv_big_button_create(scr, "F:/bmp_xAdd.bin", move_menu.x_add, INTERVAL_V, titleHeight, event_handler, ID_BABY_STEP_X_P); + lv_big_button_create(scr, "F:/bmp_xDec.bin", move_menu.x_dec, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_BABY_STEP_X_N); + lv_big_button_create(scr, "F:/bmp_yAdd.bin", move_menu.y_add, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_BABY_STEP_Y_P); + lv_big_button_create(scr, "F:/bmp_yDec.bin", move_menu.y_dec, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_BABY_STEP_Y_N); + lv_big_button_create(scr, "F:/bmp_zAdd.bin", move_menu.z_add, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_BABY_STEP_Z_P); + lv_big_button_create(scr, "F:/bmp_zDec.bin", move_menu.z_dec, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_BABY_STEP_Z_N); + buttonV = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_BABY_STEP_DIST); labelV = lv_label_create_empty(buttonV); - lv_obj_t *label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - lv_label_set_text(labelXI, move_menu.x_add); - lv_obj_align(labelXI, buttonXI, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelXD, move_menu.x_dec); - lv_obj_align(labelXD, buttonXD, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelYI, move_menu.y_add); - lv_obj_align(labelYI, buttonYI, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelYD, move_menu.y_dec); - lv_obj_align(labelYD, buttonYD, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelZI, move_menu.z_add); - lv_obj_align(labelZI, buttonZI, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelZD, move_menu.z_dec); - lv_obj_align(labelZD, buttonZD, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonXI); - lv_group_add_obj(g, buttonXD); - lv_group_add_obj(g, buttonYI); - lv_group_add_obj(g, buttonYD); - lv_group_add_obj(g, buttonZI); - lv_group_add_obj(g, buttonZD); lv_group_add_obj(g, buttonV); - lv_group_add_obj(g, buttonBack); } #endif + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_BABY_STEP_RETURN); + disp_baby_step_dist(); - zOffsetText = lv_label_create(scr, 290, TITLE_YPOS, NULL); + zOffsetText = lv_label_create(scr, 290, TITLE_YPOS, nullptr); disp_z_offset_value(); } @@ -255,7 +173,7 @@ void disp_baby_step_dist() { void disp_z_offset_value() { char buf[20]; - sprintf_P(buf, PSTR("offset Z: %.3f"), (double)TERN(HAS_BED_PROBE, probe.offset.z, 0)); + sprintf_P(buf, PSTR("offset Z: %.3f"), (float)TERN(HAS_BED_PROBE, probe.offset.z, 0)); lv_label_set_text(zOffsetText, buf); } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_change_speed.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_change_speed.cpp index 848b625559..05158b181c 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_change_speed.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_change_speed.cpp @@ -33,179 +33,136 @@ #include "../../../../module/planner.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; static lv_obj_t *labelStep, *buttonStep, *buttonMov, *buttonExt; static lv_obj_t *labelMov, *labelExt; -static lv_obj_t * printSpeedText; +static lv_obj_t *printSpeedText; -#define ID_C_ADD 1 -#define ID_C_DEC 2 -#define ID_C_MOVE 3 -#define ID_C_EXT 4 -#define ID_C_STEP 5 -#define ID_C_RETURN 6 +enum { + ID_C_ADD = 1, + ID_C_DEC, + ID_C_MOVE, + ID_C_EXT, + ID_C_STEP, + ID_C_RETURN +}; -static uint8_t speedType; +static bool editingFlowrate; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_C_ADD: - if (event == LV_EVENT_CLICKED) { - // nothing to do + if (!editingFlowrate) { + if (feedrate_percentage < MAX_EXT_SPEED_PERCENT - uiCfg.stepPrintSpeed) + feedrate_percentage += uiCfg.stepPrintSpeed; + else + feedrate_percentage = MAX_EXT_SPEED_PERCENT; } - else if (event == LV_EVENT_RELEASED) { - if (speedType == 0) { - if (feedrate_percentage < MAX_EXT_SPEED_PERCENT - uiCfg.stepPrintSpeed) - feedrate_percentage += uiCfg.stepPrintSpeed; - else - feedrate_percentage = MAX_EXT_SPEED_PERCENT; - } - else if (speedType == 1) { - if (planner.flow_percentage[0] < MAX_EXT_SPEED_PERCENT - uiCfg.stepPrintSpeed) - planner.flow_percentage[0] += uiCfg.stepPrintSpeed; - else - planner.flow_percentage[0] = MAX_EXT_SPEED_PERCENT; - //planner.e_factor[0]= planner.flow_percentage[0]*0.01; - //planner.flow_percentage[1] = planner.flow_percentage[0]; - //planner.e_factor[1]= planner.flow_percentage[1]*0.01; - planner.refresh_e_factor(0); - #if HAS_MULTI_EXTRUDER - planner.flow_percentage[1] = planner.flow_percentage[0]; - planner.refresh_e_factor(1); - #endif - } - disp_print_speed(); + else { + if (planner.flow_percentage[0] < MAX_EXT_SPEED_PERCENT - uiCfg.stepPrintSpeed) + planner.flow_percentage[0] += uiCfg.stepPrintSpeed; + else + planner.flow_percentage[0] = MAX_EXT_SPEED_PERCENT; + //planner.e_factor[0]= planner.flow_percentage[0]*0.01; + //planner.flow_percentage[1] = planner.flow_percentage[0]; + //planner.e_factor[1]= planner.flow_percentage[1]*0.01; + planner.refresh_e_factor(0); + #if HAS_MULTI_EXTRUDER + planner.flow_percentage[1] = planner.flow_percentage[0]; + planner.refresh_e_factor(1); + #endif } + disp_print_speed(); break; case ID_C_DEC: - if (event == LV_EVENT_CLICKED) { - // nothing to do + if (!editingFlowrate) { + if (feedrate_percentage > MIN_EXT_SPEED_PERCENT + uiCfg.stepPrintSpeed) + feedrate_percentage -= uiCfg.stepPrintSpeed; + else + feedrate_percentage = MIN_EXT_SPEED_PERCENT; } - else if (event == LV_EVENT_RELEASED) { - if (speedType == 0) { - if (feedrate_percentage > MIN_EXT_SPEED_PERCENT + uiCfg.stepPrintSpeed) - feedrate_percentage -= uiCfg.stepPrintSpeed; - else - feedrate_percentage = MIN_EXT_SPEED_PERCENT; - } - else if (speedType == 1) { - if (planner.flow_percentage[0] > MIN_EXT_SPEED_PERCENT + uiCfg.stepPrintSpeed) - planner.flow_percentage[0] -= uiCfg.stepPrintSpeed; - else - planner.flow_percentage[0] = MIN_EXT_SPEED_PERCENT; - //planner.e_factor[0]= planner.flow_percentage[0] * 0.01; - //planner.flow_percentage[1] = planner.flow_percentage[0]; - //planner.e_factor[1]= planner.flow_percentage[1] * 0.01; - planner.refresh_e_factor(0); - #if HAS_MULTI_EXTRUDER - planner.flow_percentage[1] = planner.flow_percentage[0]; - planner.refresh_e_factor(1); - #endif - } - disp_print_speed(); + else { + if (planner.flow_percentage[0] > MIN_EXT_SPEED_PERCENT + uiCfg.stepPrintSpeed) + planner.flow_percentage[0] -= uiCfg.stepPrintSpeed; + else + planner.flow_percentage[0] = MIN_EXT_SPEED_PERCENT; + //planner.e_factor[0]= planner.flow_percentage[0] * 0.01; + //planner.flow_percentage[1] = planner.flow_percentage[0]; + //planner.e_factor[1]= planner.flow_percentage[1] * 0.01; + planner.refresh_e_factor(0); + #if HAS_MULTI_EXTRUDER + planner.flow_percentage[1] = planner.flow_percentage[0]; + planner.refresh_e_factor(1); + #endif } + disp_print_speed(); break; case ID_C_MOVE: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - speedType = 0; - disp_speed_type(); - disp_print_speed(); - } + editingFlowrate = false; + disp_speed_type(); + disp_print_speed(); break; case ID_C_EXT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - speedType = 1; - disp_speed_type(); - disp_print_speed(); - } + editingFlowrate = true; + disp_speed_type(); + disp_print_speed(); break; case ID_C_STEP: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (uiCfg.stepPrintSpeed == 1) - uiCfg.stepPrintSpeed = 5; - else if (uiCfg.stepPrintSpeed == 5) - uiCfg.stepPrintSpeed = 10; - else - uiCfg.stepPrintSpeed = 1; - disp_speed_step(); - } + if (uiCfg.stepPrintSpeed == 1) + uiCfg.stepPrintSpeed = 5; + else if (uiCfg.stepPrintSpeed == 5) + uiCfg.stepPrintSpeed = 10; + else + uiCfg.stepPrintSpeed = 1; + disp_speed_step(); break; case ID_C_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - draw_return_ui(); - } + clear_cur_ui(); + draw_return_ui(); break; } } void lv_draw_change_speed(void) { - lv_obj_t *buttonAdd, *buttonDec; - lv_obj_t *buttonBack; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != CHANGE_SPEED_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = CHANGE_SPEED_UI; } disp_state = CHANGE_SPEED_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); // Create an Image button - buttonAdd = lv_imgbtn_create(scr, "F:/bmp_Add.bin", INTERVAL_V, titleHeight, event_handler, ID_C_ADD); - buttonDec = lv_imgbtn_create(scr, "F:/bmp_Dec.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_C_DEC); - buttonMov = lv_imgbtn_create(scr, NULL, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_C_MOVE); - buttonExt = lv_imgbtn_create(scr, NULL, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_C_EXT); - buttonStep = lv_imgbtn_create(scr, NULL, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_C_STEP); - buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_C_RETURN); + lv_big_button_create(scr, "F:/bmp_Add.bin", speed_menu.add, INTERVAL_V, titleHeight, event_handler, ID_C_ADD); + lv_big_button_create(scr, "F:/bmp_Dec.bin", speed_menu.dec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_C_DEC); + buttonMov = lv_imgbtn_create(scr, nullptr, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_C_MOVE); + buttonExt = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_C_EXT); + buttonStep = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_C_STEP); + #if HAS_ROTARY_ENCODER + if (gCfgItems.encoder_enable) { + lv_group_add_obj(g, buttonMov); + lv_group_add_obj(g, buttonExt); + lv_group_add_obj(g, buttonStep); + } + #endif + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_C_RETURN); // Create labels on the image buttons - lv_obj_t *labelAdd = lv_label_create_empty(buttonAdd); - lv_obj_t *labelDec = lv_label_create_empty(buttonDec); labelMov = lv_label_create_empty(buttonMov); labelExt = lv_label_create_empty(buttonExt); labelStep = lv_label_create_empty(buttonStep); - lv_obj_t *label_Back = lv_label_create_empty(buttonBack); - if (gCfgItems.multiple_language) { - lv_label_set_text(labelAdd, speed_menu.add); - lv_obj_align(labelAdd, buttonAdd, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelDec, speed_menu.dec); - lv_obj_align(labelDec, buttonDec, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonAdd); - lv_group_add_obj(g, buttonDec); lv_group_add_obj(g, buttonMov); lv_group_add_obj(g, buttonExt); lv_group_add_obj(g, buttonStep); - lv_group_add_obj(g, buttonBack); } #endif @@ -246,34 +203,27 @@ void disp_print_speed() { public_buf_l[0] = '\0'; - if (speedType == 0) { // move - strcat(public_buf_l, speed_menu.move_speed); - strcat_P(public_buf_l, PSTR(": ")); - sprintf_P(buf, PSTR("%d%%"), feedrate_percentage); - strcat(public_buf_l, buf); + int16_t val; + const char *lbl; + if (editingFlowrate) { + lbl = speed_menu.extrude_speed; + val = planner.flow_percentage[0]; } - else if (speedType == 1) { // e1 - strcat(public_buf_l, speed_menu.extrude_speed); - strcat_P(public_buf_l, PSTR(": ")); - sprintf_P(buf, PSTR("%d%%"), planner.flow_percentage[0]); - strcat(public_buf_l, buf); + else { + lbl = speed_menu.move_speed; + val = feedrate_percentage; } + strcpy(public_buf_l, lbl); + strcat_P(public_buf_l, PSTR(": ")); + sprintf_P(buf, PSTR("%d%%"), val); + strcat(public_buf_l, buf); lv_label_set_text(printSpeedText, public_buf_l); - lv_obj_align(printSpeedText, NULL, LV_ALIGN_CENTER, 0, -65); + lv_obj_align(printSpeedText, nullptr, LV_ALIGN_CENTER, 0, -65); } void disp_speed_type() { - switch (speedType) { - case 1: - lv_imgbtn_set_src_both(buttonMov, "F:/bmp_mov_changeSpeed.bin"); - lv_imgbtn_set_src_both(buttonExt, "F:/bmp_extruct_sel.bin"); - break; - - default: - lv_imgbtn_set_src_both(buttonMov, "F:/bmp_mov_sel.bin"); - lv_imgbtn_set_src_both(buttonExt, "F:/bmp_speed_extruct.bin"); - break; - } + lv_imgbtn_set_src_both(buttonMov, editingFlowrate ? "F:/bmp_mov_changeSpeed.bin" : "F:/bmp_mov_sel.bin"); + lv_imgbtn_set_src_both(buttonExt, editingFlowrate ? "F:/bmp_extruct_sel.bin" : "F:/bmp_speed_extruct.bin"); lv_obj_refresh_ext_draw_pad(buttonExt); lv_obj_refresh_ext_draw_pad(buttonMov); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp index 07e0665ce4..a18964919a 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp @@ -55,189 +55,162 @@ #include "../../../../feature/pause.h" #endif -extern lv_group_t * g; -static lv_obj_t * scr; -static lv_obj_t * tempText1; -static lv_obj_t * filament_bar; +extern lv_group_t *g; +static lv_obj_t *scr, *tempText1, *filament_bar; extern uint8_t sel_id; extern bool once_flag, gcode_preview_over; -extern int upload_result ; +extern int upload_result; extern uint32_t upload_time; extern uint32_t upload_size; -extern uint8_t temperature_change_frequency; +extern bool temps_update_flag; -static void btn_ok_event_cb(lv_obj_t * btn, lv_event_t event) { - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (uiCfg.dialogType == DIALOG_TYPE_PRINT_FILE) { - #if HAS_GCODE_PREVIEW - preview_gcode_prehandle(list_file.file_name[sel_id]); - #endif - reset_print_time(); - start_print_time(); - - uiCfg.print_state = WORKING; - lv_clear_dialog(); - lv_draw_printing(); - - #if ENABLED(SDSUPPORT) - if (!gcode_preview_over) { - char *cur_name; - cur_name = strrchr(list_file.file_name[sel_id], '/'); - - SdFile file, *curDir; - card.endFilePrint(); - const char * const fname = card.diveToFile(true, curDir, cur_name); - if (!fname) return; - if (file.open(curDir, fname, O_READ)) { - gCfgItems.curFilesize = file.fileSize(); - file.close(); - update_spi_flash(); - } - card.openFileRead(cur_name); - if (card.isFileOpen()) { - feedrate_percentage = 100; - //saved_feedrate_percentage = feedrate_percentage; - planner.flow_percentage[0] = 100; - planner.e_factor[0] = planner.flow_percentage[0] * 0.01f; - #if HAS_MULTI_EXTRUDER - planner.flow_percentage[1] = 100; - planner.e_factor[1] = planner.flow_percentage[1] * 0.01f; - #endif - card.startFileprint(); - #if ENABLED(POWER_LOSS_RECOVERY) - recovery.prepare(); - #endif - once_flag = false; - } +static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; + if (DIALOG_IS(TYPE_PRINT_FILE)) { + #if HAS_GCODE_PREVIEW + preview_gcode_prehandle(list_file.file_name[sel_id]); + #endif + reset_print_time(); + start_print_time(); + + uiCfg.print_state = WORKING; + lv_clear_dialog(); + lv_draw_printing(); + + #if ENABLED(SDSUPPORT) + if (!gcode_preview_over) { + char *cur_name; + cur_name = strrchr(list_file.file_name[sel_id], '/'); + + SdFile file, *curDir; + card.endFilePrint(); + const char * const fname = card.diveToFile(true, curDir, cur_name); + if (!fname) return; + if (file.open(curDir, fname, O_READ)) { + gCfgItems.curFilesize = file.fileSize(); + file.close(); + update_spi_flash(); + } + card.openFileRead(cur_name); + if (card.isFileOpen()) { + feedrate_percentage = 100; + //saved_feedrate_percentage = feedrate_percentage; + planner.flow_percentage[0] = 100; + planner.e_factor[0] = planner.flow_percentage[0] * 0.01f; + #if HAS_MULTI_EXTRUDER + planner.flow_percentage[1] = 100; + planner.e_factor[1] = planner.flow_percentage[1] * 0.01f; + #endif + card.startFileprint(); + #if ENABLED(POWER_LOSS_RECOVERY) + recovery.prepare(); + #endif + once_flag = false; } - #endif - } - else if (uiCfg.dialogType == DIALOG_TYPE_STOP) { - wait_for_heatup = false; - stop_print_time(); - lv_clear_dialog(); - lv_draw_ready_print(); - - #if ENABLED(SDSUPPORT) - //card.endFilePrint(); - //wait_for_heatup = false; - uiCfg.print_state = IDLE; - card.flag.abort_sd_printing = true; - //queue.clear(); - //quickstop_stepper(); - //print_job_timer.stop(); - //thermalManager.disable_all_heaters(); - - //#if ENABLED(POWER_LOSS_RECOVERY) - // recovery.purge(); - //#endif - //queue.enqueue_now_P(PSTR("G91\nG1 Z10\nG90\nG28 X0 Y0")); - //queue.inject_P(PSTR("G91\nG1 Z10\nG90\nG28 X0 Y0\nM84\nM107")); - #endif - } - else if (uiCfg.dialogType == DIALOG_TYPE_FINISH_PRINT) { - clear_cur_ui(); - lv_draw_ready_print(); - } - #if ENABLED(ADVANCED_PAUSE_FEATURE) - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_WAITING - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_INSERT - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_HEAT - ) { - wait_for_user = false; - } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_OPTION) { - pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE; - } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_RESUME) { - clear_cur_ui(); - draw_return_ui(); } #endif - else if (uiCfg.dialogType == DIALOG_STORE_EEPROM_TIPS) { - TERN_(EEPROM_SETTINGS, (void)settings.save()); - clear_cur_ui(); - draw_return_ui(); - } - else if (uiCfg.dialogType == DIALOG_READ_EEPROM_TIPS) { - TERN_(EEPROM_SETTINGS, (void)settings.load()); - clear_cur_ui(); - draw_return_ui(); - } - else if (uiCfg.dialogType == DIALOG_REVERT_EEPROM_TIPS) { - TERN_(EEPROM_SETTINGS, (void)settings.reset()); - clear_cur_ui(); - draw_return_ui(); - } - else if (uiCfg.dialogType == DIALOG_WIFI_CONFIG_TIPS) { - uiCfg.configWifi = 1; - clear_cur_ui(); - draw_return_ui(); - } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED) { - uiCfg.filament_heat_completed_load = 1; - } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED) { - uiCfg.filament_heat_completed_unload = 1; - } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOAD_COMPLETED - || uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOAD_COMPLETED - ) { + } + else if (DIALOG_IS(TYPE_STOP)) { + wait_for_heatup = false; + stop_print_time(); + lv_clear_dialog(); + lv_draw_ready_print(); + + #if ENABLED(SDSUPPORT) + //card.endFilePrint(); + //wait_for_heatup = false; + uiCfg.print_state = IDLE; + card.flag.abort_sd_printing = true; + //queue.clear(); + //quickstop_stepper(); + //print_job_timer.stop(); + //thermalManager.disable_all_heaters(); + + //#if ENABLED(POWER_LOSS_RECOVERY) + // recovery.purge(); + //#endif + //queue.enqueue_now_P(PSTR("G91\nG1 Z10\nG90\nG28 X0 Y0")); + //queue.inject_P(PSTR("G91\nG1 Z10\nG90\nG28 X0 Y0\nM84\nM107")); + #endif + } + else if (DIALOG_IS(TYPE_FINISH_PRINT)) { + clear_cur_ui(); + lv_draw_ready_print(); + } + #if ENABLED(ADVANCED_PAUSE_FEATURE) + else if (DIALOG_IS(PAUSE_MESSAGE_WAITING, PAUSE_MESSAGE_INSERT, PAUSE_MESSAGE_HEAT)) + wait_for_user = false; + else if (DIALOG_IS(PAUSE_MESSAGE_OPTION)) + pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE; + else if (DIALOG_IS(PAUSE_MESSAGE_RESUME)) { clear_cur_ui(); draw_return_ui(); } + #endif + else if (DIALOG_IS(STORE_EEPROM_TIPS)) { + TERN_(EEPROM_SETTINGS, (void)settings.save()); + clear_cur_ui(); + draw_return_ui(); + } + else if (DIALOG_IS(READ_EEPROM_TIPS)) { + TERN_(EEPROM_SETTINGS, (void)settings.load()); + clear_cur_ui(); + draw_return_ui(); + } + else if (DIALOG_IS(REVERT_EEPROM_TIPS)) { + TERN_(EEPROM_SETTINGS, (void)settings.reset()); + clear_cur_ui(); + draw_return_ui(); + } + else if (DIALOG_IS(WIFI_CONFIG_TIPS)) { + uiCfg.configWifi = 1; + clear_cur_ui(); + draw_return_ui(); + } + else if (DIALOG_IS(TYPE_FILAMENT_HEAT_LOAD_COMPLETED)) + uiCfg.filament_heat_completed_load = 1; + else if (DIALOG_IS(TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED)) + uiCfg.filament_heat_completed_unload = 1; + else if (DIALOG_IS(TYPE_FILAMENT_LOAD_COMPLETED, TYPE_FILAMENT_UNLOAD_COMPLETED)) { + clear_cur_ui(); + draw_return_ui(); } } -static void btn_cancel_event_cb(lv_obj_t * btn, lv_event_t event) { - if (event == LV_EVENT_CLICKED) { - // nothing to do +static void btn_cancel_event_cb(lv_obj_t *btn, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; + if (DIALOG_IS(PAUSE_MESSAGE_OPTION)) { + #if ENABLED(ADVANCED_PAUSE_FEATURE) + pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; + #endif } - else if (event == LV_EVENT_RELEASED) { - if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_OPTION) { - #if ENABLED(ADVANCED_PAUSE_FEATURE) - pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; - #endif - } - else if ((uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOAD_HEAT) - || (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOAD_HEAT) - || (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED) - || (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED) - ) { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target= uiCfg.desireSprayerTempBak; - clear_cur_ui(); - draw_return_ui(); - } - else if ((uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOADING) - || (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOADING) - ) { - queue.enqueue_one_P(PSTR("M410")); - uiCfg.filament_rate = 0; - uiCfg.filament_loading_completed = 0; - uiCfg.filament_unloading_completed = 0; - uiCfg.filament_loading_time_flg = 0; - uiCfg.filament_loading_time_cnt = 0; - uiCfg.filament_unloading_time_flg = 0; - uiCfg.filament_unloading_time_cnt = 0; - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = uiCfg.desireSprayerTempBak; - clear_cur_ui(); - draw_return_ui(); - } - else { - clear_cur_ui(); - draw_return_ui(); - } + else if (DIALOG_IS(TYPE_FILAMENT_LOAD_HEAT, TYPE_FILAMENT_UNLOAD_HEAT, TYPE_FILAMENT_HEAT_LOAD_COMPLETED, TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED)) { + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target= uiCfg.desireSprayerTempBak; + clear_cur_ui(); + draw_return_ui(); + } + else if (DIALOG_IS(TYPE_FILAMENT_LOADING, TYPE_FILAMENT_UNLOADING)) { + queue.enqueue_one_P(PSTR("M410")); + uiCfg.filament_rate = 0; + uiCfg.filament_loading_completed = 0; + uiCfg.filament_unloading_completed = 0; + uiCfg.filament_loading_time_flg = 0; + uiCfg.filament_loading_time_cnt = 0; + uiCfg.filament_unloading_time_flg = 0; + uiCfg.filament_unloading_time_cnt = 0; + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = uiCfg.desireSprayerTempBak; + clear_cur_ui(); + draw_return_ui(); + } + else { + clear_cur_ui(); + draw_return_ui(); } } void lv_draw_dialog(uint8_t type) { - - lv_obj_t * btnOk = NULL; - lv_obj_t * btnCancel = NULL; + lv_obj_t *btnOk = nullptr, *btnCancel = nullptr; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != DIALOG_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = DIALOG_UI; @@ -246,153 +219,70 @@ void lv_draw_dialog(uint8_t type) { uiCfg.dialogType = type; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); - static lv_style_t style_btn_rel; // A variable to store the released style - lv_style_copy(&style_btn_rel, &lv_style_plain); // Initialize from a built-in style - style_btn_rel.body.border.color = lv_color_hex3(0x269); - style_btn_rel.body.border.width = 1; - style_btn_rel.body.main_color = lv_color_hex3(0xADF); - style_btn_rel.body.grad_color = lv_color_hex3(0x46B); - style_btn_rel.body.shadow.width = 4; - style_btn_rel.body.shadow.type = LV_SHADOW_BOTTOM; - style_btn_rel.body.radius = LV_RADIUS_CIRCLE; - style_btn_rel.text.color = lv_color_hex3(0xDEF); - style_btn_rel.text.font = &TERN(HAS_SPI_FLASH_FONT, gb2312_puhui32, lv_font_roboto_22); - - static lv_style_t style_btn_pr; // A variable to store the pressed style - lv_style_copy(&style_btn_pr, &style_btn_rel); // Initialize from the released style - style_btn_pr.body.border.color = lv_color_hex3(0x46B); - style_btn_pr.body.main_color = lv_color_hex3(0x8BD); - style_btn_pr.body.grad_color = lv_color_hex3(0x24A); - style_btn_pr.body.shadow.width = 2; - style_btn_pr.text.color = lv_color_hex3(0xBCD); - style_btn_pr.text.font = &TERN(HAS_SPI_FLASH_FONT, gb2312_puhui32, lv_font_roboto_22); - - // Set button styles for Released and Pressed - auto lv_btn_use_button_style = [&](lv_obj_t *btn) { - lv_btn_set_style(btn, LV_BTN_STYLE_REL, &style_btn_rel); - lv_btn_set_style(btn, LV_BTN_STYLE_PR, &style_btn_pr); - }; - lv_obj_t *labelDialog = lv_label_create_empty(scr); - if (uiCfg.dialogType == DIALOG_TYPE_FINISH_PRINT || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_RESUME) { - btnOk = lv_btn_create(scr, NULL); // Add a button the current screen - lv_obj_set_pos(btnOk, BTN_OK_X + 90, BTN_OK_Y); // Set its position - lv_obj_set_size(btnOk, 100, 50); // Set its size - lv_obj_set_event_cb(btnOk, btn_ok_event_cb); - lv_btn_use_button_style(btnOk); + if (DIALOG_IS(TYPE_FINISH_PRINT, PAUSE_MESSAGE_RESUME)) { + btnOk = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_ok_event_cb); lv_obj_t *labelOk = lv_label_create_empty(btnOk); // Add a label to the button lv_label_set_text(labelOk, print_file_dialog_menu.confirm); // Set the labels text } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_WAITING - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_INSERT - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_HEAT - ) { - btnOk = lv_btn_create(scr, NULL); // Add a button the current screen - lv_obj_set_pos(btnOk, BTN_OK_X + 90, BTN_OK_Y); // Set its position - lv_obj_set_size(btnOk, 100, 50); // Set its size - lv_obj_set_event_cb(btnOk, btn_ok_event_cb); - lv_btn_use_button_style(btnOk); + else if (DIALOG_IS(PAUSE_MESSAGE_WAITING, PAUSE_MESSAGE_INSERT, PAUSE_MESSAGE_HEAT)) { + btnOk = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_ok_event_cb); lv_obj_t *labelOk = lv_label_create_empty(btnOk); // Add a label to the button lv_label_set_text(labelOk, print_file_dialog_menu.confirm); // Set the labels text } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_PAUSING - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_CHANGING - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_UNLOAD - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_LOAD - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_PURGE - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_RESUME - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_HEATING - ) { + else if (DIALOG_IS(PAUSE_MESSAGE_PAUSING, PAUSE_MESSAGE_CHANGING, PAUSE_MESSAGE_UNLOAD, PAUSE_MESSAGE_LOAD, PAUSE_MESSAGE_PURGE, PAUSE_MESSAGE_RESUME, PAUSE_MESSAGE_HEATING)) { // nothing to do } - else if (uiCfg.dialogType == WIFI_ENABLE_TIPS) { - btnCancel = lv_btn_create(scr, NULL); - lv_obj_set_pos(btnCancel, BTN_OK_X+90, BTN_OK_Y); - lv_obj_set_size(btnCancel, 100, 50); - lv_obj_set_event_cb(btnCancel, btn_cancel_event_cb); - lv_btn_use_button_style(btnCancel); + else if (DIALOG_IS(WIFI_ENABLE_TIPS)) { + btnCancel = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_cancel_event_cb); lv_obj_t *labelCancel = lv_label_create_empty(btnCancel); lv_label_set_text(labelCancel, print_file_dialog_menu.cancle); } - else if (uiCfg.dialogType == DIALOG_TRANSFER_NO_DEVICE) { - btnCancel = lv_btn_create(scr, NULL); - lv_obj_set_pos(btnCancel, BTN_OK_X+90, BTN_OK_Y); - lv_obj_set_size(btnCancel, 100, 50); - lv_obj_set_event_cb(btnCancel, btn_cancel_event_cb); - lv_btn_use_button_style(btnCancel); + else if (DIALOG_IS(TRANSFER_NO_DEVICE)) { + btnCancel = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_cancel_event_cb); lv_obj_t *labelCancel = lv_label_create_empty(btnCancel); lv_label_set_text(labelCancel, print_file_dialog_menu.cancle); } #if ENABLED(USE_WIFI_FUNCTION) - else if (uiCfg.dialogType == DIALOG_TYPE_UPLOAD_FILE) { + else if (DIALOG_IS(TYPE_UPLOAD_FILE)) { if (upload_result == 2) { - btnCancel = lv_btn_create(scr, NULL); - lv_obj_set_pos(btnCancel, BTN_OK_X+90, BTN_OK_Y); - lv_obj_set_size(btnCancel, 100, 50); - lv_obj_set_event_cb(btnCancel, btn_cancel_event_cb); - lv_btn_use_button_style(btnCancel); + btnCancel = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_cancel_event_cb); lv_obj_t *labelCancel = lv_label_create_empty(btnCancel); lv_label_set_text(labelCancel, print_file_dialog_menu.cancle); } else if (upload_result == 3) { - btnOk = lv_btn_create(scr, NULL); - lv_obj_set_pos(btnOk, BTN_OK_X+90, BTN_OK_Y); - lv_obj_set_size(btnOk, 100, 50); - lv_obj_set_event_cb(btnOk, btn_ok_event_cb); - lv_btn_use_button_style(btnOk); + btnOk = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_ok_event_cb); lv_obj_t *labelOk = lv_label_create_empty(btnOk); lv_label_set_text(labelOk, print_file_dialog_menu.confirm); } } - #endif //USE_WIFI_FUNCTION - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOAD_HEAT - || uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOAD_HEAT - ) { - btnCancel = lv_btn_create(scr, NULL); - lv_obj_set_pos(btnCancel, BTN_OK_X+90, BTN_OK_Y); - lv_obj_set_size(btnCancel, 100, 50); - lv_obj_set_event_cb(btnCancel, btn_cancel_event_cb); - lv_btn_use_button_style(btnCancel); + #endif + else if (DIALOG_IS(TYPE_FILAMENT_LOAD_HEAT, TYPE_FILAMENT_UNLOAD_HEAT)) { + btnCancel = lv_button_btn_create(scr, BTN_OK_X+90, BTN_OK_Y, 100, 50, btn_cancel_event_cb); lv_obj_t *labelCancel = lv_label_create_empty(btnCancel); lv_label_set_text(labelCancel, print_file_dialog_menu.cancle); tempText1 = lv_label_create_empty(scr); filament_sprayer_temp(); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOAD_COMPLETED - || uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOAD_COMPLETED - ) { - btnOk = lv_btn_create(scr, NULL); - lv_obj_set_pos(btnOk, BTN_OK_X + 90, BTN_OK_Y); - lv_obj_set_size(btnOk, 100, 50); - lv_obj_set_event_cb(btnOk, btn_ok_event_cb); - lv_btn_use_button_style(btnOk); + else if (DIALOG_IS(TYPE_FILAMENT_LOAD_COMPLETED, TYPE_FILAMENT_UNLOAD_COMPLETED)) { + btnOk = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_ok_event_cb); lv_obj_t *labelOk = lv_label_create_empty(btnOk); lv_label_set_text(labelOk, print_file_dialog_menu.confirm); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOADING - || uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOADING - ) { - btnCancel = lv_btn_create(scr, NULL); - lv_obj_set_pos(btnCancel, BTN_OK_X+90, BTN_OK_Y); - lv_obj_set_size(btnCancel, 100, 50); - lv_obj_set_event_cb(btnCancel, btn_cancel_event_cb); - lv_btn_use_button_style(btnCancel); + else if (DIALOG_IS(TYPE_FILAMENT_LOADING, TYPE_FILAMENT_UNLOADING)) { + btnCancel = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_cancel_event_cb); lv_obj_t *labelCancel = lv_label_create_empty(btnCancel); lv_label_set_text(labelCancel, print_file_dialog_menu.cancle); - filament_bar = lv_bar_create(scr, NULL); + filament_bar = lv_bar_create(scr, nullptr); lv_obj_set_pos(filament_bar, (TFT_WIDTH-400)/2, ((TFT_HEIGHT - titleHeight)-40)/2); lv_obj_set_size(filament_bar, 400, 25); lv_bar_set_style(filament_bar, LV_BAR_STYLE_INDIC, &lv_bar_style_indic); @@ -400,21 +290,13 @@ void lv_draw_dialog(uint8_t type) { lv_bar_set_value(filament_bar, 0, LV_ANIM_ON); } else { - btnOk = lv_btn_create(scr, NULL); // Add a button the current screen - lv_obj_set_pos(btnOk, BTN_OK_X, BTN_OK_Y); // Set its position - lv_obj_set_size(btnOk, 100, 50); // Set its size - lv_obj_set_event_cb(btnOk, btn_ok_event_cb); - lv_btn_use_button_style(btnOk); + btnOk = lv_button_btn_create(scr, BTN_OK_X, BTN_OK_Y, 100, 50, btn_ok_event_cb); lv_obj_t *labelOk = lv_label_create_empty(btnOk); // Add a label to the button - btnCancel = lv_btn_create(scr, NULL); // Add a button the current screen - lv_obj_set_pos(btnCancel, BTN_CANCEL_X, BTN_CANCEL_Y); // Set its position - lv_obj_set_size(btnCancel, 100, 50); // Set its size - lv_obj_set_event_cb(btnCancel, btn_cancel_event_cb); - lv_btn_use_button_style(btnCancel); + btnCancel = lv_button_btn_create(scr, BTN_CANCEL_X, BTN_CANCEL_Y, 100, 50, btn_cancel_event_cb); lv_obj_t *labelCancel = lv_label_create_empty(btnCancel); // Add a label to the button - if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_OPTION) { + if (DIALOG_IS(PAUSE_MESSAGE_OPTION)) { lv_label_set_text(labelOk, pause_msg_menu.purgeMore); // Set the labels text lv_label_set_text(labelCancel, pause_msg_menu.continuePrint); } @@ -423,105 +305,103 @@ void lv_draw_dialog(uint8_t type) { lv_label_set_text(labelCancel, print_file_dialog_menu.cancle); } } - if (uiCfg.dialogType == DIALOG_TYPE_PRINT_FILE) { + if (DIALOG_IS(TYPE_PRINT_FILE)) { lv_label_set_text(labelDialog, print_file_dialog_menu.print_file); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); lv_obj_t *labelFile = lv_label_create(scr, list_file.long_name[sel_id]); - lv_obj_align(labelFile, NULL, LV_ALIGN_CENTER, 0, -60); + lv_obj_align(labelFile, nullptr, LV_ALIGN_CENTER, 0, -60); } - else if (uiCfg.dialogType == DIALOG_TYPE_STOP) { + else if (DIALOG_IS(TYPE_STOP)) { lv_label_set_text(labelDialog, print_file_dialog_menu.cancle_print); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_TYPE_FINISH_PRINT) { + else if (DIALOG_IS(TYPE_FINISH_PRINT)) { lv_label_set_text(labelDialog, print_file_dialog_menu.print_finish); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_PAUSING) { + else if (DIALOG_IS(PAUSE_MESSAGE_PAUSING)) { lv_label_set_text(labelDialog, pause_msg_menu.pausing); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_CHANGING) { + else if (DIALOG_IS(PAUSE_MESSAGE_CHANGING)) { lv_label_set_text(labelDialog, pause_msg_menu.changing); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_UNLOAD) { + else if (DIALOG_IS(PAUSE_MESSAGE_UNLOAD)) { lv_label_set_text(labelDialog, pause_msg_menu.unload); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_WAITING) { + else if (DIALOG_IS(PAUSE_MESSAGE_WAITING)) { lv_label_set_text(labelDialog, pause_msg_menu.waiting); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_INSERT) { + else if (DIALOG_IS(PAUSE_MESSAGE_INSERT)) { lv_label_set_text(labelDialog, pause_msg_menu.insert); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_LOAD) { + else if (DIALOG_IS(PAUSE_MESSAGE_LOAD)) { lv_label_set_text(labelDialog, pause_msg_menu.load); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_PURGE) { + else if (DIALOG_IS(PAUSE_MESSAGE_PURGE)) { lv_label_set_text(labelDialog, pause_msg_menu.purge); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_RESUME) { + else if (DIALOG_IS(PAUSE_MESSAGE_RESUME)) { lv_label_set_text(labelDialog, pause_msg_menu.resume); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_HEAT) { + else if (DIALOG_IS(PAUSE_MESSAGE_HEAT)) { lv_label_set_text(labelDialog, pause_msg_menu.heat); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_HEATING) { + else if (DIALOG_IS(PAUSE_MESSAGE_HEATING)) { lv_label_set_text(labelDialog, pause_msg_menu.heating); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_OPTION) { + else if (DIALOG_IS(PAUSE_MESSAGE_OPTION)) { lv_label_set_text(labelDialog, pause_msg_menu.option); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_STORE_EEPROM_TIPS) { + else if (DIALOG_IS(STORE_EEPROM_TIPS)) { lv_label_set_text(labelDialog, eeprom_menu.storeTips); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_READ_EEPROM_TIPS) { + else if (DIALOG_IS(READ_EEPROM_TIPS)) { lv_label_set_text(labelDialog, eeprom_menu.readTips); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_REVERT_EEPROM_TIPS) { + else if (DIALOG_IS(REVERT_EEPROM_TIPS)) { lv_label_set_text(labelDialog, eeprom_menu.revertTips); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_WIFI_CONFIG_TIPS) { + else if (DIALOG_IS(WIFI_CONFIG_TIPS)) { lv_label_set_text(labelDialog, machine_menu.wifiConfigTips); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == WIFI_ENABLE_TIPS) { + else if (DIALOG_IS(WIFI_ENABLE_TIPS)) { lv_label_set_text(labelDialog, print_file_dialog_menu.wifi_enable_tips); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_TRANSFER_NO_DEVICE) { + else if (DIALOG_IS(TRANSFER_NO_DEVICE)) { lv_label_set_text(labelDialog, DIALOG_UPDATE_NO_DEVICE_EN); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } #if ENABLED(USE_WIFI_FUNCTION) - else if (uiCfg.dialogType == DIALOG_TYPE_UPLOAD_FILE) { + else if (DIALOG_IS(TYPE_UPLOAD_FILE)) { if (upload_result == 1) { lv_label_set_text(labelDialog, DIALOG_UPLOAD_ING_EN); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } else if (upload_result == 2) { lv_label_set_text(labelDialog, DIALOG_UPLOAD_ERROR_EN); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } else if (upload_result == 3) { char buf[200]; int _index = 0; - ZERO(buf); - strcpy(buf, DIALOG_UPLOAD_FINISH_EN); _index = strlen(buf); buf[_index] = '\n'; @@ -546,41 +426,41 @@ void lv_draw_dialog(uint8_t type) { sprintf(&buf[_index], " %d KBytes/s\n", (int)(upload_size / upload_time / 1024)); lv_label_set_text(labelDialog, buf); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } } - #endif //USE_WIFI_FUNCTION - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOAD_HEAT) { + #endif // USE_WIFI_FUNCTION + else if (DIALOG_IS(TYPE_FILAMENT_LOAD_HEAT)) { lv_label_set_text(labelDialog, filament_menu.filament_dialog_load_heat); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED) { + else if (DIALOG_IS(TYPE_FILAMENT_HEAT_LOAD_COMPLETED)) { lv_label_set_text(labelDialog, filament_menu.filament_dialog_load_heat_confirm); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOAD_HEAT) { + else if (DIALOG_IS(TYPE_FILAMENT_UNLOAD_HEAT)) { lv_label_set_text(labelDialog, filament_menu.filament_dialog_unload_heat); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED) { + else if (DIALOG_IS(TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED)) { lv_label_set_text(labelDialog, filament_menu.filament_dialog_unload_heat_confirm); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOAD_COMPLETED) { + else if (DIALOG_IS(TYPE_FILAMENT_LOAD_COMPLETED)) { lv_label_set_text(labelDialog, filament_menu.filament_dialog_load_completed); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOAD_COMPLETED) { + else if (DIALOG_IS(TYPE_FILAMENT_UNLOAD_COMPLETED)) { lv_label_set_text(labelDialog, filament_menu.filament_dialog_unload_completed); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOADING) { + else if (DIALOG_IS(TYPE_FILAMENT_LOADING)) { lv_label_set_text(labelDialog, filament_menu.filament_dialog_loading); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -70); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -70); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOADING) { + else if (DIALOG_IS(TYPE_FILAMENT_UNLOADING)) { lv_label_set_text(labelDialog, filament_menu.filament_dialog_unloading); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -70); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -70); } #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { @@ -592,28 +472,19 @@ void lv_draw_dialog(uint8_t type) { void filament_sprayer_temp() { char buf[20] = {0}; + sprintf(buf, preheat_menu.value_state, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target); - public_buf_l[0] = '\0'; - - if (uiCfg.curSprayerChoose < 1) - strcat(public_buf_l, preheat_menu.ext1); - else - strcat(public_buf_l, preheat_menu.ext2); - sprintf(buf, preheat_menu.value_state, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target); - + strcpy(public_buf_l, uiCfg.curSprayerChoose < 1 ? extrude_menu.ext1 : extrude_menu.ext2); strcat_P(public_buf_l, PSTR(": ")); strcat(public_buf_l, buf); lv_label_set_text(tempText1, public_buf_l); - lv_obj_align(tempText1, NULL, LV_ALIGN_CENTER, 0, -50); + lv_obj_align(tempText1, nullptr, LV_ALIGN_CENTER, 0, -50); } void filament_dialog_handle() { - if ((temperature_change_frequency == 1) - && ((uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOAD_HEAT) - || (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOAD_HEAT)) - ) { + if (temps_update_flag && (DIALOG_IS(TYPE_FILAMENT_LOAD_HEAT, TYPE_FILAMENT_UNLOAD_HEAT))) { filament_sprayer_temp(); - temperature_change_frequency = 0; + temps_update_flag = false; } if (uiCfg.filament_heat_completed_load == 1) { uiCfg.filament_heat_completed_load = 0; @@ -667,9 +538,8 @@ void filament_dialog_handle() { lv_draw_dialog(DIALOG_TYPE_FILAMENT_UNLOAD_COMPLETED); } - if ( uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOADING - || uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOADING - ) lv_filament_setbar(); + if (DIALOG_IS(TYPE_FILAMENT_LOADING, TYPE_FILAMENT_UNLOADING)) + lv_filament_setbar(); } void lv_filament_setbar() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.h b/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.h index dc5adc5ad6..c6f42d90b3 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.h @@ -25,52 +25,55 @@ extern "C" { /* C-declarations for C++ */ #endif -#define DIALOG_TYPE_STOP 0 -#define DIALOG_TYPE_PRINT_FILE 1 -#define DIALOG_TYPE_REPRINT_NO_FILE 2 +enum { + DIALOG_TYPE_STOP = 0, + DIALOG_TYPE_PRINT_FILE, + DIALOG_TYPE_REPRINT_NO_FILE, -#define DIALOG_TYPE_M80_FAIL 3 //** -#define DIALOG_TYPE_MESSAGE_ERR1 4 //** + DIALOG_TYPE_M80_FAIL, + DIALOG_TYPE_MESSAGE_ERR1, -#define DIALOG_TYPE_UPDATE_ESP_FIRMARE 5 -#define DIALOG_TYPE_UPDATE_ESP_DATA 6 -#define DIALOG_TYPE_UPLOAD_FILE 7 -#define DIALOG_TYPE_UNBIND 8 + DIALOG_TYPE_UPDATE_ESP_FIRMARE, + DIALOG_TYPE_UPDATE_ESP_DATA, + DIALOG_TYPE_UPLOAD_FILE, + DIALOG_TYPE_UNBIND, -#define DIALOG_TYPE_FILAMENT_LOAD_HEAT 9 -#define DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED 10 -#define DIALOG_TYPE_FILAMENT_LOADING 11 -#define DIALOG_TYPE_FILAMENT_LOAD_COMPLETED 12 -#define DIALOG_TYPE_FILAMENT_UNLOAD_HEAT 13 -#define DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED 14 -#define DIALOG_TYPE_FILAMENT_UNLOADING 15 -#define DIALOG_TYPE_FILAMENT_UNLOAD_COMPLETED 16 + DIALOG_TYPE_FILAMENT_LOAD_HEAT, + DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED, + DIALOG_TYPE_FILAMENT_LOADING, + DIALOG_TYPE_FILAMENT_LOAD_COMPLETED, + DIALOG_TYPE_FILAMENT_UNLOAD_HEAT, + DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED, + DIALOG_TYPE_FILAMENT_UNLOADING, + DIALOG_TYPE_FILAMENT_UNLOAD_COMPLETED, -#define DIALOG_TYPE_FILE_LOADING 17 //** + DIALOG_TYPE_FILE_LOADING, -#define DIALOG_TYPE_FILAMENT_NO_PRESS 18 -#define DIALOG_TYPE_FINISH_PRINT 19 + DIALOG_TYPE_FILAMENT_NO_PRESS, + DIALOG_TYPE_FINISH_PRINT, -#define WIFI_ENABLE_TIPS 20 + DIALOG_WIFI_ENABLE_TIPS, -#define DIALOG_PAUSE_MESSAGE_PAUSING 21 -#define DIALOG_PAUSE_MESSAGE_CHANGING 22 -#define DIALOG_PAUSE_MESSAGE_UNLOAD 23 -#define DIALOG_PAUSE_MESSAGE_WAITING 24 -#define DIALOG_PAUSE_MESSAGE_INSERT 25 -#define DIALOG_PAUSE_MESSAGE_LOAD 26 -#define DIALOG_PAUSE_MESSAGE_PURGE 27 -#define DIALOG_PAUSE_MESSAGE_RESUME 28 -#define DIALOG_PAUSE_MESSAGE_HEAT 29 -#define DIALOG_PAUSE_MESSAGE_HEATING 30 -#define DIALOG_PAUSE_MESSAGE_OPTION 31 + DIALOG_PAUSE_MESSAGE_PAUSING, + DIALOG_PAUSE_MESSAGE_CHANGING, + DIALOG_PAUSE_MESSAGE_UNLOAD, + DIALOG_PAUSE_MESSAGE_WAITING, + DIALOG_PAUSE_MESSAGE_INSERT, + DIALOG_PAUSE_MESSAGE_LOAD, + DIALOG_PAUSE_MESSAGE_PURGE, + DIALOG_PAUSE_MESSAGE_RESUME, + DIALOG_PAUSE_MESSAGE_HEAT, + DIALOG_PAUSE_MESSAGE_HEATING, + DIALOG_PAUSE_MESSAGE_OPTION, -#define DIALOG_STORE_EEPROM_TIPS 32 -#define DIALOG_READ_EEPROM_TIPS 33 -#define DIALOG_REVERT_EEPROM_TIPS 34 + DIALOG_STORE_EEPROM_TIPS, + DIALOG_READ_EEPROM_TIPS, + DIALOG_REVERT_EEPROM_TIPS, + + DIALOG_WIFI_CONFIG_TIPS, + DIALOG_TRANSFER_NO_DEVICE +}; -#define DIALOG_WIFI_CONFIG_TIPS 35 -#define DIALOG_TRANSFER_NO_DEVICE 36 #define BTN_OK_X 100 #define BTN_OK_Y 180 #define BTN_CANCEL_X 280 diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_eeprom_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_eeprom_settings.cpp index 59e04e7402..5e5c6b4907 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_eeprom_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_eeprom_settings.cpp @@ -28,163 +28,58 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_EEPROM_RETURN 1 -#define ID_EEPROM_STORE 2 -#define ID_EEPROM_STORE_ARROW 3 -#define ID_EEPROM_READ 4 -#define ID_EEPROM_READ_ARROW 5 -#define ID_EEPROM_REVERT 6 -#define ID_EEPROM_REVERT_ARROW 7 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_EEPROM_RETURN = 1, + ID_EEPROM_STORE, + ID_EEPROM_STORE_ARROW, + ID_EEPROM_READ, + ID_EEPROM_READ_ARROW, + ID_EEPROM_REVERT, + ID_EEPROM_REVERT_ARROW +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_EEPROM_RETURN: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_eeprom_settings(); - draw_return_ui(); - } + lv_clear_eeprom_settings(); + draw_return_ui(); break; case ID_EEPROM_STORE: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_eeprom_settings(); - lv_draw_dialog(DIALOG_STORE_EEPROM_TIPS); - } - break; - case ID_EEPROM_STORE_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_eeprom_settings(); - lv_draw_dialog(DIALOG_STORE_EEPROM_TIPS); - } + lv_clear_eeprom_settings(); + lv_draw_dialog(DIALOG_STORE_EEPROM_TIPS); break; #if 0 case ID_EEPROM_READ: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_eeprom_settings(); - lv_draw_dialog(DIALOG_READ_EEPROM_TIPS); - } - break; - case ID_EEPROM_READ_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_eeprom_settings(); - lv_draw_dialog(DIALOG_READ_EEPROM_TIPS); - } + lv_clear_eeprom_settings(); + lv_draw_dialog(DIALOG_READ_EEPROM_TIPS); break; #endif - case ID_EEPROM_REVERT: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_eeprom_settings(); - lv_draw_dialog(DIALOG_REVERT_EEPROM_TIPS); - } - break; - case ID_EEPROM_REVERT_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_eeprom_settings(); - lv_draw_dialog(DIALOG_REVERT_EEPROM_TIPS); - } + lv_clear_eeprom_settings(); + lv_draw_dialog(DIALOG_REVERT_EEPROM_TIPS); break; } } void lv_draw_eeprom_settings(void) { - lv_obj_t *buttonBack, *label_Back; - lv_obj_t *buttonStore, *labelStore; - //lv_obj_t *buttonRead,*labelRead,*buttonReadNarrow; - lv_obj_t *buttonRevert, *labelRevert; - lv_obj_t * line1, * line2; //* line3; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != EEPROM_SETTINGS_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = EEPROM_SETTINGS_UI; } disp_state = EEPROM_SETTINGS_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); - lv_refr_now(lv_refr_get_disp_refreshing()); - buttonRevert = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonRevert, PARA_UI_POS_X, PARA_UI_POS_Y); /*Set its position*/ - lv_obj_set_size(buttonRevert, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - //lv_obj_set_event_cb(buttonMotor, event_handler); - lv_obj_set_event_cb_mks(buttonRevert, event_handler, ID_EEPROM_REVERT, NULL, 0); - lv_btn_use_label_style(buttonRevert); - lv_btn_set_layout(buttonRevert, LV_LAYOUT_OFF); - labelRevert = lv_label_create_empty(buttonRevert); /*Add a label to the button*/ - - (void)lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y + PARA_UI_ARROW_V, event_handler, ID_EEPROM_REVERT_ARROW); - - //line3 = lv_line_create(scr, NULL); - //lv_ex_line(line3,line_points[2]); - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonStore = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonStore, PARA_UI_POS_X, PARA_UI_POS_Y * 2); /*Set its position*/ - lv_obj_set_size(buttonStore, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - //lv_obj_set_event_cb(buttonMotor, event_handler); - lv_obj_set_event_cb_mks(buttonStore, event_handler, ID_EEPROM_STORE, NULL, 0); - lv_btn_use_label_style(buttonStore); - lv_btn_set_layout(buttonStore, LV_LAYOUT_OFF); - labelStore = lv_label_create_empty(buttonStore); /*Add a label to the button*/ - - (void)lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 2 + PARA_UI_ARROW_V, event_handler, ID_EEPROM_STORE_ARROW); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - buttonBack = lv_imgbtn_create(scr, "F:/bmp_back70x40.bin", PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_EEPROM_RETURN); - label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelStore, eeprom_menu.store); - lv_obj_align(labelStore, buttonStore, LV_ALIGN_IN_LEFT_MID,0, 0); - - //lv_label_set_text(labelRead, eeprom_menu.read); - //lv_obj_align(labelRead, buttonRead, LV_ALIGN_IN_LEFT_MID,0, 0); - - lv_label_set_text(labelRevert, eeprom_menu.revert); - lv_obj_align(labelRevert, buttonRevert, LV_ALIGN_IN_LEFT_MID, 0, 0); - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonRevert); - lv_group_add_obj(g, buttonStore); - lv_group_add_obj(g, buttonBack); - } - #endif - + lv_screen_menu_item(scr, eeprom_menu.revert, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_EEPROM_REVERT, 0); + lv_screen_menu_item(scr, eeprom_menu.store, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_EEPROM_STORE, 1); + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_EEPROM_RETURN, true); } void lv_clear_eeprom_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_encoder_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_encoder_settings.cpp index 096e72878a..35bbc6f061 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_encoder_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_encoder_settings.cpp @@ -30,84 +30,44 @@ #if BUTTONS_EXIST(EN1, EN2) -extern lv_group_t * g; -static lv_obj_t * scr; -static lv_obj_t * buttonEncoderState = NULL; -static lv_obj_t *labelEncoderState = NULL; +extern lv_group_t *g; +static lv_obj_t *scr; +static lv_obj_t *buttonEncoderState = nullptr; -#define ID_ENCODER_RETURN 1 -#define ID_ENCODER_STATE 2 +enum { + ID_ENCODER_RETURN = 1, + ID_ENCODER_STATE +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_ENCODER_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_encoder_settings(); - draw_return_ui(); - } + lv_clear_encoder_settings(); + draw_return_ui(); break; case ID_ENCODER_STATE: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - gCfgItems.encoder_enable ^= true; - lv_imgbtn_set_src_both(buttonEncoderState, gCfgItems.encoder_enable ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin"); - lv_label_set_text(labelEncoderState, machine_menu.enable); - update_spi_flash(); - } + gCfgItems.encoder_enable ^= true; + lv_screen_menu_item_onoff_update(buttonEncoderState, gCfgItems.encoder_enable); + update_spi_flash(); break; } } void lv_draw_encoder_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL; - lv_obj_t *labelEncoderTips = NULL; - - lv_obj_t * line1 = NULL; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != ENCODER_SETTINGS_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = ENCODER_SETTINGS_UI; } disp_state = ENCODER_SETTINGS_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, machine_menu.EncoderConfTitle); - lv_refr_now(lv_refr_get_disp_refreshing()); - labelEncoderTips = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.EncoderConfText); + buttonEncoderState = lv_screen_menu_item_onoff(scr, machine_menu.EncoderConfText, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_ENCODER_STATE, 0, gCfgItems.encoder_enable); - buttonEncoderState = lv_imgbtn_create(scr, gCfgItems.encoder_enable ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin", PARA_UI_STATE_POS_X, PARA_UI_POS_Y + PARA_UI_STATE_V, event_handler, ID_ENCODER_STATE); - labelEncoderState = lv_label_create_empty(buttonEncoderState); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonBack = lv_imgbtn_create(scr, "F:/bmp_back70x40.bin", PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_ENCODER_RETURN); - label_Back = lv_label_create_empty(buttonBack); - - lv_label_set_text(labelEncoderState, gCfgItems.encoder_enable ? machine_menu.enable : machine_menu.disable); - lv_obj_align(labelEncoderState, buttonEncoderState, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonEncoderState); - lv_group_add_obj(g, buttonBack); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_ENCODER_RETURN, true); } void lv_clear_encoder_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_error_message.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_error_message.cpp index 435b91e1d8..e82229c909 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_error_message.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_error_message.cpp @@ -36,35 +36,31 @@ #include "mks_hardware_test.h" #include "../../../../inc/MarlinConfig.h" -static lv_obj_t * scr; +static lv_obj_t *scr; void lv_draw_error_message(PGM_P const msg) { #if 0 - static lv_obj_t * message = NULL, *kill_message = NULL, *reset_tips = NULL; + static lv_obj_t *message = nullptr, *kill_message = nullptr, *reset_tips = nullptr; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != ERROR_MESSAGE_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = ERROR_MESSAGE_UI; } disp_state = ERROR_MESSAGE_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); lv_refr_now(lv_refr_get_disp_refreshing()); if (msg) { message = lv_label_create(scr, msg); - lv_obj_align(message, NULL, LV_ALIGN_CENTER, 0, -50); + lv_obj_align(message, nullptr, LV_ALIGN_CENTER, 0, -50); } kill_message = lv_label_create(scr, "PRINTER HALTED"); - lv_obj_align(kill_message, NULL, LV_ALIGN_CENTER, 0, -10); + lv_obj_align(kill_message, nullptr, LV_ALIGN_CENTER, 0, -10); reset_tips = lv_label_create(scr, "Please Reset"); - lv_obj_align(reset_tips, NULL, LV_ALIGN_CENTER, 0, 30); + lv_obj_align(reset_tips, nullptr, LV_ALIGN_CENTER, 0, 30); lv_task_handler(); #endif diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_extrusion.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_extrusion.cpp index 6402040898..9f803afea9 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_extrusion.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_extrusion.cpp @@ -43,172 +43,121 @@ static lv_obj_t *labelSpeed; static lv_obj_t *tempText; static lv_obj_t *ExtruText; -#define ID_E_ADD 1 -#define ID_E_DEC 2 -#define ID_E_TYPE 3 -#define ID_E_STEP 4 -#define ID_E_SPEED 5 -#define ID_E_RETURN 6 - -static int32_t extructAmount; - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +enum { + ID_E_ADD = 1, + ID_E_DEC, + ID_E_TYPE, + ID_E_STEP, + ID_E_SPEED, + ID_E_RETURN +}; + +static int32_t extrudeAmount; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_E_ADD: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius >= EXTRUDE_MINTEMP) { - queue.enqueue_now_P(PSTR("G91")); - ZERO(public_buf_l); - sprintf_P((char *)public_buf_l, PSTR("G1 E%d F%d"), uiCfg.extruStep, 60 * uiCfg.extruSpeed); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G90")); - extructAmount += uiCfg.extruStep; - disp_extru_amount(); - } + if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius >= EXTRUDE_MINTEMP) { + queue.enqueue_now_P(PSTR("G91")); + sprintf_P((char *)public_buf_l, PSTR("G1 E%d F%d"), uiCfg.extruStep, 60 * uiCfg.extruSpeed); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G90")); + extrudeAmount += uiCfg.extruStep; + disp_extru_amount(); } break; case ID_E_DEC: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius >= EXTRUDE_MINTEMP) { - queue.enqueue_now_P(PSTR("G91")); - ZERO(public_buf_l); - sprintf_P((char *)public_buf_l, PSTR("G1 E%d F%d"), 0 - uiCfg.extruStep, 60 * uiCfg.extruSpeed); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G90")); - extructAmount -= uiCfg.extruStep; - disp_extru_amount(); - } + if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius >= EXTRUDE_MINTEMP) { + queue.enqueue_now_P(PSTR("G91")); + sprintf_P((char *)public_buf_l, PSTR("G1 E%d F%d"), 0 - uiCfg.extruStep, 60 * uiCfg.extruSpeed); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G90")); + extrudeAmount -= uiCfg.extruStep; + disp_extru_amount(); } break; case ID_E_TYPE: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (ENABLED(HAS_MULTI_EXTRUDER)) { - if (uiCfg.curSprayerChoose == 0) { - uiCfg.curSprayerChoose = 1; - queue.inject_P(PSTR("T1")); - } - else { - uiCfg.curSprayerChoose = 0; - queue.inject_P(PSTR("T0")); - } + if (ENABLED(HAS_MULTI_EXTRUDER)) { + if (uiCfg.curSprayerChoose == 0) { + uiCfg.curSprayerChoose = 1; + queue.inject_P(PSTR("T1")); } - else + else { uiCfg.curSprayerChoose = 0; - - extructAmount = 0; - disp_hotend_temp(); - disp_ext_type(); - disp_extru_amount(); + queue.inject_P(PSTR("T0")); + } } + else + uiCfg.curSprayerChoose = 0; + + extrudeAmount = 0; + disp_hotend_temp(); + disp_ext_type(); + disp_extru_amount(); break; case ID_E_STEP: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - switch (abs(uiCfg.extruStep)) { - case 1: uiCfg.extruStep = 5; break; - case 5: uiCfg.extruStep = 10; break; - case 10: uiCfg.extruStep = 1; break; - default: break; - } - disp_ext_step(); + switch (abs(uiCfg.extruStep)) { + case 1: uiCfg.extruStep = 5; break; + case 5: uiCfg.extruStep = 10; break; + case 10: uiCfg.extruStep = 1; break; + default: break; } + disp_ext_step(); break; case ID_E_SPEED: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - switch (uiCfg.extruSpeed) { - case 1: uiCfg.extruSpeed = 10; break; - case 10: uiCfg.extruSpeed = 20; break; - case 20: uiCfg.extruSpeed = 1; break; - default: break; - } - disp_ext_speed(); + switch (uiCfg.extruSpeed) { + case 1: uiCfg.extruSpeed = 10; break; + case 10: uiCfg.extruSpeed = 20; break; + case 20: uiCfg.extruSpeed = 1; break; + default: break; } + disp_ext_speed(); break; case ID_E_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - draw_return_ui(); - } + clear_cur_ui(); + draw_return_ui(); break; } } void lv_draw_extrusion(void) { - lv_obj_t *buttonAdd, *buttonDec, *buttonBack; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != EXTRUSION_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = EXTRUSION_UI; } disp_state = EXTRUSION_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); // Create image buttons - buttonAdd = lv_imgbtn_create(scr, "F:/bmp_in.bin", INTERVAL_V, titleHeight, event_handler, ID_E_ADD); + lv_obj_t *buttonAdd = lv_big_button_create(scr, "F:/bmp_in.bin", extrude_menu.in, INTERVAL_V, titleHeight, event_handler, ID_E_ADD); lv_obj_clear_protect(buttonAdd, LV_PROTECT_FOLLOW); + lv_big_button_create(scr, "F:/bmp_out.bin", extrude_menu.out, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_E_DEC); - buttonDec = lv_imgbtn_create(scr, "F:/bmp_out.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_E_DEC); - buttonType = lv_imgbtn_create(scr, NULL, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_E_TYPE); - buttonStep = lv_imgbtn_create(scr, NULL, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_E_STEP); - buttonSpeed = lv_imgbtn_create(scr, NULL, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_E_SPEED); - buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_E_RETURN); - - // Create labels on the image buttons - lv_obj_t *labelAdd = lv_label_create_empty(buttonAdd); - lv_obj_t *labelDec = lv_label_create_empty(buttonDec); - labelType = lv_label_create_empty(buttonType); - labelStep = lv_label_create_empty(buttonStep); - labelSpeed = lv_label_create_empty(buttonSpeed); - lv_obj_t *label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - lv_label_set_text(labelAdd, extrude_menu.in); - lv_obj_align(labelAdd, buttonAdd, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelDec, extrude_menu.out); - lv_obj_align(labelDec, buttonDec, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } + buttonType = lv_imgbtn_create(scr, nullptr, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_E_TYPE); + buttonStep = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_E_STEP); + buttonSpeed = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_E_SPEED); #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonAdd); - lv_group_add_obj(g, buttonDec); lv_group_add_obj(g, buttonType); lv_group_add_obj(g, buttonStep); lv_group_add_obj(g, buttonSpeed); - lv_group_add_obj(g, buttonBack); } #endif + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_E_RETURN); + + // Create labels on the image buttons + labelType = lv_label_create_empty(buttonType); + labelStep = lv_label_create_empty(buttonStep); + labelSpeed = lv_label_create_empty(buttonSpeed); + disp_ext_type(); disp_ext_step(); disp_ext_speed(); @@ -265,12 +214,11 @@ void disp_ext_speed() { void disp_hotend_temp() { char buf[20] = {0}; - public_buf_l[0] = '\0'; - strcat(public_buf_l, extrude_menu.temper_text); sprintf(buf, extrude_menu.temp_value, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target); + strcpy(public_buf_l, extrude_menu.temper_text); strcat(public_buf_l, buf); lv_label_set_text(tempText, public_buf_l); - lv_obj_align(tempText, NULL, LV_ALIGN_CENTER, 0, -50); + lv_obj_align(tempText, nullptr, LV_ALIGN_CENTER, 0, -50); } void disp_extru_amount() { @@ -278,33 +226,17 @@ void disp_extru_amount() { public_buf_l[0] = '\0'; - if (extructAmount < 999 && extructAmount > -99) { - sprintf(buf1, extrude_menu.count_value_mm, extructAmount); - if (uiCfg.curSprayerChoose < 1) - strcat(public_buf_l, extrude_menu.ext1); - else - strcat(public_buf_l, extrude_menu.ext2); - strcat(public_buf_l, buf1); - } - else if (extructAmount < 9999 && extructAmount > -999) { - sprintf(buf1, extrude_menu.count_value_cm, extructAmount / 10); - if (uiCfg.curSprayerChoose < 1) - strcat(public_buf_l, extrude_menu.ext1); - else - strcat(public_buf_l, extrude_menu.ext2); - strcat(public_buf_l, buf1); - } - else { - sprintf(buf1, extrude_menu.count_value_m, extructAmount / 1000); - if (uiCfg.curSprayerChoose < 1) - strcat(public_buf_l, extrude_menu.ext1); - else - strcat(public_buf_l, extrude_menu.ext2); - strcat(public_buf_l, buf1); - } + if (extrudeAmount < 999 && extrudeAmount > -99) + sprintf(buf1, extrude_menu.count_value_mm, extrudeAmount); + else if (extrudeAmount < 9999 && extrudeAmount > -999) + sprintf(buf1, extrude_menu.count_value_cm, extrudeAmount / 10); + else + sprintf(buf1, extrude_menu.count_value_m, extrudeAmount / 1000); + strcat(public_buf_l, uiCfg.curSprayerChoose < 1 ? extrude_menu.ext1 : extrude_menu.ext2); + strcat(public_buf_l, buf1); lv_label_set_text(ExtruText, public_buf_l); - lv_obj_align(ExtruText, NULL, LV_ALIGN_CENTER, 0, -75); + lv_obj_align(ExtruText, nullptr, LV_ALIGN_CENTER, 0, -75); } void disp_ext_step() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_fan.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_fan.cpp index 6024d58203..5306ab3a89 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_fan.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_fan.cpp @@ -35,87 +35,56 @@ #include "../../../../gcode/gcode.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; -static lv_obj_t * fanText; - -#define ID_F_ADD 1 -#define ID_F_DEC 2 -#define ID_F_HIGH 3 -#define ID_F_MID 4 -#define ID_F_OFF 5 -#define ID_F_RETURN 6 +extern lv_group_t *g; +static lv_obj_t *scr; +static lv_obj_t *fanText; + +enum { + ID_F_ADD = 1, + ID_F_DEC, + ID_F_HIGH, + ID_F_MID, + ID_F_OFF, + ID_F_RETURN +}; static uint8_t fanSpeed; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_F_ADD: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (fanSpeed + 1 <= 255) { - fanSpeed++; - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("M106 S%d"), fanSpeed); - gcode.process_subcommands_now(public_buf_l); - } + if (fanSpeed + 1 <= 255) { + fanSpeed++; + sprintf_P(public_buf_l, PSTR("M106 S%d"), fanSpeed); + gcode.process_subcommands_now(public_buf_l); } break; case ID_F_DEC: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (fanSpeed > 0) { - fanSpeed--; - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("M106 S%d"), fanSpeed); - gcode.process_subcommands_now(public_buf_l); - } + if (fanSpeed > 0) { + fanSpeed--; + sprintf_P(public_buf_l, PSTR("M106 S%d"), fanSpeed); + gcode.process_subcommands_now(public_buf_l); } - break; case ID_F_HIGH: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - gcode.process_subcommands_now_P(PSTR("M106 S255")); - } + gcode.process_subcommands_now_P(PSTR("M106 S255")); break; case ID_F_MID: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - gcode.process_subcommands_now_P(PSTR("M106 S127")); - } + gcode.process_subcommands_now_P(PSTR("M106 S127")); break; case ID_F_OFF: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - gcode.process_subcommands_now_P(PSTR("M107")); - } + gcode.process_subcommands_now_P(PSTR("M107")); break; case ID_F_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - draw_return_ui(); - } + clear_cur_ui(); + draw_return_ui(); break; } } void lv_draw_fan(void) { - lv_obj_t *buttonAdd, *buttonDec, *buttonHigh, *buttonMid; - lv_obj_t *buttonOff, *buttonBack; + lv_obj_t *buttonAdd; #if HAS_FAN fanSpeed = thermalManager.fan_speed[0]; @@ -126,63 +95,20 @@ void lv_draw_fan(void) { } disp_state = FAN_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); // Create an Image button - buttonAdd = lv_imgbtn_create(scr, "F:/bmp_Add.bin", INTERVAL_V, titleHeight, event_handler, ID_F_ADD); + buttonAdd = lv_big_button_create(scr, "F:/bmp_Add.bin", fan_menu.add, INTERVAL_V, titleHeight, event_handler, ID_F_ADD); lv_obj_clear_protect(buttonAdd, LV_PROTECT_FOLLOW); - - buttonDec = lv_imgbtn_create(scr, "F:/bmp_Dec.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_F_DEC); - buttonHigh = lv_imgbtn_create(scr, "F:/bmp_speed255.bin", INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_HIGH); - buttonMid = lv_imgbtn_create(scr, "F:/bmp_speed127.bin", BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_MID); - buttonOff = lv_imgbtn_create(scr, "F:/bmp_speed0.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_OFF); - buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_RETURN); - - // Create labels on the image buttons - lv_obj_t *labelAdd = lv_label_create_empty(buttonAdd); - lv_obj_t *labelDec = lv_label_create_empty(buttonDec); - lv_obj_t *labelHigh = lv_label_create_empty(buttonHigh); - lv_obj_t *labelMid = lv_label_create_empty(buttonMid); - lv_obj_t *labelOff = lv_label_create_empty(buttonOff); - lv_obj_t *label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - lv_label_set_text(labelAdd, fan_menu.add); - lv_obj_align(labelAdd, buttonAdd, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelDec, fan_menu.dec); - lv_obj_align(labelDec, buttonDec, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelHigh, fan_menu.full); - lv_obj_align(labelHigh, buttonHigh, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelMid, fan_menu.half); - lv_obj_align(labelMid, buttonMid, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelOff, fan_menu.off); - lv_obj_align(labelOff, buttonOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonAdd); - lv_group_add_obj(g, buttonDec); - lv_group_add_obj(g, buttonHigh); - lv_group_add_obj(g, buttonMid); - lv_group_add_obj(g, buttonOff); - lv_group_add_obj(g, buttonBack); - } - #endif + lv_big_button_create(scr, "F:/bmp_Dec.bin", fan_menu.dec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_F_DEC); + lv_big_button_create(scr, "F:/bmp_speed255.bin", fan_menu.full, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_HIGH); + lv_big_button_create(scr, "F:/bmp_speed127.bin", fan_menu.half, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_MID); + lv_big_button_create(scr, "F:/bmp_speed0.bin", fan_menu.off, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_OFF); + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_RETURN); fanText = lv_label_create_empty(scr); lv_obj_set_style(fanText, &tft_style_label_rel); @@ -197,7 +123,7 @@ void disp_fan_value() { sprintf_P(buf1, PSTR("%3d"), thermalManager.fan_speed[0]); strcat(public_buf_l, buf1); lv_label_set_text(fanText, public_buf_l); - lv_obj_align(fanText, NULL, LV_ALIGN_CENTER, 0, -65); + lv_obj_align(fanText, nullptr, LV_ALIGN_CENTER, 0, -65); } void lv_clear_fan() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_change.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_change.cpp index be6defda18..a3f18cf9cb 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_change.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_change.cpp @@ -38,150 +38,109 @@ static lv_obj_t *buttonType; static lv_obj_t *labelType; static lv_obj_t *tempText1; -#define ID_FILAMNT_IN 1 -#define ID_FILAMNT_OUT 2 -#define ID_FILAMNT_TYPE 3 -#define ID_FILAMNT_RETURN 4 +enum { + ID_FILAMNT_IN = 1, + ID_FILAMNT_OUT, + ID_FILAMNT_TYPE, + ID_FILAMNT_RETURN +}; extern feedRate_t feedrate_mm_s; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_FILAMNT_IN: - if (event == LV_EVENT_CLICKED) { - // nothing to do + uiCfg.filament_load_heat_flg = 1; + if ((abs(thermalManager.temp_hotend[uiCfg.curSprayerChoose].target - thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius) <= 1) + || (gCfgItems.filament_limit_temper <= thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius)) { + lv_clear_filament_change(); + lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED); } - else if (event == LV_EVENT_RELEASED) { - uiCfg.filament_load_heat_flg = 1; - if ((abs(thermalManager.temp_hotend[uiCfg.curSprayerChoose].target - thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius) <= 1) - || (gCfgItems.filament_limit_temper <= thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius)) { - lv_clear_filament_change(); - lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED); - } - else { - lv_clear_filament_change(); - lv_draw_dialog(DIALOG_TYPE_FILAMENT_LOAD_HEAT); - if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].target < gCfgItems.filament_limit_temper) { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = gCfgItems.filament_limit_temper; - thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); - } + else { + lv_clear_filament_change(); + lv_draw_dialog(DIALOG_TYPE_FILAMENT_LOAD_HEAT); + if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].target < gCfgItems.filament_limit_temper) { + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = gCfgItems.filament_limit_temper; + thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); } } break; case ID_FILAMNT_OUT: - if (event == LV_EVENT_CLICKED) { - // nothing to do + uiCfg.filament_unload_heat_flg=1; + if ((thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > 0) + && ((abs((int)((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target - thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius)) <= 1) + || ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius >= gCfgItems.filament_limit_temper)) + ) { + lv_clear_filament_change(); + lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED); } - else if (event == LV_EVENT_RELEASED) { - uiCfg.filament_unload_heat_flg=1; - if ((thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > 0) - && ((abs((int)((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target - thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius)) <= 1) - || ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius >= gCfgItems.filament_limit_temper)) - ) { - lv_clear_filament_change(); - lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED); - } - else { - lv_clear_filament_change(); - lv_draw_dialog(DIALOG_TYPE_FILAMENT_UNLOAD_HEAT); - if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].target < gCfgItems.filament_limit_temper) { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = gCfgItems.filament_limit_temper; - thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); - } - filament_sprayer_temp(); + else { + lv_clear_filament_change(); + lv_draw_dialog(DIALOG_TYPE_FILAMENT_UNLOAD_HEAT); + if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].target < gCfgItems.filament_limit_temper) { + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = gCfgItems.filament_limit_temper; + thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); } + filament_sprayer_temp(); } break; case ID_FILAMNT_TYPE: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - #if HAS_MULTI_EXTRUDER - if (uiCfg.curSprayerChoose == 0) - uiCfg.curSprayerChoose = 1; - else if (uiCfg.curSprayerChoose == 1) - uiCfg.curSprayerChoose = 0; - #endif - disp_filament_type(); - } + #if HAS_MULTI_EXTRUDER + if (uiCfg.curSprayerChoose == 0) + uiCfg.curSprayerChoose = 1; + else if (uiCfg.curSprayerChoose == 1) + uiCfg.curSprayerChoose = 0; + #endif + disp_filament_type(); break; case ID_FILAMNT_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - #if HAS_MULTI_EXTRUDER - if (uiCfg.print_state != IDLE && uiCfg.print_state != REPRINTED) - gcode.process_subcommands_now_P(uiCfg.curSprayerChoose_bak == 1 ? PSTR("T1") : PSTR("T0")); - #endif - feedrate_mm_s = (float)uiCfg.moveSpeed_bak; - if (uiCfg.print_state == PAUSED) - planner.set_e_position_mm((destination.e = current_position.e = uiCfg.current_e_position_bak)); - //current_position.e = destination.e = uiCfg.current_e_position_bak; - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = uiCfg.desireSprayerTempBak; - - clear_cur_ui(); - draw_return_ui(); - } + #if HAS_MULTI_EXTRUDER + if (uiCfg.print_state != IDLE && uiCfg.print_state != REPRINTED) + gcode.process_subcommands_now_P(uiCfg.curSprayerChoose_bak == 1 ? PSTR("T1") : PSTR("T0")); + #endif + feedrate_mm_s = (float)uiCfg.moveSpeed_bak; + if (uiCfg.print_state == PAUSED) + planner.set_e_position_mm((destination.e = current_position.e = uiCfg.current_e_position_bak)); + //current_position.e = destination.e = uiCfg.current_e_position_bak; + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = uiCfg.desireSprayerTempBak; + + clear_cur_ui(); + draw_return_ui(); break; } } void lv_draw_filament_change(void) { - lv_obj_t *buttonIn, *buttonOut; - lv_obj_t *buttonBack; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != FILAMENTCHANGE_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = FILAMENTCHANGE_UI; } disp_state = FILAMENTCHANGE_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); // Create an Image button - buttonIn = lv_imgbtn_create(scr, "F:/bmp_in.bin", INTERVAL_V, titleHeight, event_handler, ID_FILAMNT_IN); + lv_obj_t *buttonIn = lv_big_button_create(scr, "F:/bmp_in.bin", filament_menu.in, INTERVAL_V, titleHeight, event_handler, ID_FILAMNT_IN); lv_obj_clear_protect(buttonIn, LV_PROTECT_FOLLOW); + lv_big_button_create(scr, "F:/bmp_out.bin", filament_menu.out, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_FILAMNT_OUT); - buttonOut = lv_imgbtn_create(scr, "F:/bmp_out.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_FILAMNT_OUT); - buttonType = lv_imgbtn_create(scr, NULL, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_FILAMNT_TYPE); - buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_FILAMNT_RETURN); - - // Create labels on the image buttons - lv_obj_t *labelIn = lv_label_create_empty(buttonIn); - lv_obj_t *labelOut = lv_label_create_empty(buttonOut); - labelType = lv_label_create_empty(buttonType); - lv_obj_t *label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - lv_label_set_text(labelIn, filament_menu.in); - lv_obj_align(labelIn, buttonIn, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelOut, filament_menu.out); - lv_obj_align(labelOut, buttonOut, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - + buttonType = lv_imgbtn_create(scr, nullptr, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_FILAMNT_TYPE); #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonIn); - lv_group_add_obj(g, buttonOut); lv_group_add_obj(g, buttonType); - lv_group_add_obj(g, buttonBack); } #endif + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_FILAMNT_RETURN); + + // Create labels on the image buttons + labelType = lv_label_create_empty(buttonType); + disp_filament_type(); tempText1 = lv_label_create_empty(scr); @@ -211,16 +170,13 @@ void disp_filament_temp() { public_buf_l[0] = '\0'; - if (uiCfg.curSprayerChoose < 1) - strcat(public_buf_l, preheat_menu.ext1); - else - strcat(public_buf_l, preheat_menu.ext2); + strcat(public_buf_l, uiCfg.curSprayerChoose < 1 ? preheat_menu.ext1 : preheat_menu.ext2); sprintf(buf, preheat_menu.value_state, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target); strcat_P(public_buf_l, PSTR(": ")); strcat(public_buf_l, buf); lv_label_set_text(tempText1, public_buf_l); - lv_obj_align(tempText1, NULL, LV_ALIGN_CENTER, 0, -50); + lv_obj_align(tempText1, nullptr, LV_ALIGN_CENTER, 0, -50); } void lv_clear_filament_change() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_settings.cpp index 2a096eafac..ecaeefee56 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_settings.cpp @@ -28,233 +28,102 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_FILAMENT_SET_RETURN 1 -#define ID_FILAMENT_SET_IN_LENGTH 2 -#define ID_FILAMENT_SET_IN_SPEED 3 -#define ID_FILAMENT_SET_OUT_LENGTH 4 -#define ID_FILAMENT_SET_OUT_SPEED 5 -#define ID_FILAMENT_SET_TEMP 6 -#define ID_FILAMENT_SET_DOWN 12 -#define ID_FILAMENT_SET_UP 13 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_FILAMENT_SET_RETURN = 1, + ID_FILAMENT_SET_IN_LENGTH, + ID_FILAMENT_SET_IN_SPEED, + ID_FILAMENT_SET_OUT_LENGTH, + ID_FILAMENT_SET_OUT_SPEED, + ID_FILAMENT_SET_TEMP, + ID_FILAMENT_SET_DOWN, + ID_FILAMENT_SET_UP +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_FILAMENT_SET_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_filament_settings(); - draw_return_ui(); - } + uiCfg.para_ui_page = 0; + lv_clear_filament_settings(); + draw_return_ui(); break; case ID_FILAMENT_SET_IN_LENGTH: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = load_length; - lv_clear_filament_settings(); - lv_draw_number_key(); - } + value = load_length; + lv_clear_filament_settings(); + lv_draw_number_key(); break; case ID_FILAMENT_SET_IN_SPEED: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = load_speed; - lv_clear_filament_settings(); - lv_draw_number_key(); - } + value = load_speed; + lv_clear_filament_settings(); + lv_draw_number_key(); break; case ID_FILAMENT_SET_OUT_LENGTH: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = unload_length; - lv_clear_filament_settings(); - lv_draw_number_key(); - } + value = unload_length; + lv_clear_filament_settings(); + lv_draw_number_key(); break; case ID_FILAMENT_SET_OUT_SPEED: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = unload_speed; - lv_clear_filament_settings(); - lv_draw_number_key(); - } + value = unload_speed; + lv_clear_filament_settings(); + lv_draw_number_key(); break; case ID_FILAMENT_SET_TEMP: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = filament_temp; - lv_clear_filament_settings(); - lv_draw_number_key(); - } + value = filament_temp; + lv_clear_filament_settings(); + lv_draw_number_key(); break; case ID_FILAMENT_SET_UP: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_filament_settings(); - lv_draw_filament_settings(); - } + uiCfg.para_ui_page = 0; + lv_clear_filament_settings(); + lv_draw_filament_settings(); break; case ID_FILAMENT_SET_DOWN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 1; - lv_clear_filament_settings(); - lv_draw_filament_settings(); - } + uiCfg.para_ui_page = 1; + lv_clear_filament_settings(); + lv_draw_filament_settings(); break; } } void lv_draw_filament_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL, *buttonTurnPage = NULL, *labelTurnPage = NULL; - lv_obj_t *buttonInLengthValue = NULL, *labelInLengthValue = NULL; - lv_obj_t *buttonInSpeedValue = NULL, *labelInSpeedValue = NULL; - lv_obj_t *buttonOutLengthValue = NULL, *labelOutLengthValue = NULL; - lv_obj_t *buttonOutSpeedValue = NULL, *labelOutSpeedValue = NULL; - lv_obj_t *buttonTemperValue = NULL, *labelTemperValue = NULL; - lv_obj_t *line1 = NULL, *line2 = NULL, *line3 = NULL, *line4 = NULL; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != FILAMENT_SETTINGS_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = FILAMENT_SETTINGS_UI; } disp_state = FILAMENT_SETTINGS_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, machine_menu.FilamentConfTitle); lv_refr_now(lv_refr_get_disp_refreshing()); if (uiCfg.para_ui_page != 1) { - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.InLength); - - buttonInLengthValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_FILAMENT_SET_IN_LENGTH); - labelInLengthValue = lv_label_create_empty(buttonInLengthValue); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10, machine_menu.InSpeed); - - buttonInSpeedValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_FILAMENT_SET_IN_SPEED); - labelInSpeedValue = lv_label_create_empty(buttonInSpeedValue); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 6, machine_menu.OutLength); - - buttonOutLengthValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_FILAMENT_SET_OUT_LENGTH); - labelOutLengthValue = lv_label_create_empty(buttonOutLengthValue); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filamentchange_load_length); + lv_screen_menu_item_1_edit(scr, machine_menu.InLength, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_FILAMENT_SET_IN_LENGTH, 0, public_buf_l); - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filamentchange_load_speed); + lv_screen_menu_item_1_edit(scr, machine_menu.InSpeed, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_FILAMENT_SET_IN_SPEED, 1, public_buf_l); - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10, machine_menu.OutSpeed); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filamentchange_unload_length); + lv_screen_menu_item_1_edit(scr, machine_menu.OutLength, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_FILAMENT_SET_OUT_LENGTH, 2, public_buf_l); - buttonOutSpeedValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_FILAMENT_SET_OUT_SPEED); - labelOutSpeedValue = lv_label_create_empty(buttonOutSpeedValue); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filamentchange_unload_speed); + lv_screen_menu_item_1_edit(scr, machine_menu.OutSpeed, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_FILAMENT_SET_OUT_SPEED, 3, public_buf_l); - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - buttonTurnPage = lv_btn_create_back(scr, event_handler, ID_FILAMENT_SET_DOWN); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonInLengthValue); - lv_group_add_obj(g, buttonInSpeedValue); - lv_group_add_obj(g, buttonOutLengthValue); - lv_group_add_obj(g, buttonOutSpeedValue); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.next, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_FILAMENT_SET_DOWN, true); } else { - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.FilamentTemperature); - - buttonTemperValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_FILAMENT_SET_TEMP); - labelTemperValue = lv_label_create_empty(buttonTemperValue); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonTurnPage = lv_btn_create_back(scr, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE, event_handler, ID_FILAMENT_SET_UP); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filament_limit_temper); + lv_screen_menu_item_1_edit(scr, machine_menu.FilamentTemperature, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_FILAMENT_SET_TEMP, 0, public_buf_l); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonTemperValue); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.previous, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_FILAMENT_SET_UP, true); } - labelTurnPage = lv_label_create_empty(buttonTurnPage); - - buttonBack = lv_btn_create_back(scr, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE, event_handler, ID_FILAMENT_SET_RETURN); - label_Back = lv_label_create_empty(buttonBack); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - if (gCfgItems.multiple_language) { - if (uiCfg.para_ui_page != 1) { - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filamentchange_load_length); - lv_label_set_text(labelInLengthValue, public_buf_l); - lv_obj_align(labelInLengthValue, buttonInLengthValue, LV_ALIGN_CENTER, 0, 0); - - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filamentchange_load_speed); - lv_label_set_text(labelInSpeedValue, public_buf_l); - lv_obj_align(labelInSpeedValue, buttonInSpeedValue, LV_ALIGN_CENTER, 0, 0); - - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filamentchange_unload_length); - lv_label_set_text(labelOutLengthValue, public_buf_l); - lv_obj_align(labelOutLengthValue, buttonOutLengthValue, LV_ALIGN_CENTER, 0, 0); - - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filamentchange_unload_speed); - lv_label_set_text(labelOutSpeedValue, public_buf_l); - lv_obj_align(labelOutSpeedValue, buttonOutSpeedValue, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelTurnPage, machine_menu.next); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - } - else { - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filament_limit_temper); - lv_label_set_text(labelTemperValue, public_buf_l); - lv_obj_align(labelTemperValue, buttonTemperValue, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelTurnPage, machine_menu.previous); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - } - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_FILAMENT_SET_RETURN, true); } void lv_clear_filament_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_home.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_home.cpp index 4e22c134ac..92510cbc8e 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_home.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_home.cpp @@ -35,149 +35,67 @@ #include "../../../../gcode/queue.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_H_ALL 1 -#define ID_H_X 2 -#define ID_H_Y 3 -#define ID_H_Z 4 -#define ID_H_RETURN 5 -#define ID_H_OFF_ALL 6 -#define ID_H_OFF_XY 7 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_H_ALL = 1, + ID_H_X, + ID_H_Y, + ID_H_Z, + ID_H_RETURN, + ID_H_OFF_ALL, + ID_H_OFF_XY +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_H_ALL: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - queue.inject_P(PSTR("G28")); - } + queue.inject_P(PSTR("G28")); break; case ID_H_X: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - queue.inject_P(PSTR("G28 X0")); - } + queue.inject_P(PSTR("G28 X0")); break; case ID_H_Y: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - queue.inject_P(PSTR("G28 Y0")); - } + queue.inject_P(PSTR("G28 Y0")); break; case ID_H_Z: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - queue.inject_P(PSTR("G28 Z0")); - } + queue.inject_P(PSTR("G28 Z0")); break; case ID_H_OFF_ALL: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - queue.inject_P(PSTR("M84")); - } + queue.inject_P(PSTR("M84")); break; case ID_H_OFF_XY: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - queue.inject_P(PSTR("M84 X Y")); - } + queue.inject_P(PSTR("M84 X Y")); break; case ID_H_RETURN: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_home(); - lv_draw_tool(); - } + lv_clear_home(); + lv_draw_tool(); break; } } void lv_draw_home(void) { - lv_obj_t *buttonHomeAll, *buttonHomeX, *buttonHomeY, *buttonHomeZ; - lv_obj_t *buttonBack; - lv_obj_t *buttonOffAll, *buttonOffXY; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != ZERO_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = ZERO_UI; } disp_state = ZERO_UI; - scr = lv_obj_create(NULL, NULL); - - //static lv_style_t tool_style; - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); - // Create image buttons - //buttonWifi = lv_imgbtn_create(scr, NULL); - //buttonContinue = lv_imgbtn_create(scr, NULL); - buttonHomeAll = lv_imgbtn_create(scr, "F:/bmp_zeroAll.bin", INTERVAL_V, titleHeight, event_handler, ID_H_ALL); - buttonHomeX = lv_imgbtn_create(scr, "F:/bmp_zeroX.bin", BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_H_X); - buttonHomeY = lv_imgbtn_create(scr, "F:/bmp_zeroY.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_H_Y); - buttonHomeZ = lv_imgbtn_create(scr, "F:/bmp_zeroZ.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_H_Z); - buttonOffAll = lv_imgbtn_create(scr, "F:/bmp_function1.bin", INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_H_OFF_ALL); - buttonOffXY = lv_imgbtn_create(scr, "F:/bmp_function1.bin", BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_H_OFF_XY); - buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_H_RETURN); - - // Create labels on the image buttons - lv_obj_t *labelHomeAll = lv_label_create_empty(buttonHomeAll); - lv_obj_t *labelHomeX = lv_label_create_empty(buttonHomeX); - lv_obj_t *labelHomeY = lv_label_create_empty(buttonHomeY); - lv_obj_t *labelHomeZ = lv_label_create_empty(buttonHomeZ); - lv_obj_t *labelOffAll = lv_label_create_empty(buttonOffAll); - lv_obj_t *labelOffXY = lv_label_create_empty(buttonOffXY); - lv_obj_t *label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - lv_label_set_text(labelHomeAll, home_menu.home_all); - lv_obj_align(labelHomeAll, buttonHomeAll, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelHomeX, home_menu.home_x); - lv_obj_align(labelHomeX, buttonHomeX, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelHomeY, home_menu.home_y); - lv_obj_align(labelHomeY, buttonHomeY, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelHomeZ, home_menu.home_z); - lv_obj_align(labelHomeZ, buttonHomeZ, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelOffAll, set_menu.motoroff); - lv_obj_align(labelOffAll, buttonOffAll, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelOffXY, set_menu.motoroffXY); - lv_obj_align(labelOffXY, buttonOffXY, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonHomeAll); - lv_group_add_obj(g, buttonHomeX); - lv_group_add_obj(g, buttonHomeY); - lv_group_add_obj(g, buttonHomeZ); - lv_group_add_obj(g, buttonOffAll); - lv_group_add_obj(g, buttonOffXY); - lv_group_add_obj(g, buttonBack); - } - #endif + lv_big_button_create(scr, "F:/bmp_zeroAll.bin", home_menu.home_all, INTERVAL_V, titleHeight, event_handler, ID_H_ALL); + lv_big_button_create(scr, "F:/bmp_zeroX.bin", home_menu.home_x, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_H_X); + lv_big_button_create(scr, "F:/bmp_zeroY.bin", home_menu.home_y, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_H_Y); + lv_big_button_create(scr, "F:/bmp_zeroZ.bin", home_menu.home_z, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_H_Z); + lv_big_button_create(scr, "F:/bmp_function1.bin", set_menu.motoroff, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_H_OFF_ALL); + lv_big_button_create(scr, "F:/bmp_function1.bin", set_menu.motoroffXY, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_H_OFF_XY); + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_H_RETURN); } void lv_clear_home() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_homing_sensitivity_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_homing_sensitivity_settings.cpp index 67025f92c5..e01208605f 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_homing_sensitivity_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_homing_sensitivity_settings.cpp @@ -31,180 +31,75 @@ #include "../../../../module/stepper/indirection.h" #include "../../../../feature/tmc_util.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_SENSITIVITY_RETURN 1 -#define ID_SENSITIVITY_X 2 -#define ID_SENSITIVITY_Y 3 -#define ID_SENSITIVITY_Z 4 -#define ID_SENSITIVITY_Z2 5 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_SENSITIVITY_RETURN = 1, + ID_SENSITIVITY_X, + ID_SENSITIVITY_Y, + ID_SENSITIVITY_Z, + ID_SENSITIVITY_Z2 +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_SENSITIVITY_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_homing_sensitivity_settings(); - draw_return_ui(); - } + lv_clear_homing_sensitivity_settings(); + draw_return_ui(); break; case ID_SENSITIVITY_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = x_sensitivity; - lv_clear_homing_sensitivity_settings(); - lv_draw_number_key(); - } + value = x_sensitivity; + lv_clear_homing_sensitivity_settings(); + lv_draw_number_key(); break; case ID_SENSITIVITY_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = y_sensitivity; - lv_clear_homing_sensitivity_settings(); - lv_draw_number_key(); - } + value = y_sensitivity; + lv_clear_homing_sensitivity_settings(); + lv_draw_number_key(); break; case ID_SENSITIVITY_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = z_sensitivity; - lv_clear_homing_sensitivity_settings(); - lv_draw_number_key(); - } + value = z_sensitivity; + lv_clear_homing_sensitivity_settings(); + lv_draw_number_key(); break; #if Z2_SENSORLESS case ID_SENSITIVITY_Z2: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = z2_sensitivity; - lv_clear_homing_sensitivity_settings(); - lv_draw_number_key(); - } + value = z2_sensitivity; + lv_clear_homing_sensitivity_settings(); + lv_draw_number_key(); break; #endif } } void lv_draw_homing_sensitivity_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL; - lv_obj_t *buttonXValue = NULL, *labelXValue = NULL; - lv_obj_t *buttonYValue = NULL, *labelYValue = NULL; - lv_obj_t *buttonZValue = NULL, *labelZValue = NULL; - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL; - #if Z2_SENSORLESS - lv_obj_t *buttonZ2Value = NULL, *labelZ2Value = NULL; - lv_obj_t *line4 = NULL; - #endif if (disp_state_stack._disp_state[disp_state_stack._disp_index] != HOMING_SENSITIVITY_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = HOMING_SENSITIVITY_UI; } disp_state = HOMING_SENSITIVITY_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, machine_menu.HomingSensitivityConfTitle); - lv_refr_now(lv_refr_get_disp_refreshing()); - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.X_Sensitivity); - - buttonXValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_SENSITIVITY_X); - labelXValue = lv_label_create_empty(buttonXValue); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonXValue); - #endif - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10, machine_menu.Y_Sensitivity); - - buttonYValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_SENSITIVITY_Y); - labelYValue = lv_label_create_empty(buttonYValue); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonYValue); - #endif - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10, machine_menu.Z_Sensitivity); + sprintf_P(public_buf_l, PSTR("%d"), TERN(X_SENSORLESS, stepperX.homing_threshold(), 0)); + lv_screen_menu_item_1_edit(scr, machine_menu.X_Sensitivity, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_SENSITIVITY_X, 0, public_buf_l); - buttonZValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_SENSITIVITY_Z); - labelZValue = lv_label_create_empty(buttonZValue); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable == true) lv_group_add_obj(g, buttonZValue); - #endif + sprintf_P(public_buf_l, PSTR("%d"), TERN(Y_SENSORLESS, stepperY.homing_threshold(), 0)); + lv_screen_menu_item_1_edit(scr, machine_menu.Y_Sensitivity, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_SENSITIVITY_Y, 1, public_buf_l); - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); + sprintf_P(public_buf_l, PSTR("%d"), TERN(Z_SENSORLESS, stepperZ.homing_threshold(), 0)); + lv_screen_menu_item_1_edit(scr, machine_menu.Z_Sensitivity, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_SENSITIVITY_Z, 2, public_buf_l); #if Z2_SENSORLESS - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10, machine_menu.Z2_Sensitivity); - - buttonZ2Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_SENSITIVITY_Z2); - labelZ2Value = lv_label_create_empty(buttonZ2Value); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonZ2Value); - #endif - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); + sprintf_P(public_buf_l, PSTR("%d"), TERN(Z2_SENSORLESS, stepperZ2.homing_threshold(), 0)); + lv_screen_menu_item_1_edit(scr, machine_menu.Z2_Sensitivity, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_SENSITIVITY_Z2, 3, public_buf_l); #endif - buttonBack = lv_btn_create_back(scr, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE, event_handler, ID_SENSITIVITY_RETURN); - label_Back = lv_label_create_empty(buttonBack); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - if (gCfgItems.multiple_language) { - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), TERN(X_SENSORLESS, stepperX.homing_threshold(), 0)); - lv_label_set_text(labelXValue, public_buf_l); - lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), TERN(Y_SENSORLESS, stepperY.homing_threshold(), 0)); - lv_label_set_text(labelYValue, public_buf_l); - lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), TERN(Z_SENSORLESS, stepperZ.homing_threshold(), 0)); - lv_label_set_text(labelZValue, public_buf_l); - lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0); - - #if Z2_SENSORLESS - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), TERN(Z2_SENSORLESS, stepperZ2.homing_threshold(), 0)); - lv_label_set_text(labelZ2Value, public_buf_l); - lv_obj_align(labelZ2Value, buttonZ2Value, LV_ALIGN_CENTER, 0, 0); - #endif - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_SENSITIVITY_RETURN, true); } void lv_clear_homing_sensitivity_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_jerk_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_jerk_settings.cpp index 45d94020e2..5b8f7b45fd 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_jerk_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_jerk_settings.cpp @@ -29,161 +29,71 @@ #include "../../../../module/planner.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_JERK_RETURN 1 -#define ID_JERK_X 2 -#define ID_JERK_Y 3 -#define ID_JERK_Z 4 -#define ID_JERK_E 5 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_JERK_RETURN = 1, + ID_JERK_X, + ID_JERK_Y, + ID_JERK_Z, + ID_JERK_E +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_JERK_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_jerk_settings(); - draw_return_ui(); - } + lv_clear_jerk_settings(); + draw_return_ui(); break; case ID_JERK_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = XJerk; - lv_clear_jerk_settings(); - lv_draw_number_key(); - } + value = XJerk; + lv_clear_jerk_settings(); + lv_draw_number_key(); break; case ID_JERK_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = YJerk; - lv_clear_jerk_settings(); - lv_draw_number_key(); - } + value = YJerk; + lv_clear_jerk_settings(); + lv_draw_number_key(); break; case ID_JERK_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = ZJerk; - lv_clear_jerk_settings(); - lv_draw_number_key(); - } + value = ZJerk; + lv_clear_jerk_settings(); + lv_draw_number_key(); break; case ID_JERK_E: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = EJerk; - lv_clear_jerk_settings(); - lv_draw_number_key(); - } + value = EJerk; + lv_clear_jerk_settings(); + lv_draw_number_key(); break; } } void lv_draw_jerk_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL; - lv_obj_t *buttonXValue = NULL, *labelXValue = NULL; - lv_obj_t *buttonYValue = NULL, *labelYValue = NULL; - lv_obj_t *buttonZValue = NULL, *labelZValue = NULL; - lv_obj_t *buttonEValue = NULL, *labelEValue = NULL; - lv_obj_t *line1 = NULL, *line2 = NULL, *line3 = NULL, *line4 = NULL; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != JERK_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = JERK_UI; } disp_state = JERK_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, machine_menu.JerkConfTitle); - lv_refr_now(lv_refr_get_disp_refreshing()); - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.X_Jerk); - - buttonXValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_JERK_X); - labelXValue = lv_label_create_empty(buttonXValue); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10, machine_menu.Y_Jerk); - - buttonYValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_JERK_Y); - labelYValue = lv_label_create_empty(buttonYValue); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.max_jerk[X_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.X_Jerk, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_JERK_X, 0, public_buf_l); - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.max_jerk[Y_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.Y_Jerk, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_JERK_Y, 1, public_buf_l); - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10, machine_menu.Z_Jerk); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.max_jerk[Z_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.Z_Jerk, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_JERK_Z, 2, public_buf_l); - buttonZValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_JERK_Z); - labelZValue = lv_label_create_empty(buttonZValue); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.max_jerk[E_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.E_Jerk, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_JERK_E, 3, public_buf_l); - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10, machine_menu.E_Jerk); - - buttonEValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_JERK_E); - labelEValue = lv_label_create_empty(buttonEValue); - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - buttonBack = lv_btn_create_back(scr, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE, event_handler, ID_JERK_RETURN); - label_Back = lv_label_create_empty(buttonBack); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable == true) { - lv_group_add_obj(g, buttonXValue); - lv_group_add_obj(g, buttonYValue); - lv_group_add_obj(g, buttonZValue); - lv_group_add_obj(g, buttonEValue); - lv_group_add_obj(g, buttonBack); - } - #endif - - if (gCfgItems.multiple_language) { - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.max_jerk[X_AXIS]); - lv_label_set_text(labelXValue, public_buf_l); - lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.max_jerk[Y_AXIS]); - lv_label_set_text(labelYValue, public_buf_l); - lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.max_jerk[Z_AXIS]); - lv_label_set_text(labelZValue, public_buf_l); - lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.max_jerk[E_AXIS]); - lv_label_set_text(labelEValue, public_buf_l); - lv_obj_align(labelEValue, buttonEValue, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_JERK_RETURN, true); } void lv_clear_jerk_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp index 35ad439c6e..0debf8fa8f 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp @@ -28,8 +28,8 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; #define LV_KB_CTRL_BTN_FLAGS (LV_BTNM_CTRL_NO_REPEAT | LV_BTNM_CTRL_CLICK_TRIG) @@ -72,7 +72,7 @@ static const lv_btnm_ctrl_t kb_ctrl_num_map[] = { 1, 1, 1, 2, 1, 1, 1, 1, 1}; -static void lv_kb_event_cb(lv_obj_t * kb, lv_event_t event) { +static void lv_kb_event_cb(lv_obj_t *kb, lv_event_t event) { //LV_ASSERT_OBJ(kb, LV_OBJX_NAME); if (event != LV_EVENT_VALUE_CHANGED) return; @@ -84,7 +84,7 @@ static void lv_kb_event_cb(lv_obj_t * kb, lv_event_t event) { if (lv_btnm_get_btn_ctrl(kb, btn_id, LV_BTNM_CTRL_NO_REPEAT) && event == LV_EVENT_LONG_PRESSED_REPEAT) return; const char * txt = lv_btnm_get_active_btn_text(kb); - if (txt == NULL) return; + if (txt == nullptr) return; // Do the corresponding action according to the text of the button if (strcmp(txt, "abc") == 0) { @@ -104,13 +104,13 @@ static void lv_kb_event_cb(lv_obj_t * kb, lv_event_t event) { } else if (strcmp(txt, LV_SYMBOL_CLOSE) == 0) { if (kb->event_cb != lv_kb_def_event_cb) { - //lv_res_t res = lv_event_send(kb, LV_EVENT_CANCEL, NULL); + //lv_res_t res = lv_event_send(kb, LV_EVENT_CANCEL, nullptr); //if (res != LV_RES_OK) return; lv_clear_keyboard(); draw_return_ui(); } else { - lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/ + lv_kb_set_ta(kb, nullptr); /*De-assign the text area to hide it cursor if needed*/ lv_obj_del(kb); return; } @@ -118,7 +118,7 @@ static void lv_kb_event_cb(lv_obj_t * kb, lv_event_t event) { } else if (strcmp(txt, LV_SYMBOL_OK) == 0) { if (kb->event_cb != lv_kb_def_event_cb) { - //lv_res_t res = lv_event_send(kb, LV_EVENT_APPLY, NULL); + //lv_res_t res = lv_event_send(kb, LV_EVENT_APPLY, nullptr); //if (res != LV_RES_OK) return; const char * ret_ta_txt = lv_ta_get_text(ext->ta); switch (keyboard_value) { @@ -134,18 +134,16 @@ static void lv_kb_event_cb(lv_obj_t * kb, lv_event_t event) { draw_return_ui(); break; case wifiConfig: - memset((void *)uiCfg.wifi_name, 0, sizeof(uiCfg.wifi_name)); + ZERO(uiCfg.wifi_name); memcpy((void *)uiCfg.wifi_name, wifi_list.wifiName[wifi_list.nameIndex], 32); - memset((void *)uiCfg.wifi_key, 0, sizeof(uiCfg.wifi_key)); + ZERO(uiCfg.wifi_key); memcpy((void *)uiCfg.wifi_key, ret_ta_txt, sizeof(uiCfg.wifi_key)); gCfgItems.wifi_mode_sel = STA_MODEL; package_to_wifi(WIFI_PARA_SET, (char *)0, 0); - memset(public_buf_l,0,sizeof(public_buf_l)); - public_buf_l[0] = 0xA5; public_buf_l[1] = 0x09; public_buf_l[2] = 0x01; @@ -172,13 +170,13 @@ static void lv_kb_event_cb(lv_obj_t * kb, lv_event_t event) { } } else { - lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/ + lv_kb_set_ta(kb, nullptr); /*De-assign the text area to hide it cursor if needed*/ } return; } /*Add the characters to the text area if set*/ - if (ext->ta == NULL) return; + if (ext->ta == nullptr) return; if (strcmp(txt, "Enter") == 0 || strcmp(txt, LV_SYMBOL_NEW_LINE) == 0) lv_ta_add_char(ext->ta, '\n'); @@ -221,11 +219,7 @@ void lv_draw_keyboard() { } disp_state = KEY_BOARD_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); lv_refr_now(lv_refr_get_disp_refreshing()); @@ -245,7 +239,7 @@ void lv_draw_keyboard() { pr_style.body.grad_color = lv_color_make(0x6A, 0x3A, 0x0C); /*Create a keyboard and apply the styles*/ - lv_obj_t *kb = lv_kb_create(scr, NULL); + lv_obj_t *kb = lv_kb_create(scr, nullptr); lv_obj_set_event_cb(kb, lv_kb_event_cb); lv_kb_set_cursor_manage(kb, true); lv_kb_set_style(kb, LV_KB_STYLE_BG, &lv_style_transp_tight); @@ -259,8 +253,8 @@ void lv_draw_keyboard() { #endif /*Create a text area. The keyboard will write here*/ - lv_obj_t *ta = lv_ta_create(scr, NULL); - lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_MID, 0, 10); + lv_obj_t *ta = lv_ta_create(scr, nullptr); + lv_obj_align(ta, nullptr, LV_ALIGN_IN_TOP_MID, 0, 10); if (keyboard_value == gcodeCommand) { get_gcode_command(AUTO_LEVELING_COMMAND_ADDR,(uint8_t *)public_buf_m); public_buf_m[sizeof(public_buf_m)-1] = 0; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_language.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_language.cpp index b5c2da09aa..1ff60d9b9b 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_language.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_language.cpp @@ -33,139 +33,98 @@ #include "../../../../inc/MarlinConfig.h" #include -//static lv_obj_t *buttonMoveZ,*buttonTest,*buttonZ0,*buttonStop,*buttonReturn; - -#define ID_CN 1 -#define ID_T_CN 2 -#define ID_EN 3 -#define ID_RU 4 -#define ID_ES 5 -#define ID_FR 6 -#define ID_IT 7 -#define ID_L_RETURN 8 +enum { + ID_CN = 1, + ID_T_CN, + ID_EN, + ID_RU, + ID_ES, + ID_FR, + ID_IT, + ID_L_RETURN +}; #define SELECTED 1 #define UNSELECTED 0 static void disp_language(uint8_t language, uint8_t state); -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; static lv_obj_t *buttonCN, *buttonT_CN, *buttonEN, *buttonRU; -static lv_obj_t *buttonES, *buttonFR, *buttonIT, *buttonBack; +static lv_obj_t *buttonES, *buttonFR, *buttonIT; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_CN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - disp_language(gCfgItems.language, UNSELECTED); - lv_imgbtn_set_src_both(buttonCN, "F:/bmp_simplified_cn_sel.bin"); - lv_obj_refresh_ext_draw_pad(buttonCN); - gCfgItems.language = LANG_SIMPLE_CHINESE; - update_spi_flash(); - disp_language_init(); - } + disp_language(gCfgItems.language, UNSELECTED); + lv_imgbtn_set_src_both(buttonCN, "F:/bmp_simplified_cn_sel.bin"); + lv_obj_refresh_ext_draw_pad(buttonCN); + gCfgItems.language = LANG_SIMPLE_CHINESE; + update_spi_flash(); + disp_language_init(); break; case ID_T_CN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - disp_language(gCfgItems.language, UNSELECTED); - lv_imgbtn_set_src_both(buttonT_CN, "F:/bmp_traditional_cn_sel.bin"); - lv_obj_refresh_ext_draw_pad(buttonT_CN); - gCfgItems.language = LANG_COMPLEX_CHINESE; - update_spi_flash(); - disp_language_init(); - } + disp_language(gCfgItems.language, UNSELECTED); + lv_imgbtn_set_src_both(buttonT_CN, "F:/bmp_traditional_cn_sel.bin"); + lv_obj_refresh_ext_draw_pad(buttonT_CN); + gCfgItems.language = LANG_COMPLEX_CHINESE; + update_spi_flash(); + disp_language_init(); break; case ID_EN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - disp_language(gCfgItems.language, UNSELECTED); - lv_imgbtn_set_src_both(buttonEN, "F:/bmp_english_sel.bin"); - lv_obj_refresh_ext_draw_pad(buttonEN); - gCfgItems.language = LANG_ENGLISH; - update_spi_flash(); - disp_language_init(); - } + disp_language(gCfgItems.language, UNSELECTED); + lv_imgbtn_set_src_both(buttonEN, "F:/bmp_english_sel.bin"); + lv_obj_refresh_ext_draw_pad(buttonEN); + gCfgItems.language = LANG_ENGLISH; + update_spi_flash(); + disp_language_init(); break; case ID_RU: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - disp_language(gCfgItems.language, UNSELECTED); - lv_imgbtn_set_src_both(buttonRU, "F:/bmp_russian_sel.bin"); - lv_obj_refresh_ext_draw_pad(buttonRU); - gCfgItems.language = LANG_RUSSIAN; - update_spi_flash(); - disp_language_init(); - } + disp_language(gCfgItems.language, UNSELECTED); + lv_imgbtn_set_src_both(buttonRU, "F:/bmp_russian_sel.bin"); + lv_obj_refresh_ext_draw_pad(buttonRU); + gCfgItems.language = LANG_RUSSIAN; + update_spi_flash(); + disp_language_init(); break; case ID_ES: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - disp_language(gCfgItems.language, UNSELECTED); - lv_imgbtn_set_src_both(buttonES, "F:/bmp_spanish_sel.bin"); - lv_obj_refresh_ext_draw_pad(buttonES); - gCfgItems.language = LANG_SPANISH; - update_spi_flash(); - disp_language_init(); - } + disp_language(gCfgItems.language, UNSELECTED); + lv_imgbtn_set_src_both(buttonES, "F:/bmp_spanish_sel.bin"); + lv_obj_refresh_ext_draw_pad(buttonES); + gCfgItems.language = LANG_SPANISH; + update_spi_flash(); + disp_language_init(); break; case ID_FR: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - disp_language(gCfgItems.language, UNSELECTED); - lv_imgbtn_set_src_both(buttonFR, "F:/bmp_french_sel.bin"); - lv_obj_refresh_ext_draw_pad(buttonFR); - gCfgItems.language = LANG_FRENCH; - update_spi_flash(); - disp_language_init(); - } + disp_language(gCfgItems.language, UNSELECTED); + lv_imgbtn_set_src_both(buttonFR, "F:/bmp_french_sel.bin"); + lv_obj_refresh_ext_draw_pad(buttonFR); + gCfgItems.language = LANG_FRENCH; + update_spi_flash(); + disp_language_init(); break; case ID_IT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - disp_language(gCfgItems.language, UNSELECTED); - lv_imgbtn_set_src_both(buttonIT, "F:/bmp_italy_sel.bin"); - lv_obj_refresh_ext_draw_pad(buttonIT); - gCfgItems.language = LANG_ITALY; - update_spi_flash(); - disp_language_init(); - } + disp_language(gCfgItems.language, UNSELECTED); + lv_imgbtn_set_src_both(buttonIT, "F:/bmp_italy_sel.bin"); + lv_obj_refresh_ext_draw_pad(buttonIT); + gCfgItems.language = LANG_ITALY; + update_spi_flash(); + disp_language_init(); break; case ID_L_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - buttonCN = NULL; - buttonT_CN = NULL; - buttonEN = NULL; - buttonRU = NULL; - buttonES = NULL; - buttonFR = NULL; - buttonFR = NULL; - buttonIT = NULL; - buttonBack = NULL; - lv_clear_language(); - lv_draw_set(); - } + buttonCN = nullptr; + buttonT_CN = nullptr; + buttonEN = nullptr; + buttonRU = nullptr; + buttonES = nullptr; + buttonFR = nullptr; + buttonFR = nullptr; + buttonIT = nullptr; + lv_clear_language(); + lv_draw_set(); break; - } } @@ -222,7 +181,7 @@ static void disp_language(uint8_t language, uint8_t state) { strcat_P(public_buf_l, PSTR(".bin")); - lv_obj_set_event_cb_mks(obj, event_handler, id, NULL, 0); + lv_obj_set_event_cb_mks(obj, event_handler, id, nullptr, 0); lv_imgbtn_set_src_both(obj, public_buf_l); if (state == UNSELECTED) lv_obj_refresh_ext_draw_pad(obj); @@ -236,78 +195,24 @@ void lv_draw_language(void) { } disp_state = LANGUAGE_UI; - scr = lv_obj_create(NULL, NULL); - - // static lv_style_t tool_style; - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); // Create image buttons - buttonCN = lv_imgbtn_create(scr, "F:/bmp_simplified_cn.bin", INTERVAL_V, titleHeight, event_handler, ID_CN); + buttonCN = lv_big_button_create(scr, "F:/bmp_simplified_cn.bin", language_menu.chinese_s, INTERVAL_V, titleHeight, event_handler, ID_CN); lv_obj_clear_protect(buttonCN, LV_PROTECT_FOLLOW); - buttonT_CN = lv_imgbtn_create(scr, "F:/bmp_traditional_cn.bin", BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_T_CN); - buttonEN = lv_imgbtn_create(scr, "F:/bmp_english.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_EN); - buttonRU = lv_imgbtn_create(scr, "F:/bmp_russian.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_RU); - buttonES = lv_imgbtn_create(scr, "F:/bmp_spanish.bin", INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_ES); - buttonFR = lv_imgbtn_create(scr, "F:/bmp_french.bin", BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_FR); - buttonIT = lv_imgbtn_create(scr, "F:/bmp_italy.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_IT); - buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_L_RETURN); - - // Create labels on the image buttons - lv_obj_t *label_CN = lv_label_create_empty(buttonCN); - lv_obj_t *label_T_CN = lv_label_create_empty(buttonT_CN); - lv_obj_t *label_EN = lv_label_create_empty(buttonEN); - lv_obj_t *label_RU = lv_label_create_empty(buttonRU); - lv_obj_t *label_ES = lv_label_create_empty(buttonES); - lv_obj_t *label_FR = lv_label_create_empty(buttonFR); - lv_obj_t *label_IT = lv_label_create_empty(buttonIT); - lv_obj_t *label_Back = lv_label_create_empty(buttonBack); + buttonT_CN = lv_big_button_create(scr, "F:/bmp_traditional_cn.bin", language_menu.chinese_t, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_T_CN); + buttonEN = lv_big_button_create(scr, "F:/bmp_english.bin", language_menu.english, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_EN); + buttonRU = lv_big_button_create(scr, "F:/bmp_russian.bin", language_menu.russian, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_RU); + buttonES = lv_big_button_create(scr, "F:/bmp_spanish.bin", language_menu.spanish, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_ES); + buttonFR = lv_big_button_create(scr, "F:/bmp_french.bin", language_menu.french, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_FR); + buttonIT = lv_big_button_create(scr, "F:/bmp_italy.bin", language_menu.italy, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_IT); + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_L_RETURN); disp_language(gCfgItems.language, SELECTED); - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_CN, language_menu.chinese_s); - lv_obj_align(label_CN, buttonCN, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_T_CN, language_menu.chinese_t); - lv_obj_align(label_T_CN, buttonT_CN, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_EN, language_menu.english); - lv_obj_align(label_EN, buttonEN, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_RU, language_menu.russian); - lv_obj_align(label_RU, buttonRU, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_ES, language_menu.spanish); - lv_obj_align(label_ES, buttonES, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_FR, language_menu.french); - lv_obj_align(label_FR, buttonFR, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_IT, language_menu.italy); - lv_obj_align(label_IT, buttonIT, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonCN); - lv_group_add_obj(g, buttonT_CN); - lv_group_add_obj(g, buttonEN); - lv_group_add_obj(g, buttonRU); - lv_group_add_obj(g, buttonES); - lv_group_add_obj(g, buttonFR); - lv_group_add_obj(g, buttonIT); - lv_group_add_obj(g, buttonBack); - } - #endif } void lv_clear_language() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_level_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_level_settings.cpp index d742f79e59..7bd2b83ace 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_level_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_level_settings.cpp @@ -28,194 +28,57 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_LEVEL_RETURN 1 -#define ID_LEVEL_POSITION 2 -#define ID_LEVEL_POSITION_ARROW 3 -#define ID_LEVEL_COMMAND 4 -#define ID_LEVEL_COMMAND_ARROW 5 -#define ID_LEVEL_ZOFFSET 6 -#define ID_LEVEL_ZOFFSET_ARROW 7 +enum { + ID_LEVEL_RETURN = 1, + ID_LEVEL_POSITION, + ID_LEVEL_COMMAND, + ID_LEVEL_ZOFFSET +}; - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { switch (obj->mks_obj_id) { case ID_LEVEL_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_level_settings(); - draw_return_ui(); - } + lv_clear_level_settings(); + draw_return_ui(); break; case ID_LEVEL_POSITION: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_level_settings(); - lv_draw_manual_level_pos_settings(); - } - break; - case ID_LEVEL_POSITION_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_level_settings(); - lv_draw_manual_level_pos_settings(); - } + lv_clear_level_settings(); + lv_draw_manual_level_pos_settings(); break; case ID_LEVEL_COMMAND: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - keyboard_value = gcodeCommand; - lv_clear_level_settings(); - lv_draw_keyboard(); - } - break; - case ID_LEVEL_COMMAND_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - keyboard_value = gcodeCommand; - lv_clear_level_settings(); - lv_draw_keyboard(); - } + keyboard_value = gcodeCommand; + lv_clear_level_settings(); + lv_draw_keyboard(); break; #if HAS_BED_PROBE case ID_LEVEL_ZOFFSET: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_level_settings(); - lv_draw_auto_level_offset_settings(); - } - break; - case ID_LEVEL_ZOFFSET_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_level_settings(); - lv_draw_auto_level_offset_settings(); - } + lv_clear_level_settings(); + lv_draw_auto_level_offset_settings(); break; #endif } } void lv_draw_level_settings(void) { - lv_obj_t *buttonBack, *label_Back; - lv_obj_t *buttonPosition, *labelPosition, *buttonPositionNarrow; - lv_obj_t *buttonCommand, *labelCommand, *buttonCommandNarrow; - #if HAS_BED_PROBE - lv_obj_t *buttonZoffset, *labelZoffset, *buttonZoffsetNarrow; - lv_obj_t * line3; - #endif - lv_obj_t * line1, * line2; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != LEVELING_PARA_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = LEVELING_PARA_UI; } disp_state = LEVELING_PARA_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, machine_menu.LevelingParaConfTitle); - lv_refr_now(lv_refr_get_disp_refreshing()); - - buttonPosition = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonPosition, PARA_UI_POS_X, PARA_UI_POS_Y); /*Set its position*/ - lv_obj_set_size(buttonPosition, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - lv_obj_set_event_cb_mks(buttonPosition, event_handler, ID_LEVEL_POSITION, NULL, 0); - lv_btn_use_label_style(buttonPosition); - lv_btn_set_layout(buttonPosition, LV_LAYOUT_OFF); - labelPosition = lv_label_create_empty(buttonPosition); /*Add a label to the button*/ - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonPosition); - #endif - - buttonPositionNarrow = lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y + PARA_UI_ARROW_V, event_handler, ID_LEVEL_POSITION_ARROW); - lv_btn_set_layout(buttonPositionNarrow, LV_LAYOUT_OFF); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonCommand = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonCommand, PARA_UI_POS_X, PARA_UI_POS_Y * 2); - lv_obj_set_size(buttonCommand, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); - lv_obj_set_event_cb_mks(buttonCommand, event_handler, ID_LEVEL_COMMAND, NULL, 0); - lv_btn_use_label_style(buttonCommand); - lv_btn_set_layout(buttonCommand, LV_LAYOUT_OFF); - labelCommand = lv_label_create_empty(buttonCommand); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonCommand); - #endif - - buttonCommandNarrow = lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 2 + PARA_UI_ARROW_V, event_handler, ID_LEVEL_COMMAND_ARROW); - lv_btn_set_layout(buttonCommandNarrow, LV_LAYOUT_OFF); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - + lv_screen_menu_item(scr, machine_menu.LevelingManuPosConf, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_LEVEL_POSITION, 0); + lv_screen_menu_item(scr, machine_menu.LevelingAutoCommandConf, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_LEVEL_COMMAND, 1); #if HAS_BED_PROBE - - buttonZoffset = lv_btn_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3, PARA_UI_SIZE_X, PARA_UI_SIZE_Y, event_handler, ID_LEVEL_ZOFFSET); - lv_btn_set_layout(buttonZoffset, LV_LAYOUT_OFF); - labelZoffset = lv_label_create_empty(buttonZoffset); /*Add a label to the button*/ - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonZoffset); - #endif - - buttonZoffsetNarrow = lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 3 + PARA_UI_ARROW_V, event_handler, ID_LEVEL_ZOFFSET_ARROW); - lv_btn_set_layout(buttonZoffsetNarrow, LV_LAYOUT_OFF); - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - #endif // HAS_BED_PROBE - - buttonBack = lv_imgbtn_create(scr, "F:/bmp_back70x40.bin", event_handler, ID_LEVEL_RETURN); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); + lv_screen_menu_item(scr, machine_menu.LevelingAutoZoffsetConf, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_LEVEL_ZOFFSET, 2); #endif - - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelPosition, machine_menu.LevelingManuPosConf); - lv_obj_align(labelPosition, buttonPosition, LV_ALIGN_IN_LEFT_MID, 0, 0); - - lv_label_set_text(labelCommand, machine_menu.LevelingAutoCommandConf); - lv_obj_align(labelCommand, buttonCommand, LV_ALIGN_IN_LEFT_MID, 0, 0); - #if HAS_BED_PROBE - lv_label_set_text(labelZoffset, machine_menu.LevelingAutoZoffsetConf); - lv_obj_align(labelZoffset, buttonZoffset, LV_ALIGN_IN_LEFT_MID, 0, 0); - #endif - } - + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X + 10, PARA_UI_BACL_POS_Y, event_handler, ID_LEVEL_RETURN, true); } void lv_clear_level_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_machine_para.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_machine_para.cpp index 2309822e86..45aabae079 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_machine_para.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_machine_para.cpp @@ -28,209 +28,60 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_PARA_RETURN 1 -#define ID_PARA_MACHINE 2 -#define ID_PARA_MACHINE_ARROW 3 -#define ID_PARA_MOTOR 4 -#define ID_PARA_MOTOR_ARROW 5 -#define ID_PARA_LEVEL 6 -#define ID_PARA_LEVEL_ARROW 7 -#define ID_PARA_ADVANCE 8 -#define ID_PARA_ADVANCE_ARROW 9 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_PARA_RETURN = 1, + ID_PARA_MACHINE, + ID_PARA_MOTOR, + ID_PARA_LEVEL, + ID_PARA_ADVANCE +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_PARA_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - draw_return_ui(); - } + lv_clear_machine_para(); + draw_return_ui(); break; case ID_PARA_MACHINE: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - lv_draw_machine_settings(); - } - break; - case ID_PARA_MACHINE_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - lv_draw_machine_settings(); - } + lv_clear_machine_para(); + lv_draw_machine_settings(); break; case ID_PARA_MOTOR: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - lv_draw_motor_settings(); - } - break; - case ID_PARA_MOTOR_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - lv_draw_motor_settings(); - } + lv_clear_machine_para(); + lv_draw_motor_settings(); break; case ID_PARA_LEVEL: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - lv_draw_level_settings(); - } - break; - case ID_PARA_LEVEL_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - lv_draw_level_settings(); - } + lv_clear_machine_para(); + lv_draw_level_settings(); break; case ID_PARA_ADVANCE: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - lv_draw_advance_settings(); - } - break; - case ID_PARA_ADVANCE_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - lv_draw_advance_settings(); - } + lv_clear_machine_para(); + lv_draw_advance_settings(); break; } } void lv_draw_machine_para(void) { - lv_obj_t *buttonBack, *label_Back; - lv_obj_t *buttonMachine, *labelMachine, *buttonMachineNarrow; - lv_obj_t *buttonMotor, *labelMotor, *buttonMotorNarrow; - lv_obj_t *buttonLevel, *labelLevel, *buttonLevelNarrow; - lv_obj_t *buttonAdvance, *labelAdvance, *buttonAdvanceNarrow; - lv_obj_t * line1, * line2, * line3, * line4; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != MACHINE_PARA_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = MACHINE_PARA_UI; } disp_state = MACHINE_PARA_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); - lv_refr_now(lv_refr_get_disp_refreshing()); - buttonMachine = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonMachine, PARA_UI_POS_X, PARA_UI_POS_Y); /*Set its position*/ - lv_obj_set_size(buttonMachine, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - //lv_obj_set_event_cb(buttonMachine, event_handler); - lv_obj_set_event_cb_mks(buttonMachine, event_handler, ID_PARA_MACHINE, NULL, 0); - lv_btn_use_label_style(buttonMachine); - lv_btn_set_layout(buttonMachine, LV_LAYOUT_OFF); - labelMachine = lv_label_create_empty(buttonMachine); /*Add a label to the button*/ - - buttonMachineNarrow = lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y + PARA_UI_ARROW_V, event_handler, ID_PARA_MACHINE_ARROW); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonMotor = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonMotor, PARA_UI_POS_X, PARA_UI_POS_Y * 2); /*Set its position*/ - lv_obj_set_size(buttonMotor, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - //lv_obj_set_event_cb(buttonMotor, event_handler); - lv_obj_set_event_cb_mks(buttonMotor, event_handler, ID_PARA_MOTOR, NULL, 0); - lv_btn_use_label_style(buttonMotor); - lv_btn_set_layout(buttonMotor, LV_LAYOUT_OFF); - labelMotor = lv_label_create_empty(buttonMotor); /*Add a label to the button*/ - - buttonMotorNarrow = lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 2 + PARA_UI_ARROW_V, event_handler, ID_PARA_MOTOR_ARROW); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - buttonLevel = lv_btn_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3, PARA_UI_SIZE_X, PARA_UI_SIZE_Y, event_handler, ID_PARA_LEVEL); - //lv_obj_set_event_cb(buttonMotor, event_handler); - lv_btn_set_layout(buttonLevel, LV_LAYOUT_OFF); - labelLevel = lv_label_create_empty(buttonLevel); /*Add a label to the button*/ - - buttonLevelNarrow = lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 3 + PARA_UI_ARROW_V, event_handler, ID_PARA_LEVEL_ARROW); - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - buttonAdvance = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonAdvance, PARA_UI_POS_X, PARA_UI_POS_Y * 4); /*Set its position*/ - lv_obj_set_size(buttonAdvance, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - //lv_obj_set_event_cb(buttonMotor, event_handler); - lv_obj_set_event_cb_mks(buttonAdvance, event_handler, ID_PARA_ADVANCE, NULL, 0); - lv_btn_use_label_style(buttonAdvance); - lv_btn_set_layout(buttonAdvance, LV_LAYOUT_OFF); - labelAdvance = lv_label_create_empty(buttonAdvance); /*Add a label to the button*/ - - buttonAdvanceNarrow = lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 4 + PARA_UI_ARROW_V, event_handler, ID_PARA_ADVANCE_ARROW); - lv_btn_set_layout(buttonAdvanceNarrow, LV_LAYOUT_OFF); - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - buttonBack = lv_imgbtn_create(scr, "F:/bmp_back70x40.bin", PARA_UI_BACL_POS_X + 10, PARA_UI_BACL_POS_Y, event_handler, ID_PARA_RETURN); - label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, -2); - - lv_label_set_text(labelMachine, MachinePara_menu.MachineSetting); - lv_obj_align(labelMachine, buttonMachine, LV_ALIGN_IN_LEFT_MID, 0, -3); - - lv_label_set_text(labelMotor, MachinePara_menu.MotorSetting); - lv_obj_align(labelMotor, buttonMotor, LV_ALIGN_IN_LEFT_MID, 0, -3); - - lv_label_set_text(labelLevel, MachinePara_menu.leveling); - lv_obj_align(labelLevel, buttonLevel, LV_ALIGN_IN_LEFT_MID, 0, -3); - - lv_label_set_text(labelAdvance, MachinePara_menu.AdvanceSetting); - lv_obj_align(labelAdvance, buttonAdvance, LV_ALIGN_IN_LEFT_MID, 0, -3); - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonMachine); - lv_group_add_obj(g, buttonMotor); - lv_group_add_obj(g, buttonLevel); - lv_group_add_obj(g, buttonAdvance); - lv_group_add_obj(g, buttonBack); - } - #endif + lv_screen_menu_item(scr, MachinePara_menu.MachineSetting, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_PARA_MACHINE, 0); + lv_screen_menu_item(scr, MachinePara_menu.MotorSetting, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_PARA_MOTOR, 1); + lv_screen_menu_item(scr, MachinePara_menu.leveling, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_PARA_LEVEL, 2); + lv_screen_menu_item(scr, MachinePara_menu.AdvanceSetting, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_PARA_ADVANCE, 3); + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X + 10, PARA_UI_BACL_POS_Y, event_handler, ID_PARA_RETURN, true); } void lv_clear_machine_para() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_machine_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_machine_settings.cpp index ae83b7efbc..000b122b34 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_machine_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_machine_settings.cpp @@ -28,188 +28,59 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_MACHINE_RETURN 1 -#define ID_MACHINE_ACCELERATION 2 -#define ID_MACHINE_ACCELERATION_ARROW 3 -#define ID_MACHINE_FEEDRATE 4 -#define ID_MACHINE_FEEDRATE_ARROW 5 -#define ID_MACHINE_JERK 6 -#define ID_MACHINE_JERK_ARROW 7 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_MACHINE_RETURN = 1, + ID_MACHINE_ACCELERATION, + ID_MACHINE_FEEDRATE, + ID_MACHINE_JERK +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_MACHINE_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_settings(); - draw_return_ui(); - } + lv_clear_machine_settings(); + draw_return_ui(); break; case ID_MACHINE_ACCELERATION: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_settings(); - lv_draw_acceleration_settings(); - } - break; - case ID_MACHINE_ACCELERATION_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_settings(); - lv_draw_acceleration_settings(); - } + lv_clear_machine_settings(); + lv_draw_acceleration_settings(); break; case ID_MACHINE_FEEDRATE: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_settings(); - lv_draw_max_feedrate_settings(); - } + lv_clear_machine_settings(); + lv_draw_max_feedrate_settings(); break; - case ID_MACHINE_FEEDRATE_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { + #if HAS_CLASSIC_JERK + case ID_MACHINE_JERK: lv_clear_machine_settings(); - lv_draw_max_feedrate_settings(); - } - break; - #if HAS_CLASSIC_JERK - case ID_MACHINE_JERK: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_settings(); - lv_draw_jerk_settings(); - } - break; - case ID_MACHINE_JERK_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_settings(); - lv_draw_jerk_settings(); - } - break; - #endif + lv_draw_jerk_settings(); + break; + #endif } } void lv_draw_machine_settings(void) { - lv_obj_t *buttonBack, *label_Back; - lv_obj_t *buttonAcceleration, *labelAcceleration, *buttonAccelerationNarrow; - lv_obj_t *buttonMaxFeedrate, *labelMaxFeedrate, *buttonMaxFeedrateNarrow; - #if HAS_CLASSIC_JERK - lv_obj_t *buttonJerk, *labelJerk, *buttonJerkNarrow; - #endif - lv_obj_t * line1, * line2; - #if HAS_CLASSIC_JERK - lv_obj_t * line3; - #endif if (disp_state_stack._disp_state[disp_state_stack._disp_index] != MACHINE_SETTINGS_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = MACHINE_SETTINGS_UI; } disp_state = MACHINE_SETTINGS_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, machine_menu.MachineConfigTitle); lv_refr_now(lv_refr_get_disp_refreshing()); - buttonAcceleration = lv_btn_create(scr, NULL); // Add a button the current screen - lv_obj_set_pos(buttonAcceleration, PARA_UI_POS_X, PARA_UI_POS_Y); // Set its position - lv_obj_set_size(buttonAcceleration, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); // Set its size - //lv_obj_set_event_cb(buttonMachine, event_handler); - lv_obj_set_event_cb_mks(buttonAcceleration, event_handler, ID_MACHINE_ACCELERATION, NULL, 0); - lv_btn_use_label_style(buttonAcceleration); - lv_btn_set_layout(buttonAcceleration, LV_LAYOUT_OFF); - labelAcceleration = lv_label_create_empty(buttonAcceleration); // Add a label to the button - - buttonAccelerationNarrow = lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y + PARA_UI_ARROW_V, event_handler, ID_MACHINE_ACCELERATION_ARROW); - - line1 = lv_line_create(lv_scr_act(), NULL); - lv_ex_line(line1, line_points[0]); - - buttonMaxFeedrate = lv_btn_create(scr, NULL); // Add a button the current screen - lv_obj_set_pos(buttonMaxFeedrate, PARA_UI_POS_X, PARA_UI_POS_Y * 2); // Set its position - lv_obj_set_size(buttonMaxFeedrate, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); // Set its size - //lv_obj_set_event_cb(buttonMachine, event_handler); - lv_obj_set_event_cb_mks(buttonMaxFeedrate, event_handler, ID_MACHINE_FEEDRATE, NULL, 0); - lv_btn_use_label_style(buttonMaxFeedrate); - lv_btn_set_layout(buttonMaxFeedrate, LV_LAYOUT_OFF); - labelMaxFeedrate = lv_label_create_empty(buttonMaxFeedrate); // Add a label to the button - - buttonMaxFeedrateNarrow = lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 2 + PARA_UI_ARROW_V, event_handler, ID_MACHINE_FEEDRATE_ARROW); - - line2 = lv_line_create(lv_scr_act(), NULL); - lv_ex_line(line2, line_points[1]); - + lv_screen_menu_item(scr, machine_menu.AccelerationConf, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_MACHINE_ACCELERATION, 0); + lv_screen_menu_item(scr, machine_menu.MaxFeedRateConf, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_MACHINE_FEEDRATE, 1); #if HAS_CLASSIC_JERK - buttonJerk = lv_btn_create(scr, NULL); // Add a button the current screen - lv_obj_set_pos(buttonJerk, PARA_UI_POS_X, PARA_UI_POS_Y * 3); // Set its position - lv_obj_set_size(buttonJerk, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); // Set its size - //lv_obj_set_event_cb(buttonMotor, event_handler); - lv_obj_set_event_cb_mks(buttonJerk, event_handler, ID_MACHINE_JERK, NULL, 0); - lv_btn_use_label_style(buttonJerk); - lv_btn_set_layout(buttonJerk, LV_LAYOUT_OFF); - labelJerk = lv_label_create_empty(buttonJerk); // Add a label to the button - - buttonJerkNarrow = lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 3 + PARA_UI_ARROW_V, event_handler, ID_MACHINE_JERK_ARROW); - - line3 = lv_line_create(lv_scr_act(), NULL); - lv_ex_line(line3, line_points[2]); - #endif - - buttonBack = lv_imgbtn_create(scr, "F:/bmp_back70x40.bin", event_handler, ID_MACHINE_RETURN); - - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelAcceleration, machine_menu.AccelerationConf); - lv_obj_align(labelAcceleration, buttonAcceleration, LV_ALIGN_IN_LEFT_MID, 0, 0); - - lv_label_set_text(labelMaxFeedrate, machine_menu.MaxFeedRateConf); - lv_obj_align(labelMaxFeedrate, buttonMaxFeedrate, LV_ALIGN_IN_LEFT_MID, 0, 0); - #if HAS_CLASSIC_JERK - lv_label_set_text(labelJerk, machine_menu.JerkConf); - lv_obj_align(labelJerk, buttonJerk, LV_ALIGN_IN_LEFT_MID, 0, 0); - #endif - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonAcceleration); - lv_group_add_obj(g, buttonMaxFeedrate); - #if HAS_CLASSIC_JERK - lv_group_add_obj(g, buttonJerk); - #endif - lv_group_add_obj(g, buttonBack); - } + lv_screen_menu_item(scr, machine_menu.JerkConf, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_MACHINE_JERK, 2); #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X + 10, PARA_UI_BACL_POS_Y, event_handler, ID_MACHINE_RETURN, true); } void lv_clear_machine_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_manuaLevel.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_manuaLevel.cpp index 8c0575d343..0513437353 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_manuaLevel.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_manuaLevel.cpp @@ -33,201 +33,109 @@ #include "../../../../gcode/queue.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_M_POINT1 1 -#define ID_M_POINT2 2 -#define ID_M_POINT3 3 -#define ID_M_POINT4 4 -#define ID_M_POINT5 5 -#define ID_MANUAL_RETURN 6 +enum { + ID_M_POINT1 = 1, + ID_M_POINT2, + ID_M_POINT3, + ID_M_POINT4, + ID_M_POINT5, + ID_MANUAL_RETURN +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; -static void event_handler(lv_obj_t * obj, lv_event_t event) { switch (obj->mks_obj_id) { case ID_M_POINT1: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - - if (queue.length == 0) { - if (uiCfg.leveling_first_time) { - queue.enqueue_now_P(PSTR("G28")); - uiCfg.leveling_first_time = 0; - } - - queue.enqueue_now_P(PSTR("G1 Z10")); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[0][0], (int)gCfgItems.levelingPos[0][1]); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G1 Z0")); + if (queue.length == 0) { + if (uiCfg.leveling_first_time) { + queue.enqueue_now_P(PSTR("G28")); + uiCfg.leveling_first_time = 0; } + queue.enqueue_now_P(PSTR("G1 Z10")); + sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[0][0], (int)gCfgItems.levelingPos[0][1]); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G1 Z0")); } break; case ID_M_POINT2: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length == 0) { - if (uiCfg.leveling_first_time) { - queue.enqueue_now_P(PSTR("G28")); - uiCfg.leveling_first_time = 0; - } - - queue.enqueue_now_P(PSTR("G1 Z10")); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[1][0], (int)gCfgItems.levelingPos[1][1]); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G1 Z0")); + if (queue.length == 0) { + if (uiCfg.leveling_first_time) { + queue.enqueue_now_P(PSTR("G28")); + uiCfg.leveling_first_time = 0; } + queue.enqueue_now_P(PSTR("G1 Z10")); + sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[1][0], (int)gCfgItems.levelingPos[1][1]); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G1 Z0")); } break; case ID_M_POINT3: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length == 0) { - if (uiCfg.leveling_first_time) { - queue.enqueue_now_P(PSTR("G28")); - uiCfg.leveling_first_time = 0; - } - - queue.enqueue_now_P(PSTR("G1 Z10")); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[2][0], (int)gCfgItems.levelingPos[2][1]); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G1 Z0")); + if (queue.length == 0) { + if (uiCfg.leveling_first_time) { + queue.enqueue_now_P(PSTR("G28")); + uiCfg.leveling_first_time = 0; } + queue.enqueue_now_P(PSTR("G1 Z10")); + sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[2][0], (int)gCfgItems.levelingPos[2][1]); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G1 Z0")); } break; case ID_M_POINT4: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length == 0) { - if (uiCfg.leveling_first_time) { - queue.enqueue_now_P(PSTR("G28")); - uiCfg.leveling_first_time = 0; - } - - queue.enqueue_now_P(PSTR("G1 Z10")); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[3][0], (int)gCfgItems.levelingPos[3][1]); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G1 Z0")); + if (queue.length == 0) { + if (uiCfg.leveling_first_time) { + queue.enqueue_now_P(PSTR("G28")); + uiCfg.leveling_first_time = 0; } + queue.enqueue_now_P(PSTR("G1 Z10")); + sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[3][0], (int)gCfgItems.levelingPos[3][1]); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G1 Z0")); } break; case ID_M_POINT5: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length == 0) { - if (uiCfg.leveling_first_time) { - queue.enqueue_now_P(PSTR("G28")); - uiCfg.leveling_first_time = 0; - } - - queue.enqueue_now_P(PSTR("G1 Z10")); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[4][0], (int)gCfgItems.levelingPos[4][1]); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G1 Z0")); + if (queue.length == 0) { + if (uiCfg.leveling_first_time) { + queue.enqueue_now_P(PSTR("G28")); + uiCfg.leveling_first_time = 0; } + queue.enqueue_now_P(PSTR("G1 Z10")); + sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[4][0], (int)gCfgItems.levelingPos[4][1]); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G1 Z0")); } - break; case ID_MANUAL_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_manualLevel(); - lv_draw_tool(); - } + lv_clear_manualLevel(); + lv_draw_tool(); break; } } void lv_draw_manualLevel(void) { - lv_obj_t *buttonPoint1, *buttonPoint2, *buttonPoint3, *buttonPoint4, *buttonPoint5; - lv_obj_t *buttonBack; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != LEVELING_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = LEVELING_UI; } disp_state = LEVELING_UI; - scr = lv_obj_create(NULL, NULL); - - // static lv_style_t tool_style; - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); - lv_refr_now(lv_refr_get_disp_refreshing()); // Create an Image button - buttonPoint1 = lv_imgbtn_create(scr, "F:/bmp_leveling1.bin", INTERVAL_V, titleHeight, event_handler, ID_M_POINT1); + lv_obj_t *buttonPoint1 = lv_big_button_create(scr, "F:/bmp_leveling1.bin", leveling_menu.position1, INTERVAL_V, titleHeight, event_handler, ID_M_POINT1); lv_obj_clear_protect(buttonPoint1, LV_PROTECT_FOLLOW); - buttonPoint2 = lv_imgbtn_create(scr, "F:/bmp_leveling2.bin", BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_M_POINT2); - buttonPoint3 = lv_imgbtn_create(scr, "F:/bmp_leveling3.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_M_POINT3); - buttonPoint4 = lv_imgbtn_create(scr, "F:/bmp_leveling4.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_M_POINT4); - buttonPoint5 = lv_imgbtn_create(scr, "F:/bmp_leveling5.bin", INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_POINT5); - buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_MANUAL_RETURN); - - // Create labels on the image buttons - lv_obj_t *label_Point1 = lv_label_create_empty(buttonPoint1); - lv_obj_t *label_Point2 = lv_label_create_empty(buttonPoint2); - lv_obj_t *label_Point3 = lv_label_create_empty(buttonPoint3); - lv_obj_t *label_Point4 = lv_label_create_empty(buttonPoint4); - lv_obj_t *label_Point5 = lv_label_create_empty(buttonPoint5); - lv_obj_t *label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_Point1, leveling_menu.position1); - lv_obj_align(label_Point1, buttonPoint1, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Point2, leveling_menu.position2); - lv_obj_align(label_Point2, buttonPoint2, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Point3, leveling_menu.position3); - lv_obj_align(label_Point3, buttonPoint3, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Point4, leveling_menu.position4); - lv_obj_align(label_Point4, buttonPoint4, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Point5, leveling_menu.position5); - lv_obj_align(label_Point5, buttonPoint5, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonPoint1); - lv_group_add_obj(g, buttonPoint2); - lv_group_add_obj(g, buttonPoint3); - lv_group_add_obj(g, buttonPoint4); - lv_group_add_obj(g, buttonPoint5); - lv_group_add_obj(g, buttonBack); - } - #endif + lv_big_button_create(scr, "F:/bmp_leveling2.bin", leveling_menu.position2, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_M_POINT2); + lv_big_button_create(scr, "F:/bmp_leveling3.bin", leveling_menu.position3, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_M_POINT3); + lv_big_button_create(scr, "F:/bmp_leveling4.bin", leveling_menu.position4, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_M_POINT4); + lv_big_button_create(scr, "F:/bmp_leveling5.bin", leveling_menu.position5, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_POINT5); + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_MANUAL_RETURN); } void lv_clear_manualLevel() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_manual_level_pos_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_manual_level_pos_settings.cpp index 3f51bc1a74..8dedcd4c7b 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_manual_level_pos_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_manual_level_pos_settings.cpp @@ -29,353 +29,136 @@ #include "../../../../module/planner.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_MANUAL_POS_RETURN 1 -#define ID_MANUAL_POS_X1 2 -#define ID_MANUAL_POS_Y1 3 -#define ID_MANUAL_POS_X2 4 -#define ID_MANUAL_POS_Y2 5 -#define ID_MANUAL_POS_X3 6 -#define ID_MANUAL_POS_Y3 7 -#define ID_MANUAL_POS_X4 8 -#define ID_MANUAL_POS_Y4 9 -#define ID_MANUAL_POS_X5 10 -#define ID_MANUAL_POS_Y5 11 -#define ID_MANUAL_POS_DOWN 12 -#define ID_MANUAL_POS_UP 13 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_MANUAL_POS_RETURN = 1, + ID_MANUAL_POS_X1, + ID_MANUAL_POS_Y1, + ID_MANUAL_POS_X2, + ID_MANUAL_POS_Y2, + ID_MANUAL_POS_X3, + ID_MANUAL_POS_Y3, + ID_MANUAL_POS_X4, + ID_MANUAL_POS_Y4, + ID_MANUAL_POS_X5, + ID_MANUAL_POS_Y5, + ID_MANUAL_POS_DOWN, + ID_MANUAL_POS_UP +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_MANUAL_POS_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_manual_level_pos_settings(); - draw_return_ui(); - } + uiCfg.para_ui_page = 0; + lv_clear_manual_level_pos_settings(); + draw_return_ui(); break; case ID_MANUAL_POS_X1: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_x1; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_x1; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_Y1: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_y1; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_y1; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_X2: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_x2; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_x2; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_Y2: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_y2; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_y2; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_X3: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_x3; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_x3; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_Y3: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_y3; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_y3; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_X4: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_x4; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_x4; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_Y4: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_y4; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_y4; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_X5: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_y5; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_y5; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_Y5: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_y5; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_y5; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_UP: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_manual_level_pos_settings(); - lv_draw_manual_level_pos_settings(); - } + uiCfg.para_ui_page = 0; + lv_clear_manual_level_pos_settings(); + lv_draw_manual_level_pos_settings(); break; case ID_MANUAL_POS_DOWN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 1; - lv_clear_manual_level_pos_settings(); - lv_draw_manual_level_pos_settings(); - } + uiCfg.para_ui_page = 1; + lv_clear_manual_level_pos_settings(); + lv_draw_manual_level_pos_settings(); break; } } void lv_draw_manual_level_pos_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL, *buttonTurnPage = NULL, *labelTurnPage = NULL; - lv_obj_t *buttonX1Value = NULL, *labelX1Value = NULL; - lv_obj_t *buttonY1Value = NULL, *labelY1Value = NULL; - lv_obj_t *buttonX2Value = NULL, *labelX2Value = NULL; - lv_obj_t *buttonY2Value = NULL, *labelY2Value = NULL; - lv_obj_t *buttonX3Value = NULL, *labelX3Value = NULL; - lv_obj_t *buttonY3Value = NULL, *labelY3Value = NULL; - lv_obj_t *buttonX4Value = NULL, *labelX4Value = NULL; - lv_obj_t *buttonY4Value = NULL, *labelY4Value = NULL; - lv_obj_t *buttonX5Value = NULL, *labelX5Value = NULL; - lv_obj_t *buttonY5Value = NULL, *labelY5Value = NULL; - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL, * line4 = NULL; + char buf2[50]; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != MANUAL_LEVELING_POSIGION_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = MANUAL_LEVELING_POSIGION_UI; } disp_state = MANUAL_LEVELING_POSIGION_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, machine_menu.LevelingParaConfTitle); - lv_refr_now(lv_refr_get_disp_refreshing()); if (uiCfg.para_ui_page != 1) { - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, leveling_menu.position1); - - buttonX1Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X_2, PARA_UI_POS_Y + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_MANUAL_POS_X1); - labelX1Value = lv_label_create_empty(buttonX1Value); - - buttonY1Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_MANUAL_POS_Y1); - labelY1Value = lv_label_create_empty(buttonY1Value); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10, leveling_menu.position2); - - buttonX2Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X_2, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_MANUAL_POS_X2); - labelX2Value = lv_label_create_empty(buttonX2Value); - - buttonY2Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_MANUAL_POS_Y2); - labelY2Value = lv_label_create_empty(buttonY2Value); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10, leveling_menu.position3); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[0][0]); + sprintf_P(buf2, PSTR("%d"), gCfgItems.levelingPos[0][1]); + lv_screen_menu_item_2_edit(scr, leveling_menu.position1, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_MANUAL_POS_Y1, 0, buf2, ID_MANUAL_POS_X1, public_buf_l); - buttonX3Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X_2, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_MANUAL_POS_X3); - labelX3Value = lv_label_create_empty(buttonX3Value); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[1][0]); + sprintf_P(buf2, PSTR("%d"), gCfgItems.levelingPos[1][1]); + lv_screen_menu_item_2_edit(scr, leveling_menu.position2, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_MANUAL_POS_Y2, 1, buf2, ID_MANUAL_POS_X2, public_buf_l); - buttonY3Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_MANUAL_POS_Y3); - labelY3Value = lv_label_create_empty(buttonY3Value); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[2][0]); + sprintf_P(buf2, PSTR("%d"), gCfgItems.levelingPos[2][1]); + lv_screen_menu_item_2_edit(scr, leveling_menu.position3, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_MANUAL_POS_Y3, 2, buf2, ID_MANUAL_POS_X3, public_buf_l); - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[3][0]); + sprintf_P(buf2, PSTR("%d"), gCfgItems.levelingPos[3][1]); + lv_screen_menu_item_2_edit(scr, leveling_menu.position4, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_MANUAL_POS_Y4, 3, buf2, ID_MANUAL_POS_X4, public_buf_l); - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10, leveling_menu.position4); - - buttonX4Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X_2, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_MANUAL_POS_X4); - labelX4Value = lv_label_create_empty(buttonX4Value); - - buttonY4Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_MANUAL_POS_Y4); - labelY4Value = lv_label_create_empty(buttonY4Value); - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_MANUAL_POS_DOWN, NULL, 0); - lv_btn_set_style_both(buttonTurnPage, &style_para_back); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonX1Value); - lv_group_add_obj(g, buttonY1Value); - lv_group_add_obj(g, buttonX2Value); - lv_group_add_obj(g, buttonY2Value); - lv_group_add_obj(g, buttonX3Value); - lv_group_add_obj(g, buttonY3Value); - lv_group_add_obj(g, buttonX4Value); - lv_group_add_obj(g, buttonY4Value); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.next, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_MANUAL_POS_DOWN, true); } else { - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, leveling_menu.position5); - - buttonX5Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X_2, PARA_UI_POS_Y + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_MANUAL_POS_X5); - labelX5Value = lv_label_create_empty(buttonX5Value); - - buttonY5Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_MANUAL_POS_Y5); - labelY5Value = lv_label_create_empty(buttonY5Value); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[4][0]); + sprintf_P(buf2, PSTR("%d"), gCfgItems.levelingPos[4][1]); + lv_screen_menu_item_2_edit(scr, leveling_menu.position4, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_MANUAL_POS_Y5, 0, buf2, ID_MANUAL_POS_X5, public_buf_l); - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_MANUAL_POS_UP, NULL, 0); - lv_btn_set_style_both(buttonTurnPage, &style_para_back); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonX5Value); - lv_group_add_obj(g, buttonY5Value); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.previous, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_MANUAL_POS_UP, true); } - lv_obj_set_pos(buttonTurnPage, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y); - lv_obj_set_size(buttonTurnPage, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - labelTurnPage = lv_label_create_empty(buttonTurnPage); - - buttonBack = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_MANUAL_POS_RETURN, NULL, 0); - lv_btn_set_style_both(buttonBack, &style_para_back); - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_obj_set_size(buttonBack, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - label_Back = lv_label_create_empty(buttonBack); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - if (gCfgItems.multiple_language) { - if (uiCfg.para_ui_page != 1) { - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[0][0]); - lv_label_set_text(labelX1Value, public_buf_l); - lv_obj_align(labelX1Value, buttonX1Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[0][1]); - lv_label_set_text(labelY1Value, public_buf_l); - lv_obj_align(labelY1Value, buttonY1Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[1][0]); - lv_label_set_text(labelX2Value, public_buf_l); - lv_obj_align(labelX2Value, buttonX2Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[1][1]); - lv_label_set_text(labelY2Value, public_buf_l); - lv_obj_align(labelY2Value, buttonY2Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[2][0]); - lv_label_set_text(labelX3Value, public_buf_l); - lv_obj_align(labelX3Value, buttonX3Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[2][1]); - lv_label_set_text(labelY3Value, public_buf_l); - lv_obj_align(labelY3Value, buttonY3Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[3][0]); - lv_label_set_text(labelX4Value, public_buf_l); - lv_obj_align(labelX4Value, buttonX4Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[3][1]); - lv_label_set_text(labelY4Value, public_buf_l); - lv_obj_align(labelY4Value, buttonY4Value, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelTurnPage, machine_menu.next); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - } - else { - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[4][0]); - lv_label_set_text(labelX5Value, public_buf_l); - lv_obj_align(labelX5Value, buttonX5Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[4][1]); - lv_label_set_text(labelY5Value, public_buf_l); - lv_obj_align(labelY5Value, buttonY5Value, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelTurnPage, machine_menu.previous); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - } - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X + 10, PARA_UI_BACL_POS_Y, event_handler, ID_MANUAL_POS_RETURN, true); } void lv_clear_manual_level_pos_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_max_feedrate_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_max_feedrate_settings.cpp index ff01ceaa6e..5088e859c0 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_max_feedrate_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_max_feedrate_settings.cpp @@ -29,254 +29,100 @@ #include "../../../../module/planner.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_FEED_RETURN 1 -#define ID_FEED_X 2 -#define ID_FEED_Y 3 -#define ID_FEED_Z 4 -#define ID_FEED_E0 5 -#define ID_FEED_E1 6 -#define ID_FEED_DOWN 7 -#define ID_FEED_UP 8 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_FEED_RETURN = 1, + ID_FEED_X, + ID_FEED_Y, + ID_FEED_Z, + ID_FEED_E0, + ID_FEED_E1, + ID_FEED_DOWN, + ID_FEED_UP +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_FEED_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_max_feedrate_settings(); - draw_return_ui(); - } + uiCfg.para_ui_page = 0; + lv_clear_max_feedrate_settings(); + draw_return_ui(); break; case ID_FEED_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = XMaxFeedRate; - lv_clear_max_feedrate_settings(); - lv_draw_number_key(); - } + value = XMaxFeedRate; + lv_clear_max_feedrate_settings(); + lv_draw_number_key(); break; case ID_FEED_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = YMaxFeedRate; - lv_clear_max_feedrate_settings(); - lv_draw_number_key(); - } + value = YMaxFeedRate; + lv_clear_max_feedrate_settings(); + lv_draw_number_key(); break; case ID_FEED_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = ZMaxFeedRate; - lv_clear_max_feedrate_settings(); - lv_draw_number_key(); - } + value = ZMaxFeedRate; + lv_clear_max_feedrate_settings(); + lv_draw_number_key(); break; case ID_FEED_E0: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = E0MaxFeedRate; - lv_clear_max_feedrate_settings(); - lv_draw_number_key(); - } + value = E0MaxFeedRate; + lv_clear_max_feedrate_settings(); + lv_draw_number_key(); break; case ID_FEED_E1: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = E1MaxFeedRate; - lv_clear_max_feedrate_settings(); - lv_draw_number_key(); - } + value = E1MaxFeedRate; + lv_clear_max_feedrate_settings(); + lv_draw_number_key(); break; case ID_FEED_UP: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_max_feedrate_settings(); - lv_draw_max_feedrate_settings(); - } + uiCfg.para_ui_page = 0; + lv_clear_max_feedrate_settings(); + lv_draw_max_feedrate_settings(); break; case ID_FEED_DOWN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 1; - lv_clear_max_feedrate_settings(); - lv_draw_max_feedrate_settings(); - } + uiCfg.para_ui_page = 1; + lv_clear_max_feedrate_settings(); + lv_draw_max_feedrate_settings(); break; } } void lv_draw_max_feedrate_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL, *buttonTurnPage = NULL, *labelTurnPage = NULL; - lv_obj_t *buttonXValue = NULL, *labelXValue = NULL; - lv_obj_t *buttonYValue = NULL, *labelYValue = NULL; - lv_obj_t *buttonZValue = NULL, *labelZValue = NULL; - lv_obj_t *buttonE0Value = NULL, *labelE0Value = NULL; - lv_obj_t *buttonE1Value = NULL, *labelE1Value = NULL; - lv_obj_t *line1 = NULL, *line2 = NULL, *line3 = NULL, *line4 = NULL; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != MAXFEEDRATE_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = MAXFEEDRATE_UI; } disp_state = MAXFEEDRATE_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, machine_menu.MaxFeedRateConfTitle); - lv_refr_now(lv_refr_get_disp_refreshing()); if (uiCfg.para_ui_page != 1) { - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.XMaxFeedRate); - - buttonXValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_FEED_X); - lv_btn_set_layout(buttonXValue, LV_LAYOUT_OFF); - labelXValue = lv_label_create_empty(buttonXValue); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10, machine_menu.YMaxFeedRate); - - buttonYValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_FEED_Y); - lv_btn_set_layout(buttonYValue, LV_LAYOUT_OFF); - labelYValue = lv_label_create_empty(buttonYValue); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10, machine_menu.ZMaxFeedRate); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[X_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.XMaxFeedRate, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_FEED_X, 0, public_buf_l); - buttonZValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_FEED_Z); - lv_btn_set_layout(buttonZValue, LV_LAYOUT_OFF); - labelZValue = lv_label_create_empty(buttonZValue); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[Y_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.YMaxFeedRate, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_FEED_Y, 1, public_buf_l); - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[Z_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.ZMaxFeedRate, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_FEED_Z, 2, public_buf_l); - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10, machine_menu.E0MaxFeedRate); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[E_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.E0MaxFeedRate, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_FEED_E0, 3, public_buf_l); - buttonE0Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_FEED_E0); - lv_btn_set_layout(buttonE0Value, LV_LAYOUT_OFF); - labelE0Value = lv_label_create_empty(buttonE0Value); - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_FEED_DOWN, NULL, 0); - lv_btn_set_style_both(buttonTurnPage, &style_para_back); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonXValue); - lv_group_add_obj(g, buttonYValue); - lv_group_add_obj(g, buttonZValue); - lv_group_add_obj(g, buttonE0Value); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.next, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_FEED_DOWN, true); } else { - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.E1MaxFeedRate); - - buttonE1Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_FEED_E1); - lv_btn_set_layout(buttonE1Value, LV_LAYOUT_OFF); - labelE1Value = lv_label_create_empty(buttonE1Value); - + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[E_AXIS_N(1)]); + lv_screen_menu_item_1_edit(scr, machine_menu.E1MaxFeedRate, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_FEED_E1, 0, public_buf_l); - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_FEED_UP, NULL, 0); - lv_btn_set_style_both(buttonTurnPage, &style_para_back); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonE1Value); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.previous, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_FEED_UP, true); } - lv_obj_set_pos(buttonTurnPage, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y); - lv_obj_set_size(buttonTurnPage, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - labelTurnPage = lv_label_create_empty(buttonTurnPage); - - buttonBack = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_FEED_RETURN, NULL, 0); - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_obj_set_size(buttonBack, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - lv_btn_set_style_both(buttonBack, &style_para_back); - label_Back = lv_label_create_empty(buttonBack); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - if (gCfgItems.multiple_language) { - if (uiCfg.para_ui_page != 1) { - - lv_label_set_text(labelTurnPage, machine_menu.next); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[X_AXIS]); - lv_label_set_text(labelXValue, public_buf_l); - lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[Y_AXIS]); - lv_label_set_text(labelYValue, public_buf_l); - lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[Z_AXIS]); - lv_label_set_text(labelZValue, public_buf_l); - lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[E_AXIS]); - lv_label_set_text(labelE0Value, public_buf_l); - lv_obj_align(labelE0Value, buttonE0Value, LV_ALIGN_CENTER, 0, 0); - } - else { - lv_label_set_text(labelTurnPage, machine_menu.previous); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[E_AXIS_N(1)]); - lv_label_set_text(labelE1Value, public_buf_l); - lv_obj_align(labelE1Value, buttonE1Value, LV_ALIGN_CENTER, 0, 0); - } - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_FEED_RETURN, true); } void lv_clear_max_feedrate_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_motor_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_motor_settings.cpp index c54318a1b2..697b7de345 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_motor_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_motor_settings.cpp @@ -28,258 +28,78 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_MOTOR_RETURN 1 -#define ID_MOTOR_STEPS 2 -#define ID_MOTOR_STEPS_ARROW 3 -#define ID_MOTOR_TMC_CURRENT 4 -#define ID_MOTOR_TMC_CURRENT_ARROW 5 -#define ID_MOTOR_STEP_MODE 6 -#define ID_MOTOR_STEP_MODE_ARROW 7 -#define ID_HOME_SENSE 8 -#define ID_HOME_SENSE_ARROW 9 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_MOTOR_RETURN = 1, + ID_MOTOR_STEPS, + ID_MOTOR_TMC_CURRENT, + ID_MOTOR_STEP_MODE, + ID_HOME_SENSE +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_MOTOR_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_motor_settings(); - draw_return_ui(); - } + lv_clear_motor_settings(); + draw_return_ui(); break; case ID_MOTOR_STEPS: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_motor_settings(); - lv_draw_step_settings(); - } - break; - case ID_MOTOR_STEPS_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_motor_settings(); - lv_draw_step_settings(); - } + lv_clear_motor_settings(); + lv_draw_step_settings(); break; #if USE_SENSORLESS - case ID_HOME_SENSE: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { + case ID_HOME_SENSE: lv_clear_motor_settings(); lv_draw_homing_sensitivity_settings(); - } - break; - case ID_HOME_SENSE_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_motor_settings(); - lv_draw_homing_sensitivity_settings(); - } - break; + break; #endif - #if HAS_TRINAMIC_CONFIG - case ID_MOTOR_TMC_CURRENT: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_motor_settings(); - lv_draw_tmc_current_settings(); - } - break; - case ID_MOTOR_TMC_CURRENT_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_motor_settings(); - lv_draw_tmc_current_settings(); - } + #if HAS_TRINAMIC_CONFIG + case ID_MOTOR_TMC_CURRENT: + lv_clear_motor_settings(); + lv_draw_tmc_current_settings(); + break; + #if HAS_STEALTHCHOP + case ID_MOTOR_STEP_MODE: + lv_clear_motor_settings(); + lv_draw_tmc_step_mode_settings(); break; - #if HAS_STEALTHCHOP - case ID_MOTOR_STEP_MODE: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_motor_settings(); - lv_draw_tmc_step_mode_settings(); - } - break; - case ID_MOTOR_STEP_MODE_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_motor_settings(); - lv_draw_tmc_step_mode_settings(); - } - break; - #endif #endif + #endif } } void lv_draw_motor_settings(void) { - lv_obj_t *buttonBack, *label_Back; - lv_obj_t *buttonSteps, *labelSteps, *buttonStepsNarrow; - lv_obj_t * line1; - #if USE_SENSORLESS - lv_obj_t *buttonSensitivity, *labelSensitivity, *buttonSensitivityNarrow; - lv_obj_t * line2; - #endif - #if HAS_TRINAMIC_CONFIG - #if USE_SENSORLESS - lv_obj_t * line3; - #else - lv_obj_t * line2; - #endif - lv_obj_t *buttonTMCcurrent, *labelTMCcurrent, *buttonTMCcurrentNarrow; - #if HAS_STEALTHCHOP - #if USE_SENSORLESS - lv_obj_t * line4; - #else - lv_obj_t * line3; - #endif - lv_obj_t *buttonStepMode, *labelStepMode, *buttonStepModeNarrow; - #endif - #endif if (disp_state_stack._disp_state[disp_state_stack._disp_index] != MOTOR_SETTINGS_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = MOTOR_SETTINGS_UI; } disp_state = MOTOR_SETTINGS_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, machine_menu.MotorConfTitle); lv_refr_now(lv_refr_get_disp_refreshing()); - buttonSteps = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonSteps, PARA_UI_POS_X, PARA_UI_POS_Y); /*Set its position*/ - lv_obj_set_size(buttonSteps, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - //lv_obj_set_event_cb(buttonMachine, event_handler); - lv_obj_set_event_cb_mks(buttonSteps, event_handler, ID_MOTOR_STEPS, NULL, 0); - lv_btn_use_label_style(buttonSteps); - lv_btn_set_layout(buttonSteps, LV_LAYOUT_OFF); - labelSteps = lv_label_create_empty(buttonSteps); /*Add a label to the button*/ - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonSteps); - #endif - - buttonStepsNarrow = lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y + PARA_UI_ARROW_V, event_handler, ID_MOTOR_STEPS_ARROW); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - + int index = 0; + lv_screen_menu_item(scr, machine_menu.StepsConf, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_MOTOR_STEPS, index++); #if USE_SENSORLESS - buttonSensitivity = lv_btn_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2, PARA_UI_SIZE_X, PARA_UI_SIZE_Y, event_handler, ID_HOME_SENSE); - //lv_obj_set_event_cb(buttonMachine, event_handler); - labelSensitivity = lv_label_create_empty(buttonSensitivity); /*Add a label to the button*/ - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonSensitivity); - #endif - - buttonSensitivityNarrow = lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 2 + PARA_UI_ARROW_V, event_handler, ID_HOME_SENSE_ARROW); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); + lv_screen_menu_item(scr, machine_menu.HomingSensitivityConf, PARA_UI_POS_X, PARA_UI_POS_Y * (index + 1), event_handler, ID_HOME_SENSE, index); + index++; #endif - - #if HAS_TRINAMIC_CONFIG - buttonTMCcurrent = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonTMCcurrent, PARA_UI_POS_X, TERN(USE_SENSORLESS, PARA_UI_POS_Y * 3, PARA_UI_POS_Y * 2)); - lv_obj_set_size(buttonTMCcurrent, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - //lv_obj_set_event_cb(buttonMachine, event_handler); - lv_obj_set_event_cb_mks(buttonTMCcurrent, event_handler, ID_MOTOR_TMC_CURRENT, NULL, 0); - lv_btn_use_label_style(buttonTMCcurrent); - lv_btn_set_layout(buttonTMCcurrent, LV_LAYOUT_OFF); - labelTMCcurrent = lv_label_create_empty(buttonTMCcurrent); /*Add a label to the button*/ - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonTMCcurrent); - #endif - - buttonTMCcurrentNarrow = lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, TERN(USE_SENSORLESS, PARA_UI_POS_Y * 3, PARA_UI_POS_Y * 2) + PARA_UI_ARROW_V, event_handler, ID_MOTOR_TMC_CURRENT_ARROW); - - #if USE_SENSORLESS - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - #else - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - #endif - + lv_screen_menu_item(scr, machine_menu.TMCcurrentConf, PARA_UI_POS_X, PARA_UI_POS_Y * (index + 1), event_handler, ID_MOTOR_TMC_CURRENT, index); + index++; #if HAS_STEALTHCHOP - buttonStepMode = lv_btn_create(scr, NULL, PARA_UI_POS_X, TERN(USE_SENSORLESS, PARA_UI_POS_Y * 4, PARA_UI_POS_Y * 3), PARA_UI_SIZE_X, PARA_UI_SIZE_Y, event_handler, ID_MOTOR_STEP_MODE); - labelStepMode = lv_label_create_empty(buttonStepMode); /*Add a label to the button*/ - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonStepMode); - #endif - - buttonStepModeNarrow = lv_imgbtn_create(scr, "F:/bmp_arrow.bin", PARA_UI_POS_X + PARA_UI_SIZE_X, TERN(USE_SENSORLESS, PARA_UI_POS_Y * 4, PARA_UI_POS_Y * 3) + PARA_UI_ARROW_V, event_handler, ID_MOTOR_STEP_MODE_ARROW); - - #if USE_SENSORLESS - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - #else - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - #endif - - #endif // HAS_STEALTHCHOP - - #endif // HAS_TRINAMIC_CONFIG - - buttonBack = lv_imgbtn_create(scr, "F:/bmp_back70x40.bin", PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_MOTOR_RETURN); - label_Back = lv_label_create_empty(buttonBack); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelSteps, machine_menu.StepsConf); - lv_obj_align(labelSteps, buttonSteps, LV_ALIGN_IN_LEFT_MID, 0, 0); - - #if USE_SENSORLESS - lv_label_set_text(labelSensitivity, machine_menu.HomingSensitivityConf); - lv_obj_align(labelSensitivity, buttonSensitivity, LV_ALIGN_IN_LEFT_MID, 0, 0); + lv_screen_menu_item(scr, machine_menu.TMCStepModeConf, PARA_UI_POS_X, PARA_UI_POS_Y * (index + 1), event_handler, ID_MOTOR_STEP_MODE, index); + index++; #endif - #if HAS_TRINAMIC_CONFIG - lv_label_set_text(labelTMCcurrent, machine_menu.TMCcurrentConf); - lv_obj_align(labelTMCcurrent, buttonTMCcurrent, LV_ALIGN_IN_LEFT_MID, 0, 0); - #if HAS_STEALTHCHOP - lv_label_set_text(labelStepMode, machine_menu.TMCStepModeConf); - lv_obj_align(labelStepMode, buttonStepMode, LV_ALIGN_IN_LEFT_MID, 0, 0); - #endif - #endif - } - + #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X + 10, PARA_UI_BACL_POS_Y, event_handler, ID_MOTOR_RETURN, true); } void lv_clear_motor_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_move_motor.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_move_motor.cpp index 3dde4ad5a0..0718ffd86e 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_move_motor.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_move_motor.cpp @@ -33,210 +33,119 @@ #include "../../../../gcode/queue.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; static lv_obj_t *labelV, *buttonV; -#define ID_M_X_P 1 -#define ID_M_X_N 2 -#define ID_M_Y_P 3 -#define ID_M_Y_N 4 -#define ID_M_Z_P 5 -#define ID_M_Z_N 6 -#define ID_M_STEP 7 -#define ID_M_RETURN 8 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +enum { + ID_M_X_P = 1, + ID_M_X_N, + ID_M_Y_P, + ID_M_Y_N, + ID_M_Z_P, + ID_M_Z_N, + ID_M_STEP, + ID_M_RETURN +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_M_X_P: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length <= (BUFSIZE - 3)) { - ZERO(public_buf_l); - queue.enqueue_one_P(PSTR("G91")); - sprintf_P(public_buf_l, PSTR("G1 X%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_one_P(PSTR("G90")); - } + if (queue.length <= (BUFSIZE - 3)) { + queue.enqueue_one_P(PSTR("G91")); + sprintf_P(public_buf_l, PSTR("G1 X%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_one_P(PSTR("G90")); } break; case ID_M_X_N: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length <= (BUFSIZE - 3)) { - ZERO(public_buf_l); - queue.enqueue_now_P(PSTR("G91")); - sprintf_P(public_buf_l, PSTR("G1 X-%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G90")); - } + if (queue.length <= (BUFSIZE - 3)) { + queue.enqueue_now_P(PSTR("G91")); + sprintf_P(public_buf_l, PSTR("G1 X-%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G90")); } break; case ID_M_Y_P: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length <= (BUFSIZE - 3)) { - ZERO(public_buf_l); - queue.enqueue_now_P(PSTR("G91")); - sprintf_P(public_buf_l, PSTR("G1 Y%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G90")); - } + if (queue.length <= (BUFSIZE - 3)) { + queue.enqueue_now_P(PSTR("G91")); + sprintf_P(public_buf_l, PSTR("G1 Y%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G90")); } break; case ID_M_Y_N: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length <= (BUFSIZE - 3)) { - ZERO(public_buf_l); - queue.enqueue_now_P(PSTR("G91")); - sprintf_P(public_buf_l, PSTR("G1 Y-%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G90")); - } + if (queue.length <= (BUFSIZE - 3)) { + queue.enqueue_now_P(PSTR("G91")); + sprintf_P(public_buf_l, PSTR("G1 Y-%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G90")); } break; case ID_M_Z_P: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length <= (BUFSIZE - 3)) { - ZERO(public_buf_l); - queue.enqueue_now_P(PSTR("G91")); - sprintf_P(public_buf_l, PSTR("G1 Z%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G90")); - } + if (queue.length <= (BUFSIZE - 3)) { + queue.enqueue_now_P(PSTR("G91")); + sprintf_P(public_buf_l, PSTR("G1 Z%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G90")); } break; case ID_M_Z_N: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length <= (BUFSIZE - 3)) { - ZERO(public_buf_l); - queue.enqueue_now_P(PSTR("G91")); - sprintf_P(public_buf_l, PSTR("G1 Z-%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G90")); - } + if (queue.length <= (BUFSIZE - 3)) { + queue.enqueue_now_P(PSTR("G91")); + sprintf_P(public_buf_l, PSTR("G1 Z-%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G90")); } break; case ID_M_STEP: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (abs(10 * (int)uiCfg.move_dist) == 100) - uiCfg.move_dist = 0.1; - else - uiCfg.move_dist *= (float)10; - - disp_move_dist(); - } - + if (abs(10 * (int)uiCfg.move_dist) == 100) + uiCfg.move_dist = 0.1; + else + uiCfg.move_dist *= (float)10; + disp_move_dist(); break; case ID_M_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - draw_return_ui(); - } + clear_cur_ui(); + draw_return_ui(); break; } } void lv_draw_move_motor(void) { - lv_obj_t *buttonXI, *buttonXD, *buttonYI, *buttonYD, *buttonZI, *buttonZD, *buttonBack; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != MOVE_MOTOR_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = MOVE_MOTOR_UI; } disp_state = MOVE_MOTOR_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); - // Create an Image button - buttonXI = lv_imgbtn_create(scr, "F:/bmp_xAdd.bin", INTERVAL_V, titleHeight, event_handler, ID_M_X_P); + lv_obj_t *buttonXI = lv_big_button_create(scr, "F:/bmp_xAdd.bin", move_menu.x_add, INTERVAL_V, titleHeight, event_handler, ID_M_X_P); lv_obj_clear_protect(buttonXI, LV_PROTECT_FOLLOW); - buttonXD = lv_imgbtn_create(scr, "F:/bmp_xDec.bin", INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_X_N); - buttonYI = lv_imgbtn_create(scr, "F:/bmp_yAdd.bin", BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_M_Y_P); - buttonYD = lv_imgbtn_create(scr, "F:/bmp_yDec.bin", BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_Y_N); - buttonZI = lv_imgbtn_create(scr, "F:/bmp_zAdd.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_M_Z_P); - buttonZD = lv_imgbtn_create(scr, "F:/bmp_zDec.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_Z_N); - - buttonV = lv_imgbtn_create(scr, NULL, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_M_STEP); - //lv_obj_set_event_cb_mks(buttonV, event_handler,ID_T_MORE,"bmp_More.bin",0); - - buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_RETURN); - - // Create labels on the image buttons - lv_obj_t *labelXI = lv_label_create_empty(buttonXI); - lv_obj_t *labelXD = lv_label_create_empty(buttonXD); - lv_obj_t *labelYI = lv_label_create_empty(buttonYI); - lv_obj_t *labelYD = lv_label_create_empty(buttonYD); - lv_obj_t *labelZI = lv_label_create_empty(buttonZI); - lv_obj_t *labelZD = lv_label_create_empty(buttonZD); + lv_big_button_create(scr, "F:/bmp_xDec.bin", move_menu.x_dec, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_X_N); + lv_big_button_create(scr, "F:/bmp_yAdd.bin", move_menu.y_add, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_M_Y_P); + lv_big_button_create(scr, "F:/bmp_yDec.bin", move_menu.y_dec, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_Y_N); + lv_big_button_create(scr, "F:/bmp_zAdd.bin", move_menu.z_add, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_M_Z_P); + lv_big_button_create(scr, "F:/bmp_zDec.bin", move_menu.z_dec, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_Z_N); + + // button with image and label changed dinamycally by disp_move_dist + buttonV = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_M_STEP); labelV = lv_label_create_empty(buttonV); - lv_obj_t *label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - lv_label_set_text(labelXI, move_menu.x_add); - lv_obj_align(labelXI, buttonXI, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelXD, move_menu.x_dec); - lv_obj_align(labelXD, buttonXD, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelYI, move_menu.y_add); - lv_obj_align(labelYI, buttonYI, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelYD, move_menu.y_dec); - lv_obj_align(labelYD, buttonYD, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelZI, move_menu.z_add); - lv_obj_align(labelZI, buttonZI, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelZD, move_menu.z_dec); - lv_obj_align(labelZD, buttonZD, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonXI); - lv_group_add_obj(g, buttonXD); - lv_group_add_obj(g, buttonYI); - lv_group_add_obj(g, buttonYD); - lv_group_add_obj(g, buttonZI); - lv_group_add_obj(g, buttonZD); lv_group_add_obj(g, buttonV); - lv_group_add_obj(g, buttonBack); } #endif + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_RETURN); + disp_move_dist(); } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_number_key.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_number_key.cpp index 01d6e9a2d5..9ed4d60139 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_number_key.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_number_key.cpp @@ -49,30 +49,32 @@ #include "../../../../module/probe.h" #endif -extern lv_group_t * g; -static lv_obj_t * scr; -static lv_obj_t *buttonValue = NULL; -static lv_obj_t *labelValue = NULL; - -static char key_value[11] = {0}; -static uint8_t cnt = 0; -static char point_flg = 1; - -#define ID_NUM_KEY1 1 -#define ID_NUM_KEY2 2 -#define ID_NUM_KEY3 3 -#define ID_NUM_KEY4 4 -#define ID_NUM_KEY5 5 -#define ID_NUM_KEY6 6 -#define ID_NUM_KEY7 7 -#define ID_NUM_KEY8 8 -#define ID_NUM_KEY9 9 -#define ID_NUM_KEY0 10 -#define ID_NUM_BACK 11 -#define ID_NUM_RESET 12 -#define ID_NUM_CONFIRM 13 -#define ID_NUM_POINT 14 -#define ID_NUM_NAGETIVE 15 +extern lv_group_t *g; +static lv_obj_t *scr; +static lv_obj_t *buttonValue = nullptr; +static lv_obj_t *labelValue = nullptr; + +static char key_value[11] = { 0 }; +static uint8_t cnt = 0; +static bool point_flag = true; + +enum { + ID_NUM_KEY1 = 1, + ID_NUM_KEY2, + ID_NUM_KEY3, + ID_NUM_KEY4, + ID_NUM_KEY5, + ID_NUM_KEY6, + ID_NUM_KEY7, + ID_NUM_KEY8, + ID_NUM_KEY9, + ID_NUM_KEY0, + ID_NUM_BACK, + ID_NUM_RESET, + ID_NUM_CONFIRM, + ID_NUM_POINT, + ID_NUM_NEGATIVE +}; static void disp_key_value() { char *temp; @@ -80,8 +82,6 @@ static void disp_key_value() { float milliamps; #endif - ZERO(public_buf_m); - switch (value) { case PrintAcceleration: sprintf_P(public_buf_m, PSTR("%.1f"), planner.settings.acceleration); @@ -289,14 +289,11 @@ static void disp_key_value() { #endif break; } - ZERO(key_value); + strcpy(key_value, public_buf_m); cnt = strlen(key_value); temp = strchr(key_value, '.'); - if (temp) - point_flg = 0; - else - point_flg = 1; + point_flag = !temp; lv_label_set_text(labelValue, key_value); lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); @@ -540,406 +537,218 @@ static void set_value_confirm() { gcode.process_subcommands_now_P(PSTR("M500")); } -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_NUM_KEY1: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'1'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'1'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_KEY2: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'2'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'2'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_KEY3: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'3'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'3'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_KEY4: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'4'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'4'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_KEY5: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'5'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'5'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_KEY6: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'6'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'6'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_KEY7: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'7'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'7'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_KEY8: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'8'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'8'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_KEY9: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'9'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } - } - break; - case ID_NUM_KEY0: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'0'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } - } - break; - case ID_NUM_BACK: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt > 0) - cnt--; - if (key_value[cnt] == (char)'.') point_flg = 1; - key_value[cnt] = (char)'\0'; + if (cnt <= 10) { + key_value[cnt] = (char)'9'; lv_label_set_text(labelValue, key_value); lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; - case ID_NUM_RESET: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - ZERO(key_value); - cnt = 0; + case ID_NUM_KEY0: + if (cnt <= 10) { key_value[cnt] = (char)'0'; - point_flg = 1; lv_label_set_text(labelValue, key_value); lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; + case ID_NUM_BACK: + if (cnt > 0) cnt--; + if (key_value[cnt] == (char)'.') point_flag = true; + key_value[cnt] = (char)'\0'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + break; + case ID_NUM_RESET: + ZERO(key_value); + cnt = 0; + key_value[cnt] = (char)'0'; + point_flag = true; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + break; case ID_NUM_POINT: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if ((cnt != 0) && (point_flg == 1)) { - point_flg = 0; - key_value[cnt] = (char)'.'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt != 0 && point_flag) { + point_flag = false; + key_value[cnt] = (char)'.'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; - case ID_NUM_NAGETIVE: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt == 0) { - key_value[cnt] = (char)'-'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + case ID_NUM_NEGATIVE: + if (cnt == 0) { + key_value[cnt] = (char)'-'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_CONFIRM: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - last_disp_state = NUMBER_KEY_UI; - if (strlen(key_value) != 0) - set_value_confirm(); - lv_clear_number_key(); - draw_return_ui(); - } + last_disp_state = NUMBER_KEY_UI; + if (strlen(key_value) != 0) set_value_confirm(); + lv_clear_number_key(); + draw_return_ui(); break; } } void lv_draw_number_key(void) { - lv_obj_t *NumberKey_1 = NULL, *NumberKey_2 = NULL, *NumberKey_3 = NULL, *NumberKey_4 = NULL, *NumberKey_5 = NULL; - lv_obj_t *NumberKey_6 = NULL, *NumberKey_7 = NULL, *NumberKey_8 = NULL, *NumberKey_9 = NULL, *NumberKey_0 = NULL; - lv_obj_t *KeyPoint = NULL, *KeyConfirm = NULL, *KeyReset = NULL, *KeyBack = NULL; - lv_obj_t *Minus = NULL; - lv_obj_t *labelKey_1 = NULL, *labelKey_2 = NULL, *labelKey_3 = NULL, *labelKey_4 = NULL, *labelKey_5 = NULL; - lv_obj_t *labelKey_6 = NULL, *labelKey_7 = NULL, *labelKey_8 = NULL, *labelKey_9 = NULL, *labelKey_0 = NULL; - lv_obj_t *labelKeyPoint = NULL, *labelKeyConfirm = NULL, *labelKeyReset = NULL, *labelKeyBack = NULL; - lv_obj_t *labelMinus = NULL; - - buttonValue = NULL; - labelValue = NULL; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != NUMBER_KEY_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = NUMBER_KEY_UI; } disp_state = NUMBER_KEY_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); //(void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); - buttonValue = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonValue, 92, 40); /*Set its position*/ - lv_obj_set_size(buttonValue, 296, 40); - lv_obj_set_event_cb_mks(buttonValue, event_handler, ID_NUM_KEY1, NULL, 0); - lv_btn_set_style(buttonValue, LV_BTN_STYLE_REL, &style_num_text); /*Set the button's released style*/ - lv_btn_set_style(buttonValue, LV_BTN_STYLE_PR, &style_num_text); /*Set the button's pressed style*/ - //lv_btn_set_layout(buttonValue, LV_LAYOUT_OFF); - labelValue = lv_label_create_empty(buttonValue); /*Add a label to the button*/ - - NumberKey_1 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_1, 92, 90); /*Set its position*/ - lv_obj_set_size(NumberKey_1, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_1, event_handler, ID_NUM_KEY1, NULL, 0); - lv_btn_set_style(NumberKey_1, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_1, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_1, LV_LAYOUT_OFF); - labelKey_1 = lv_label_create_empty(NumberKey_1); /*Add a label to the button*/ + buttonValue = lv_btn_create(scr, 92, 40, 296, 40, event_handler, ID_NUM_KEY1, &style_num_text); + labelValue = lv_label_create_empty(buttonValue); + + lv_obj_t *NumberKey_1 = lv_btn_create(scr, 92, 90, 68, 40, event_handler, ID_NUM_KEY1, &style_num_key_pre); + lv_obj_t *labelKey_1 = lv_label_create_empty(NumberKey_1); lv_label_set_text(labelKey_1, machine_menu.key_1); lv_obj_align(labelKey_1, NumberKey_1, LV_ALIGN_CENTER, 0, 0); - NumberKey_2 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_2, 168, 90); /*Set its position*/ - lv_obj_set_size(NumberKey_2, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_2, event_handler, ID_NUM_KEY2, NULL, 0); - lv_btn_set_style(NumberKey_2, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_2, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_2, LV_LAYOUT_OFF); - labelKey_2 = lv_label_create_empty(NumberKey_2); /*Add a label to the button*/ + lv_obj_t *NumberKey_2 = lv_btn_create(scr, 168, 90, 68, 40, event_handler, ID_NUM_KEY2, &style_num_key_pre); + lv_obj_t *labelKey_2 = lv_label_create_empty(NumberKey_2); lv_label_set_text(labelKey_2, machine_menu.key_2); lv_obj_align(labelKey_2, NumberKey_2, LV_ALIGN_CENTER, 0, 0); - NumberKey_3 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_3, 244, 90); /*Set its position*/ - lv_obj_set_size(NumberKey_3, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_3, event_handler, ID_NUM_KEY3, NULL, 0); - lv_btn_set_style(NumberKey_3, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_3, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_3, LV_LAYOUT_OFF); - labelKey_3 = lv_label_create_empty(NumberKey_3); /*Add a label to the button*/ + lv_obj_t *NumberKey_3 = lv_btn_create(scr, 244, 90, 68, 40, event_handler, ID_NUM_KEY3, &style_num_key_pre); + lv_obj_t *labelKey_3 = lv_label_create_empty(NumberKey_3); lv_label_set_text(labelKey_3, machine_menu.key_3); lv_obj_align(labelKey_3, NumberKey_3, LV_ALIGN_CENTER, 0, 0); - NumberKey_4 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_4, 92, 140); /*Set its position*/ - lv_obj_set_size(NumberKey_4, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_4, event_handler, ID_NUM_KEY4, NULL, 0); - lv_btn_set_style(NumberKey_4, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_4, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_4, LV_LAYOUT_OFF); - labelKey_4 = lv_label_create_empty(NumberKey_4); /*Add a label to the button*/ + lv_obj_t *NumberKey_4 = lv_btn_create(scr, 92, 140, 68, 40, event_handler, ID_NUM_KEY4, &style_num_key_pre); + lv_obj_t *labelKey_4 = lv_label_create_empty(NumberKey_4); lv_label_set_text(labelKey_4, machine_menu.key_4); lv_obj_align(labelKey_4, NumberKey_4, LV_ALIGN_CENTER, 0, 0); - NumberKey_5 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_5, 168, 140); /*Set its position*/ - lv_obj_set_size(NumberKey_5, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_5, event_handler, ID_NUM_KEY5, NULL, 0); - lv_btn_set_style(NumberKey_5, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_5, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_5, LV_LAYOUT_OFF); - labelKey_5 = lv_label_create_empty(NumberKey_5); /*Add a label to the button*/ + lv_obj_t *NumberKey_5 = lv_btn_create(scr, 168, 140, 68, 40, event_handler, ID_NUM_KEY5, &style_num_key_pre); + lv_obj_t *labelKey_5 = lv_label_create_empty(NumberKey_5); lv_label_set_text(labelKey_5, machine_menu.key_5); lv_obj_align(labelKey_5, NumberKey_5, LV_ALIGN_CENTER, 0, 0); - NumberKey_6 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_6, 244, 140); /*Set its position*/ - lv_obj_set_size(NumberKey_6, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_6, event_handler, ID_NUM_KEY6, NULL, 0); - lv_btn_set_style(NumberKey_6, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_6, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_6, LV_LAYOUT_OFF); - labelKey_6 = lv_label_create_empty(NumberKey_6); /*Add a label to the button*/ + lv_obj_t *NumberKey_6 = lv_btn_create(scr, 244, 140, 68, 40, event_handler, ID_NUM_KEY6, &style_num_key_pre); + lv_obj_t *labelKey_6 = lv_label_create_empty(NumberKey_6); lv_label_set_text(labelKey_6, machine_menu.key_6); lv_obj_align(labelKey_6, NumberKey_6, LV_ALIGN_CENTER, 0, 0); - NumberKey_7 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_7, 92, 190); /*Set its position*/ - lv_obj_set_size(NumberKey_7, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_7, event_handler, ID_NUM_KEY7, NULL, 0); - lv_btn_set_style(NumberKey_7, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_7, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_7, LV_LAYOUT_OFF); - labelKey_7 = lv_label_create_empty(NumberKey_7); /*Add a label to the button*/ + lv_obj_t *NumberKey_7 = lv_btn_create(scr, 92, 190, 68, 40, event_handler, ID_NUM_KEY7, &style_num_key_pre); + lv_obj_t *labelKey_7 = lv_label_create_empty(NumberKey_7); lv_label_set_text(labelKey_7, machine_menu.key_7); lv_obj_align(labelKey_7, NumberKey_7, LV_ALIGN_CENTER, 0, 0); - NumberKey_8 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_8, 168, 190); /*Set its position*/ - lv_obj_set_size(NumberKey_8, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_8, event_handler, ID_NUM_KEY8, NULL, 0); - lv_btn_set_style(NumberKey_8, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_8, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_8, LV_LAYOUT_OFF); - labelKey_8 = lv_label_create_empty(NumberKey_8); /*Add a label to the button*/ + lv_obj_t *NumberKey_8 = lv_btn_create(scr, 168, 190, 68, 40, event_handler, ID_NUM_KEY8, &style_num_key_pre); + lv_obj_t *labelKey_8 = lv_label_create_empty(NumberKey_8); lv_label_set_text(labelKey_8, machine_menu.key_8); lv_obj_align(labelKey_8, NumberKey_8, LV_ALIGN_CENTER, 0, 0); - NumberKey_9 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_9, 244, 190); /*Set its position*/ - lv_obj_set_size(NumberKey_9, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_9, event_handler, ID_NUM_KEY9, NULL, 0); - lv_btn_set_style(NumberKey_9, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_9, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_9, LV_LAYOUT_OFF); - labelKey_9 = lv_label_create_empty(NumberKey_9); /*Add a label to the button*/ + lv_obj_t *NumberKey_9 = lv_btn_create(scr, 244, 190, 68, 40, event_handler, ID_NUM_KEY9, &style_num_key_pre); + lv_obj_t *labelKey_9 = lv_label_create_empty(NumberKey_9); lv_label_set_text(labelKey_9, machine_menu.key_9); lv_obj_align(labelKey_9, NumberKey_9, LV_ALIGN_CENTER, 0, 0); - NumberKey_0 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_0, 92, 240); /*Set its position*/ - lv_obj_set_size(NumberKey_0, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_0, event_handler, ID_NUM_KEY0, NULL, 0); - lv_btn_set_style(NumberKey_0, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_0, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_0, LV_LAYOUT_OFF); - labelKey_0 = lv_label_create_empty(NumberKey_0); /*Add a label to the button*/ + lv_obj_t *NumberKey_0 = lv_btn_create(scr, 92, 240, 68, 40, event_handler, ID_NUM_KEY0, &style_num_key_pre); + lv_obj_t *labelKey_0 = lv_label_create_empty(NumberKey_0); lv_label_set_text(labelKey_0, machine_menu.key_0); lv_obj_align(labelKey_0, NumberKey_0, LV_ALIGN_CENTER, 0, 0); - KeyBack = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(KeyBack, 320, 90); /*Set its position*/ - lv_obj_set_size(KeyBack, 68, 40); - lv_obj_set_event_cb_mks(KeyBack, event_handler, ID_NUM_BACK, NULL, 0); - lv_btn_set_style(KeyBack, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(KeyBack, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(KeyBack, LV_LAYOUT_OFF); - labelKeyBack = lv_label_create_empty(KeyBack); /*Add a label to the button*/ + lv_obj_t *KeyBack = lv_btn_create(scr, 320, 90, 68, 40, event_handler, ID_NUM_BACK, &style_num_key_pre); + lv_obj_t *labelKeyBack = lv_label_create_empty(KeyBack); lv_label_set_text(labelKeyBack, machine_menu.key_back); lv_obj_align(labelKeyBack, KeyBack, LV_ALIGN_CENTER, 0, 0); - KeyReset = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(KeyReset, 320, 140); /*Set its position*/ - lv_obj_set_size(KeyReset, 68, 40); - lv_obj_set_event_cb_mks(KeyReset, event_handler, ID_NUM_RESET, NULL, 0); - lv_btn_set_style(KeyReset, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(KeyReset, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(KeyReset, LV_LAYOUT_OFF); - labelKeyReset = lv_label_create_empty(KeyReset); /*Add a label to the button*/ + lv_obj_t *KeyReset = lv_btn_create(scr, 320, 140, 68, 40, event_handler, ID_NUM_RESET, &style_num_key_pre); + lv_obj_t *labelKeyReset = lv_label_create_empty(KeyReset); lv_label_set_text(labelKeyReset, machine_menu.key_reset); lv_obj_align(labelKeyReset, KeyReset, LV_ALIGN_CENTER, 0, 0); - KeyConfirm = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(KeyConfirm, 320, 190); /*Set its position*/ - lv_obj_set_size(KeyConfirm, 68, 90); - lv_obj_set_event_cb_mks(KeyConfirm, event_handler, ID_NUM_CONFIRM, NULL, 0); - lv_btn_set_style(KeyConfirm, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(KeyConfirm, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(KeyConfirm, LV_LAYOUT_OFF); - labelKeyConfirm = lv_label_create_empty(KeyConfirm); /*Add a label to the button*/ + lv_obj_t *KeyConfirm = lv_btn_create(scr, 320, 190, 68, 90, event_handler, ID_NUM_CONFIRM, &style_num_key_pre); + lv_obj_t *labelKeyConfirm = lv_label_create_empty(KeyConfirm); lv_label_set_text(labelKeyConfirm, machine_menu.key_confirm); lv_obj_align(labelKeyConfirm, KeyConfirm, LV_ALIGN_CENTER, 0, 0); - KeyPoint = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(KeyPoint, 244, 240); /*Set its position*/ - lv_obj_set_size(KeyPoint, 68, 40); - lv_obj_set_event_cb_mks(KeyPoint, event_handler, ID_NUM_POINT, NULL, 0); - lv_btn_set_style(KeyPoint, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(KeyPoint, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(KeyPoint, LV_LAYOUT_OFF); - labelKeyPoint = lv_label_create_empty(KeyPoint); /*Add a label to the button*/ + lv_obj_t *KeyPoint = lv_btn_create(scr, 244, 240, 68, 40, event_handler, ID_NUM_POINT, &style_num_key_pre); + lv_obj_t *labelKeyPoint = lv_label_create_empty(KeyPoint); lv_label_set_text(labelKeyPoint, machine_menu.key_point); lv_obj_align(labelKeyPoint, KeyPoint, LV_ALIGN_CENTER, 0, 0); - Minus = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(Minus, 168, 240); /*Set its position*/ - lv_obj_set_size(Minus, 68, 40); - lv_obj_set_event_cb_mks(Minus, event_handler, ID_NUM_NAGETIVE, NULL, 0); - lv_btn_set_style(Minus, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(Minus, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(Minus, LV_LAYOUT_OFF); - labelMinus = lv_label_create_empty(Minus); /*Add a label to the button*/ + lv_obj_t *Minus = lv_btn_create(scr, 168, 240, 68, 40, event_handler, ID_NUM_NEGATIVE, &style_num_key_pre); + lv_obj_t *labelMinus = lv_label_create_empty(Minus); lv_label_set_text(labelMinus, machine_menu.negative); lv_obj_align(labelMinus, Minus, LV_ALIGN_CENTER, 0, 0); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_operation.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_operation.cpp index dc8bb57149..16f50c16c5 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_operation.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_operation.cpp @@ -35,141 +35,99 @@ #include "../../../../sd/cardreader.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_O_PRE_HEAT 1 -#define ID_O_EXTRUCT 2 -#define ID_O_MOV 3 -#define ID_O_FILAMENT 4 -#define ID_O_SPEED 5 -#define ID_O_RETURN 6 -#define ID_O_FAN 7 -#define ID_O_POWER_OFF 8 -#define ID_O_BABY_STEP 9 +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_O_PRE_HEAT = 1, + ID_O_EXTRUCT, + ID_O_MOV, + ID_O_FILAMENT, + ID_O_SPEED, + ID_O_RETURN, + ID_O_FAN, + ID_O_POWER_OFF, + ID_O_BABY_STEP +}; static lv_obj_t *label_PowerOff; static lv_obj_t *buttonPowerOff; extern feedRate_t feedrate_mm_s; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_O_PRE_HEAT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_operation(); - lv_draw_preHeat(); - } + lv_clear_operation(); + lv_draw_preHeat(); break; case ID_O_EXTRUCT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_operation(); - lv_draw_extrusion(); - } + lv_clear_operation(); + lv_draw_extrusion(); break; case ID_O_MOV: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_operation(); - lv_draw_move_motor(); - } + lv_clear_operation(); + lv_draw_move_motor(); break; case ID_O_FILAMENT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - #if HAS_MULTI_EXTRUDER - uiCfg.curSprayerChoose_bak = active_extruder; + #if HAS_MULTI_EXTRUDER + uiCfg.curSprayerChoose_bak = active_extruder; + #endif + if (uiCfg.print_state == WORKING) { + #if ENABLED(SDSUPPORT) + card.pauseSDPrint(); + stop_print_time(); + uiCfg.print_state = PAUSING; #endif - if (uiCfg.print_state == WORKING) { - #if ENABLED(SDSUPPORT) - card.pauseSDPrint(); - stop_print_time(); - uiCfg.print_state = PAUSING; - #endif - } - uiCfg.moveSpeed_bak = (uint16_t)feedrate_mm_s; - uiCfg.desireSprayerTempBak = thermalManager.temp_hotend[active_extruder].target; - lv_clear_operation(); - lv_draw_filament_change(); } + uiCfg.moveSpeed_bak = (uint16_t)feedrate_mm_s; + uiCfg.desireSprayerTempBak = thermalManager.temp_hotend[active_extruder].target; + lv_clear_operation(); + lv_draw_filament_change(); break; case ID_O_FAN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_operation(); - lv_draw_fan(); - } + lv_clear_operation(); + lv_draw_fan(); break; case ID_O_SPEED: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_operation(); - lv_draw_change_speed(); - } + lv_clear_operation(); + lv_draw_change_speed(); break; case ID_O_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - draw_return_ui(); - } + clear_cur_ui(); + draw_return_ui(); break; case ID_O_POWER_OFF: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (gCfgItems.finish_power_off) { - gCfgItems.finish_power_off = false; - lv_imgbtn_set_src_both(buttonPowerOff, "F:/bmp_manual_off.bin"); - lv_label_set_text(label_PowerOff, printing_more_menu.manual); - } - else { - gCfgItems.finish_power_off = true; - lv_imgbtn_set_src_both(buttonPowerOff, "F:/bmp_auto_off.bin"); - lv_label_set_text(label_PowerOff, printing_more_menu.auto_close); - } - lv_obj_align(label_PowerOff, buttonPowerOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - lv_obj_refresh_ext_draw_pad(label_PowerOff); - update_spi_flash(); - } + if (gCfgItems.finish_power_off) { + gCfgItems.finish_power_off = false; + lv_imgbtn_set_src_both(buttonPowerOff, "F:/bmp_manual_off.bin"); + lv_label_set_text(label_PowerOff, printing_more_menu.manual); + } + else { + gCfgItems.finish_power_off = true; + lv_imgbtn_set_src_both(buttonPowerOff, "F:/bmp_auto_off.bin"); + lv_label_set_text(label_PowerOff, printing_more_menu.auto_close); + } + lv_obj_align(label_PowerOff, buttonPowerOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); + lv_obj_refresh_ext_draw_pad(label_PowerOff); + update_spi_flash(); break; case ID_O_BABY_STEP: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_operation(); - lv_draw_baby_stepping(); - } + lv_clear_operation(); + lv_draw_baby_stepping(); break; } } void lv_draw_operation(void) { - lv_obj_t *buttonPreHeat = NULL, *buttonExtrusion = NULL, *buttonSpeed = NULL; - lv_obj_t *buttonBack = NULL, *buttonFan = NULL; - lv_obj_t *labelPreHeat = NULL, *labelExtrusion = NULL; - lv_obj_t *label_Back = NULL, *label_Speed = NULL, *label_Fan = NULL; - lv_obj_t *buttonMove = NULL, *label_Move = NULL; - lv_obj_t *buttonBabyStep = NULL, *label_BabyStep = NULL; - lv_obj_t *buttonFilament = NULL, *label_Filament = NULL; + lv_obj_t *buttonExtrusion = nullptr, *buttonSpeed = nullptr, + *buttonBack = nullptr, + *labelPreHeat = nullptr, *labelExtrusion = nullptr, + *label_Back = nullptr, *label_Speed = nullptr, *label_Fan = nullptr, + *buttonMove = nullptr, *label_Move = nullptr, + *buttonBabyStep = nullptr, *label_BabyStep = nullptr, + *label_Filament = nullptr; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != OPERATE_UI) { disp_state_stack._disp_index++; @@ -177,20 +135,16 @@ void lv_draw_operation(void) { } disp_state = OPERATE_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); // Create image buttons - buttonPreHeat = lv_imgbtn_create(scr, "F:/bmp_temp.bin", INTERVAL_V, titleHeight, event_handler, ID_O_PRE_HEAT); - buttonFilament = lv_imgbtn_create(scr, "F:/bmp_filamentchange.bin", BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_O_FILAMENT); - buttonFan = lv_imgbtn_create(scr, "F:/bmp_fan.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_O_FAN); + lv_obj_t *buttonPreHeat = lv_imgbtn_create(scr, "F:/bmp_temp.bin", INTERVAL_V, titleHeight, event_handler, ID_O_PRE_HEAT); + lv_obj_t *buttonFilament = lv_imgbtn_create(scr, "F:/bmp_filamentchange.bin", BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_O_FILAMENT); + lv_obj_t *buttonFan = lv_imgbtn_create(scr, "F:/bmp_fan.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_O_FAN); buttonPowerOff = lv_imgbtn_create(scr, gCfgItems.finish_power_off ? "F:/bmp_auto_off.bin" : "F:/bmp_manual_off.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_O_POWER_OFF); #if HAS_ROTARY_ENCODER diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_pause_position.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_pause_position.cpp index c7d2de2e1b..930773b129 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_pause_position.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_pause_position.cpp @@ -29,132 +29,62 @@ #include "../../../../module/planner.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_PAUSE_RETURN 1 -#define ID_PAUSE_X 2 -#define ID_PAUSE_Y 3 -#define ID_PAUSE_Z 4 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_PAUSE_RETURN = 1, + ID_PAUSE_X, + ID_PAUSE_Y, + ID_PAUSE_Z +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_PAUSE_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_pause_position(); - draw_return_ui(); - } + lv_clear_pause_position(); + draw_return_ui(); break; case ID_PAUSE_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = pause_pos_x; - lv_clear_pause_position(); - lv_draw_number_key(); - } + value = pause_pos_x; + lv_clear_pause_position(); + lv_draw_number_key(); break; case ID_PAUSE_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = pause_pos_y; - lv_clear_pause_position(); - lv_draw_number_key(); - } + value = pause_pos_y; + lv_clear_pause_position(); + lv_draw_number_key(); break; case ID_PAUSE_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = pause_pos_z; - lv_clear_pause_position(); - lv_draw_number_key(); - } + value = pause_pos_z; + lv_clear_pause_position(); + lv_draw_number_key(); break; } } void lv_draw_pause_position(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL; - lv_obj_t *buttonXValue = NULL, *labelXValue = NULL; - lv_obj_t *buttonYValue = NULL, *labelYValue = NULL; - lv_obj_t *buttonZValue = NULL, *labelZValue = NULL; - - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != PAUSE_POS_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = PAUSE_POS_UI; } disp_state = PAUSE_POS_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, machine_menu.PausePosText); - lv_refr_now(lv_refr_get_disp_refreshing()); - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.xPos); - - buttonXValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_PAUSE_X); - labelXValue = lv_label_create_empty(buttonXValue); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); + sprintf_P(public_buf_l, PSTR("%.1f"), gCfgItems.pausePosX); + lv_screen_menu_item_1_edit(scr, machine_menu.xPos, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_PAUSE_X, 0, public_buf_l); - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10, machine_menu.yPos); + sprintf_P(public_buf_l, PSTR("%.1f"), gCfgItems.pausePosY); + lv_screen_menu_item_1_edit(scr, machine_menu.yPos, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_PAUSE_Y, 1, public_buf_l); - buttonYValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_PAUSE_Y); - labelYValue = lv_label_create_empty(buttonYValue); + sprintf_P(public_buf_l, PSTR("%.1f"), gCfgItems.pausePosZ); + lv_screen_menu_item_1_edit(scr, machine_menu.zPos, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_PAUSE_Z, 2, public_buf_l); - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10, machine_menu.zPos); - - buttonZValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_PAUSE_Z); - labelZValue = lv_label_create_empty(buttonZValue); - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - buttonBack = lv_btn_create_back(scr, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE, event_handler, ID_PAUSE_RETURN); - label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - sprintf_P(public_buf_l, PSTR("%.1f"), gCfgItems.pausePosX); - lv_label_set_text(labelXValue, public_buf_l); - lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0); - - sprintf_P(public_buf_l, PSTR("%.1f"), gCfgItems.pausePosY); - lv_label_set_text(labelYValue, public_buf_l); - lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0); - - sprintf_P(public_buf_l, PSTR("%.1f"), gCfgItems.pausePosZ); - lv_label_set_text(labelZValue, public_buf_l); - lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonXValue); - lv_group_add_obj(g, buttonYValue); - lv_group_add_obj(g, buttonZValue); - lv_group_add_obj(g, buttonBack); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_PAUSE_RETURN, true); } void lv_clear_pause_position() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp index 966d85b6de..a222c7adbf 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp @@ -33,221 +33,163 @@ #include "../../../../module/temperature.h" #include "../../../../inc/MarlinConfig.h" -static lv_obj_t * scr; +static lv_obj_t *scr; extern lv_group_t* g; static lv_obj_t *buttonType, *buttonStep; static lv_obj_t *labelType; static lv_obj_t *labelStep; -static lv_obj_t * tempText1; +static lv_obj_t *tempText1; -#define ID_P_ADD 1 -#define ID_P_DEC 2 -#define ID_P_TYPE 3 -#define ID_P_STEP 4 -#define ID_P_OFF 5 -#define ID_P_RETURN 6 +enum { + ID_P_ADD = 1, + ID_P_DEC, + ID_P_TYPE, + ID_P_STEP, + ID_P_OFF, + ID_P_RETURN +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_P_ADD: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (uiCfg.curTempType == 0) { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target += uiCfg.stepHeat; - if (uiCfg.curSprayerChoose == 0) { - if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > (HEATER_0_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1))) { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)HEATER_0_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1); - } + if (uiCfg.curTempType == 0) { + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target += uiCfg.stepHeat; + if (uiCfg.curSprayerChoose == 0) { + if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > (HEATER_0_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1))) { + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)HEATER_0_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1); } - #if !defined(SINGLENOZZLE) && HAS_MULTI_EXTRUDER - else if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > (HEATER_1_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1))) { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)HEATER_1_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1); - } - #endif - thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); } - #if HAS_HEATED_BED - else { - thermalManager.temp_bed.target += uiCfg.stepHeat; - if ((int)thermalManager.temp_bed.target > BED_MAXTEMP - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1)) { - thermalManager.temp_bed.target = (float)BED_MAXTEMP - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1); - } - thermalManager.start_watching_bed(); + #if !defined(SINGLENOZZLE) && HAS_MULTI_EXTRUDER + else if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > (HEATER_1_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1))) { + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)HEATER_1_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1); } #endif - disp_desire_temp(); + thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); } - break; - case ID_P_DEC: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (uiCfg.curTempType == 0) { - if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > uiCfg.stepHeat) { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target -= uiCfg.stepHeat; - } - else { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)0; + #if HAS_HEATED_BED + else { + thermalManager.temp_bed.target += uiCfg.stepHeat; + if ((int)thermalManager.temp_bed.target > BED_MAXTEMP - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1)) { + thermalManager.temp_bed.target = (float)BED_MAXTEMP - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1); } - thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); + thermalManager.start_watching_bed(); } - #if HAS_HEATED_BED - else { - if ((int)thermalManager.temp_bed.target > uiCfg.stepHeat) { - thermalManager.temp_bed.target -= uiCfg.stepHeat; - } - else { - thermalManager.temp_bed.target = (float)0; - } - thermalManager.start_watching_bed(); - } - #endif - disp_desire_temp(); + #endif + disp_desire_temp(); + break; + case ID_P_DEC: + if (uiCfg.curTempType == 0) { + if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > uiCfg.stepHeat) + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target -= uiCfg.stepHeat; + else + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = 0; + + thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); } + #if HAS_HEATED_BED + else { + if ((int)thermalManager.temp_bed.target > uiCfg.stepHeat) + thermalManager.temp_bed.target -= uiCfg.stepHeat; + else + thermalManager.temp_bed.target = 0; + thermalManager.start_watching_bed(); + } + #endif + disp_desire_temp(); break; case ID_P_TYPE: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (uiCfg.curTempType == 0) { - if (ENABLED(HAS_MULTI_EXTRUDER)) { - if (uiCfg.curSprayerChoose == 0) { - uiCfg.curSprayerChoose = 1; - } - else if (uiCfg.curSprayerChoose == 1) { - if (TEMP_SENSOR_BED != 0) { - uiCfg.curTempType = 1; - } - else { - uiCfg.curTempType = 0; - uiCfg.curSprayerChoose = 0; - } - } + if (uiCfg.curTempType == 0) { + if (ENABLED(HAS_MULTI_EXTRUDER)) { + if (uiCfg.curSprayerChoose == 0) { + uiCfg.curSprayerChoose = 1; } - else if (uiCfg.curSprayerChoose == 0) { - if (TEMP_SENSOR_BED != 0) + else if (uiCfg.curSprayerChoose == 1) { + if (TEMP_SENSOR_BED != 0) { uiCfg.curTempType = 1; - else - uiCfg.curTempType = 0; + } + else { + uiCfg.curTempType = 0; + uiCfg.curSprayerChoose = 0; + } } } - else if (uiCfg.curTempType == 1) { - uiCfg.curSprayerChoose = 0; - uiCfg.curTempType = 0; + else if (uiCfg.curSprayerChoose == 0) { + if (TEMP_SENSOR_BED != 0) + uiCfg.curTempType = 1; + else + uiCfg.curTempType = 0; } - disp_temp_type(); } + else if (uiCfg.curTempType == 1) { + uiCfg.curSprayerChoose = 0; + uiCfg.curTempType = 0; + } + disp_temp_type(); break; case ID_P_STEP: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - switch (uiCfg.stepHeat) { - case 1: uiCfg.stepHeat = 5; break; - case 5: uiCfg.stepHeat = 10; break; - case 10: uiCfg.stepHeat = 1; break; - default: break; - } - disp_step_heat(); + switch (uiCfg.stepHeat) { + case 1: uiCfg.stepHeat = 5; break; + case 5: uiCfg.stepHeat = 10; break; + case 10: uiCfg.stepHeat = 1; break; + default: break; } + disp_step_heat(); break; case ID_P_OFF: - if (event == LV_EVENT_CLICKED) { - // nothing to do + if (uiCfg.curTempType == 0) { + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = 0; + thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); } - else if (event == LV_EVENT_RELEASED) { - if (uiCfg.curTempType == 0) { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)0; - thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); + #if HAS_HEATED_BED + else { + thermalManager.temp_bed.target = 0; + thermalManager.start_watching_bed(); } - #if HAS_HEATED_BED - else { - thermalManager.temp_bed.target = (float)0; - thermalManager.start_watching_bed(); - } - #endif - disp_desire_temp(); - } + #endif + disp_desire_temp(); break; case ID_P_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - draw_return_ui(); - } + clear_cur_ui(); + draw_return_ui(); break; } } void lv_draw_preHeat(void) { - lv_obj_t *buttonAdd, *buttonDec; - lv_obj_t *buttonOff, *buttonBack; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != PRE_HEAT_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = PRE_HEAT_UI; } disp_state = PRE_HEAT_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); // Create image buttons - buttonAdd = lv_imgbtn_create(scr, "F:/bmp_Add.bin", INTERVAL_V, titleHeight, event_handler, ID_P_ADD); - lv_obj_clear_protect(buttonAdd, LV_PROTECT_FOLLOW); - buttonDec = lv_imgbtn_create(scr, "F:/bmp_Dec.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_P_DEC); - buttonType = lv_imgbtn_create(scr, NULL, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_TYPE); - buttonStep = lv_imgbtn_create(scr, NULL, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_STEP); - buttonOff = lv_imgbtn_create(scr, "F:/bmp_speed0.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_OFF); - buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_RETURN); - - // Create labels on the image buttons - lv_obj_t *labelAdd = lv_label_create_empty(buttonAdd); - lv_obj_t *labelDec = lv_label_create_empty(buttonDec); - labelType = lv_label_create_empty(buttonType); - labelStep = lv_label_create_empty(buttonStep); - lv_obj_t *labelOff = lv_label_create_empty(buttonOff); - lv_obj_t *label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - lv_label_set_text(labelAdd, preheat_menu.add); - lv_obj_align(labelAdd, buttonAdd, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelDec, preheat_menu.dec); - lv_obj_align(labelDec, buttonDec, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelOff, preheat_menu.off); - lv_obj_align(labelOff, buttonOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); + lv_big_button_create(scr, "F:/bmp_Add.bin", preheat_menu.add, INTERVAL_V, titleHeight, event_handler, ID_P_ADD); + lv_big_button_create(scr, "F:/bmp_Dec.bin", preheat_menu.dec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_P_DEC); - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } + buttonType = lv_imgbtn_create(scr, nullptr, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_TYPE); + buttonStep = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_STEP); #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonAdd); - lv_group_add_obj(g, buttonDec); lv_group_add_obj(g, buttonType); lv_group_add_obj(g, buttonStep); - lv_group_add_obj(g, buttonOff); - lv_group_add_obj(g, buttonBack); } #endif + lv_big_button_create(scr, "F:/bmp_speed0.bin", preheat_menu.off, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_OFF); + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_RETURN); + + // Create labels on the image buttons + labelType = lv_label_create_empty(buttonType); + labelStep = lv_label_create_empty(buttonStep); + disp_temp_type(); disp_step_heat(); @@ -289,10 +231,7 @@ void disp_desire_temp() { public_buf_l[0] = '\0'; if (uiCfg.curTempType == 0) { - if (uiCfg.curSprayerChoose < 1) - strcat(public_buf_l, preheat_menu.ext1); - else - strcat(public_buf_l, preheat_menu.ext2); + strcat(public_buf_l, uiCfg.curSprayerChoose < 1 ? preheat_menu.ext1 : preheat_menu.ext2); sprintf(buf, preheat_menu.value_state, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target); } #if HAS_HEATED_BED @@ -304,7 +243,7 @@ void disp_desire_temp() { strcat_P(public_buf_l, PSTR(": ")); strcat(public_buf_l, buf); lv_label_set_text(tempText1, public_buf_l); - lv_obj_align(tempText1, NULL, LV_ALIGN_CENTER, 0, -50); + lv_obj_align(tempText1, nullptr, LV_ALIGN_CENTER, 0, -50); } void disp_step_heat() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp index 8db84c5159..141ea4cd6f 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp @@ -33,15 +33,17 @@ #include "../../../../sd/cardreader.h" #include "../../../../inc/MarlinConfig.h" -static lv_obj_t * scr; +static lv_obj_t *scr; extern lv_group_t* g; static lv_obj_t *buttonPageUp, *buttonPageDown, *buttonBack, *buttonGcode[FILE_BTN_CNT], *labelPageUp[FILE_BTN_CNT], *buttonText[FILE_BTN_CNT]; -#define ID_P_UP 7 -#define ID_P_DOWN 8 -#define ID_P_RETURN 9 +enum { + ID_P_UP = 7, + ID_P_DOWN, + ID_P_RETURN +}; int8_t curDirLever = 0; LIST_FILE list_file; @@ -74,38 +76,21 @@ uint8_t sel_id = 0; const uint16_t nr = SD_ORDER(i, fileCnt); card.getfilename_sorted(nr); - if (card.flag.filenameIsDir) { - //SERIAL_ECHOLN(card.longest_filename); - list_file.IsFolder[valid_name_cnt] = 1; - } - else { - //SERIAL_ECHOLN(card.longFilename); - list_file.IsFolder[valid_name_cnt] = 0; - } - - #if 1 - // - memset(list_file.file_name[valid_name_cnt], 0, strlen(list_file.file_name[valid_name_cnt])); - strcpy(list_file.file_name[valid_name_cnt], list_file.curDirPath); - strcat_P(list_file.file_name[valid_name_cnt], PSTR("/")); - strcat(list_file.file_name[valid_name_cnt], card.filename); - // - memset(list_file.long_name[valid_name_cnt], 0, strlen(list_file.long_name[valid_name_cnt])); - if (card.longFilename[0] == 0) - strncpy(list_file.long_name[valid_name_cnt], card.filename, strlen(card.filename)); - else - strncpy(list_file.long_name[valid_name_cnt], card.longFilename, strlen(card.longFilename)); - - valid_name_cnt++; - if (valid_name_cnt == 1) - dir_offset[curDirLever].cur_page_first_offset = list_file.Sd_file_offset; - if (valid_name_cnt >= FILE_NUM) { - dir_offset[curDirLever].cur_page_last_offset = list_file.Sd_file_offset; - list_file.Sd_file_offset++; - break; - } + list_file.IsFolder[valid_name_cnt] = card.flag.filenameIsDir; + strcpy(list_file.file_name[valid_name_cnt], list_file.curDirPath); + strcat_P(list_file.file_name[valid_name_cnt], PSTR("/")); + strcat(list_file.file_name[valid_name_cnt], card.filename); + strcpy(list_file.long_name[valid_name_cnt], card.longest_filename()); + + valid_name_cnt++; + if (valid_name_cnt == 1) + dir_offset[curDirLever].cur_page_first_offset = list_file.Sd_file_offset; + if (valid_name_cnt >= FILE_NUM) { + dir_offset[curDirLever].cur_page_last_offset = list_file.Sd_file_offset; list_file.Sd_file_offset++; - #endif + break; + } + list_file.Sd_file_offset++; } list_file.Sd_file_cnt++; } @@ -115,125 +100,105 @@ uint8_t sel_id = 0; #endif // SDSUPPORT -uint8_t have_pre_pic(char *path) { +bool have_pre_pic(char *path) { #if ENABLED(SDSUPPORT) char *ps1, *ps2, *cur_name = strrchr(path, '/'); - card.openFileRead(cur_name); card.read(public_buf, 512); ps1 = strstr((char *)public_buf, ";simage:"); card.read(public_buf, 512); ps2 = strstr((char *)public_buf, ";simage:"); - if (ps1 || ps2) { - card.closefile(); - return 1; - } card.closefile(); + if (ps1 || ps2) return true; #endif - return 0; + return false; } -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; uint8_t i, file_count = 0; //switch (obj->mks_obj_id) //{ if (obj->mks_obj_id == ID_P_UP) { - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - if (dir_offset[curDirLever].curPage > 0) { - // 2015.05.19 - list_file.Sd_file_cnt = 0; + if (dir_offset[curDirLever].curPage > 0) { + // 2015.05.19 + list_file.Sd_file_cnt = 0; - if (dir_offset[curDirLever].cur_page_first_offset >= FILE_NUM) - list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset - FILE_NUM; + if (dir_offset[curDirLever].cur_page_first_offset >= FILE_NUM) + list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset - FILE_NUM; - #if ENABLED(SDSUPPORT) - file_count = search_file(); - #endif - if (file_count != 0) { - dir_offset[curDirLever].curPage--; - lv_clear_print_file(); - disp_gcode_icon(file_count); - } + #if ENABLED(SDSUPPORT) + file_count = search_file(); + #endif + if (file_count != 0) { + dir_offset[curDirLever].curPage--; + lv_clear_print_file(); + disp_gcode_icon(file_count); } } } else if (obj->mks_obj_id == ID_P_DOWN) { - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - if (dir_offset[curDirLever].cur_page_last_offset > 0) { - list_file.Sd_file_cnt = 0; - list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_last_offset + 1; - #if ENABLED(SDSUPPORT) - file_count = search_file(); - #endif - if (file_count != 0) { - dir_offset[curDirLever].curPage++; - lv_clear_print_file(); - disp_gcode_icon(file_count); - } - if (file_count < FILE_NUM) - dir_offset[curDirLever].cur_page_last_offset = 0; + if (dir_offset[curDirLever].cur_page_last_offset > 0) { + list_file.Sd_file_cnt = 0; + list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_last_offset + 1; + #if ENABLED(SDSUPPORT) + file_count = search_file(); + #endif + if (file_count != 0) { + dir_offset[curDirLever].curPage++; + lv_clear_print_file(); + disp_gcode_icon(file_count); } + if (file_count < FILE_NUM) + dir_offset[curDirLever].cur_page_last_offset = 0; } } else if (obj->mks_obj_id == ID_P_RETURN) { - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - if (curDirLever > 0) { - int8_t *ch = (int8_t *)strrchr(list_file.curDirPath, '/'); - if (ch) { - *ch = 0; - #if ENABLED(SDSUPPORT) - card.cdup(); - #endif - dir_offset[curDirLever].curPage = 0; - dir_offset[curDirLever].cur_page_first_offset = 0; - dir_offset[curDirLever].cur_page_last_offset = 0; - curDirLever--; - list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset; - #if ENABLED(SDSUPPORT) - file_count = search_file(); - #endif - lv_clear_print_file(); - disp_gcode_icon(file_count); - } - } - else { + if (curDirLever > 0) { + int8_t *ch = (int8_t *)strrchr(list_file.curDirPath, '/'); + if (ch) { + *ch = 0; + #if ENABLED(SDSUPPORT) + card.cdup(); + #endif + dir_offset[curDirLever].curPage = 0; + dir_offset[curDirLever].cur_page_first_offset = 0; + dir_offset[curDirLever].cur_page_last_offset = 0; + curDirLever--; + list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset; + #if ENABLED(SDSUPPORT) + file_count = search_file(); + #endif lv_clear_print_file(); - lv_draw_ready_print(); + disp_gcode_icon(file_count); } } + else { + lv_clear_print_file(); + lv_draw_ready_print(); + } } else { for (i = 0; i < FILE_BTN_CNT; i++) { if (obj->mks_obj_id == (i + 1)) { - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - if (list_file.file_name[i][0] != 0) { - if (list_file.IsFolder[i] == 1) { - ZERO(list_file.curDirPath); - strcpy(list_file.curDirPath, list_file.file_name[i]); - curDirLever++; - list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset; - #if ENABLED(SDSUPPORT) - file_count = search_file(); - #endif - lv_clear_print_file(); - disp_gcode_icon(file_count); - } - else { - sel_id = i; - lv_clear_print_file(); - lv_draw_dialog(DIALOG_TYPE_PRINT_FILE); - } - break; + if (list_file.file_name[i][0] != 0) { + if (list_file.IsFolder[i]) { + strcpy(list_file.curDirPath, list_file.file_name[i]); + curDirLever++; + list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset; + #if ENABLED(SDSUPPORT) + file_count = search_file(); + #endif + lv_clear_print_file(); + disp_gcode_icon(file_count); } + else { + sel_id = i; + lv_clear_print_file(); + lv_draw_dialog(DIALOG_TYPE_PRINT_FILE); + } + break; } } } @@ -249,11 +214,11 @@ void lv_draw_print_file(void) { } disp_state = PRINT_FILE_UI; - curDirLever = 0; + curDirLever = 0; dir_offset[curDirLever].curPage = 0; list_file.Sd_file_offset = 0; - list_file.Sd_file_cnt = 0; + list_file.Sd_file_cnt = 0; ZERO(dir_offset); ZERO(list_file.IsFolder); @@ -287,14 +252,7 @@ static char test_public_buf_l[40]; void disp_gcode_icon(uint8_t file_num) { uint8_t i; - scr = lv_obj_create(NULL, NULL); - - //static lv_style_t tool_style; - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); @@ -319,17 +277,17 @@ void disp_gcode_icon(uint8_t file_num) { if (i >= file_num) break; #ifdef TFT35 - buttonGcode[i] = lv_imgbtn_create(scr, NULL); + buttonGcode[i] = lv_imgbtn_create(scr, nullptr); lv_imgbtn_use_label_style(buttonGcode[i]); lv_obj_clear_protect(buttonGcode[i], LV_PROTECT_FOLLOW); lv_btn_set_layout(buttonGcode[i], LV_LAYOUT_OFF); ZERO(public_buf_m); - cutFileName((char *)list_file.long_name[i], 16, 8, (char *)public_buf_m); + cutFileName((char *)list_file.long_name[i], 16, 8, (char *)public_buf_m); - if (list_file.IsFolder[i] == 1) { - lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), NULL, 0); + if (list_file.IsFolder[i]) { + lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), nullptr, 0); lv_imgbtn_set_src_both(buttonGcode[i], "F:/bmp_dir.bin"); if (i < 3) lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * i + INTERVAL_V * (i + 1), titleHeight); @@ -344,34 +302,33 @@ void disp_gcode_icon(uint8_t file_num) { //lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), list_file.file_name[i], 1); - ZERO(test_public_buf_l); - strcat(test_public_buf_l,"S:"); - strcat(test_public_buf_l,list_file.file_name[i]); - char *temp = strstr(test_public_buf_l,".GCO"); - if (temp) { strcpy(temp,".bin"); } - lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), NULL, 0); + strcpy(test_public_buf_l, "S:"); + strcat(test_public_buf_l, list_file.file_name[i]); + char *temp = strstr(test_public_buf_l, ".GCO"); + if (temp) strcpy(temp, ".bin"); + lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), nullptr, 0); lv_imgbtn_set_src_both(buttonGcode[i], test_public_buf_l); if (i < 3) { lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * i + INTERVAL_V * (i + 1) + FILE_PRE_PIC_X_OFFSET, titleHeight + FILE_PRE_PIC_Y_OFFSET); - buttonText[i] = lv_btn_create(scr, NULL); + buttonText[i] = lv_btn_create(scr, nullptr); //lv_obj_set_event_cb(buttonText[i], event_handler); lv_btn_use_label_style(buttonText[i]); lv_obj_clear_protect(buttonText[i], LV_PROTECT_FOLLOW); lv_btn_set_layout(buttonText[i], LV_LAYOUT_OFF); - //lv_obj_set_event_cb_mks(buttonText[i], event_handler,(i+10),NULL, 0); + //lv_obj_set_event_cb_mks(buttonText[i], event_handler,(i+10),nullptr, 0); lv_obj_set_pos(buttonText[i], BTN_X_PIXEL * i + INTERVAL_V * (i + 1) + FILE_PRE_PIC_X_OFFSET, titleHeight + FILE_PRE_PIC_Y_OFFSET + 100); lv_obj_set_size(buttonText[i], 100, 40); } else { lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * (i - 3) + INTERVAL_V * ((i - 3) + 1) + FILE_PRE_PIC_X_OFFSET, BTN_Y_PIXEL + INTERVAL_H + titleHeight + FILE_PRE_PIC_Y_OFFSET); - buttonText[i] = lv_btn_create(scr, NULL); + buttonText[i] = lv_btn_create(scr, nullptr); //lv_obj_set_event_cb(buttonText[i], event_handler); lv_btn_use_label_style(buttonText[i]); lv_obj_clear_protect(buttonText[i], LV_PROTECT_FOLLOW); lv_btn_set_layout(buttonText[i], LV_LAYOUT_OFF); - //lv_obj_set_event_cb_mks(buttonText[i], event_handler,(i+10),NULL, 0); + //lv_obj_set_event_cb_mks(buttonText[i], event_handler,(i+10),nullptr, 0); lv_obj_set_pos(buttonText[i], BTN_X_PIXEL * (i - 3) + INTERVAL_V * ((i - 3) + 1) + FILE_PRE_PIC_X_OFFSET, BTN_Y_PIXEL + INTERVAL_H + titleHeight + FILE_PRE_PIC_Y_OFFSET + 100); lv_obj_set_size(buttonText[i], 100, 40); } @@ -379,7 +336,7 @@ void disp_gcode_icon(uint8_t file_num) { lv_obj_align(labelPageUp[i], buttonText[i], LV_ALIGN_IN_BOTTOM_MID, 0, 0); } else { - lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), NULL, 0); + lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), nullptr, 0); lv_imgbtn_set_src_both(buttonGcode[i], "F:/bmp_file.bin"); if (i < 3) lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * i + INTERVAL_V * (i + 1), titleHeight); @@ -502,7 +459,7 @@ void lv_gcode_file_seek(uint32_t pos) { card.setIndex(pos); } -void cutFileName(char *path, int len, int bytePerLine, char *outStr) { +void cutFileName(char *path, int len, int bytePerLine, char *outStr) { #if _LFN_UNICODE TCHAR *tmpFile; TCHAR *strIndex1 = 0, *strIndex2 = 0, *beginIndex; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.h b/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.h index 083b3d9acf..94786ab070 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.h @@ -43,7 +43,7 @@ typedef struct { char file_name[FILE_NUM][SHORT_NEME_LEN * MAX_DIR_LEVEL + 1]; char curDirPath[SHORT_NEME_LEN * MAX_DIR_LEVEL + 1]; char long_name[FILE_NUM][SHORT_NEME_LEN * 2 + 1]; - char IsFolder[FILE_NUM]; + bool IsFolder[FILE_NUM]; char Sd_file_cnt; char sd_file_index; char Sd_file_offset; @@ -55,7 +55,7 @@ extern void lv_draw_print_file(void); extern uint32_t lv_open_gcode_file(char *path); extern void lv_gcode_file_read(uint8_t *data_buf); extern void lv_close_gcode_file(); -extern void cutFileName(char *path, int len, int bytePerLine, char *outStr); +extern void cutFileName(char *path, int len, int bytePerLine, char *outStr); extern int ascii2dec_test(char *ascii); extern void lv_clear_print_file(); extern void lv_gcode_file_seek(uint32_t pos); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp index 312ce69d0c..8191d5fb65 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp @@ -59,78 +59,61 @@ TERN_(HAS_MULTI_EXTRUDER, static lv_obj_t *labelExt2); static lv_obj_t* labelBed; #endif -#define ID_PAUSE 1 -#define ID_STOP 2 -#define ID_OPTION 3 +enum { + ID_PAUSE = 1, + ID_STOP, + ID_OPTION +}; bool once_flag; // = false extern bool flash_preview_begin, default_preview_flg, gcode_preview_over; extern uint32_t To_pre_view; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; + if (gcode_preview_over) return; switch (obj->mks_obj_id) { case ID_PAUSE: - if (event == LV_EVENT_CLICKED) { - // nothing to do + if (uiCfg.print_state == WORKING) { + // #if ENABLED(PARK_HEAD_ON_PAUSE) + // queue.inject_P(PSTR("M25 P\nM24")); + #if ENABLED(SDSUPPORT) + // queue.inject_P(PSTR("M25\nG91\nG1 Z10\nG90")); + card.pauseSDPrint(); + stop_print_time(); + uiCfg.print_state = PAUSING; + #endif + lv_imgbtn_set_src_both(buttonPause, "F:/bmp_resume.bin"); + lv_label_set_text(labelPause, printing_menu.resume); + lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0); } - else if (event == LV_EVENT_RELEASED) { - if (!gcode_preview_over) { - if (uiCfg.print_state == WORKING) { - // #if ENABLED(PARK_HEAD_ON_PAUSE) - // queue.inject_P(PSTR("M25 P\nM24")); - #if ENABLED(SDSUPPORT) - // queue.inject_P(PSTR("M25\nG91\nG1 Z10\nG90")); - card.pauseSDPrint(); - stop_print_time(); - uiCfg.print_state = PAUSING; - #endif - lv_imgbtn_set_src_both(buttonPause, "F:/bmp_resume.bin"); - lv_label_set_text(labelPause, printing_menu.resume); - lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0); - } - else if (uiCfg.print_state == PAUSED) { - uiCfg.print_state = RESUMING; - lv_imgbtn_set_src_both(obj, "F:/bmp_pause.bin"); - lv_label_set_text(labelPause, printing_menu.pause); - lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0); - } - #if ENABLED(POWER_LOSS_RECOVERY) - else if (uiCfg.print_state == REPRINTING) { - uiCfg.print_state = REPRINTED; - lv_imgbtn_set_src_both(obj, "F:/bmp_pause.bin"); - lv_label_set_text(labelPause, printing_menu.pause); - lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0); - // recovery.resume(); - print_time.minutes = recovery.info.print_job_elapsed / 60; - print_time.seconds = recovery.info.print_job_elapsed % 60; - print_time.hours = print_time.minutes / 60; - } - #endif - } + else if (uiCfg.print_state == PAUSED) { + uiCfg.print_state = RESUMING; + lv_imgbtn_set_src_both(obj, "F:/bmp_pause.bin"); + lv_label_set_text(labelPause, printing_menu.pause); + lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0); } + #if ENABLED(POWER_LOSS_RECOVERY) + else if (uiCfg.print_state == REPRINTING) { + uiCfg.print_state = REPRINTED; + lv_imgbtn_set_src_both(obj, "F:/bmp_pause.bin"); + lv_label_set_text(labelPause, printing_menu.pause); + lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0); + // recovery.resume(); + print_time.minutes = recovery.info.print_job_elapsed / 60; + print_time.seconds = recovery.info.print_job_elapsed % 60; + print_time.hours = print_time.minutes / 60; + } + #endif break; case ID_STOP: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (!gcode_preview_over) { - lv_clear_printing(); - lv_draw_dialog(DIALOG_TYPE_STOP); - } - } + lv_clear_printing(); + lv_draw_dialog(DIALOG_TYPE_STOP); break; case ID_OPTION: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (!gcode_preview_over) { - lv_clear_printing(); - lv_draw_operation(); - } - } + lv_clear_printing(); + lv_draw_operation(); break; } } @@ -142,44 +125,38 @@ void lv_draw_printing(void) { disp_state = PRINTING_UI; - scr = lv_obj_create(NULL, NULL); - - // static lv_style_t tool_style; - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); // Create image buttons - lv_obj_t *buttonExt1 = lv_img_create(scr, NULL); + lv_obj_t *buttonExt1 = lv_img_create(scr, nullptr); lv_img_set_src(buttonExt1, "F:/bmp_ext1_state.bin"); lv_obj_set_pos(buttonExt1, 205, 136); #if HAS_MULTI_EXTRUDER - lv_obj_t *buttonExt2 = lv_img_create(scr, NULL); + lv_obj_t *buttonExt2 = lv_img_create(scr, nullptr); lv_img_set_src(buttonExt2, "F:/bmp_ext2_state.bin"); lv_obj_set_pos(buttonExt2, 350, 136); #endif #if HAS_HEATED_BED - lv_obj_t *buttonBedstate = lv_img_create(scr, NULL); + lv_obj_t *buttonBedstate = lv_img_create(scr, nullptr); lv_img_set_src(buttonBedstate, "F:/bmp_bed_state.bin"); lv_obj_set_pos(buttonBedstate, 205, 186); #endif - lv_obj_t *buttonFanstate = lv_img_create(scr, NULL); + lv_obj_t *buttonFanstate = lv_img_create(scr, nullptr); lv_img_set_src(buttonFanstate, "F:/bmp_fan_state.bin"); lv_obj_set_pos(buttonFanstate, 350, 186); - lv_obj_t *buttonTime = lv_img_create(scr, NULL); + lv_obj_t *buttonTime = lv_img_create(scr, nullptr); lv_img_set_src(buttonTime, "F:/bmp_time_state.bin"); lv_obj_set_pos(buttonTime, 205, 86); - lv_obj_t *buttonZpos = lv_img_create(scr, NULL); + lv_obj_t *buttonZpos = lv_img_create(scr, nullptr); lv_img_set_src(buttonZpos, "F:/bmp_zpos_state.bin"); lv_obj_set_pos(buttonZpos, 350, 86); @@ -209,19 +186,19 @@ void lv_draw_printing(void) { //lv_btn_set_layout(buttonTime, LV_LAYOUT_OFF); //lv_btn_set_layout(buttonZpos, LV_LAYOUT_OFF); - labelExt1 = lv_label_create(scr, 250, 146, NULL); + labelExt1 = lv_label_create(scr, 250, 146, nullptr); #if HAS_MULTI_EXTRUDER - labelExt2 = lv_label_create(scr, 395, 146, NULL); + labelExt2 = lv_label_create(scr, 395, 146, nullptr); #endif #if HAS_HEATED_BED - labelBed = lv_label_create(scr, 250, 196, NULL); + labelBed = lv_label_create(scr, 250, 196, nullptr); #endif - labelFan = lv_label_create(scr, 395, 196, NULL); - labelTime = lv_label_create(scr, 250, 96, NULL); - labelZpos = lv_label_create(scr, 395, 96, NULL); + labelFan = lv_label_create(scr, 395, 196, nullptr); + labelTime = lv_label_create(scr, 250, 96, nullptr); + labelZpos = lv_label_create(scr, 395, 96, nullptr); labelPause = lv_label_create_empty(buttonPause); labelStop = lv_label_create_empty(buttonStop); @@ -238,7 +215,7 @@ void lv_draw_printing(void) { lv_obj_align(labelOperat, buttonOperat, LV_ALIGN_CENTER, 20, 0); } - bar1 = lv_bar_create(scr, NULL); + bar1 = lv_bar_create(scr, nullptr); lv_obj_set_pos(bar1, 205, 36); lv_obj_set_size(bar1, 270, 40); lv_bar_set_style(bar1, LV_BAR_STYLE_INDIC, &lv_bar_style_indic); @@ -256,12 +233,10 @@ void lv_draw_printing(void) { } void disp_ext_temp() { - ZERO(public_buf_l); sprintf(public_buf_l, printing_menu.temp1, (int)thermalManager.temp_hotend[0].celsius, (int)thermalManager.temp_hotend[0].target); lv_label_set_text(labelExt1, public_buf_l); #if HAS_MULTI_EXTRUDER - ZERO(public_buf_l); sprintf(public_buf_l, printing_menu.temp1, (int)thermalManager.temp_hotend[1].celsius, (int)thermalManager.temp_hotend[1].target); lv_label_set_text(labelExt2, public_buf_l); #endif @@ -269,20 +244,17 @@ void disp_ext_temp() { void disp_bed_temp() { #if HAS_HEATED_BED - ZERO(public_buf_l); sprintf(public_buf_l, printing_menu.bed_temp, (int)thermalManager.temp_bed.celsius, (int)thermalManager.temp_bed.target); lv_label_set_text(labelBed, public_buf_l); #endif } void disp_fan_speed() { - ZERO(public_buf_l); sprintf_P(public_buf_l, PSTR("%3d"), thermalManager.fan_speed[0]); lv_label_set_text(labelFan, public_buf_l); } void disp_print_time() { - ZERO(public_buf_l); #if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME) const uint32_t r = ui.get_remaining_time(); sprintf_P(public_buf_l, PSTR("%02d:%02d R"), r / 3600, (r % 3600) / 60); @@ -293,7 +265,6 @@ void disp_print_time() { } void disp_fan_Zpos() { - ZERO(public_buf_l); sprintf_P(public_buf_l, PSTR("%.3f"), current_position[Z_AXIS]); lv_label_set_text(labelZpos, public_buf_l); } @@ -333,7 +304,6 @@ void setProBarRate() { if (disp_state == PRINTING_UI) { lv_bar_set_value(bar1, rate, LV_ANIM_ON); - ZERO(public_buf_l); sprintf_P(public_buf_l, "%d%%", rate); lv_label_set_text(bar1ValueText,public_buf_l); lv_obj_align(bar1ValueText, bar1, LV_ALIGN_CENTER, 0, 0); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.h b/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.h index b7d464e4f0..466efe01cb 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.h @@ -25,14 +25,16 @@ extern "C" { /* C-declarations for C++ */ #endif -#define IDLE 0 -#define WORKING 1 -#define PAUSING 2 -#define PAUSED 3 -#define REPRINTING 4 -#define REPRINTED 5 -#define RESUMING 6 -#define STOP 7 +enum { + IDLE, + WORKING, + PAUSING, + PAUSED, + REPRINTING, + REPRINTED, + RESUMING, + STOP +}; extern void lv_draw_printing(void); extern void lv_clear_printing(); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp index 765570ca3b..3e8a9aad5b 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp @@ -43,44 +43,31 @@ //static lv_obj_t *buttonPrint, *buttonTool, *buttonSet; extern lv_group_t* g; -static lv_obj_t * scr; +static lv_obj_t *scr; #if ENABLED(MKS_TEST) uint8_t curent_disp_ui = 0; #endif -#define ID_TOOL 1 -#define ID_SET 2 -#define ID_PRINT 3 +enum { + ID_TOOL = 1, + ID_SET, + ID_PRINT +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_TOOL: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - - lv_clear_ready_print(); - lv_draw_tool(); - } + lv_clear_ready_print(); + lv_draw_tool(); break; case ID_SET: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_ready_print(); - lv_draw_set(); - } + lv_clear_ready_print(); + lv_draw_set(); break; case ID_PRINT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_ready_print(); - lv_draw_print_file(); - } + lv_clear_ready_print(); + lv_draw_print_file(); break; } } @@ -114,20 +101,16 @@ void mks_disp_test() { char buf[30] = {0}; //lv_obj_t *label_tool2 = lv_label_create_empty(scr); //lv_obj_set_pos(label_tool, 20, 50); - ZERO(buf); sprintf_P(buf, PSTR("e1:%d"), (int)thermalManager.temp_hotend[0].celsius); lv_label_set_text(e1, buf); #if HAS_MULTI_HOTEND - ZERO(buf); sprintf_P(buf, PSTR("e2:%d"), (int)thermalManager.temp_hotend[1].celsius); lv_label_set_text(e2, buf); #endif - //ZERO(buf); //sprintf_P(buf, PSTR("e3:%d"), (int)thermalManager.temp_hotend[2].celsius); //lv_label_set_text(e3, buf); #if HAS_HEATED_BED - ZERO(buf); sprintf_P(buf, PSTR("bed:%d"), (int)thermalManager.temp_bed.celsius); lv_label_set_text(bed, buf); #endif @@ -135,7 +118,7 @@ void mks_disp_test() { void lv_draw_ready_print(void) { char buf[30] = {0}; - lv_obj_t *buttonPrint, *buttonTool, *buttonSet; + lv_obj_t *buttonTool; disp_state_stack._disp_index = 0; ZERO(disp_state_stack._disp_state); @@ -143,11 +126,7 @@ void lv_draw_ready_print(void) { disp_state = PRINT_READY_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); //lv_obj_set_hidden(scr, true); lv_refr_now(lv_refr_get_disp_refreshing()); @@ -155,12 +134,12 @@ void lv_draw_ready_print(void) { //(void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); // Create image buttons - //buttonPrint = lv_imgbtn_create(scr, NULL); + //buttonPrint = lv_imgbtn_create(scr, nullptr); buttonTool = lv_imgbtn_create(scr, "F:/bmp_tool.bin", event_handler, ID_TOOL); lv_obj_set_pos(buttonTool, 360, 180); - //buttonSet = lv_imgbtn_create(scr, NULL); + //buttonSet = lv_imgbtn_create(scr, nullptr); //lv_obj_set_pos(buttonSet, 180, 90); //lv_obj_set_pos(buttonPrint, 340, 90); @@ -237,34 +216,9 @@ void lv_draw_ready_print(void) { } else { - // Create an Image button - buttonTool = lv_imgbtn_create(scr, "F:/bmp_tool.bin", 20, 90, event_handler, ID_TOOL); - lv_obj_t *label_tool = lv_label_create_empty(buttonTool); - - buttonSet = lv_imgbtn_create(scr, "F:/bmp_set.bin", 180, 90, event_handler, ID_SET); - lv_obj_t *label_set = lv_label_create_empty(buttonSet); - - buttonPrint = lv_imgbtn_create(scr, "F:/bmp_printing.bin", 340, 90, event_handler, ID_PRINT); - lv_obj_t *label_print = lv_label_create_empty(buttonPrint); - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_print, main_menu.print); - lv_obj_align(label_print, buttonPrint, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_set, main_menu.set); - lv_obj_align(label_set, buttonSet, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_tool, main_menu.tool); - lv_obj_align(label_tool, buttonTool, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable == true) { - lv_group_add_obj(g, buttonTool); - lv_group_add_obj(g, buttonSet); - lv_group_add_obj(g, buttonPrint); - } - #endif + lv_big_button_create(scr, "F:/bmp_tool.bin", main_menu.tool, 20, 90, event_handler, ID_TOOL); + lv_big_button_create(scr, "F:/bmp_set.bin", main_menu.set, 180, 90, event_handler, ID_SET); + lv_big_button_create(scr, "F:/bmp_printing.bin", main_menu.print, 340, 90, event_handler, ID_PRINT); } } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_set.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_set.cpp index e4896866cf..46ea04deaf 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_set.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_set.cpp @@ -37,100 +37,58 @@ #include "../../../../gcode/queue.h" #include "../../../../inc/MarlinConfig.h" -static lv_obj_t * scr; +static lv_obj_t *scr; extern lv_group_t* g; -#define ID_S_WIFI 1 -#define ID_S_FAN 2 -#define ID_S_ABOUT 3 -#define ID_S_CONTINUE 4 -#define ID_S_MOTOR_OFF 5 -#define ID_S_LANGUAGE 6 -#define ID_S_MACHINE_PARA 7 -#define ID_S_EEPROM_SET 8 -#define ID_S_RETURN 9 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +enum { + ID_S_WIFI = 1, + ID_S_FAN, + ID_S_ABOUT, + ID_S_CONTINUE, + ID_S_MOTOR_OFF, + ID_S_LANGUAGE, + ID_S_MACHINE_PARA, + ID_S_EEPROM_SET, + ID_S_RETURN +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; #if ENABLED(USE_WIFI_FUNCTION) char buf[6] = { 0 }; #endif switch (obj->mks_obj_id) { - case ID_S_FAN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_set(); - lv_draw_fan(); - } + lv_clear_set(); + lv_draw_fan(); break; case ID_S_ABOUT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_set(); - lv_draw_about(); - } - break; - case ID_S_CONTINUE: - + lv_clear_set(); + lv_draw_about(); break; + case ID_S_CONTINUE: break; case ID_S_MOTOR_OFF: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - #if HAS_SUICIDE - suicide(); - #else - queue.enqueue_now_P(PSTR("M84")); - #endif - } + TERN(HAS_SUICIDE, suicide(), queue.enqueue_now_P(PSTR("M84"))); break; case ID_S_LANGUAGE: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_set(); - lv_draw_language(); - } + lv_clear_set(); + lv_draw_language(); break; case ID_S_MACHINE_PARA: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_set(); - lv_draw_machine_para(); - } + lv_clear_set(); + lv_draw_machine_para(); break; case ID_S_EEPROM_SET: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_set(); - lv_draw_eeprom_settings(); - } + lv_clear_set(); + lv_draw_eeprom_settings(); break; case ID_S_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_set(); - lv_draw_ready_print(); - } + lv_clear_set(); + lv_draw_ready_print(); break; + #if ENABLED(USE_WIFI_FUNCTION) case ID_S_WIFI: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { if (gCfgItems.wifi_mode_sel == STA_MODEL) { if (wifi_link_state == WIFI_CONNECTED) { last_disp_state = SET_UI; @@ -153,7 +111,7 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) { else { last_disp_state = SET_UI; lv_clear_set(); - lv_draw_dialog(WIFI_ENABLE_TIPS); + lv_draw_dialog(DIALOG_WIFI_ENABLE_TIPS); } } } @@ -162,131 +120,36 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) { lv_clear_set(); lv_draw_wifi(); } - } - break; + break; #endif } } void lv_draw_set(void) { - lv_obj_t *buttonFan, *buttonAbout; - lv_obj_t *buMotorOff, *buttonBack; - #if HAS_LANG_SELECT_SCREEN - lv_obj_t *buttonLanguage; - #endif - lv_obj_t *buttonMachinePara; - lv_obj_t *buttonEepromSet; - #if ENABLED(USE_WIFI_FUNCTION) - lv_obj_t *buttonWifi; - #endif - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != SET_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = SET_UI; } disp_state = SET_UI; - scr = lv_obj_create(NULL, NULL); - - //static lv_style_t tool_style; - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); - // Create image buttons - buttonEepromSet = lv_imgbtn_create(scr, "F:/bmp_eeprom_settings.bin", INTERVAL_V, titleHeight, event_handler, ID_S_EEPROM_SET); - //buttonWifi = lv_imgbtn_create(scr, NULL); - buttonFan = lv_imgbtn_create(scr, "F:/bmp_fan.bin", BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_S_FAN); - buttonAbout = lv_imgbtn_create(scr, "F:/bmp_about.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_S_ABOUT); - //buttonContinue = lv_imgbtn_create(scr, NULL); - buMotorOff = lv_imgbtn_create(scr, ENABLED(HAS_SUICIDE) ? "F:/bmp_manual_off.bin" : "F:/bmp_function1.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_S_MOTOR_OFF); - buttonMachinePara = lv_imgbtn_create(scr, "F:/bmp_machine_para.bin", INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_S_MACHINE_PARA); + lv_big_button_create(scr, "F:/bmp_eeprom_settings.bin", set_menu.eepromSet, INTERVAL_V, titleHeight, event_handler, ID_S_EEPROM_SET); + lv_big_button_create(scr, "F:/bmp_fan.bin", set_menu.fan, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_S_FAN); + lv_big_button_create(scr, "F:/bmp_about.bin", set_menu.about, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_S_ABOUT); + lv_big_button_create(scr, ENABLED(HAS_SUICIDE) ? "F:/bmp_manual_off.bin" : "F:/bmp_function1.bin", set_menu.TERN(HAS_SUICIDE, shutdown, motoroff), BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_S_MOTOR_OFF); + lv_big_button_create(scr, "F:/bmp_machine_para.bin", set_menu.machine_para, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_S_MACHINE_PARA); #if HAS_LANG_SELECT_SCREEN - buttonLanguage = lv_imgbtn_create(scr, "F:/bmp_language.bin", BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_S_LANGUAGE); + lv_big_button_create(scr, "F:/bmp_language.bin", set_menu.language, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_S_LANGUAGE); #endif #if ENABLED(USE_WIFI_FUNCTION) - buttonWifi = lv_imgbtn_create(scr, "F:/bmp_wifi.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_S_WIFI); - #endif - buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_S_RETURN); - - /*lv_obj_set_pos(buttonWifi,INTERVAL_V,titleHeight); - lv_obj_set_pos(buttonFan,BTN_X_PIXEL+INTERVAL_V*2,titleHeight); - lv_obj_set_pos(buttonAbout,BTN_X_PIXEL*2+INTERVAL_V*3,titleHeight); - lv_obj_set_pos(buttonContinue,BTN_X_PIXEL*3+INTERVAL_V*4,titleHeight); - lv_obj_set_pos(buMotorOff,INTERVAL_V, BTN_Y_PIXEL+INTERVAL_H+titleHeight); - lv_obj_set_pos(buttonLanguage,BTN_X_PIXEL+INTERVAL_V*2,BTN_Y_PIXEL+INTERVAL_H+titleHeight); - lv_obj_set_pos(buttonBack,BTN_X_PIXEL*3+INTERVAL_V*4, BTN_Y_PIXEL+INTERVAL_H+titleHeight);*/ - - //lv_obj_set_pos(buttonWifi,INTERVAL_V,titleHeight); - //lv_obj_set_pos(buttonContinue,BTN_X_PIXEL*3+INTERVAL_V*4,titleHeight); - - /// Create labels on the buttons - //lv_obj_t *labelWifi= lv_label_create_empty(buttonWifi); - lv_obj_t *label_EepromSet = lv_label_create_empty(buttonEepromSet); - lv_obj_t *labelFan = lv_label_create_empty(buttonFan); - lv_obj_t *label_About = lv_label_create_empty(buttonAbout); - //lv_obj_t *label_Continue = lv_label_create_empty(buttonContinue); - lv_obj_t *label_MotorOff = lv_label_create_empty(buMotorOff); - lv_obj_t *label_MachinePara = lv_label_create_empty(buttonMachinePara); - #if HAS_LANG_SELECT_SCREEN - lv_obj_t *label_Language = lv_label_create_empty(buttonLanguage); - #endif - #if ENABLED(USE_WIFI_FUNCTION) - lv_obj_t *label_Wifi = lv_label_create_empty(buttonWifi); - #endif - lv_obj_t *label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - - lv_label_set_text(label_EepromSet, set_menu.eepromSet); - lv_obj_align(label_EepromSet, buttonEepromSet, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelFan, set_menu.fan); - lv_obj_align(labelFan, buttonFan, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_About, set_menu.about); - lv_obj_align(label_About, buttonAbout, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - //lv_label_set_text(label_Continue, set_menu.breakpoint); - //lv_obj_align(label_Continue, buttonContinue, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET); - lv_label_set_text(label_MotorOff, set_menu.TERN(HAS_SUICIDE, shutdown, motoroff)); - lv_obj_align(label_MotorOff, buMotorOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_MachinePara, set_menu.machine_para); - lv_obj_align(label_MachinePara, buttonMachinePara, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - #if HAS_LANG_SELECT_SCREEN - lv_label_set_text(label_Language, set_menu.language); - lv_obj_align(label_Language, buttonLanguage, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - #endif - - #if ENABLED(USE_WIFI_FUNCTION) - lv_label_set_text(label_Wifi, set_menu.wifi); - lv_obj_align(label_Wifi, buttonWifi, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET); - #endif - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonEepromSet); - lv_group_add_obj(g, buttonFan); - lv_group_add_obj(g, buttonAbout); - lv_group_add_obj(g, buMotorOff); - lv_group_add_obj(g, buttonMachinePara); - lv_group_add_obj(g, buttonLanguage); - #if ENABLED(USE_WIFI_FUNCTION) - lv_group_add_obj(g, buttonWifi); - #endif - lv_group_add_obj(g, buttonBack); - } + lv_big_button_create(scr, "F:/bmp_wifi.bin", set_menu.wifi, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_S_WIFI); #endif + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_S_RETURN); } void lv_clear_set() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_step_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_step_settings.cpp index 9f09389146..b2b1b00c3b 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_step_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_step_settings.cpp @@ -29,243 +29,100 @@ #include "../../../../module/planner.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_STEP_RETURN 1 -#define ID_STEP_X 2 -#define ID_STEP_Y 3 -#define ID_STEP_Z 4 -#define ID_STEP_E0 5 -#define ID_STEP_E1 6 -#define ID_STEP_DOWN 7 -#define ID_STEP_UP 8 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_STEP_RETURN = 1, + ID_STEP_X, + ID_STEP_Y, + ID_STEP_Z, + ID_STEP_E0, + ID_STEP_E1, + ID_STEP_DOWN, + ID_STEP_UP +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_STEP_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_step_settings(); - draw_return_ui(); - } + uiCfg.para_ui_page = 0; + lv_clear_step_settings(); + draw_return_ui(); break; case ID_STEP_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = Xstep; - lv_clear_step_settings(); - lv_draw_number_key(); - } + value = Xstep; + lv_clear_step_settings(); + lv_draw_number_key(); break; case ID_STEP_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = Ystep; - lv_clear_step_settings(); - lv_draw_number_key(); - } + value = Ystep; + lv_clear_step_settings(); + lv_draw_number_key(); break; case ID_STEP_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = Zstep; - lv_clear_step_settings(); - lv_draw_number_key(); - } + value = Zstep; + lv_clear_step_settings(); + lv_draw_number_key(); break; case ID_STEP_E0: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = E0step; - lv_clear_step_settings(); - lv_draw_number_key(); - } + value = E0step; + lv_clear_step_settings(); + lv_draw_number_key(); break; case ID_STEP_E1: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = E1step; - lv_clear_step_settings(); - lv_draw_number_key(); - } + value = E1step; + lv_clear_step_settings(); + lv_draw_number_key(); break; case ID_STEP_UP: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_step_settings(); - lv_draw_step_settings(); - } + uiCfg.para_ui_page = 0; + lv_clear_step_settings(); + lv_draw_step_settings(); break; case ID_STEP_DOWN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 1; - lv_clear_step_settings(); - lv_draw_step_settings(); - } + uiCfg.para_ui_page = 1; + lv_clear_step_settings(); + lv_draw_step_settings(); break; } } void lv_draw_step_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL, *buttonTurnPage = NULL, *labelTurnPage = NULL; - lv_obj_t *buttonXValue = NULL, *labelXValue = NULL; - lv_obj_t *buttonYValue = NULL, *labelYValue = NULL; - lv_obj_t *buttonZValue = NULL, *labelZValue = NULL; - lv_obj_t *buttonE0Value = NULL, *labelE0Value = NULL; - lv_obj_t *buttonE1Value = NULL, *labelE1Value = NULL; - lv_obj_t *line1 = NULL, *line2 = NULL, *line3 = NULL, *line4 = NULL; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != STEPS_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = STEPS_UI; } disp_state = STEPS_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, machine_menu.StepsConfTitle); - lv_refr_now(lv_refr_get_disp_refreshing()); if (uiCfg.para_ui_page != 1) { - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.X_Steps); - - buttonXValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_STEP_X); - labelXValue = lv_label_create_empty(buttonXValue); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10, machine_menu.Y_Steps); - - buttonYValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_STEP_Y); - labelYValue = lv_label_create_empty(buttonYValue); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[X_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.X_Steps, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_STEP_X, 0, public_buf_l); - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10, machine_menu.Z_Steps); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[Y_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.Y_Steps, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_STEP_Y, 1, public_buf_l); - buttonZValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_STEP_Z); - labelZValue = lv_label_create_empty(buttonZValue); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[Z_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.Z_Steps, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_STEP_Z, 2, public_buf_l); - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[E_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.E0_Steps, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_STEP_E0, 3, public_buf_l); - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10, machine_menu.E0_Steps); - - buttonE0Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_STEP_E0); - labelE0Value = lv_label_create_empty(buttonE0Value); - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - buttonTurnPage = lv_btn_create(scr, event_handler, ID_STEP_DOWN); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonXValue); - lv_group_add_obj(g, buttonYValue); - lv_group_add_obj(g, buttonZValue); - lv_group_add_obj(g, buttonE0Value); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.next, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_STEP_DOWN, true); } else { - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.E1_Steps); - - buttonE1Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_STEP_E1); - labelE1Value = lv_label_create_empty(buttonE1Value); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[E_AXIS_N(1)]); + lv_screen_menu_item_1_edit(scr, machine_menu.E1_Steps, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_STEP_E1, 0, public_buf_l); - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonTurnPage = lv_btn_create(scr, event_handler, ID_STEP_UP); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonE1Value); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.previous, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_STEP_UP, true); } - lv_obj_set_pos(buttonTurnPage, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y); - lv_obj_set_size(buttonTurnPage, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - labelTurnPage = lv_label_create_empty(buttonTurnPage); - - buttonBack = lv_btn_create(scr, NULL); - lv_btn_set_style_both(buttonBack, &style_para_back); - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_obj_set_size(buttonBack, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_STEP_RETURN, NULL, 0); - label_Back = lv_label_create_empty(buttonBack); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - if (gCfgItems.multiple_language) { - if (uiCfg.para_ui_page != 1) { - lv_label_set_text(labelTurnPage, machine_menu.next); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[X_AXIS]); - lv_label_set_text(labelXValue, public_buf_l); - lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[Y_AXIS]); - lv_label_set_text(labelYValue, public_buf_l); - lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[Z_AXIS]); - lv_label_set_text(labelZValue, public_buf_l); - lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[E_AXIS]); - lv_label_set_text(labelE0Value, public_buf_l); - lv_obj_align(labelE0Value, buttonE0Value, LV_ALIGN_CENTER, 0, 0); - } - else { - lv_label_set_text(labelTurnPage, machine_menu.previous); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[E_AXIS_N(1)]); - lv_label_set_text(labelE1Value, public_buf_l); - lv_obj_align(labelE1Value, buttonE1Value, LV_ALIGN_CENTER, 0, 0); - } - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_STEP_RETURN, true); } void lv_clear_step_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_tmc_current_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_tmc_current_settings.cpp index a05cc257a8..777b93d1f5 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_tmc_current_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_tmc_current_settings.cpp @@ -30,304 +30,138 @@ #include "../../../../feature/tmc_util.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_TMC_CURRENT_RETURN 1 -#define ID_TMC_CURRENT_X 2 -#define ID_TMC_CURRENT_Y 3 -#define ID_TMC_CURRENT_Z 4 -#define ID_TMC_CURRENT_E0 5 -#define ID_TMC_CURRENT_E1 6 -#define ID_TMC_CURRENT_DOWN 7 -#define ID_TMC_CURRENT_UP 8 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_TMC_CURRENT_RETURN = 1, + ID_TMC_CURRENT_X, + ID_TMC_CURRENT_Y, + ID_TMC_CURRENT_Z, + ID_TMC_CURRENT_E0, + ID_TMC_CURRENT_E1, + ID_TMC_CURRENT_DOWN, + ID_TMC_CURRENT_UP +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_TMC_CURRENT_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_tmc_current_settings(); - draw_return_ui(); - } + uiCfg.para_ui_page = 0; + lv_clear_tmc_current_settings(); + draw_return_ui(); break; + #if AXIS_IS_TMC(X) case ID_TMC_CURRENT_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = Xcurrent; - lv_clear_tmc_current_settings(); - lv_draw_number_key(); - } + value = Xcurrent; + lv_clear_tmc_current_settings(); + lv_draw_number_key(); break; #endif - #if AXIS_IS_TMC(Y) - case ID_TMC_CURRENT_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { + case ID_TMC_CURRENT_Y: value = Ycurrent; lv_clear_tmc_current_settings(); lv_draw_number_key(); - } - break; + break; #endif - #if AXIS_IS_TMC(Z) - case ID_TMC_CURRENT_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { + case ID_TMC_CURRENT_Z: value = Zcurrent; lv_clear_tmc_current_settings(); lv_draw_number_key(); - } - break; + break; #endif - #if AXIS_IS_TMC(E0) case ID_TMC_CURRENT_E0: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = E0current; - lv_clear_tmc_current_settings(); - lv_draw_number_key(); - } + value = E0current; + lv_clear_tmc_current_settings(); + lv_draw_number_key(); break; #endif - #if AXIS_IS_TMC(E1) case ID_TMC_CURRENT_E1: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = E1current; - lv_clear_tmc_current_settings(); - lv_draw_number_key(); - } + value = E1current; + lv_clear_tmc_current_settings(); + lv_draw_number_key(); break; #endif - case ID_TMC_CURRENT_UP: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_tmc_current_settings(); - lv_draw_tmc_current_settings(); - } + case ID_TMC_CURRENT_UP: + uiCfg.para_ui_page = 0; + lv_clear_tmc_current_settings(); + lv_draw_tmc_current_settings(); break; case ID_TMC_CURRENT_DOWN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 1; - lv_clear_tmc_current_settings(); - lv_draw_tmc_current_settings(); - } + uiCfg.para_ui_page = 1; + lv_clear_tmc_current_settings(); + lv_draw_tmc_current_settings(); break; } } void lv_draw_tmc_current_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL; - lv_obj_t *buttonXValue = NULL, *labelXValue = NULL; - lv_obj_t *buttonYValue = NULL, *labelYValue = NULL; - lv_obj_t *buttonZValue = NULL, *labelZValue = NULL; - lv_obj_t *buttonE0Value = NULL, *labelE0Value = NULL; - - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL, * line4 = NULL; - //#if AXIS_IS_TMC(E1) - lv_obj_t *buttonTurnPage = NULL, *labelTurnPage = NULL; - lv_obj_t *labelE1Text = NULL, *buttonE1Value = NULL, *labelE1Value = NULL; - //#endif - float milliamps; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != TMC_CURRENT_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = TMC_CURRENT_UI; } disp_state = TMC_CURRENT_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, machine_menu.TmcCurrentConfTitle); - lv_refr_now(lv_refr_get_disp_refreshing()); + float milliamps; if (uiCfg.para_ui_page != 1) { - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.X_Current); - - buttonXValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_TMC_CURRENT_X); - labelXValue = lv_label_create_empty(buttonXValue); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10, machine_menu.Y_Current); - - buttonYValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_TMC_CURRENT_Y); - labelYValue = lv_label_create_empty(buttonYValue); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10, machine_menu.Z_Current); - - buttonZValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_TMC_CURRENT_Z); - labelZValue = lv_label_create_empty(buttonZValue); - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - (void)lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10, machine_menu.E0_Current); - - buttonE0Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_TMC_CURRENT_E0); - labelE0Value = lv_label_create_empty(buttonE0Value); + #if AXIS_IS_TMC(X) + milliamps = stepperX.getMilliamps(); + #else + milliamps = -1; + #endif + sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); + lv_screen_menu_item_1_edit(scr, machine_menu.X_Current, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_TMC_CURRENT_X, 0, public_buf_l); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonXValue); - lv_group_add_obj(g, buttonYValue); - lv_group_add_obj(g, buttonZValue); - lv_group_add_obj(g, buttonE0Value); - } + #if AXIS_IS_TMC(Y) + milliamps = stepperY.getMilliamps(); + #else + milliamps = -1; #endif + sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); + lv_screen_menu_item_1_edit(scr, machine_menu.Y_Current, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_TMC_CURRENT_Y, 1, public_buf_l); - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); + #if AXIS_IS_TMC(Z) + milliamps = stepperZ.getMilliamps(); + #else + milliamps = -1; + #endif + sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); + lv_screen_menu_item_1_edit(scr, machine_menu.Z_Current, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_TMC_CURRENT_Z, 2, public_buf_l); - //#if AXIS_IS_TMC(E1) - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_TMC_CURRENT_DOWN, NULL, 0); - lv_btn_set_style_both(buttonTurnPage, &style_para_back); + #if AXIS_IS_TMC(E0) + milliamps = stepperE0.getMilliamps(); + #else + milliamps = -1; + #endif + sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); + lv_screen_menu_item_1_edit(scr, machine_menu.E0_Current, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_TMC_CURRENT_E0, 3, public_buf_l); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonTurnPage); - #endif - //#endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.next, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_TMC_CURRENT_DOWN, true); } else { - //#if AXIS_IS_TMC(E1) - labelE1Text = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.E1_Current); - - buttonE1Value = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_TMC_CURRENT_E1); - labelE1Value = lv_label_create_empty(buttonE1Value); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_TMC_CURRENT_UP, NULL, 0); - lv_btn_set_style_both(buttonTurnPage, &style_para_back); + #if AXIS_IS_TMC(E1) + milliamps = stepperE1.getMilliamps(); + #else + milliamps = -1; + #endif + sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); + lv_screen_menu_item_1_edit(scr, machine_menu.E1_Current, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_TMC_CURRENT_E1, 0, public_buf_l); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonE1Value); - lv_group_add_obj(g, buttonTurnPage); - } - #endif - //#endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.previous, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_TMC_CURRENT_UP, true); } - //#if AXIS_IS_TMC(E1) - lv_obj_set_pos(buttonTurnPage, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y); - lv_obj_set_size(buttonTurnPage, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - labelTurnPage = lv_label_create_empty(buttonTurnPage); - //#endif - buttonBack = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_TMC_CURRENT_RETURN, NULL, 0); - lv_btn_set_style_both(buttonBack, &style_para_back); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_obj_set_size(buttonBack, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - if (uiCfg.para_ui_page != 1) { - //#if AXIS_IS_TMC(E1) - lv_label_set_text(labelTurnPage, machine_menu.next); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - //#endif - #if AXIS_IS_TMC(X) - milliamps = stepperX.getMilliamps(); - #else - milliamps = -1; - #endif - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); - lv_label_set_text(labelXValue, public_buf_l); - lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0); - - #if AXIS_IS_TMC(Y) - milliamps = stepperY.getMilliamps(); - #else - milliamps = -1; - #endif - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); - lv_label_set_text(labelYValue, public_buf_l); - lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0); - - #if AXIS_IS_TMC(Z) - milliamps = stepperZ.getMilliamps(); - #else - milliamps = -1; - #endif - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); - lv_label_set_text(labelZValue, public_buf_l); - lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0); - - #if AXIS_IS_TMC(E0) - milliamps = stepperE0.getMilliamps(); - #else - milliamps = -1; - #endif - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); - lv_label_set_text(labelE0Value, public_buf_l); - lv_obj_align(labelE0Value, buttonE0Value, LV_ALIGN_CENTER, 0, 0); - } - else { - //#if AXIS_IS_TMC(E1) - lv_label_set_text(labelTurnPage, machine_menu.previous); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - #if AXIS_IS_TMC(E1) - milliamps = stepperE1.getMilliamps(); - #else - milliamps = -1; - #endif - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); - lv_label_set_text(labelE1Value, public_buf_l); - lv_obj_align(labelE1Value, buttonE1Value, LV_ALIGN_CENTER, 0, 0); - //#endif - } - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_TMC_CURRENT_RETURN, true); } void lv_clear_tmc_current_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_tmc_step_mode_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_tmc_step_mode_settings.cpp index 2140af0793..3814dacfe1 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_tmc_step_mode_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_tmc_step_mode_settings.cpp @@ -34,185 +34,83 @@ #include "../../../../module/settings.h" #endif -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_TMC_MODE_RETURN 1 -#define ID_TMC_MODE_X 2 -#define ID_TMC_MODE_Y 3 -#define ID_TMC_MODE_Z 4 -#define ID_TMC_MODE_E0 5 -#define ID_TMC_MODE_E1 6 -#define ID_TMC_MODE_DOWN 7 -#define ID_TMC_MODE_UP 8 - -static lv_obj_t *labelXState = NULL, *labelYState = NULL, *labelZState = NULL, *labelE0State = NULL; -static lv_obj_t *buttonXState = NULL, *buttonYState = NULL, *buttonZState = NULL, *buttonE0State = NULL; +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_TMC_MODE_RETURN = 1, + ID_TMC_MODE_X, + ID_TMC_MODE_Y, + ID_TMC_MODE_Z, + ID_TMC_MODE_E0, + ID_TMC_MODE_E1, + ID_TMC_MODE_DOWN, + ID_TMC_MODE_UP +}; + +static lv_obj_t *buttonXState = nullptr, *buttonYState = nullptr, *buttonZState = nullptr, *buttonE0State = nullptr; //#if AXIS_HAS_STEALTHCHOP(E1) - static lv_obj_t *labelE1State = NULL, *buttonE1State = NULL; + static lv_obj_t *buttonE1State = nullptr; //#endif -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; + + auto toggle_chop = [&](auto &stepper, auto &button) { + const bool isena = stepper.toggle_stepping_mode(); + lv_screen_menu_item_onoff_update(button, isena); + TERN_(EEPROM_SETTINGS, (void)settings.save()); + }; + switch (obj->mks_obj_id) { case ID_TMC_MODE_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_tmc_step_mode_settings(); - draw_return_ui(); - } + uiCfg.para_ui_page = 0; + lv_clear_tmc_step_mode_settings(); + draw_return_ui(); break; #if AXIS_HAS_STEALTHCHOP(X) case ID_TMC_MODE_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (stepperX.toggle_stepping_mode()) { - lv_imgbtn_set_src_both(buttonXState, "F:/bmp_enable.bin"); - lv_label_set_text(labelXState, machine_menu.enable); - } - else { - lv_imgbtn_set_src_both(buttonXState, "F:/bmp_disable.bin"); - lv_label_set_text(labelXState, machine_menu.disable); - //lv_obj_align(labelXState, buttonE1State, LV_ALIGN_IN_LEFT_MID,0, 0); - } - TERN_(EEPROM_SETTINGS, (void)settings.save()); - } + toggle_chop(stepperX, buttonXState); break; - #endif // if AXIS_HAS_STEALTHCHOP(X) - + #endif #if AXIS_HAS_STEALTHCHOP(Y) case ID_TMC_MODE_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (stepperY.toggle_stepping_mode()) { - lv_imgbtn_set_src_both(buttonYState, "F:/bmp_enable.bin"); - lv_label_set_text(labelYState, machine_menu.enable); - } - else { - lv_imgbtn_set_src_both(buttonYState, "F:/bmp_disable.bin"); - lv_label_set_text(labelYState, machine_menu.disable); - //lv_obj_align(labelXState, buttonE1State, LV_ALIGN_IN_LEFT_MID,0, 0); - } - TERN_(EEPROM_SETTINGS, (void)settings.save()); - } + toggle_chop(stepperY, buttonYState); break; - #endif // if AXIS_HAS_STEALTHCHOP(Y) - + #endif #if AXIS_HAS_STEALTHCHOP(Z) case ID_TMC_MODE_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (stepperZ.toggle_stepping_mode()) { - lv_imgbtn_set_src_both(buttonZState, "F:/bmp_enable.bin"); - lv_label_set_text(labelZState, machine_menu.enable); - } - else { - lv_imgbtn_set_src_both(buttonZState, "F:/bmp_disable.bin"); - lv_label_set_text(labelZState, machine_menu.disable); - //lv_obj_align(labelXState, buttonE1State, LV_ALIGN_IN_LEFT_MID,0, 0); - } - TERN_(EEPROM_SETTINGS, (void)settings.save()); - } + toggle_chop(stepperZ, buttonZState); break; - #endif // if AXIS_HAS_STEALTHCHOP(Z) - + #endif #if AXIS_HAS_STEALTHCHOP(E0) case ID_TMC_MODE_E0: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (stepperE0.toggle_stepping_mode()) { - lv_imgbtn_set_src_both(buttonE0State, "F:/bmp_enable.bin"); - lv_label_set_text(labelE0State, machine_menu.enable); - } - else { - lv_imgbtn_set_src_both(buttonE0State, "F:/bmp_disable.bin"); - lv_label_set_text(labelE0State, machine_menu.disable); - //lv_obj_align(labelXState, buttonE1State, LV_ALIGN_IN_LEFT_MID,0, 0); - } - TERN_(EEPROM_SETTINGS, (void)settings.save()); - } + toggle_chop(stepperE0, buttonE0State); break; - #endif // if AXIS_HAS_STEALTHCHOP(E0) - + #endif #if AXIS_HAS_STEALTHCHOP(E1) case ID_TMC_MODE_E1: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (stepperE1.toggle_stepping_mode()) { - lv_imgbtn_set_src_both(buttonE1State, "F:/bmp_enable.bin"); - lv_label_set_text(labelE1State, machine_menu.enable); - } - else { - lv_imgbtn_set_src_both(buttonE1State, "F:/bmp_disable.bin"); - lv_label_set_text(labelE1State, machine_menu.disable); - //lv_obj_align(labelXState, buttonE1State, LV_ALIGN_IN_LEFT_MID,0, 0); - } - TERN_(EEPROM_SETTINGS, (void)settings.save()); - } + toggle_chop(stepperE1, buttonE1State); break; - #endif // if AXIS_HAS_STEALTHCHOP(E1) - case ID_TMC_MODE_UP: - if (event == LV_EVENT_CLICKED) { + #endif - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_tmc_step_mode_settings(); - lv_draw_tmc_step_mode_settings(); - } + case ID_TMC_MODE_UP: + uiCfg.para_ui_page = 0; + lv_clear_tmc_step_mode_settings(); + lv_draw_tmc_step_mode_settings(); break; case ID_TMC_MODE_DOWN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 1; - lv_clear_tmc_step_mode_settings(); - lv_draw_tmc_step_mode_settings(); - } + uiCfg.para_ui_page = 1; + lv_clear_tmc_step_mode_settings(); + lv_draw_tmc_step_mode_settings(); break; } } void lv_draw_tmc_step_mode_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL; - lv_obj_t *buttonXText = NULL, *labelXText = NULL; - lv_obj_t *buttonYText = NULL, *labelYText = NULL; - lv_obj_t *buttonZText = NULL, *labelZText = NULL; - lv_obj_t *buttonE0Text = NULL, *labelE0Text = NULL; - - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL, * line4 = NULL; - //#if AXIS_HAS_STEALTHCHOP(E1) - lv_obj_t *buttonTurnPage = NULL, *labelTurnPage = NULL; - lv_obj_t *buttonE1Text = NULL, *labelE1Text = NULL; - //#endif - - labelXState = NULL; - buttonXState = NULL; - labelYState = NULL; - buttonYState = NULL; - labelZState = NULL; - buttonZState = NULL; - labelE0State = NULL; - buttonE0State = NULL; - //#if AXIS_HAS_STEALTHCHOP(E1) - labelE1State = NULL; - buttonE1State = NULL; - //#endif + buttonXState = buttonYState = buttonZState = buttonE0State = buttonE1State = nullptr; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != TMC_MODE_UI) { disp_state_stack._disp_index++; @@ -220,14 +118,8 @@ void lv_draw_tmc_step_mode_settings(void) { } disp_state = TMC_MODE_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, machine_menu.TmcStepModeConfTitle); - lv_refr_now(lv_refr_get_disp_refreshing()); bool stealth_X = false, stealth_Y = false, stealth_Z = false, stealth_E0 = false, stealth_E1 = false; @@ -248,136 +140,18 @@ void lv_draw_tmc_step_mode_settings(void) { #endif if (uiCfg.para_ui_page != 1) { - buttonXText = lv_btn_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y, PARA_UI_VALUE_SIZE_X, PARA_UI_SIZE_Y, event_handler, 0); - labelXText = lv_label_create_empty(buttonXText); /*Add a label to the button*/ - - buttonXState = lv_imgbtn_create(scr, stealth_X ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin", PARA_UI_STATE_POS_X, PARA_UI_POS_Y + PARA_UI_STATE_V, event_handler, ID_TMC_MODE_X); - labelXState = lv_label_create_empty(buttonXState); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonXState); - #endif - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonYText = lv_btn_create(scr, NULL, PARA_UI_POS_X, PARA_UI_POS_Y * 2, PARA_UI_VALUE_SIZE_X, PARA_UI_SIZE_Y, event_handler, 0); - labelYText = lv_label_create_empty(buttonYText); /*Add a label to the button*/ - - buttonYState = lv_imgbtn_create(scr, stealth_Y ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin", PARA_UI_STATE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_STATE_V, event_handler, ID_TMC_MODE_Y); - labelYState = lv_label_create_empty(buttonYState); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonYState); - #endif - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - buttonZText = lv_btn_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3, PARA_UI_VALUE_SIZE_X, PARA_UI_SIZE_Y, event_handler, 0); - labelZText = lv_label_create_empty(buttonZText); /*Add a label to the button*/ - - buttonZState = lv_imgbtn_create(scr, stealth_Z ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin", PARA_UI_STATE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_STATE_V, event_handler, ID_TMC_MODE_Z); - labelZState = lv_label_create_empty(buttonZState); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonZState); - #endif - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - buttonE0Text = lv_btn_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 4, PARA_UI_VALUE_SIZE_X, PARA_UI_SIZE_Y, event_handler, 0); - labelE0Text = lv_label_create_empty(buttonE0Text); /*Add a label to the button*/ - - buttonE0State = lv_imgbtn_create(scr, stealth_E0 ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin", PARA_UI_STATE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_STATE_V, event_handler, ID_TMC_MODE_E0); - labelE0State = lv_label_create_empty(buttonE0State); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonE0State); - #endif - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - //#if AXIS_HAS_STEALTHCHOP(E1) - buttonTurnPage = lv_imgbtn_create(scr, "F:/bmp_back70x40.bin", event_handler, ID_TMC_MODE_DOWN); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonTurnPage); - #endif - //#endif + buttonXState = lv_screen_menu_item_onoff(scr, machine_menu.X_StepMode, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_TMC_MODE_X, 0, stealth_X); + buttonYState = lv_screen_menu_item_onoff(scr, machine_menu.Y_StepMode, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_TMC_MODE_Y, 1, stealth_Y); + buttonZState = lv_screen_menu_item_onoff(scr, machine_menu.Z_StepMode, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_TMC_MODE_Z, 2, stealth_Z); + buttonE0State = lv_screen_menu_item_onoff(scr, machine_menu.E0_StepMode, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_TMC_MODE_E0, 2, stealth_E0); + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.next, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_TMC_MODE_DOWN, true); } else { - //#if AXIS_HAS_STEALTHCHOP(E1) - buttonE1Text = lv_btn_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y, PARA_UI_VALUE_SIZE_X, PARA_UI_SIZE_Y, event_handler, 0); - labelE1Text = lv_label_create_empty(buttonE1Text); /*Add a label to the button*/ - - buttonE1State = lv_imgbtn_create(scr, stealth_E1 ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin", PARA_UI_STATE_POS_X, PARA_UI_POS_Y + PARA_UI_STATE_V, event_handler, ID_TMC_MODE_E1); - labelE1State = lv_label_create_empty(buttonE1State); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonE1State); - #endif - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonTurnPage = lv_imgbtn_create(scr, "F:/bmp_back70x40.bin", event_handler, ID_TMC_MODE_UP); - //#endif + buttonE1State = lv_screen_menu_item_onoff(scr, machine_menu.E1_StepMode, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_TMC_MODE_E1, 0, stealth_E1); + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.previous, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_TMC_MODE_UP, true); } - //#if AXIS_HAS_STEALTHCHOP(E1) - lv_obj_set_pos(buttonTurnPage, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y); - lv_btn_set_layout(buttonTurnPage, LV_LAYOUT_OFF); - labelTurnPage = lv_label_create_empty(buttonTurnPage); - //#endif - - buttonBack = lv_imgbtn_create(scr, "F:/bmp_back70x40.bin", PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_TMC_MODE_RETURN); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - if (uiCfg.para_ui_page != 1) { - lv_label_set_text(labelXText, machine_menu.X_StepMode); - lv_obj_align(labelXText, buttonXText, LV_ALIGN_IN_LEFT_MID, 0, 0); - - lv_label_set_text(labelYText, machine_menu.Y_StepMode); - lv_obj_align(labelYText, buttonYText, LV_ALIGN_IN_LEFT_MID, 0, 0); - - lv_label_set_text(labelZText, machine_menu.Z_StepMode); - lv_obj_align(labelZText, buttonZText, LV_ALIGN_IN_LEFT_MID, 0, 0); - - lv_label_set_text(labelE0Text, machine_menu.E0_StepMode); - lv_obj_align(labelE0Text, buttonE0Text, LV_ALIGN_IN_LEFT_MID, 0, 0); - lv_label_set_text(labelXState, stealth_X ? machine_menu.enable : machine_menu.disable); - lv_obj_align(labelXState, buttonXState, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelYState, stealth_Y ? machine_menu.enable : machine_menu.disable); - lv_obj_align(labelYState, buttonYState, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelZState, stealth_Z ? machine_menu.enable : machine_menu.disable); - lv_obj_align(labelZState, buttonZState, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelE0State, stealth_E0 ? machine_menu.enable : machine_menu.disable); - lv_obj_align(labelE0State, buttonE0State, LV_ALIGN_CENTER, 0, 0); - - //#if AXIS_HAS_STEALTHCHOP(E1) - lv_label_set_text(labelTurnPage, machine_menu.next); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - //#endif - } - else { - //#if AXIS_HAS_STEALTHCHOP(E1) - lv_label_set_text(labelE1Text, machine_menu.E1_StepMode); - lv_obj_align(labelE1Text, buttonE1Text, LV_ALIGN_IN_LEFT_MID, 0, 0); - lv_label_set_text(labelE1State, stealth_E1 ? machine_menu.enable : machine_menu.disable); - lv_obj_align(labelE1State, buttonE1State, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelTurnPage, machine_menu.previous); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - //#endif - } - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_TMC_MODE_RETURN, true); } void lv_clear_tmc_step_mode_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_tool.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_tool.cpp index 8f31072978..2bbd544cc8 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_tool.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_tool.cpp @@ -34,182 +34,92 @@ #include "../../../../module/temperature.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; - -#define ID_T_PRE_HEAT 1 -#define ID_T_EXTRUCT 2 -#define ID_T_MOV 3 -#define ID_T_HOME 4 -#define ID_T_LEVELING 5 -#define ID_T_FILAMENT 6 -#define ID_T_MORE 7 -#define ID_T_RETURN 8 +extern lv_group_t *g; +static lv_obj_t *scr; + +enum { + ID_T_PRE_HEAT = 1, + ID_T_EXTRUCT, + ID_T_MOV, + ID_T_HOME, + ID_T_LEVELING, + ID_T_FILAMENT, + ID_T_MORE, + ID_T_RETURN +}; #if ENABLED(MKS_TEST) extern uint8_t curent_disp_ui; #endif -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_T_PRE_HEAT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_tool(); - lv_draw_preHeat(); - } + lv_clear_tool(); + lv_draw_preHeat(); break; case ID_T_EXTRUCT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_tool(); - lv_draw_extrusion(); - } + lv_clear_tool(); + lv_draw_extrusion(); break; case ID_T_MOV: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_tool(); - lv_draw_move_motor(); - } + lv_clear_tool(); + lv_draw_move_motor(); break; case ID_T_HOME: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_tool(); - lv_draw_home(); - } + lv_clear_tool(); + lv_draw_home(); break; case ID_T_LEVELING: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - #if ENABLED(AUTO_BED_LEVELING_BILINEAR) - //queue.enqueue_one_P(PSTR("G28")); - //queue.enqueue_one_P(PSTR("G29")); - get_gcode_command(AUTO_LEVELING_COMMAND_ADDR,(uint8_t *)public_buf_m); - public_buf_m[sizeof(public_buf_m)-1] = 0; - queue.inject_P(PSTR(public_buf_m)); - #else - uiCfg.leveling_first_time = 1; - lv_clear_tool(); - lv_draw_manualLevel(); - #endif - } + #if ENABLED(AUTO_BED_LEVELING_BILINEAR) + //queue.enqueue_one_P(PSTR("G28")); + //queue.enqueue_one_P(PSTR("G29")); + get_gcode_command(AUTO_LEVELING_COMMAND_ADDR,(uint8_t *)public_buf_m); + public_buf_m[sizeof(public_buf_m)-1] = 0; + queue.inject_P(PSTR(public_buf_m)); + #else + uiCfg.leveling_first_time = 1; + lv_clear_tool(); + lv_draw_manualLevel(); + #endif break; case ID_T_FILAMENT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.desireSprayerTempBak = thermalManager.temp_hotend[uiCfg.curSprayerChoose].target; - lv_clear_tool(); - lv_draw_filament_change(); - } + uiCfg.desireSprayerTempBak = thermalManager.temp_hotend[uiCfg.curSprayerChoose].target; + lv_clear_tool(); + lv_draw_filament_change(); break; case ID_T_MORE: break; case ID_T_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - TERN_(MKS_TEST, curent_disp_ui = 1); - lv_clear_tool(); - lv_draw_ready_print(); - } + TERN_(MKS_TEST, curent_disp_ui = 1); + lv_clear_tool(); + lv_draw_ready_print(); break; } } void lv_draw_tool(void) { - lv_obj_t *buttonPreHeat, *buttonExtrusion, *buttonMove, *buttonHome, *buttonLevel; - lv_obj_t *buttonFilament; - lv_obj_t *buttonBack; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != TOOL_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = TOOL_UI; } disp_state = TOOL_UI; - scr = lv_obj_create(NULL, NULL); - - //static lv_style_t tool_style; - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); - // Create image buttons - buttonPreHeat = lv_imgbtn_create(scr, "F:/bmp_preHeat.bin", INTERVAL_V, titleHeight, event_handler, ID_T_PRE_HEAT); - buttonExtrusion = lv_imgbtn_create(scr, "F:/bmp_extruct.bin", BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_T_EXTRUCT); - buttonMove = lv_imgbtn_create(scr, "F:/bmp_mov.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_T_MOV); - buttonHome = lv_imgbtn_create(scr, "F:/bmp_zero.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_T_HOME); - buttonLevel = lv_imgbtn_create(scr, "F:/bmp_leveling.bin", INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_T_LEVELING); - buttonFilament = lv_imgbtn_create(scr, "F:/bmp_filamentchange.bin",BTN_X_PIXEL+INTERVAL_V*2,BTN_Y_PIXEL+INTERVAL_H+titleHeight, event_handler,ID_T_FILAMENT); - //buttonMore = lv_imgbtn_createx(scr, NULL); - //lv_obj_set_pos(buttonMore,BTN_X_PIXEL*2+INTERVAL_V*3, BTN_Y_PIXEL+INTERVAL_H+titleHeight); - buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_T_RETURN); - - // Create labels on the image buttons - lv_obj_t *labelPreHeat = lv_label_create_empty(buttonPreHeat); - lv_obj_t *labelExtrusion = lv_label_create_empty(buttonExtrusion); - lv_obj_t *label_Move = lv_label_create_empty(buttonMove); - lv_obj_t *label_Home = lv_label_create_empty(buttonHome); - lv_obj_t *label_Level = lv_label_create_empty(buttonLevel); - lv_obj_t *label_Filament = lv_label_create_empty(buttonFilament); - //lv_obj_t *label_More = lv_label_create_empty(buttonMore); - lv_obj_t *label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.multiple_language) { - lv_label_set_text(labelPreHeat, tool_menu.preheat); - lv_obj_align(labelPreHeat, buttonPreHeat, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelExtrusion, tool_menu.extrude); - lv_obj_align(labelExtrusion, buttonExtrusion, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Move, tool_menu.move); - lv_obj_align(label_Move, buttonMove, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Home, tool_menu.home); - lv_obj_align(label_Home, buttonHome, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Level, tool_menu.TERN(AUTO_BED_LEVELING_BILINEAR, autoleveling, leveling)); - lv_obj_align(label_Level, buttonLevel, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Filament, tool_menu.filament); - lv_obj_align(label_Filament, buttonFilament, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - //lv_label_set_text(label_More, tool_menu.more); - //lv_obj_align(label_More, buttonMore, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonPreHeat); - lv_group_add_obj(g, buttonExtrusion); - lv_group_add_obj(g, buttonMove); - lv_group_add_obj(g, buttonHome); - lv_group_add_obj(g, buttonLevel); - lv_group_add_obj(g, buttonFilament); - lv_group_add_obj(g, buttonBack); - } - #endif + lv_big_button_create(scr, "F:/bmp_preHeat.bin", tool_menu.preheat, INTERVAL_V, titleHeight, event_handler, ID_T_PRE_HEAT); + lv_big_button_create(scr, "F:/bmp_extruct.bin", tool_menu.extrude, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_T_EXTRUCT); + + lv_big_button_create(scr, "F:/bmp_mov.bin", tool_menu.move, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_T_MOV); + lv_big_button_create(scr, "F:/bmp_zero.bin", tool_menu.home, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_T_HOME); + + lv_big_button_create(scr, "F:/bmp_leveling.bin", tool_menu.TERN(AUTO_BED_LEVELING_BILINEAR, autoleveling, leveling), INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_T_LEVELING); + lv_big_button_create(scr, "F:/bmp_filamentchange.bin", tool_menu.filament, BTN_X_PIXEL+INTERVAL_V*2,BTN_Y_PIXEL+INTERVAL_H+titleHeight, event_handler,ID_T_FILAMENT); + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_T_RETURN); } void lv_clear_tool() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp index ef23305285..2de5bf25e1 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp @@ -61,13 +61,14 @@ uint32_t To_pre_view; bool gcode_preview_over, flash_preview_begin, default_preview_flg; uint32_t size = 809; uint16_t row; -uint8_t temperature_change_frequency; +bool temps_update_flag; uint8_t printing_rate_update_flag; extern bool once_flag; extern uint8_t sel_id; extern uint8_t public_buf[512]; extern uint8_t bmp_public_buf[17 * 1024]; +extern lv_group_t *g; extern void LCD_IO_WriteData(uint16_t RegValue); @@ -282,6 +283,9 @@ lv_style_t style_para_back; lv_style_t lv_bar_style_indic; +lv_style_t style_btn_pr; +lv_style_t style_btn_rel; + void tft_style_init() { lv_style_copy(&tft_style_scr, &lv_style_scr); tft_style_scr.body.main_color = LV_COLOR_BACKGROUND; @@ -399,6 +403,25 @@ void tft_style_init() { style_para_back.text.color = LV_COLOR_WHITE; style_para_back.text.font = &TERN(HAS_SPI_FLASH_FONT, gb2312_puhui32, lv_font_roboto_22); + lv_style_copy(&style_btn_rel, &lv_style_plain); + style_btn_rel.body.border.color = lv_color_hex3(0x269); + style_btn_rel.body.border.width = 1; + style_btn_rel.body.main_color = lv_color_hex3(0xADF); + style_btn_rel.body.grad_color = lv_color_hex3(0x46B); + style_btn_rel.body.shadow.width = 4; + style_btn_rel.body.shadow.type = LV_SHADOW_BOTTOM; + style_btn_rel.body.radius = LV_RADIUS_CIRCLE; + style_btn_rel.text.color = lv_color_hex3(0xDEF); + style_btn_rel.text.font = &TERN(HAS_SPI_FLASH_FONT, gb2312_puhui32, lv_font_roboto_22); + + lv_style_copy(&style_btn_pr, &style_btn_rel); + style_btn_pr.body.border.color = lv_color_hex3(0x46B); + style_btn_pr.body.main_color = lv_color_hex3(0x8BD); + style_btn_pr.body.grad_color = lv_color_hex3(0x24A); + style_btn_pr.body.shadow.width = 2; + style_btn_pr.text.color = lv_color_hex3(0xBCD); + style_btn_pr.text.font = &TERN(HAS_SPI_FLASH_FONT, gb2312_puhui32, lv_font_roboto_22); + lv_style_copy(&lv_bar_style_indic, &lv_style_pretty_color); lv_bar_style_indic.text.color = lv_color_hex3(0xADF); lv_bar_style_indic.image.color = lv_color_hex3(0xADF); @@ -421,7 +444,6 @@ void titleText_cat(char *str, int strSize, char *addPart) { char *getDispText(int index) { - ZERO(public_buf_l); switch (disp_state_stack._disp_state[index]) { case PRINT_READY_UI: @@ -926,30 +948,30 @@ void print_time_run() { } void GUI_RefreshPage() { - if ((systick_uptime_millis % 1000) == 0) temperature_change_frequency = 1; - if ((systick_uptime_millis % 3000) == 0) printing_rate_update_flag = 1; + if ((systick_uptime_millis % 1000) == 0) temps_update_flag = true; + if ((systick_uptime_millis % 3000) == 0) printing_rate_update_flag = true; switch (disp_state) { case MAIN_UI: //lv_draw_ready_print(); break; case EXTRUSION_UI: - if (temperature_change_frequency == 1) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_hotend_temp(); } break; case PRE_HEAT_UI: - if (temperature_change_frequency == 1) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_desire_temp(); } break; case PRINT_READY_UI: /* if (gCfgItems.display_style == 2) { - if (temperature_change_frequency) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_restro_state(); } } @@ -959,8 +981,8 @@ void GUI_RefreshPage() { case PRINT_FILE_UI: break; case PRINTING_UI: - if (temperature_change_frequency) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_ext_temp(); disp_bed_temp(); disp_fan_speed(); @@ -968,15 +990,15 @@ void GUI_RefreshPage() { disp_fan_Zpos(); } if (printing_rate_update_flag || marlin_state == MF_SD_COMPLETE) { - printing_rate_update_flag = 0; + printing_rate_update_flag = false; if (!gcode_preview_over) setProBarRate(); } break; case OPERATE_UI: /* - if (temperature_change_frequency == 1) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_temp_operate(); } @@ -986,16 +1008,16 @@ void GUI_RefreshPage() { case PAUSE_UI: /* - if (temperature_change_frequency == 1) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_temp_pause(); } */ break; case FAN_UI: - if (temperature_change_frequency == 1) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_fan_value(); } break; @@ -1003,14 +1025,12 @@ void GUI_RefreshPage() { case MOVE_MOTOR_UI: /* if (mksReprint.mks_printer_state == MKS_IDLE) { - if ((z_high_count==1)&&(temper_error_flg != 1)) { + if (z_high_count == 1 && temper_error_flg != 1) { z_high_count = 0; - { - memset((char *)gCfgItems.move_z_coordinate, ' ', sizeof(gCfgItems.move_z_coordinate)); - GUI_DispStringAt((const char *)gCfgItems.move_z_coordinate, 380, TITLE_YPOS); - sprintf_P((char *)gCfgItems.move_z_coordinate, PSTR("Z: %.3f"), current_position[Z_AXIS]); - GUI_DispStringAt((const char *)gCfgItems.move_z_coordinate, 380, TITLE_YPOS); - } + memset((char *)gCfgItems.move_z_coordinate, ' ', sizeof(gCfgItems.move_z_coordinate)); + GUI_DispStringAt((const char *)gCfgItems.move_z_coordinate, 380, TITLE_YPOS); + sprintf_P((char *)gCfgItems.move_z_coordinate, PSTR("Z: %.3f"), current_position[Z_AXIS]); + GUI_DispStringAt((const char *)gCfgItems.move_z_coordinate, 380, TITLE_YPOS); } } */ @@ -1018,9 +1038,9 @@ void GUI_RefreshPage() { #if ENABLED(USE_WIFI_FUNCTION) case WIFI_UI: - if (temperature_change_frequency == 1) { + if (temps_update_flag) { disp_wifi_state(); - temperature_change_frequency = 0; + temps_update_flag = false; } break; #endif @@ -1030,8 +1050,8 @@ void GUI_RefreshPage() { break; case FILAMENTCHANGE_UI: - if (temperature_change_frequency) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_filament_temp(); } break; @@ -1046,9 +1066,9 @@ void GUI_RefreshPage() { break; case WIFI_LIST_UI: #if ENABLED(USE_WIFI_FUNCTION) - if (printing_rate_update_flag == 1) { + if (printing_rate_update_flag) { disp_wifi_list(); - printing_rate_update_flag = 0; + printing_rate_update_flag = false; } #endif break; @@ -1103,8 +1123,8 @@ void GUI_RefreshPage() { #endif case BABY_STEP_UI: - if (temperature_change_frequency == 1) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_z_offset_value(); } break; @@ -1589,21 +1609,36 @@ void lv_imgbtn_use_label_style(lv_obj_t *imgbtn) { lv_imgbtn_set_style(imgbtn, LV_BTN_STATE_PR, &tft_style_label_pre); } -// Use label style for the image button +// Use label style for the button void lv_btn_use_label_style(lv_obj_t *btn) { lv_btn_set_style(btn, LV_BTN_STYLE_REL, &tft_style_label_rel); lv_btn_set_style(btn, LV_BTN_STYLE_PR, &tft_style_label_pre); } +// Use button style for the button +void lv_btn_use_button_style(lv_obj_t *btn) { + lv_btn_set_style(btn, LV_BTN_STYLE_REL, &style_btn_rel); + lv_btn_set_style(btn, LV_BTN_STYLE_PR, &style_btn_pr); +} + // Use a single style for both Released and Pressed void lv_btn_set_style_both(lv_obj_t *btn, lv_style_t *style) { lv_btn_set_style(btn, LV_BTN_STYLE_REL, style); lv_btn_set_style(btn, LV_BTN_STYLE_PR, style); } +// Create a screen +lv_obj_t* lv_screen_create() { + lv_obj_t *scr = lv_obj_create(nullptr, nullptr); + lv_obj_set_style(scr, &tft_style_scr); + lv_scr_load(scr); + lv_obj_clean(scr); + return scr; +} + // Create an empty label lv_obj_t* lv_label_create_empty(lv_obj_t *par) { - return lv_label_create(par, (lv_obj_t*)NULL); + return lv_label_create(par, (lv_obj_t*)nullptr); } // Create a label with style and text @@ -1621,35 +1656,66 @@ lv_obj_t* lv_label_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, const char } // Create a button with callback, ID, and Style. -lv_obj_t* lv_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id, lv_style_t *style) { - lv_obj_t *btn = lv_btn_create(par, NULL); +lv_obj_t* lv_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id/*=0*/, lv_style_t *style/*=&style_para_value*/) { + lv_obj_t *btn = lv_btn_create(par, nullptr); if (id) - lv_obj_set_event_cb_mks(btn, cb, id, NULL, 0); + lv_obj_set_event_cb_mks(btn, cb, id, nullptr, 0); else lv_obj_set_event_cb(btn, cb); lv_btn_set_style_both(btn, style); return btn; } -// Create a button with callback and ID. Style set to style_para_value. -lv_obj_t* lv_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id) { - return lv_btn_create(par, cb, id, &style_para_value); +// Create a button with callback and ID, with label style. +lv_obj_t* lv_label_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id/*=0*/) { + lv_obj_t *btn = lv_btn_create(par, cb, id, nullptr); + lv_btn_use_label_style(btn); + return btn; +} + +// Create a button with callback and ID, with button style. +lv_obj_t* lv_button_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id/*=0*/) { + lv_obj_t *btn = lv_btn_create(par, cb, id, nullptr); + lv_btn_use_button_style(btn); + return btn; +} + +// Create a button with position, size, callback, ID, and style. +lv_obj_t* lv_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id, lv_style_t *style) { + lv_obj_t *btn = lv_btn_create(par, cb, id, style); + lv_obj_set_pos(btn, x, y); + lv_obj_set_size(btn, w, h); + return btn; } // Create a button with position, size, callback, and ID. Style set to style_para_value. -lv_obj_t* lv_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id) { - lv_obj_t *btn = lv_btn_create(par, cb, id); +lv_obj_t* lv_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id/*=0*/) { + lv_obj_t *btn = lv_btn_create(par, x, y, w, h, cb, id, &style_para_value); + return btn; +} + +// Create a button with position, size, callback, and ID, with label style. +lv_obj_t* lv_label_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id/*=0*/) { + lv_obj_t *btn = lv_label_btn_create(par, cb, id); + lv_obj_set_pos(btn, x, y); + lv_obj_set_size(btn, w, h); + return btn; +} + +// Create a button with position, size, callback, and ID, with label style. +lv_obj_t* lv_button_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id/*=0*/) { + lv_obj_t *btn = lv_button_btn_create(par, cb, id); lv_obj_set_pos(btn, x, y); lv_obj_set_size(btn, w, h); return btn; } // Create a button with callback and ID. Style set to style_para_back. -lv_obj_t* lv_btn_create_back(lv_obj_t *par, lv_event_cb_t cb, const int id) { +lv_obj_t* lv_btn_create_back(lv_obj_t *par, lv_event_cb_t cb, const int id/*=0*/) { return lv_btn_create(par, cb, id, &style_para_back); } // Create a button with position, size, callback, and ID. Style set to style_para_back. -lv_obj_t* lv_btn_create_back(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id) { +lv_obj_t* lv_btn_create_back(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id/*=0*/) { lv_obj_t *btn = lv_btn_create_back(par, cb, id); lv_obj_set_pos(btn, x, y); lv_obj_set_size(btn, w, h); @@ -1657,11 +1723,11 @@ lv_obj_t* lv_btn_create_back(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord } // Create an image button with image, callback, and ID. Use label style. -lv_obj_t* lv_imgbtn_create(lv_obj_t *par, const char *img, lv_event_cb_t cb, const int id) { - lv_obj_t *btn = lv_imgbtn_create(par, NULL); +lv_obj_t* lv_imgbtn_create(lv_obj_t *par, const char *img, lv_event_cb_t cb, const int id/*=0*/) { + lv_obj_t *btn = lv_imgbtn_create(par, nullptr); if (img) lv_imgbtn_set_src_both(btn, img); if (id) - lv_obj_set_event_cb_mks(btn, cb, id, NULL, 0); + lv_obj_set_event_cb_mks(btn, cb, id, nullptr, 0); else lv_obj_set_event_cb(btn, cb); lv_imgbtn_use_label_style(btn); @@ -1670,12 +1736,96 @@ lv_obj_t* lv_imgbtn_create(lv_obj_t *par, const char *img, lv_event_cb_t cb, con } // Create an image button with image, position, callback, and ID. Use label style. -lv_obj_t* lv_imgbtn_create(lv_obj_t *par, const char *img, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id) { +lv_obj_t* lv_imgbtn_create(lv_obj_t *par, const char *img, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id/*=0*/) { + lv_obj_t *btn = lv_imgbtn_create(par, img, cb, id); + lv_obj_set_pos(btn, x, y); + return btn; +} + +lv_obj_t* lv_big_button_create(lv_obj_t *par, const char *img, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, bool centerLabel) { lv_obj_t *btn = lv_imgbtn_create(par, img, cb, id); lv_obj_set_pos(btn, x, y); + lv_obj_t *label = lv_label_create_empty(btn); + if (gCfgItems.multiple_language) { + lv_label_set_text(label, text); + if (centerLabel) + lv_obj_align(label, btn, LV_ALIGN_CENTER, 0, 0); + else + lv_obj_align(label, btn, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); + } + #if HAS_ROTARY_ENCODER + if (gCfgItems.encoder_enable == true) + lv_group_add_obj(g, btn); + #endif + return btn; +} + +lv_obj_t* lv_screen_menu_item(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, bool drawArrow) { + lv_obj_t *btn = lv_btn_create(par, nullptr); /*Add a button the current screen*/ + lv_obj_set_pos(btn, x, y); /*Set its position*/ + lv_obj_set_size(btn, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ + if (id > -1) lv_obj_set_event_cb_mks(btn, cb, id, nullptr, 0); + lv_btn_use_label_style(btn); + lv_btn_set_layout(btn, LV_LAYOUT_OFF); + lv_obj_t *label = lv_label_create_empty(btn); /*Add a label to the button*/ + if (gCfgItems.multiple_language) { + lv_label_set_text(label, text); + lv_obj_align(label, btn, LV_ALIGN_IN_LEFT_MID, 0, 0); + } + #if HAS_ROTARY_ENCODER + if (gCfgItems.encoder_enable == true) { + lv_group_add_obj(g, btn); + } + #endif + + if (drawArrow) (void)lv_imgbtn_create(par, "F:/bmp_arrow.bin", x + PARA_UI_SIZE_X, y + PARA_UI_ARROW_V, cb, id); + + lv_obj_t *line1 = lv_line_create(par, nullptr); + lv_ex_line(line1, line_points[index]); + return btn; } +lv_obj_t* lv_screen_menu_item_1_edit(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, const char *editValue) { + lv_obj_t* btn = lv_screen_menu_item(par, text, x, y, cb, -1, index, false); + lv_obj_t* btnValue = lv_btn_create(par, PARA_UI_VALUE_POS_X, y + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, cb, id); + lv_obj_t* labelValue = lv_label_create_empty(btnValue); + lv_label_set_text(labelValue, editValue); + lv_obj_align(labelValue, btnValue, LV_ALIGN_CENTER, 0, 0); + return btn; +} + +lv_obj_t* lv_screen_menu_item_2_edit(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, const char *editValue, const int idEdit2, const char *editValue2) { + lv_obj_t* btn = lv_screen_menu_item(par, text, x, y, cb, -1, index, false); + + lv_obj_t* btnValue = lv_btn_create(par, PARA_UI_VALUE_POS_X_2, y + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, cb, idEdit2); + lv_obj_t* labelValue = lv_label_create_empty(btnValue); + lv_label_set_text(labelValue, editValue2); + lv_obj_align(labelValue, btnValue, LV_ALIGN_CENTER, 0, 0); + + btnValue = lv_btn_create(par, PARA_UI_VALUE_POS_X, y + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, cb, id); + labelValue = lv_label_create_empty(btnValue); + lv_label_set_text(labelValue, editValue); + lv_obj_align(labelValue, btnValue, LV_ALIGN_CENTER, 0, 0); + + return btn; +} + +lv_obj_t* lv_screen_menu_item_onoff(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, const bool curValue) { + lv_screen_menu_item(par, text, x, y, cb, -1, index, false); + lv_obj_t* btnValue = lv_imgbtn_create(par, curValue ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin", PARA_UI_STATE_POS_X, y + PARA_UI_STATE_V, cb, id); + lv_obj_t* labelValue = lv_label_create_empty(btnValue); + lv_label_set_text(labelValue, curValue ? machine_menu.enable : machine_menu.disable); + lv_obj_align(labelValue, btnValue, LV_ALIGN_CENTER, 0, 0); + return btnValue; +} + +void lv_screen_menu_item_onoff_update(lv_obj_t *btn, const bool curValue) { + lv_imgbtn_set_src_both(btn, curValue ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin"); + lv_label_set_text((lv_obj_t*)btn->child_ll.head, curValue ? machine_menu.enable : machine_menu.disable); +} + + #if ENABLED(SDSUPPORT) void sd_detection() { @@ -1689,11 +1839,11 @@ lv_obj_t* lv_imgbtn_create(lv_obj_t *par, const char *img, lv_coord_t x, lv_coor #endif -void lv_ex_line(lv_obj_t * line, lv_point_t *points) { +void lv_ex_line(lv_obj_t *line, lv_point_t *points) { // Copy the previous line and apply the new style lv_line_set_points(line, points, 2); // Set the points lv_line_set_style(line, LV_LINE_STYLE_MAIN, &style_line); - lv_obj_align(line, NULL, LV_ALIGN_IN_TOP_MID, 0, 0); + lv_obj_align(line, nullptr, LV_ALIGN_IN_TOP_MID, 0, 0); } extern volatile uint32_t systick_uptime_millis; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h index 5ad0bd87b5..479166cd8f 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h @@ -164,48 +164,6 @@ #endif // ifdef TFT35 -// Set the same image for both Released and Pressed -void lv_imgbtn_set_src_both(lv_obj_t *imgbtn, const void *src); - -// Set label styles for Released and Pressed -void lv_imgbtn_use_label_style(lv_obj_t *imgbtn); - -// Set label styles for Released and Pressed -void lv_btn_use_label_style(lv_obj_t *btn); - -// Set the same style for both Released and Pressed -void lv_btn_set_style_both(lv_obj_t *btn, lv_style_t *style); - -// Create an empty label -lv_obj_t* lv_label_create_empty(lv_obj_t *par); - -// Create a label with style and text -lv_obj_t* lv_label_create(lv_obj_t *par, const char *text); - -// Create a label with style, position, and text -lv_obj_t* lv_label_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, const char *text); - -// Create a button with callback, ID, and Style. -lv_obj_t* lv_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id, lv_style_t *style); - -// Create a button with callback and ID. Style set to style_para_value. -lv_obj_t* lv_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id); - -// Create a button with position, size, callback, and ID. Style set to style_para_value. -lv_obj_t* lv_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id); - -// Create a button with callback and ID. Style set to style_para_back. -lv_obj_t* lv_btn_create_back(lv_obj_t *par, lv_event_cb_t cb, const int id); - -// Create a button with position, size, callback, and ID. Style set to style_para_back. -lv_obj_t* lv_btn_create_back(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id); - -// Create an image button with image, callback, and ID. Use label style. -lv_obj_t* lv_imgbtn_create(lv_obj_t *par, const char *img, lv_event_cb_t cb, const int id); - -// Create an image button with image, position, callback, and ID. Use label style. -lv_obj_t* lv_imgbtn_create(lv_obj_t *par, const char *img, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id); - #ifdef __cplusplus extern "C" { /* C-declarations for C++ */ #endif @@ -240,10 +198,10 @@ typedef struct { } CFG_ITMES; typedef struct { - uint8_t curTempType : 1, - curSprayerChoose : 3, - stepHeat : 4; - uint8_t leveling_first_time : 1, + uint8_t curTempType:1, + curSprayerChoose:3, + stepHeat:4; + uint8_t leveling_first_time:1, para_ui_page:1, configWifi:1, command_send:1, @@ -467,6 +425,8 @@ extern lv_style_t style_sel_text; extern lv_style_t style_para_value; extern lv_style_t style_para_back; extern lv_style_t lv_bar_style_indic; +extern lv_style_t style_btn_pr; +extern lv_style_t style_btn_rel; extern lv_point_t line_points[4][2]; @@ -489,8 +449,78 @@ extern void gCfg_to_spiFlah(); extern void print_time_count(); extern void LV_TASK_HANDLER(); -extern void lv_ex_line(lv_obj_t * line, lv_point_t *points); +extern void lv_ex_line(lv_obj_t *line, lv_point_t *points); #ifdef __cplusplus } /* C-declarations for C++ */ #endif + +// Set the same image for both Released and Pressed +void lv_imgbtn_set_src_both(lv_obj_t *imgbtn, const void *src); + +// Set label styles for Released and Pressed +void lv_imgbtn_use_label_style(lv_obj_t *imgbtn); + +// Set label styles for Released and Pressed +void lv_btn_use_label_style(lv_obj_t *btn); + +// Set the same style for both Released and Pressed +void lv_btn_set_style_both(lv_obj_t *btn, lv_style_t *style); + +// Create a screen +lv_obj_t* lv_screen_create(); + +// Create an empty label +lv_obj_t* lv_label_create_empty(lv_obj_t *par); + +// Create a label with style and text +lv_obj_t* lv_label_create(lv_obj_t *par, const char *text); + +// Create a label with style, position, and text +lv_obj_t* lv_label_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, const char *text); + +// Create a button with callback, ID, and Style. +lv_obj_t* lv_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id, lv_style_t *style=&style_para_value); + +// Create a button with callback and ID, with label style. +lv_obj_t* lv_label_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id=0); + +// Create a button with callback and ID, with button style. +lv_obj_t* lv_button_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id=0); + +// Create a button with position, size, callback, ID, and style. +lv_obj_t* lv_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id, lv_style_t *style); + +// Create a button with position, size, callback, and ID. Style set to style_para_value. +lv_obj_t* lv_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id=0); + +// Create a button with position, size, callback, and ID, with label style. +lv_obj_t* lv_label_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id=0); + +// Create a button with position, size, callback, and ID, with button style. +lv_obj_t* lv_button_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id=0); + +// Create a button with callback and ID. Style set to style_para_back. +lv_obj_t* lv_btn_create_back(lv_obj_t *par, lv_event_cb_t cb, const int id=0); + +// Create a button with position, size, callback, and ID. Style set to style_para_back. +lv_obj_t* lv_btn_create_back(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id=0); + +// Create an image button with image, callback, and ID. Use label style. +lv_obj_t* lv_imgbtn_create(lv_obj_t *par, const char *img, lv_event_cb_t cb, const int id=0); + +// Create an image button with image, position, callback, and ID. Use label style. +lv_obj_t* lv_imgbtn_create(lv_obj_t *par, const char *img, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id=0); + +// Create a big image button with a label, follow the LVGL UI standard. +lv_obj_t* lv_big_button_create(lv_obj_t *par, const char *img, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, bool centerLabel = false); + +// Create a menu item, follow the LVGL UI standard. +lv_obj_t* lv_screen_menu_item(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, bool drawArrow = true); +lv_obj_t* lv_screen_menu_item_1_edit(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, const char *editValue); +lv_obj_t* lv_screen_menu_item_2_edit(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, const char *editValue, const int idEdit2, const char *editValue2); +lv_obj_t* lv_screen_menu_item_onoff(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, const bool curValue); +void lv_screen_menu_item_onoff_update(lv_obj_t *btn, const bool curValue); + +#define _DIA_1(T) (uiCfg.dialogType == DIALOG_##T) +#define DIALOG_IS(V...) DO(DIA,||,V) diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi.cpp index 78cf35fd07..e8214cad3a 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi.cpp @@ -30,80 +30,60 @@ #include "draw_ui.h" -extern lv_group_t * g; +extern lv_group_t *g; static lv_obj_t *scr, *wifi_name_text, *wifi_key_text, *wifi_state_text, *wifi_ip_text; -#define ID_W_RETURN 1 -#define ID_W_CLOUD 2 -#define ID_W_RECONNECT 3 +enum { + ID_W_RETURN = 1, + ID_W_CLOUD, + ID_W_RECONNECT +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_W_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - lv_draw_set(); - } - break; + clear_cur_ui(); + lv_draw_set(); + break; case ID_W_CLOUD: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - //clear_cur_ui(); - //draw_return_ui(); - } - break; + //clear_cur_ui(); + //draw_return_ui(); + break; case ID_W_RECONNECT: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - lv_draw_wifi_list(); - } - break; + clear_cur_ui(); + lv_draw_wifi_list(); + break; } } void lv_draw_wifi(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL; - lv_obj_t *buttonCloud = NULL, *label_Cloud = NULL; - lv_obj_t *buttonReconnect = NULL, *label_Reconnect=NULL; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != WIFI_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = WIFI_UI; } disp_state = WIFI_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); // Create an Image button - buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_W_RETURN); - + lv_obj_t *buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_W_RETURN); #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); #endif + lv_obj_t *label_Back = lv_label_create_empty(buttonBack); - if (gCfgItems.wifi_mode_sel == STA_MODEL) { - //buttonCloud = lv_imgbtn_create(scr, NULL); - buttonReconnect = lv_imgbtn_create(scr, NULL); - } + lv_obj_t *buttonReconnect = nullptr, *label_Reconnect = nullptr; if (gCfgItems.wifi_mode_sel == STA_MODEL) { - lv_obj_set_event_cb_mks(buttonReconnect, event_handler,ID_W_RECONNECT, NULL, 0); + buttonReconnect = lv_imgbtn_create(scr, nullptr); + + lv_obj_set_event_cb_mks(buttonReconnect, event_handler, ID_W_RECONNECT, nullptr, 0); lv_imgbtn_set_src_both(buttonReconnect, "F:/bmp_wifi.bin"); lv_imgbtn_use_label_style(buttonReconnect); @@ -113,12 +93,7 @@ void lv_draw_wifi(void) { lv_obj_set_pos(buttonReconnect, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight); lv_btn_set_layout(buttonReconnect, LV_LAYOUT_OFF); - } - label_Back = lv_label_create_empty(buttonBack); - - if (gCfgItems.wifi_mode_sel == STA_MODEL) { - //label_Cloud = lv_label_create_empty(buttonCloud); label_Reconnect = lv_label_create_empty(buttonReconnect); } @@ -127,9 +102,6 @@ void lv_draw_wifi(void) { lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); if (gCfgItems.wifi_mode_sel == STA_MODEL) { - //lv_label_set_text(label_Cloud, common_menu.text_back); - //lv_obj_align(label_Cloud, buttonCloud, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - lv_label_set_text(label_Reconnect, wifi_menu.reconnect); lv_obj_align(label_Reconnect, buttonReconnect, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); } @@ -148,38 +120,33 @@ void lv_draw_wifi(void) { } void disp_wifi_state() { - memset(public_buf_m, 0, sizeof(public_buf_m)); - strcpy(public_buf_m,wifi_menu.ip); - strcat(public_buf_m,ipPara.ip_addr); + strcpy(public_buf_m, wifi_menu.ip); + strcat(public_buf_m, ipPara.ip_addr); lv_label_set_text(wifi_ip_text, public_buf_m); - lv_obj_align(wifi_ip_text, NULL, LV_ALIGN_CENTER, 0, -100); + lv_obj_align(wifi_ip_text, nullptr, LV_ALIGN_CENTER, 0, -100); - memset(public_buf_m, 0, sizeof(public_buf_m)); - strcpy(public_buf_m,wifi_menu.wifi); - strcat(public_buf_m,wifiPara.ap_name); + strcpy(public_buf_m, wifi_menu.wifi); + strcat(public_buf_m, wifiPara.ap_name); lv_label_set_text(wifi_name_text, public_buf_m); - lv_obj_align(wifi_name_text, NULL, LV_ALIGN_CENTER, 0, -70); + lv_obj_align(wifi_name_text, nullptr, LV_ALIGN_CENTER, 0, -70); if (wifiPara.mode == AP_MODEL) { - memset(public_buf_m, 0, sizeof(public_buf_m)); - strcpy(public_buf_m,wifi_menu.key); - strcat(public_buf_m,wifiPara.keyCode); + strcpy(public_buf_m, wifi_menu.key); + strcat(public_buf_m, wifiPara.keyCode); lv_label_set_text(wifi_key_text, public_buf_m); - lv_obj_align(wifi_key_text, NULL, LV_ALIGN_CENTER, 0, -40); + lv_obj_align(wifi_key_text, nullptr, LV_ALIGN_CENTER, 0, -40); - memset(public_buf_m, 0, sizeof(public_buf_m)); - strcpy(public_buf_m,wifi_menu.state_ap); + strcpy(public_buf_m, wifi_menu.state_ap); if (wifi_link_state == WIFI_CONNECTED) - strcat(public_buf_m,wifi_menu.connected); + strcat(public_buf_m, wifi_menu.connected); else if (wifi_link_state == WIFI_NOT_CONFIG) - strcat(public_buf_m,wifi_menu.disconnected); + strcat(public_buf_m, wifi_menu.disconnected); else - strcat(public_buf_m,wifi_menu.exception); + strcat(public_buf_m, wifi_menu.exception); lv_label_set_text(wifi_state_text, public_buf_m); - lv_obj_align(wifi_state_text, NULL, LV_ALIGN_CENTER, 0, -10); + lv_obj_align(wifi_state_text, nullptr, LV_ALIGN_CENTER, 0, -10); } else { - ZERO(public_buf_m); strcpy(public_buf_m, wifi_menu.state_sta); if (wifi_link_state == WIFI_CONNECTED) strcat(public_buf_m, wifi_menu.connected); @@ -188,10 +155,10 @@ void disp_wifi_state() { else strcat(public_buf_m, wifi_menu.exception); lv_label_set_text(wifi_state_text, public_buf_m); - lv_obj_align(wifi_state_text, NULL, LV_ALIGN_CENTER, 0, -40); + lv_obj_align(wifi_state_text, nullptr, LV_ALIGN_CENTER, 0, -40); lv_label_set_text(wifi_key_text, ""); - lv_obj_align(wifi_key_text, NULL, LV_ALIGN_CENTER, 0, -10); + lv_obj_align(wifi_key_text, nullptr, LV_ALIGN_CENTER, 0, -10); } } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_list.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_list.cpp index b52dbc5e59..cb72469bd4 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_list.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_list.cpp @@ -39,61 +39,48 @@ WIFI_LIST wifi_list; list_menu_def list_menu; -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; static lv_obj_t *buttonWifiN[NUMBER_OF_PAGE]; static lv_obj_t *labelWifiText[NUMBER_OF_PAGE]; static lv_obj_t *labelPageText; -#define ID_WL_RETURN 11 -#define ID_WL_DOWN 12 +#define ID_WL_RETURN 11 +#define ID_WL_DOWN 12 -static void event_handler(lv_obj_t * obj, lv_event_t event) { - if (obj->mks_obj_id == ID_WL_RETURN) { - if (event == LV_EVENT_CLICKED) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - lv_draw_set(); - } + if (obj->mks_obj_id == ID_WL_RETURN) { + clear_cur_ui(); + lv_draw_set(); } else if (obj->mks_obj_id == ID_WL_DOWN) { - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (wifi_list.getNameNum > 0) { - if ((wifi_list.nameIndex + NUMBER_OF_PAGE) >= wifi_list.getNameNum) { - wifi_list.nameIndex = 0; - wifi_list.currentWifipage = 1; - } - else { - wifi_list.nameIndex += NUMBER_OF_PAGE; - wifi_list.currentWifipage++; - } - disp_wifi_list(); + if (wifi_list.getNameNum > 0) { + if ((wifi_list.nameIndex + NUMBER_OF_PAGE) >= wifi_list.getNameNum) { + wifi_list.nameIndex = 0; + wifi_list.currentWifipage = 1; + } + else { + wifi_list.nameIndex += NUMBER_OF_PAGE; + wifi_list.currentWifipage++; } + disp_wifi_list(); } } else { for (uint8_t i = 0; i < NUMBER_OF_PAGE; i++) { if (obj->mks_obj_id == i + 1) { - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (wifi_list.getNameNum != 0) { - const bool do_wifi = wifi_link_state == WIFI_CONNECTED && strcmp((const char *)wifi_list.wifiConnectedName, (const char *)wifi_list.wifiName[wifi_list.nameIndex + i]) == 0; - wifi_list.nameIndex += i; - last_disp_state = WIFI_LIST_UI; - lv_clear_wifi_list(); - if (do_wifi) - lv_draw_wifi(); - else { - keyboard_value = wifiConfig; - lv_draw_keyboard(); - } + if (wifi_list.getNameNum != 0) { + const bool do_wifi = wifi_link_state == WIFI_CONNECTED && strcmp((const char *)wifi_list.wifiConnectedName, (const char *)wifi_list.wifiName[wifi_list.nameIndex + i]) == 0; + wifi_list.nameIndex += i; + last_disp_state = WIFI_LIST_UI; + lv_clear_wifi_list(); + if (do_wifi) + lv_draw_wifi(); + else { + keyboard_value = wifiConfig; + lv_draw_keyboard(); } } } @@ -102,34 +89,23 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) { } void lv_draw_wifi_list(void) { - lv_obj_t *buttonBack = NULL, *buttonDown = NULL; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != WIFI_LIST_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = WIFI_LIST_UI; } disp_state = WIFI_LIST_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); lv_refr_now(lv_refr_get_disp_refreshing()); - buttonDown = lv_imgbtn_create(scr, "F:/bmp_pageDown.bin", OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight + OTHER_BTN_YPIEL + INTERVAL_H, event_handler, ID_WL_DOWN); - buttonBack = lv_imgbtn_create(scr, "F:/bmp_back.bin", OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight + (OTHER_BTN_YPIEL + INTERVAL_H) * 2, event_handler, ID_WL_RETURN); + lv_obj_t *buttonDown = lv_imgbtn_create(scr, "F:/bmp_pageDown.bin", OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight + OTHER_BTN_YPIEL + INTERVAL_H, event_handler, ID_WL_DOWN); + lv_obj_t *buttonBack = lv_imgbtn_create(scr, "F:/bmp_back.bin", OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight + (OTHER_BTN_YPIEL + INTERVAL_H) * 2, event_handler, ID_WL_RETURN); for (uint8_t i = 0; i < NUMBER_OF_PAGE; i++) { - buttonWifiN[i] = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonWifiN[i], 0, NAME_BTN_Y*i+10+titleHeight); /*Set its position*/ - lv_obj_set_size(buttonWifiN[i], NAME_BTN_X, NAME_BTN_Y); /*Set its size*/ - lv_obj_set_event_cb_mks(buttonWifiN[i], event_handler, (i+1), NULL, 0); - lv_btn_use_label_style(buttonWifiN[i]); - lv_btn_set_layout(buttonWifiN[i], LV_LAYOUT_OFF); + buttonWifiN[i] = lv_label_btn_create(scr, 0, NAME_BTN_Y * i + 10 + titleHeight, NAME_BTN_X, NAME_BTN_Y, event_handler, i + 1); labelWifiText[i] = lv_label_create_empty(buttonWifiN[i]); #if HAS_ROTARY_ENCODER uint8_t j = 0; @@ -147,9 +123,10 @@ void lv_draw_wifi_list(void) { wifi_list.currentWifipage = 1; if (wifi_link_state == WIFI_CONNECTED && wifiPara.mode == STA_MODEL) { - memset(wifi_list.wifiConnectedName, 0, sizeof(&wifi_list.wifiConnectedName)); + ZERO(wifi_list.wifiConnectedName); memcpy(wifi_list.wifiConnectedName, wifiPara.ap_name, sizeof(wifi_list.wifiConnectedName)); } + #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { lv_group_add_obj(g, buttonDown); @@ -166,10 +143,10 @@ void disp_wifi_list(void) { sprintf((char *)tmpStr, list_menu.file_pages, wifi_list.currentWifipage, wifi_list.getPage); lv_label_set_text(labelPageText, (const char *)tmpStr); - lv_obj_align(labelPageText, NULL, LV_ALIGN_CENTER, 50, -100); + lv_obj_align(labelPageText, nullptr, LV_ALIGN_CENTER, 50, -100); for (i = 0; i < NUMBER_OF_PAGE; i++) { - memset(tmpStr, 0, sizeof(tmpStr)); + ZERO(tmpStr); j = wifi_list.nameIndex + i; if (j >= wifi_list.getNameNum) { @@ -187,7 +164,7 @@ void disp_wifi_list(void) { } void wifi_scan_handle() { - if (uiCfg.dialogType != WIFI_ENABLE_TIPS || uiCfg.command_send != 1) return; + if (!DIALOG_IS(WIFI_ENABLE_TIPS) || uiCfg.command_send != 1) return; last_disp_state = DIALOG_UI; lv_clear_dialog(); if (wifi_link_state == WIFI_CONNECTED && wifiPara.mode != AP_MODEL) diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_settings.cpp index 0902135835..0c4fe61132 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_settings.cpp @@ -30,161 +30,117 @@ #include "draw_ui.h" -extern lv_group_t * g; -static lv_obj_t *scr, *labelModelValue = NULL, *buttonModelValue = NULL, *labelCloudValue = NULL; - -#define ID_WIFI_RETURN 1 -#define ID_WIFI_MODEL 2 -#define ID_WIFI_NAME 3 -#define ID_WIFI_PASSWORD 4 -#define ID_WIFI_CLOUD 5 -#define ID_WIFI_CONFIG 6 - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +extern lv_group_t *g; +static lv_obj_t *scr, *labelModelValue = nullptr, *buttonModelValue = nullptr, *labelCloudValue = nullptr; + +enum { + ID_WIFI_RETURN = 1, + ID_WIFI_MODEL, + ID_WIFI_NAME, + ID_WIFI_PASSWORD, + ID_WIFI_CLOUD, + ID_WIFI_CONFIG +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_WIFI_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_wifi_settings(); - draw_return_ui(); - } - break; + lv_clear_wifi_settings(); + draw_return_ui(); + break; case ID_WIFI_MODEL: - if (event == LV_EVENT_CLICKED) { - + if (gCfgItems.wifi_mode_sel == AP_MODEL) { + gCfgItems.wifi_mode_sel = STA_MODEL; + lv_label_set_text(labelModelValue, WIFI_STA_TEXT); + lv_obj_align(labelModelValue, buttonModelValue, LV_ALIGN_CENTER, 0, 0); + update_spi_flash(); } - else if (event == LV_EVENT_RELEASED) { - if (gCfgItems.wifi_mode_sel == AP_MODEL) { - gCfgItems.wifi_mode_sel = STA_MODEL; - lv_label_set_text(labelModelValue, WIFI_STA_TEXT); - lv_obj_align(labelModelValue, buttonModelValue, LV_ALIGN_CENTER, 0, 0); - update_spi_flash(); - } - else { - gCfgItems.wifi_mode_sel = AP_MODEL; - lv_label_set_text(labelModelValue, WIFI_AP_TEXT); - lv_obj_align(labelModelValue, buttonModelValue, LV_ALIGN_CENTER, 0, 0); - update_spi_flash(); - } + else { + gCfgItems.wifi_mode_sel = AP_MODEL; + lv_label_set_text(labelModelValue, WIFI_AP_TEXT); + lv_obj_align(labelModelValue, buttonModelValue, LV_ALIGN_CENTER, 0, 0); + update_spi_flash(); } - break; + break; case ID_WIFI_NAME: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - keyboard_value = wifiName; - lv_clear_wifi_settings(); - lv_draw_keyboard(); - } - break; + keyboard_value = wifiName; + lv_clear_wifi_settings(); + lv_draw_keyboard(); + break; case ID_WIFI_PASSWORD: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { keyboard_value = wifiPassWord; - lv_clear_wifi_settings(); - lv_draw_keyboard(); - } - break; + lv_clear_wifi_settings(); + lv_draw_keyboard(); + break; case ID_WIFI_CLOUD: - if (event == LV_EVENT_CLICKED) { - + if (gCfgItems.cloud_enable) { + gCfgItems.cloud_enable = false; + lv_obj_set_event_cb_mks(obj, event_handler, ID_WIFI_CLOUD, "bmp_disable.bin", 0); + lv_label_set_text(labelCloudValue, machine_menu.disable); } - else if (event == LV_EVENT_RELEASED) { - if (gCfgItems.cloud_enable) { - gCfgItems.cloud_enable = false; - lv_obj_set_event_cb_mks(obj, event_handler, ID_WIFI_CLOUD, "bmp_disable.bin", 0); - lv_label_set_text(labelCloudValue, machine_menu.disable); - } - else { - gCfgItems.cloud_enable = true; - lv_obj_set_event_cb_mks(obj, event_handler, ID_WIFI_CLOUD, "bmp_enable.bin", 0); - lv_label_set_text(labelCloudValue, machine_menu.enable); - } - update_spi_flash(); + else { + gCfgItems.cloud_enable = true; + lv_obj_set_event_cb_mks(obj, event_handler, ID_WIFI_CLOUD, "bmp_enable.bin", 0); + lv_label_set_text(labelCloudValue, machine_menu.enable); } - break; + update_spi_flash(); + break; case ID_WIFI_CONFIG: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_wifi_settings(); - lv_draw_dialog(DIALOG_WIFI_CONFIG_TIPS); - } - break; + lv_clear_wifi_settings(); + lv_draw_dialog(DIALOG_WIFI_CONFIG_TIPS); + break; } } void lv_draw_wifi_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL, *buttonConfig = NULL, *labelConfig = NULL; - lv_obj_t *labelModelText = NULL; - lv_obj_t *labelNameText = NULL, *buttonNameValue = NULL, *labelNameValue = NULL; - lv_obj_t *labelPassWordText = NULL, *buttonPassWordValue = NULL, *labelPassWordValue = NULL; - lv_obj_t *labelCloudText = NULL, *buttonCloudValue = NULL; - lv_obj_t * line1 = NULL, *line2 = NULL, *line3 = NULL, *line4 = NULL; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != WIFI_SETTINGS_UI) { disp_state_stack._disp_index++; disp_state_stack._disp_state[disp_state_stack._disp_index] = WIFI_SETTINGS_UI; } disp_state = WIFI_SETTINGS_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); (void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, machine_menu.WifiConfTitle); lv_refr_now(lv_refr_get_disp_refreshing()); - labelModelText = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.wifiMode); + lv_obj_t *labelModelText = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.wifiMode); - buttonModelValue = lv_imgbtn_create(scr, NULL); - lv_imgbtn_set_src_both(buttonModelValue, "F:/bmp_blank_sel.bin"); - lv_obj_set_pos(buttonModelValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V); - lv_obj_set_event_cb_mks(buttonModelValue, event_handler, ID_WIFI_MODEL, NULL, 0); + lv_obj_t *buttonModelValue = lv_imgbtn_create(scr, "F:/bmp_blank_sel.bin", PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V, event_handler, ID_WIFI_MODEL); lv_btn_set_style_both(buttonModelValue, &style_para_value_pre); - lv_btn_set_layout(buttonModelValue, LV_LAYOUT_OFF); labelModelValue = lv_label_create_empty(buttonModelValue); - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1,line_points[0]); - - labelNameText = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10, NULL); - - buttonNameValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_WIFI_NAME); - labelNameValue = lv_label_create_empty(buttonNameValue); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2,line_points[1]); + lv_obj_t *line1 = lv_line_create(scr, nullptr); + lv_ex_line(line1, line_points[0]); - labelPassWordText = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10, NULL); + lv_obj_t *labelNameText = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10, nullptr); + lv_obj_t *buttonNameValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_WIFI_NAME); + lv_obj_t *labelNameValue = lv_label_create_empty(buttonNameValue); - buttonPassWordValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_WIFI_PASSWORD); - labelPassWordValue = lv_label_create_empty(buttonPassWordValue); + lv_obj_t *line2 = lv_line_create(scr, nullptr); + lv_ex_line(line2, line_points[1]); - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3,line_points[2]); + lv_obj_t *labelPassWordText = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10, nullptr); + lv_obj_t *buttonPassWordValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_WIFI_PASSWORD); + lv_obj_t *labelPassWordValue = lv_label_create_empty(buttonPassWordValue); - labelCloudText = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10, machine_menu.wifiCloud); + lv_obj_t *line3 = lv_line_create(scr, nullptr); + lv_ex_line(line3, line_points[2]); - buttonCloudValue = lv_imgbtn_create(scr, gCfgItems.cloud_enable ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin", PARA_UI_STATE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_STATE_V, event_handler, ID_WIFI_CLOUD); + lv_obj_t *labelCloudText = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10, machine_menu.wifiCloud); + lv_obj_t *buttonCloudValue = lv_imgbtn_create(scr, gCfgItems.cloud_enable ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin", PARA_UI_STATE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_STATE_V, event_handler, ID_WIFI_CLOUD); labelCloudValue = lv_label_create_empty(buttonCloudValue); - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4,line_points[3]); + lv_obj_t *line4 = lv_line_create(scr, nullptr); + lv_ex_line(line4, line_points[3]); - buttonConfig = lv_imgbtn_create(scr, "F:/bmp_back70x40.bin", PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_WIFI_CONFIG); - labelConfig = lv_label_create_empty(buttonConfig); + lv_obj_t *buttonConfig = lv_imgbtn_create(scr, "F:/bmp_back70x40.bin", PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_WIFI_CONFIG); + lv_obj_t *labelConfig = lv_label_create_empty(buttonConfig); - buttonBack = lv_imgbtn_create(scr, "F:/bmp_back70x40.bin", PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_WIFI_RETURN); - label_Back = lv_label_create_empty(buttonBack); + lv_obj_t *buttonBack = lv_imgbtn_create(scr, "F:/bmp_back70x40.bin", PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_WIFI_RETURN); + lv_obj_t *label_Back = lv_label_create_empty(buttonBack); if (gCfgItems.multiple_language) { if (gCfgItems.wifi_mode_sel == AP_MODEL) { @@ -195,26 +151,24 @@ void lv_draw_wifi_settings(void) { lv_label_set_text(labelModelValue, WIFI_STA_TEXT); lv_obj_align(labelModelValue, buttonModelValue, LV_ALIGN_CENTER, 0, 0); } - memset(public_buf_m,0,sizeof(public_buf_m)); - strcat(public_buf_m,machine_menu.wifiName); - strcat(public_buf_m,(const char *)uiCfg.wifi_name); - lv_label_set_text(labelNameText,public_buf_m); + strcat(public_buf_m, machine_menu.wifiName); + strcat(public_buf_m, (const char *)uiCfg.wifi_name); + lv_label_set_text(labelNameText, public_buf_m); - lv_label_set_text(labelNameValue,machine_menu.wifiEdit); + lv_label_set_text(labelNameValue, machine_menu.wifiEdit); lv_obj_align(labelNameValue, buttonNameValue, LV_ALIGN_CENTER, 0, 0); - memset(public_buf_m,0,sizeof(public_buf_m)); - strcat(public_buf_m,machine_menu.wifiPassWord); - strcat(public_buf_m,(const char *)uiCfg.wifi_key); - lv_label_set_text(labelPassWordText,public_buf_m); + strcat(public_buf_m, machine_menu.wifiPassWord); + strcat(public_buf_m, (const char *)uiCfg.wifi_key); + lv_label_set_text(labelPassWordText, public_buf_m); - lv_label_set_text(labelPassWordValue,machine_menu.wifiEdit); + lv_label_set_text(labelPassWordValue, machine_menu.wifiEdit); lv_obj_align(labelPassWordValue, buttonPassWordValue, LV_ALIGN_CENTER, 0, 0); lv_label_set_text(labelCloudValue, gCfgItems.cloud_enable ? machine_menu.enable : machine_menu.disable); lv_obj_align(labelCloudValue, buttonCloudValue, LV_ALIGN_CENTER, 0, 0); - lv_label_set_text(labelConfig,machine_menu.wifiConfig); + lv_label_set_text(labelConfig, machine_menu.wifiConfig); lv_obj_align(labelConfig, buttonConfig, LV_ALIGN_CENTER, 0, 0); lv_label_set_text(label_Back, common_menu.text_back); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_tips.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_tips.cpp index 86ac5dffac..57f2584fa3 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_tips.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_tips.cpp @@ -30,14 +30,14 @@ #include "draw_ui.h" -static lv_obj_t * scr; +static lv_obj_t *scr; TIPS_TYPE wifi_tips_type; TIPS_DISP tips_disp; tips_menu_def tips_menu; void lv_draw_wifi_tips(void) { - static lv_obj_t * text_tips,*wifi_name; + static lv_obj_t *text_tips,*wifi_name; if (disp_state_stack._disp_state[disp_state_stack._disp_index] != WIFI_TIPS_UI) { disp_state_stack._disp_index++; @@ -45,28 +45,24 @@ void lv_draw_wifi_tips(void) { } disp_state = WIFI_TIPS_UI; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + scr = lv_screen_create(); lv_refr_now(lv_refr_get_disp_refreshing()); wifi_name = lv_label_create(scr, (const char *)wifi_list.wifiName[wifi_list.nameIndex]); - lv_obj_align(wifi_name, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(wifi_name, nullptr, LV_ALIGN_CENTER, 0, -20); text_tips = lv_label_create_empty(scr); if (wifi_tips_type == TIPS_TYPE_JOINING) { lv_label_set_text(text_tips, tips_menu.joining); - lv_obj_align(text_tips, NULL, LV_ALIGN_CENTER, 0, -60); + lv_obj_align(text_tips, nullptr, LV_ALIGN_CENTER, 0, -60); } else if (wifi_tips_type == TIPS_TYPE_TAILED_JOIN) { lv_label_set_text(text_tips, tips_menu.failedJoin); - lv_obj_align(text_tips, NULL, LV_ALIGN_CENTER, 0, -60); + lv_obj_align(text_tips, nullptr, LV_ALIGN_CENTER, 0, -60); } else if (wifi_tips_type == TIPS_TYPE_WIFI_CONECTED) { lv_label_set_text(text_tips, tips_menu.wifiConected); - lv_obj_align(text_tips, NULL, LV_ALIGN_CENTER, 0, -60); + lv_obj_align(text_tips, nullptr, LV_ALIGN_CENTER, 0, -60); } tips_disp.timer = TIPS_TIMER_START; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/gb2312_puhui16.cpp b/Marlin/src/lcd/extui/lib/mks_ui/gb2312_puhui16.cpp index 856d645e9e..fbc8192ffb 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/gb2312_puhui16.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/gb2312_puhui16.cpp @@ -62,7 +62,7 @@ static const uint8_t * __user_font_get_bitmap(const lv_font_t * font, uint32_t u memcpy(&__g_xbf_hd, p, sizeof(x_header_t)); } if (unicode_letter > __g_xbf_hd.max || unicode_letter < __g_xbf_hd.min) - return NULL; + return nullptr; uint32_t unicode_offset = sizeof(x_header_t) + (unicode_letter - __g_xbf_hd.min) * 4; uint32_t *p_pos = (uint32_t *)__user_font_getdata(unicode_offset, 4); if (p_pos[0] != 0) { @@ -72,7 +72,7 @@ static const uint8_t * __user_font_get_bitmap(const lv_font_t * font, uint32_t u //return __user_font_getdata(pos+2, gdsc->box_w*__g_xbf_hd.bpp/8); return __user_font_getdata(pos + 2, sizeof(__g_font_buf)); } - return NULL; + return nullptr; } static bool __user_font_get_glyph_dsc(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) { @@ -81,7 +81,7 @@ static bool __user_font_get_glyph_dsc(const lv_font_t * font, lv_font_glyph_dsc_ memcpy(&__g_xbf_hd, p, sizeof(x_header_t)); } if (unicode_letter > __g_xbf_hd.max || unicode_letter < __g_xbf_hd.min) - return NULL; + return false; uint32_t unicode_offset = sizeof(x_header_t) + (unicode_letter - __g_xbf_hd.min) * 4; uint32_t *p_pos = (uint32_t *)__user_font_getdata(unicode_offset, 4); if (p_pos[0] != 0) { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp b/Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp index bc329aa82b..06d6ca6b72 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp @@ -637,7 +637,7 @@ void disp_string(uint16_t x, uint16_t y, const char * string, uint16_t charColor } } -//static lv_obj_t * scr_test; +//static lv_obj_t *scr_test; void disp_assets_update() { SPI_TFT.LCD_clear(0x0000); disp_string(100, 140, "Assets Updating...", 0xFFFF, 0x0000); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/printer_operation.cpp b/Marlin/src/lcd/extui/lib/mks_ui/printer_operation.cpp index e6c30b30f8..edd90848d5 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/printer_operation.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/printer_operation.cpp @@ -58,13 +58,11 @@ void printer_state_polling() { if (gCfgItems.pausePosZ != (float)-1) { gcode.process_subcommands_now_P(PSTR("G91")); - ZERO(public_buf_l); sprintf_P(public_buf_l, PSTR("G1 Z%.1f"), gCfgItems.pausePosZ); gcode.process_subcommands_now(public_buf_l); gcode.process_subcommands_now_P(PSTR("G90")); } if (gCfgItems.pausePosX != (float)-1 && gCfgItems.pausePosY != (float)-1) { - ZERO(public_buf_l); sprintf_P(public_buf_l, PSTR("G1 X%.1f Y%.1f"), gCfgItems.pausePosX, gCfgItems.pausePosY); gcode.process_subcommands_now(public_buf_l); } @@ -88,13 +86,11 @@ void printer_state_polling() { if (uiCfg.print_state == RESUMING) { if (IS_SD_PAUSED()) { if (gCfgItems.pausePosX != (float)-1 && gCfgItems.pausePosY != (float)-1) { - ZERO(public_buf_m); sprintf_P(public_buf_m, PSTR("G1 X%.1f Y%.1f"), uiCfg.current_x_position_bak, uiCfg.current_y_position_bak); gcode.process_subcommands_now(public_buf_m); } if (gCfgItems.pausePosZ != (float)-1) { gcode.process_subcommands_now_P(PSTR("G91")); - ZERO(public_buf_l); sprintf_P(public_buf_l, PSTR("G1 Z-%.1f"), gCfgItems.pausePosZ); gcode.process_subcommands_now(public_buf_l); gcode.process_subcommands_now_P(PSTR("G90")); @@ -109,7 +105,6 @@ void printer_state_polling() { } #if ENABLED(POWER_LOSS_RECOVERY) if (uiCfg.print_state == REPRINTED) { - ZERO(public_buf_m); #if HAS_HOTEND HOTEND_LOOP() { const int16_t et = recovery.info.target_temperature[e]; @@ -128,7 +123,6 @@ void printer_state_polling() { #if 0 // Move back to the saved XY char str_1[16], str_2[16]; - ZERO(public_buf_m); sprintf_P(public_buf_m, PSTR("G1 X%s Y%s F2000"), dtostrf(recovery.info.current_position.x, 1, 3, str_1), dtostrf(recovery.info.current_position.y, 1, 3, str_2) @@ -137,7 +131,6 @@ void printer_state_polling() { if (gCfgItems.pause_reprint && gCfgItems.pausePosZ != -1.0f) { gcode.process_subcommands_now_P(PSTR("G91")); - ZERO(public_buf_l); sprintf_P(public_buf_l, PSTR("G1 Z-%.1f"), gCfgItems.pausePosZ); gcode.process_subcommands_now(public_buf_l); gcode.process_subcommands_now_P(PSTR("G90")); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp index 6143037c2b..2f1ec48b44 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp @@ -99,7 +99,7 @@ void SysTick_Callback() { uiCfg.filament_unloading_time_cnt = 0; uiCfg.filament_unloading_time_flg = 0; uiCfg.filament_unloading_completed = 1; - uiCfg.filament_rate = 100; + uiCfg.filament_rate = 100; } } } @@ -133,7 +133,7 @@ void tft_lvgl_init() { lv_init(); - lv_disp_buf_init(&disp_buf, bmp_public_buf, NULL, LV_HOR_RES_MAX * 18); /*Initialize the display buffer*/ + lv_disp_buf_init(&disp_buf, bmp_public_buf, nullptr, LV_HOR_RES_MAX * 18); /*Initialize the display buffer*/ lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/ lv_disp_drv_init(&disp_drv); /*Basic initialization*/ @@ -199,7 +199,6 @@ void tft_lvgl_init() { uiCfg.print_state = REPRINTING; - ZERO(public_buf_m); strncpy(public_buf_m, recovery.info.sd_filename, sizeof(public_buf_m)); card.printLongPath(public_buf_m); @@ -216,15 +215,14 @@ void tft_lvgl_init() { } void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) { - uint16_t i, width, height; - - width = area->x2 - area->x1 + 1; - height = area->y2 - area->y1 + 1; + uint16_t width = area->x2 - area->x1 + 1, + height = area->y2 - area->y1 + 1; SPI_TFT.setWindow((uint16_t)area->x1, (uint16_t)area->y1, width, height); - for (i = 0; i < height; i++) { + + for (uint16_t i = 0; i < height; i++) SPI_TFT.tftio.WriteSequence((uint16_t*)(color_p + width * i), width); - } + lv_disp_flush_ready(disp); /* Indicate you are ready with the flushing*/ W25QXX.init(SPI_QUARTER_SPEED); @@ -310,10 +308,9 @@ extern uint8_t currentFlashPage; uint32_t pic_read_base_addr = 0, pic_read_addr_offset = 0; lv_fs_res_t spi_flash_open_cb (lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode) { static char last_path_name[30]; - if (strcasecmp(last_path_name,path) != 0) { + if (strcasecmp(last_path_name, path) != 0) { pic_read_base_addr = lv_get_pic_addr((uint8_t *)path); - ZERO(last_path_name); - strcpy(last_path_name,path); + strcpy(last_path_name, path); } else { W25QXX.init(SPI_QUARTER_SPEED); @@ -362,11 +359,10 @@ uint32_t sd_read_base_addr = 0,sd_read_addr_offset = 0; lv_fs_res_t sd_open_cb (lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode) { //cur_namefff = strrchr(path, '/'); char name_buf[100]; - ZERO(name_buf); - strcat(name_buf,"/"); - strcat(name_buf,path); - char *temp = strstr(name_buf,".bin"); - if (temp) { strcpy(temp,".GCO"); } + *name_buf = '/'; + strcpy(name_buf + 1, path); + char *temp = strstr(name_buf, ".bin"); + if (temp) strcpy(temp, ".GCO"); sd_read_base_addr = lv_open_gcode_file((char *)name_buf); sd_read_addr_offset = sd_read_base_addr; if (sd_read_addr_offset == 0) return LV_FS_RES_NOT_EX; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/wifi_upload.cpp b/Marlin/src/lcd/extui/lib/mks_ui/wifi_upload.cpp index 087a3b2110..1ab186a6be 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/wifi_upload.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/wifi_upload.cpp @@ -260,7 +260,7 @@ void WriteByteSlip(uint8_t b) { // Wait for a data packet to be returned. If the body of the packet is // non-zero length, return an allocated buffer indirectly containing the // data and return the data length. Note that if the pointer for returning -// the data buffer is NULL, the response is expected to be two bytes of zero. +// the data buffer is nullptr, the response is expected to be two bytes of zero. // // If an error occurs, return a negative value. Otherwise, return the number // of bytes in the response (or zero if the response was not the standard "two bytes of zero"). @@ -533,7 +533,7 @@ EspUploadResult flashFinish(signed char reboot) { // Compute the checksum of a block of data uint16_t checksum(const uint8_t *data, uint16_t dataLen, uint16_t cksum) { - if (data != NULL) { + if (data != nullptr) { while (dataLen--) { cksum ^= (uint16_t)*data++; } diff --git a/buildroot/tests/mks_robin_nano35-tests b/buildroot/tests/mks_robin_nano35-tests index ce98f563b9..d67fa516b8 100644 --- a/buildroot/tests/mks_robin_nano35-tests +++ b/buildroot/tests/mks_robin_nano35-tests @@ -53,5 +53,17 @@ opt_disable TFT_INTERFACE_FSMC TFT_RES_320x240 opt_enable TFT_INTERFACE_SPI TFT_RES_480x320 exec_test $1 $2 "MKS Robin v2 nano New Color UI 480x320 SPI" +# +# MKS Robin v2 nano LVGL SPI + TMC +# (Robin v2 nano has no FSMC interface) +# +use_example_configs Mks/Robin +opt_set MOTHERBOARD BOARD_MKS_ROBIN_NANO_V2 +opt_disable TFT_INTERFACE_FSMC TFT_COLOR_UI TOUCH_SCREEN TFT_RES_320x240 +opt_enable TFT_INTERFACE_SPI TFT_LVGL_UI TFT_RES_480x320 +opt_set X_DRIVER_TYPE TMC2209 +opt_set Y_DRIVER_TYPE TMC2209 +exec_test $1 $2 "MKS Robin v2 nano LVGL SPI + TMC" + # cleanup restore_configs