diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 70346324216c..00311e5d9258 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1196,7 +1196,7 @@ // @section lcd -#if EITHER(IS_ULTIPANEL, EXTENSIBLE_UI) +#if ANY(IS_ULTIPANEL, EXTENSIBLE_UI, DWIN_CREALITY_LCD) #define MANUAL_FEEDRATE { 50*60, 50*60, 4*60, 2*60 } // (mm/min) Feedrates for manual moves along X, Y, Z, E from panel #define FINE_MANUAL_MOVE 0.025 // (mm) Smallest manual move (< 0.1mm) applying to Z on most machines #if IS_ULTIPANEL diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index e259185ac18f..dcf7feff633f 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -75,8 +75,8 @@ #endif #if ENABLED(DWIN_CREALITY_LCD) - #include "lcd/dwin/creality_dwin.h" - #include "lcd/dwin/rotary_encoder.h" + #include "lcd/dwin/e3v2/dwin.h" + #include "lcd/dwin/e3v2/rotary_encoder.h" #endif #if ENABLED(EXTENSIBLE_UI) @@ -868,6 +868,7 @@ void idle(bool no_stepper_sleep/*=false*/) { TERN_(AUTO_REPORT_TEMPERATURES, thermalManager.auto_reporter.tick()); TERN_(AUTO_REPORT_SD_STATUS, card.auto_reporter.tick()); TERN_(AUTO_REPORT_POSITION, position_auto_reporter.tick()); + TERN_(BUFFER_MONITORING, queue.auto_report_buffer_statistics()); } #endif diff --git a/Marlin/src/gcode/feature/powerloss/M1000.cpp b/Marlin/src/gcode/feature/powerloss/M1000.cpp index 1ad955d628e5..63b951449d9a 100644 --- a/Marlin/src/gcode/feature/powerloss/M1000.cpp +++ b/Marlin/src/gcode/feature/powerloss/M1000.cpp @@ -30,9 +30,8 @@ #include "../../../lcd/marlinui.h" #if ENABLED(EXTENSIBLE_UI) #include "../../../lcd/extui/ui_api.h" -#endif -#if ENABLED(DWIN_CREALITY_LCD) - #include "../../../lcd/dwin/creality_dwin.h" // Temporary fix until it can be better implemented +#elif ENABLED(DWIN_CREALITY_LCD) + #include "../../../lcd/dwin/e3v2/dwin.h" // Temporary fix until it can be better implemented #endif #define DEBUG_OUT ENABLED(DEBUG_POWER_LOSS_RECOVERY) diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 76f22a94d2c3..0309d4348081 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -242,6 +242,7 @@ * M553 - Get or set IP netmask. (Requires enabled Ethernet port) * M554 - Get or set IP gateway. (Requires enabled Ethernet port) * M569 - Enable stealthChop on an axis. (Requires at least one _DRIVER_TYPE to be TMC2130/2160/2208/2209/5130/5160) + * M575 - Change the serial baud rate. (Requires BAUD_RATE_GCODE) * M600 - Pause for filament change: "M600 X Y Z E L". (Requires ADVANCED_PAUSE_FEATURE) * M603 - Configure filament change: "M603 T U L". (Requires ADVANCED_PAUSE_FEATURE) * M605 - Set Dual X-Carriage movement mode: "M605 S [X] [R]". (Requires DUAL_X_CARRIAGE) @@ -298,6 +299,7 @@ * M997 - Perform in-application firmware update * M999 - Restart after being stopped by error * D... - Custom Development G-code. Add hooks to 'gcode_D.cpp' for developers to test features. (Requires MARLIN_DEV_MODE) + * D576 - Set buffer monitoring options. (Requires BUFFER_MONITORING) * * "T" Codes * diff --git a/Marlin/src/gcode/lcd/M251.cpp b/Marlin/src/gcode/lcd/M251.cpp index 825a20bbd958..728756405bac 100644 --- a/Marlin/src/gcode/lcd/M251.cpp +++ b/Marlin/src/gcode/lcd/M251.cpp @@ -1,3 +1,24 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ #include "../../inc/MarlinConfig.h" #if HAS_LCD_BRIGHTNESS @@ -9,7 +30,8 @@ * M251: Set the LCD brightness */ void GcodeSuite::M251() { - if (parser.seen('B')) ui.set_brightness(parser.value_int()); + if (parser.seenval('B')) ui.set_brightness(parser.value_int()); + SERIAL_ECHOLNPAIR("LCD Brightness: ", ui.brightness); } #endif // HAS_LCD_BRIGHTNESS diff --git a/Marlin/src/gcode/lcd/M73.cpp b/Marlin/src/gcode/lcd/M73.cpp index 5b135bdff8bd..e94a2825f7b8 100644 --- a/Marlin/src/gcode/lcd/M73.cpp +++ b/Marlin/src/gcode/lcd/M73.cpp @@ -35,13 +35,13 @@ * M73 P25 ; Set progress to 25% */ void GcodeSuite::M73() { - if (parser.seen('P')) + if (parser.seenval('P')) ui.set_progress((PROGRESS_SCALE) > 1 ? parser.value_float() * (PROGRESS_SCALE) : parser.value_byte() ); #if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME) - if (parser.seen('R')) ui.set_remaining_time(60 * parser.value_ulong()); + if (parser.seenval('R')) ui.set_remaining_time(60 * parser.value_ulong()); #endif } diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 6803e6a885d4..01a8bf98aaf3 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -475,7 +475,7 @@ #endif // Aliases for LCD features -#if EITHER(IS_ULTRA_LCD, EXTENSIBLE_UI) +#if ANY(IS_ULTRA_LCD, EXTENSIBLE_UI, DWIN_CREALITY_LCD) #define HAS_DISPLAY 1 #endif @@ -490,7 +490,7 @@ #endif #endif -#if ANY(HAS_DISPLAY, DWIN_CREALITY_LCD, GLOBAL_STATUS_MESSAGE) +#if EITHER(HAS_DISPLAY, GLOBAL_STATUS_MESSAGE) #define HAS_STATUS_MESSAGE 1 #endif @@ -1081,10 +1081,13 @@ #endif #if ENABLED(DWIN_CREALITY_LCD) - #define HAS_DISPLAY 1 #define SERIAL_CATCHALL 0 #ifndef LCD_SERIAL_PORT - #define LCD_SERIAL_PORT 3 // Creality 4.x board + #if MB(BTT_SKR_MINI_E3_V1_0, BTT_SKR_MINI_E3_V1_2, BTT_SKR_MINI_E3_V2_0, BTT_SKR_E3_TURBO) + #define LCD_SERIAL_PORT 1 + #else + #define LCD_SERIAL_PORT 3 // Creality 4.x board + #endif #endif #endif diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 0dd9394d5cee..03236ecc2d91 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -423,9 +423,12 @@ #if ENABLED(DWIN_CREALITY_LCD) #define HAS_LCD_BRIGHTNESS 1 - #define MAX_LCD_BRIGHTNESS 255 - #define MIN_LCD_BRIGHTNESS 1 - #define DEFAULT_LCD_BRIGHTNESS 255 +#endif + +#if HAS_LCD_BRIGHTNESS + #define MIN_LCD_BRIGHTNESS 1 + #define MAX_LCD_BRIGHTNESS 255 + #define DEFAULT_LCD_BRIGHTNESS MAX_LCD_BRIGHTNESS #endif /** diff --git a/Marlin/src/lcd/dwin/creality_marlinui.cpp b/Marlin/src/lcd/dwin/creality_marlinui.cpp index 1935a85c6cf3..d82c382163ec 100644 --- a/Marlin/src/lcd/dwin/creality_marlinui.cpp +++ b/Marlin/src/lcd/dwin/creality_marlinui.cpp @@ -1,6 +1,6 @@ /** * Marlin 3D Printer Firmware - * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm @@ -22,7 +22,7 @@ /** * DWIN by Creality3D - * Rewrite and Extui Port by Jacob Myers + * Rewrite by Jacob Myers */ #include "../../inc/MarlinConfigPre.h" @@ -33,41 +33,17 @@ #include "../../feature/pause.h" #endif -#include "creality_dwin.h" +#include "e3v2/dwin.h" #include "../marlinui.h" -uint8_t MarlinUI::brightness = DEFAULT_LCD_BRIGHTNESS; -bool MarlinUI::backlight = true; - -void MarlinUI::set_brightness(const uint8_t value) { - if (value == 0) { - backlight = false; - DWIN_Backlight_SetLuminance(0); - } - else { - backlight = true; - brightness = constrain(value, MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS); - DWIN_Backlight_SetLuminance(brightness); - } -} - #if ENABLED(ADVANCED_PAUSE_FEATURE) void MarlinUI::pause_show_message(const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, const uint8_t extruder/*=active_extruder*/) { - switch(message) { - case PAUSE_MESSAGE_INSERT: - CrealityDWIN.Confirm_Handler(FilInsert); - break; - case PAUSE_MESSAGE_OPTION: - CrealityDWIN.Popup_Handler(PurgeMore); - break; - case PAUSE_MESSAGE_HEAT: - CrealityDWIN.Confirm_Handler(HeaterTime); - break; - case PAUSE_MESSAGE_WAITING: - CrealityDWIN.Draw_Print_Screen(); - break; - default: - break; + switch (message) { + case PAUSE_MESSAGE_INSERT: CrealityDWIN.Confirm_Handler(FilInsert); break; + case PAUSE_MESSAGE_OPTION: CrealityDWIN.Popup_Handler(PurgeMore); break; + case PAUSE_MESSAGE_HEAT: CrealityDWIN.Confirm_Handler(HeaterTime); break; + case PAUSE_MESSAGE_WAITING: CrealityDWIN.Draw_Print_Screen(); break; + default: break; } } #endif @@ -83,9 +59,7 @@ bool MarlinUI::get_blink() { return blink != 0; } -void MarlinUI::update() { - CrealityDWIN.Update(); -} +void MarlinUI::update() { CrealityDWIN.Update(); } void MarlinUI::init() { delay(800); @@ -105,7 +79,7 @@ void MarlinUI::init() { } void MarlinUI::kill_screen(PGM_P const error, PGM_P const component) { - CrealityDWIN.Draw_Popup((char*)"Printer Kill Reason:", error, (char*)"Restart Required", Wait, ICON_BLTouch); + CrealityDWIN.Draw_Popup(PSTR("Printer Kill Reason:"), error, PSTR("Restart Required"), Wait, ICON_BLTouch); } -#endif \ No newline at end of file +#endif // DWIN_CREALITY_LCD diff --git a/Marlin/src/lcd/dwin/dwin_lcd.cpp b/Marlin/src/lcd/dwin/dwin_lcd.cpp index b45042b06d5a..84333ed0cb27 100644 --- a/Marlin/src/lcd/dwin/dwin_lcd.cpp +++ b/Marlin/src/lcd/dwin/dwin_lcd.cpp @@ -67,7 +67,7 @@ inline void DWIN_Long(size_t &i, const uint32_t lval) { inline void DWIN_String(size_t &i, const char * const string) { const size_t len = _MIN(sizeof(DWIN_SendBuf) - i, strlen(string)); - memcpy(&DWIN_SendBuf[i+1], string, len); + memcpy(&DWIN_SendBuf[i + 1], string, len); i += len; } @@ -75,7 +75,7 @@ inline void DWIN_String(size_t &i, const __FlashStringHelper * string) { if (!string) return; const size_t len = strlen_P((PGM_P)string); // cast it to PGM_P, which is basically const char *, and measure it using the _P version of strlen. if (len == 0) return; - memcpy(&DWIN_SendBuf[i+1], string, len); + memcpy(&DWIN_SendBuf[i + 1], string, len); i += len; } @@ -95,7 +95,7 @@ bool DWIN_Handshake(void) { #endif LCD_SERIAL.begin(LCD_BAUDRATE); const millis_t serial_connect_timeout = millis() + 1000UL; - while (!LCD_SERIAL.connected() && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } + while (!LCD_SERIAL && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } size_t i = 0; DWIN_Byte(i, 0x00); @@ -211,18 +211,17 @@ void DWIN_Draw_Rectangle(uint8_t mode, uint16_t color, //Color: color //x/y: Upper-left coordinate of the first pixel -void DWIN_Draw_DegreeSymbol(uint16_t Color, uint16_t x, uint16_t y) { - DWIN_Draw_Point(Color, 1, 1, x + 1, y); - DWIN_Draw_Point(Color, 1, 1, x + 2, y); - DWIN_Draw_Point(Color, 1, 1, x, y + 1); - DWIN_Draw_Point(Color, 1, 1, x + 3, y + 1); - DWIN_Draw_Point(Color, 1, 1, x, y + 2); - DWIN_Draw_Point(Color, 1, 1, x + 3, y + 2); - DWIN_Draw_Point(Color, 1, 1, x + 1, y + 3); - DWIN_Draw_Point(Color, 1, 1, x + 2, y + 3); +void DWIN_Draw_DegreeSymbol(uint16_t Color, uint16_t x, uint16_t y) { + DWIN_Draw_Point(Color, 1, 1, x + 1, y); + DWIN_Draw_Point(Color, 1, 1, x + 2, y); + DWIN_Draw_Point(Color, 1, 1, x, y + 1); + DWIN_Draw_Point(Color, 1, 1, x + 3, y + 1); + DWIN_Draw_Point(Color, 1, 1, x, y + 2); + DWIN_Draw_Point(Color, 1, 1, x + 3, y + 2); + DWIN_Draw_Point(Color, 1, 1, x + 1, y + 3); + DWIN_Draw_Point(Color, 1, 1, x + 2, y + 3); } - // Move a screen area // mode: 0, circle shift; 1, translation // dir: 0=left, 1=right, 2=up, 3=down diff --git a/Marlin/src/lcd/dwin/e3v2/dwin.cpp b/Marlin/src/lcd/dwin/e3v2/dwin.cpp index b8a0e2830e10..6a829c553b62 100644 --- a/Marlin/src/lcd/dwin/e3v2/dwin.cpp +++ b/Marlin/src/lcd/dwin/e3v2/dwin.cpp @@ -22,7 +22,7 @@ /** * DWIN by Creality3D - * Rewrite and Extui Port by Jacob Myers + * Rewrite by Jacob Myers */ #include "../../../inc/MarlinConfigPre.h" @@ -52,10 +52,6 @@ #include "../../../feature/host_actions.h" #endif -#if ANY(AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_3POINT) && DISABLED(PROBE_MANUALLY) - #define HAS_ONESTEP_LEVELING 1 -#endif - #if ANY(BABYSTEPPING, HAS_BED_PROBE, HAS_WORKSPACE_OFFSET) #define HAS_ZOFFSET_ITEM 1 #endif @@ -87,9 +83,9 @@ #define MACHINE_SIZE STRINGIFY(X_BED_SIZE) "x" STRINGIFY(Y_BED_SIZE) "x" STRINGIFY(Z_MAX_POS) -#define CORP_WEBSITE_E "github.com/Jyers" - -#define BUILD_NUMBER "1.3.4" +#ifndef CORP_WEBSITE + #define CORP_WEBSITE WEBSITE_URL + #endif #define DWIN_FONT_MENU font8x16 #define DWIN_FONT_STAT font10x20 @@ -349,16 +345,14 @@ CrealityDWINClass CrealityDWIN; DWIN_Draw_String(false, false, font6x12, Color_White, Color_Bg_Blue, start_x_px + cell_width_px / 2 - 5, start_y_px + offset_y, F("X")); } else { // has value - if (GRID_MAX_POINTS_X < 10) { - sprintf(buf, "%s", dtostrf(abs(mesh_z_values[x][y]), 1, 2, str_1)); - } - else { - sprintf(buf, "%02i", (uint16_t)(abs(mesh_z_values[x][y] - (int16_t)mesh_z_values[x][y]) * 100)); - } + if (GRID_MAX_POINTS_X < 10) + sprintf_P(buf, PSTR("%s"), dtostrf(abs(mesh_z_values[x][y]), 1, 2, str_1)); + else + sprintf_P(buf, PSTR("%02i"), (uint16_t)(abs(mesh_z_values[x][y] - (int16_t)mesh_z_values[x][y]) * 100)); offset_x = cell_width_px / 2 - 3 * (strlen(buf)) - 2; if (!(GRID_MAX_POINTS_X < 10)) - DWIN_Draw_String(false, false, font6x12, Color_White, Color_Bg_Blue, start_x_px-2 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, F(".")); - DWIN_Draw_String(false, false, font6x12, Color_White, Color_Bg_Blue, start_x_px+1 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, buf); + DWIN_Draw_String(false, false, font6x12, Color_White, Color_Bg_Blue, start_x_px - 2 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, F(".")); + DWIN_Draw_String(false, false, font6x12, Color_White, Color_Bg_Blue, start_x_px + 1 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, buf); } } } @@ -371,11 +365,14 @@ CrealityDWINClass CrealityDWIN; if (range > 3e+10F) range = 0.0000001; char msg[32]; if (viewer_asymmetric_range) { - sprintf(msg, "Red %s..0..%s Green", dtostrf(-v_min, 1, 3, str_1), dtostrf(v_max, 1, 3, str_2)); + dtostrf(-v_min, 1, 3, str_1); + dtostrf( v_max, 1, 3, str_2); } else { - sprintf(msg, "Red %s..0..%s Green", dtostrf(-range, 1, 3, str_1), dtostrf(range, 1, 3, str_2)); + dtostrf(-range, 1, 3, str_1); + dtostrf( range, 1, 3, str_2); } + sprintf_P(msg, PSTR("Red %s..0..%s Green"), str_1, str_2); CrealityDWIN.Update_Status(msg); drawing_mesh = false; } @@ -386,30 +383,35 @@ CrealityDWINClass CrealityDWIN; /* General Display Functions */ +struct CrealityDWINClass::EEPROM_Settings CrealityDWINClass::eeprom_settings{0}; +constexpr const char * const CrealityDWINClass::color_names[11]; +constexpr const char * const CrealityDWINClass::preheat_modes[3]; + // Clear a part of the screen // 4=Entire screen // 3=Title bar and Menu area (default) // 2=Menu area // 1=Title bar void CrealityDWINClass::Clear_Screen(uint8_t e/*=3*/) { - if (e==1||e==3||e==4) DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.menu_top_bg, Color_Bg_Blue, false), 0, 0, DWIN_WIDTH, TITLE_HEIGHT); // Clear Title Bar - if (e==2||e==3) DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, 31, DWIN_WIDTH, STATUS_Y); // Clear Menu Area - if (e==4) DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, 31, DWIN_WIDTH, DWIN_HEIGHT); // Clear Popup Area + if (e == 1 || e == 3 || e == 4) DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.menu_top_bg, Color_Bg_Blue, false), 0, 0, DWIN_WIDTH, TITLE_HEIGHT); // Clear Title Bar + if (e == 2 || e == 3) DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, 31, DWIN_WIDTH, STATUS_Y); // Clear Menu Area + if (e == 4) DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, 31, DWIN_WIDTH, DWIN_HEIGHT); // Clear Popup Area } void CrealityDWINClass::Draw_Float(float value, uint8_t row, bool selected/*=false*/, uint8_t minunit/*=10*/) { const uint8_t digits = (uint8_t)floor(log10(abs(value))) + log10(minunit) + (minunit > 1); const uint16_t bColor = (selected) ? Select_Color : Color_Bg_Black; const uint16_t xpos = 240 - (digits * 8); - DWIN_Draw_Rectangle(1, Color_Bg_Black, 194, MBASE(row), 234 - (digits * 8), MBASE(row)+16); + DWIN_Draw_Rectangle(1, Color_Bg_Black, 194, MBASE(row), 234 - (digits * 8), MBASE(row) + 16); if (isnan(value)) { DWIN_Draw_String(false, true, DWIN_FONT_MENU, Color_White, bColor, xpos - 8, MBASE(row), F(" NaN")); - } else if (value < 0) { - DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, Color_White, bColor, digits-log10(minunit)+1, log10(minunit), xpos, MBASE(row), -value * minunit); + } + else if (value < 0) { + DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, Color_White, bColor, digits - log10(minunit) + 1, log10(minunit), xpos, MBASE(row), -value * minunit); DWIN_Draw_String(false, true, DWIN_FONT_MENU, Color_White, bColor, xpos - 8, MBASE(row), F("-")); } else { - DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, Color_White, bColor, digits-log10(minunit)+1, log10(minunit), xpos, MBASE(row), value * minunit); + DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, Color_White, bColor, digits - log10(minunit) + 1, log10(minunit), xpos, MBASE(row), value * minunit); DWIN_Draw_String(false, true, DWIN_FONT_MENU, Color_White, bColor, xpos - 8, MBASE(row), F(" ")); } } @@ -493,38 +495,31 @@ void CrealityDWINClass::Draw_Checkbox(uint8_t row, bool value) { } void CrealityDWINClass::Draw_Menu(uint8_t menu, uint8_t select/*=0*/, uint8_t scroll/*=0*/) { - if (active_menu!=menu) { + if (active_menu != menu) { last_menu = active_menu; if (process == Menu) last_selection = selection; } selection = min(select, Get_Menu_Size(menu)); scrollpos = scroll; - if (selection-scrollpos > MROWS) + if (selection - scrollpos > MROWS) scrollpos = selection - MROWS; process = Menu; active_menu = menu; Clear_Screen(); Draw_Title(Get_Menu_Title(menu)); LOOP_L_N(i, TROWS) Menu_Item_Handler(menu, i + scrollpos); - DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(selection-scrollpos) - 18, 14, MBASE(selection-scrollpos) + 33); + DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33); } void CrealityDWINClass::Redraw_Menu(bool lastprocess/*=true*/, bool lastselection/*=false*/, bool lastmenu/*=false*/) { - switch((lastprocess) ? last_process : process) { + switch ((lastprocess) ? last_process : process) { case Menu: Draw_Menu((lastmenu) ? last_menu : active_menu, (lastselection) ? last_selection : selection, (lastmenu) ? 0 : scrollpos); break; - case Main: - Draw_Main_Menu((lastselection) ? last_selection : selection); - break; - case Print: - Draw_Print_Screen(); - break; - case File: - Draw_SD_List(); - break; - default: - break; + case Main: Draw_Main_Menu((lastselection) ? last_selection : selection); break; + case Print: Draw_Print_Screen(); break; + case File: Draw_SD_List(); break; + default: break; } } @@ -564,7 +559,7 @@ void CrealityDWINClass::Main_Menu_Icons() { DWIN_ICON_Show(ICON, ICON_Control_0, 17, 246); DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 43, 317, F("Control")); } - #if ANY(HAS_ONESTEP_LEVELING, AUTO_BED_LEVELING_UBL, PROBE_MANUALLY) + #if HAS_ABL_OR_UBL if (selection == 3) { DWIN_ICON_Show(ICON, ICON_Leveling_1, 145, 246); DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 145, 246, 254, 345); @@ -646,7 +641,7 @@ void CrealityDWINClass::Draw_Print_Screen() { process = Print; selection = 0; Clear_Screen(); - DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH-8, 376); + DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH - 8, 376); Draw_Title("Printing..."); Print_Screen_Icons(); DWIN_ICON_Show(ICON, ICON_PrintTime, 14, 171); @@ -656,11 +651,11 @@ void CrealityDWINClass::Draw_Print_Screen() { Update_Status_Bar(true); Draw_Print_ProgressBar(); Draw_Print_ProgressElapsed(); - Draw_Print_ProgressRemain(); + TERN_(USE_M73_REMAINING_TIME, Draw_Print_ProgressRemain()); Draw_Print_Filename(true); } -void CrealityDWINClass::Draw_Print_Filename(bool reset/*=false*/) { +void CrealityDWINClass::Draw_Print_Filename(const bool reset/*=false*/) { static uint8_t namescrl = 0; if (reset) namescrl = 0; if (process == Print) { @@ -668,27 +663,24 @@ void CrealityDWINClass::Draw_Print_Filename(bool reset/*=false*/) { int8_t pos = len; if (pos > 30) { pos -= namescrl; - len = pos; - if (len > 30) - len = 30; - char dispname[len+1]; + len = _MIN(pos, 30); + char dispname[len + 1]; if (pos >= 0) { - LOOP_L_N(i, len) dispname[i] = filename[i+namescrl]; + LOOP_L_N(i, len) dispname[i] = filename[i + namescrl]; } else { - LOOP_L_N(i, 30+pos) dispname[i] = ' '; - LOOP_S_L_N(i, 30+pos, 30) dispname[i] = filename[i-(30+pos)]; + LOOP_L_N(i, 30 + pos) dispname[i] = ' '; + LOOP_S_L_N(i, 30 + pos, 30) dispname[i] = filename[i - (30 + pos)]; } dispname[len] = '\0'; - DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 50, DWIN_WIDTH-8, 80); + DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 50, DWIN_WIDTH - 8, 80); const int8_t npos = (DWIN_WIDTH - 30 * MENU_CHR_W) / 2; DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, npos, 60, dispname); - if (-pos >= 30) - namescrl = 0; + if (-pos >= 30) namescrl = 0; namescrl++; } else { - DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 50, DWIN_WIDTH-8, 80); + DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 50, DWIN_WIDTH - 8, 80); const int8_t npos = (DWIN_WIDTH - strlen(filename) * MENU_CHR_W) / 2; DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, npos, 60, filename); } @@ -696,25 +688,28 @@ void CrealityDWINClass::Draw_Print_Filename(bool reset/*=false*/) { } void CrealityDWINClass::Draw_Print_ProgressBar() { - uint8_t printpercent = sdprint ? card.percentDone() : (ui._get_progress()/100); + uint8_t printpercent = sdprint ? card.percentDone() : (ui._get_progress() / 100); DWIN_ICON_Show(ICON, ICON_Bar, 15, 93); DWIN_Draw_Rectangle(1, BarFill_Color, 16 + printpercent * 240 / 100, 93, 256, 113); DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_percent, Percent_Color), Color_Bg_Black, 3, 109, 133, printpercent); DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_percent, Percent_Color), Color_Bg_Black, 133, 133, "%"); } -void CrealityDWINClass::Draw_Print_ProgressRemain() { - uint16_t remainingtime = ui.get_remaining_time(); - DWIN_Draw_IntValue(true, true, 1, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 2, 176, 187, remainingtime / 3600); - DWIN_Draw_IntValue(true, true, 1, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 2, 200, 187, (remainingtime % 3600) / 60); - if (eeprom_settings.time_format_textual) { - DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 192, 187, "h"); - DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 216, 187, "m"); - } - else { - DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 192, 187, ":"); +#if ENABLED(USE_M73_REMAINING_TIME) + + void CrealityDWINClass::Draw_Print_ProgressRemain() { + uint16_t remainingtime = ui.get_remaining_time(); + DWIN_Draw_IntValue(true, true, 1, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 2, 176, 187, remainingtime / 3600); + DWIN_Draw_IntValue(true, true, 1, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 2, 200, 187, (remainingtime % 3600) / 60); + if (eeprom_settings.time_format_textual) { + DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 192, 187, "h"); + DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 216, 187, "m"); + } + else + DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 192, 187, ":"); } -} + +#endif void CrealityDWINClass::Draw_Print_ProgressElapsed() { duration_t elapsed = print_job_timer.duration(); @@ -724,9 +719,8 @@ void CrealityDWINClass::Draw_Print_ProgressElapsed() { DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 58, 187, "h"); DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 82, 187, "m"); } - else { + else DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 58, 187, ":"); - } } void CrealityDWINClass::Draw_Print_confirm() { @@ -740,14 +734,10 @@ void CrealityDWINClass::Draw_Print_confirm() { } void CrealityDWINClass::Draw_SD_Item(uint8_t item, uint8_t row) { - if (item == 0) { - if (card.flag.workDirIsRoot) - Draw_Menu_Item(0, ICON_Back, "Back"); - else - Draw_Menu_Item(0, ICON_Back, ".."); - } + if (item == 0) + Draw_Menu_Item(0, ICON_Back, card.flag.workDirIsRoot ? "Back" : ".."); else { - card.getfilename_sorted(SD_ORDER(item-1, card.get_num_Files())); + card.getfilename_sorted(SD_ORDER(item - 1, card.get_num_Files())); char * const filename = card.longest_filename(); size_t max = MENU_CHAR_LIMIT; size_t pos = strlen(filename), len = pos; @@ -755,10 +745,10 @@ void CrealityDWINClass::Draw_SD_Item(uint8_t item, uint8_t row) { while (pos && filename[pos] != '.') pos--; len = pos; if (len > max) len = max; - char name[len+1]; + char name[len + 1]; LOOP_L_N(i, len) name[i] = filename[i]; if (pos > max) - LOOP_S_L_N(i, len-3, len) name[i] = '.'; + LOOP_S_L_N(i, len - 3, len) name[i] = '.'; name[len] = '\0'; Draw_Menu_Item(row, card.flag.filenameIsDir ? ICON_More : ICON_File, name); } @@ -771,7 +761,7 @@ void CrealityDWINClass::Draw_SD_List(bool removed/*=false*/) { scrollpos = 0; process = File; if (card.isMounted() && !removed) { - LOOP_L_N(i, _MIN(card.get_num_Files()+1, TROWS)) + LOOP_L_N(i, _MIN(card.get_num_Files() + 1, TROWS)) Draw_SD_Item(i, i); } else { @@ -784,12 +774,11 @@ void CrealityDWINClass::Draw_SD_List(bool removed/*=false*/) { void CrealityDWINClass::Draw_Status_Area(bool icons/*=false*/) { - if(icons) DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, STATUS_Y, DWIN_WIDTH, DWIN_HEIGHT - 1); + if (icons) DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, STATUS_Y, DWIN_WIDTH, DWIN_HEIGHT - 1); #if HAS_HOTEND static float hotend = -1; - static int16_t hotendtarget = -1; - static int16_t flow = -1; + static int16_t hotendtarget = -1, flow = -1; if (icons) { hotend = -1; hotendtarget = -1; @@ -881,23 +870,17 @@ void CrealityDWINClass::Draw_Status_Area(bool icons/*=false*/) { DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 3, 116 + 2 * STAT_CHR_W, 384, feedrate_percentage); } - static float x = -1; - static float y = -1; - static float z = -1; - static bool update_x = false; - static bool update_y = false; - static bool update_z = false; + static float x = -1, y = -1, z = -1; + static bool update_x = false, update_y = false, update_z = false; update_x = (current_position.x != x || axis_should_home(X_AXIS) || update_x); update_y = (current_position.y != y || axis_should_home(Y_AXIS) || update_y); update_z = (current_position.z != z || axis_should_home(Z_AXIS) || update_z); if (icons) { - x = -1; - y = -1; - z = -1; + x = y = z = -1; DWIN_Draw_Line(GetColor(eeprom_settings.coordinates_split_line, Line_Color, true), 16, 450, 256, 450); - DWIN_ICON_Show(ICON, ICON_MaxSpeedX, 10, 456); - DWIN_ICON_Show(ICON, ICON_MaxSpeedY, 95, 456); - DWIN_ICON_Show(ICON, ICON_MaxSpeedZ, 180, 456); + DWIN_ICON_Show(ICON, ICON_MaxSpeedX, 10, 456); + DWIN_ICON_Show(ICON, ICON_MaxSpeedY, 95, 456); + DWIN_ICON_Show(ICON, ICON_MaxSpeedZ, 180, 456); } if (update_x) { x = current_position.x; @@ -917,29 +900,24 @@ void CrealityDWINClass::Draw_Status_Area(bool icons/*=false*/) { z = current_position.z; if ((update_z = axis_should_home(Z_AXIS) && ui.get_blink())) DWIN_Draw_String(false, true, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 205, 459, " -?- "); - else + else DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 3, 2, 205, 459, (current_position.z>=0) ? current_position.z * 100 : 0); } DWIN_UpdateLCD(); } -void CrealityDWINClass::Draw_Popup(const char *line1, const char *line2,const char *line3, uint8_t mode, uint8_t icon/*=0*/) { +void CrealityDWINClass::Draw_Popup(PGM_P const line1, PGM_P const line2, PGM_P const line3, uint8_t mode, uint8_t icon/*=0*/) { if (process != Confirm && process != Popup && process != Wait) last_process = process; if ((process == Menu || process == Wait) && mode == Popup) last_selection = selection; process = mode; Clear_Screen(); DWIN_Draw_Rectangle(0, Color_White, 13, 59, 259, 351); DWIN_Draw_Rectangle(1, Color_Bg_Window, 14, 60, 258, 350); - uint8_t ypos; - if (mode == Popup || mode == Confirm) - ypos = 150; - else - ypos = 230; - if (icon > 0) - DWIN_ICON_Show(ICON, icon, 101, 105); - DWIN_Draw_String(false, true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen(line1)) / 2, ypos, F(line1)); - DWIN_Draw_String(false, true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen(line2)) / 2, ypos+30, F(line2)); - DWIN_Draw_String(false, true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen(line3)) / 2, ypos+60, F(line3)); + const uint8_t ypos = (mode == Popup || mode == Confirm) ? 150 : 230; + if (icon > 0) DWIN_ICON_Show(ICON, icon, 101, 105); + DWIN_Draw_String(false, true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen_P(line1)) / 2, ypos, line1); + DWIN_Draw_String(false, true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen_P(line2)) / 2, ypos + 30, line2); + DWIN_Draw_String(false, true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen_P(line3)) / 2, ypos + 60, line3); if (mode == Popup) { selection = 0; DWIN_Draw_Rectangle(1, Confirm_Color, 26, 280, 125, 317); @@ -955,8 +933,8 @@ void CrealityDWINClass::Draw_Popup(const char *line1, const char *line2,const ch } void CrealityDWINClass::Popup_Select() { - const uint16_t c1 = (selection==0) ? GetColor(eeprom_settings.highlight_box, Color_White) : Color_Bg_Window, - c2 = (selection==0) ? Color_Bg_Window : GetColor(eeprom_settings.highlight_box, Color_White); + const uint16_t c1 = (selection == 0) ? GetColor(eeprom_settings.highlight_box, Color_White) : Color_Bg_Window, + c2 = (selection == 0) ? Color_Bg_Window : GetColor(eeprom_settings.highlight_box, Color_White); DWIN_Draw_Rectangle(0, c1, 25, 279, 126, 318); DWIN_Draw_Rectangle(0, c1, 24, 278, 127, 319); DWIN_Draw_Rectangle(0, c2, 145, 279, 246, 318); @@ -979,39 +957,38 @@ void CrealityDWINClass::Update_Status_Bar(bool refresh/*=false*/) { len = pos; if (len > 30) len = 30; - char dispmsg[len+1]; + char dispmsg[len + 1]; if (pos >= 0) { - LOOP_L_N(i, len) dispmsg[i] = statusmsg[i+msgscrl]; + LOOP_L_N(i, len) dispmsg[i] = statusmsg[i + msgscrl]; } else { - LOOP_L_N(i, 30+pos) dispmsg[i] = ' '; - LOOP_S_L_N(i, 30+pos, 30) dispmsg[i] = statusmsg[i-(30+pos)]; + LOOP_L_N(i, 30 + pos) dispmsg[i] = ' '; + LOOP_S_L_N(i, 30 + pos, 30) dispmsg[i] = statusmsg[i - (30 + pos)]; } dispmsg[len] = '\0'; if (process == Print) { - DWIN_Draw_Rectangle(1, Color_Grey, 8, 214, DWIN_WIDTH-8, 238); + DWIN_Draw_Rectangle(1, Color_Grey, 8, 214, DWIN_WIDTH - 8, 238); const int8_t npos = (DWIN_WIDTH - 30 * MENU_CHR_W) / 2; DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 219, dispmsg); } else { - DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH-8, 376); + DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH - 8, 376); const int8_t npos = (DWIN_WIDTH - 30 * MENU_CHR_W) / 2; DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 357, dispmsg); } - if (-pos >= 30) - msgscrl = 0; + if (-pos >= 30) msgscrl = 0; msgscrl++; } else { if (new_msg) { new_msg = false; if (process == Print) { - DWIN_Draw_Rectangle(1, Color_Grey, 8, 214, DWIN_WIDTH-8, 238); + DWIN_Draw_Rectangle(1, Color_Grey, 8, 214, DWIN_WIDTH - 8, 238); const int8_t npos = (DWIN_WIDTH - strlen(statusmsg) * MENU_CHR_W) / 2; DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 219, statusmsg); } else { - DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH-8, 376); + DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH - 8, 376); const int8_t npos = (DWIN_WIDTH - strlen(statusmsg) * MENU_CHR_W) / 2; DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 357, statusmsg); } @@ -1042,41 +1019,32 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case PREPARE_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Main_Menu(1); - } break; case PREPARE_MOVE: - if (draw) { - Draw_Menu_Item(row, ICON_Axis, "Move", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_Axis, "Move", nullptr, true); + else Draw_Menu(Move); - } break; case PREPARE_DISABLE: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_CloseMotor, "Disable Stepper"); - } - else { + else queue.inject_P(PSTR("M84")); - } break; case PREPARE_HOME: - if (draw) { - Draw_Menu_Item(row, ICON_SetHome, "Homing", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_SetHome, "Homing", nullptr, true); + else Draw_Menu(HomeMenu); - } break; case PREPARE_MANUALLEVEL: - if (draw) { - Draw_Menu_Item(row, ICON_PrintSize, "Manual Leveling", NULL, true); - } + if (draw) + Draw_Menu_Item(row, ICON_PrintSize, "Manual Leveling", nullptr, true); else { if (axes_should_home()) { Popup_Handler(Home); @@ -1089,11 +1057,11 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu(ManualLevel); } break; + #if HAS_ZOFFSET_ITEM case PREPARE_ZOFFSET: - if (draw) { - Draw_Menu_Item(row, ICON_Zoffset, "Z-Offset", NULL, true); - } + if (draw) + Draw_Menu_Item(row, ICON_Zoffset, "Z-Offset", nullptr, true); else { #if HAS_LEVELING level_state = planner.leveling_active; @@ -1103,43 +1071,41 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; #endif + #if HAS_PREHEAT case PREPARE_PREHEAT: - if (draw) { - Draw_Menu_Item(row, ICON_Temperature, "Preheat", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_Temperature, "Preheat", nullptr, true); + else Draw_Menu(Preheat); - } break; case PREPARE_COOLDOWN: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Cool, "Cooldown"); - } else { - thermalManager.zero_fan_speeds(); + TERN_(HAS_FAN, thermalManager.zero_fan_speeds()); thermalManager.disable_all_heaters(); } break; #endif + #if ENABLED(ADVANCED_PAUSE_FEATURE) case PREPARE_CHANGEFIL: if (draw) { - #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES) - Draw_Menu_Item(row, ICON_ResumeEEPROM, "Change Filament", NULL, true); - #else - Draw_Menu_Item(row, ICON_ResumeEEPROM, "Change Filament"); - #endif + Draw_Menu_Item(row, ICON_ResumeEEPROM, "Change Filament" + #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES) + , nullptr, true + #endif + ); } else { #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES) Draw_Menu(ChangeFilament); #else - if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) { + if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) Popup_Handler(ETemp); - } else { - if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target-2) { + if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) { Popup_Handler(Heating); thermalManager.wait_for_hotend(0); } @@ -1156,27 +1122,24 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ case HomeMenu: - #define HOME_BACK 0 - #define HOME_ALL (HOME_BACK + 1) - #define HOME_X (HOME_ALL + 1) - #define HOME_Y (HOME_X + 1) - #define HOME_Z (HOME_Y + 1) - #define HOME_SET (HOME_Z + 1) + #define HOME_BACK 0 + #define HOME_ALL (HOME_BACK + 1) + #define HOME_X (HOME_ALL + 1) + #define HOME_Y (HOME_X + 1) + #define HOME_Z (HOME_Y + 1) + #define HOME_SET (HOME_Z + 1) #define HOME_TOTAL HOME_SET - switch(item) { + switch (item) { case HOME_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(Prepare, PREPARE_HOME); - } break; case HOME_ALL: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Homing, "Home All"); - } else { Popup_Handler(Home); gcode.home_all_axes(true); @@ -1184,9 +1147,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case HOME_X: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_MoveX, "Home X"); - } else { Popup_Handler(Home); gcode.process_subcommands_now_P(PSTR("G28 X")); @@ -1195,9 +1157,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case HOME_Y: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_MoveY, "Home Y"); - } else { Popup_Handler(Home); gcode.process_subcommands_now_P(PSTR("G28 Y")); @@ -1206,9 +1167,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case HOME_Z: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_MoveZ,"Home Z"); - } else { Popup_Handler(Home); gcode.process_subcommands_now_P(PSTR("G28 Z")); @@ -1217,9 +1177,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case HOME_SET: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_SetHome, "Set Home Position"); - } else { gcode.process_subcommands_now_P(PSTR("G92 X0 Y0 Z0")); AudioFeedback(); @@ -1227,6 +1186,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ break; } break; + case Move: #define MOVE_BACK 0 @@ -1240,9 +1200,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case MOVE_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } else { #if HAS_BED_PROBE probe_deployed = false; @@ -1256,28 +1215,26 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_MoveX, "Move X"); Draw_Float(current_position.x, row, false); } - else { + else Modify_Value(current_position.x, X_MIN_POS, X_MAX_POS, 10); - } break; case MOVE_Y: if (draw) { Draw_Menu_Item(row, ICON_MoveY, "Move Y"); Draw_Float(current_position.y, row); } - else { + else Modify_Value(current_position.y, Y_MIN_POS, Y_MAX_POS, 10); - } break; case MOVE_Z: if (draw) { Draw_Menu_Item(row, ICON_MoveZ, "Move Z"); Draw_Float(current_position.z, row); } - else { + else Modify_Value(current_position.z, Z_MIN_POS, Z_MAX_POS, 10); - } break; + #if HAS_HOTEND case MOVE_E: if (draw) { @@ -1291,7 +1248,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Popup_Handler(ETemp); } else { - if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target-2) { + if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) { Popup_Handler(Heating); thermalManager.wait_for_hotend(0); Redraw_Menu(); @@ -1302,7 +1259,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } } break; - #endif + #endif // HAS_HOTEND + #if HAS_BED_PROBE case MOVE_P: if (draw) { @@ -1316,6 +1274,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; #endif + case MOVE_LIVE: if (draw) { Draw_Menu_Item(row, ICON_Axis, "Live Movement"); @@ -1345,13 +1304,10 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case MLEVEL_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } else { - #if HAS_LEVELING - set_bed_leveling_enabled(level_state); - #endif + TERN_(HAS_LEVELING, set_bed_leveling_enabled(level_state)); Draw_Menu(Prepare, PREPARE_MANUALLEVEL); } break; @@ -1382,9 +1338,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ break; #endif case MLEVEL_BL: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_AxisBL, "Bottom Left"); - } else { Popup_Handler(MoveWait); if (use_probe) { @@ -1404,9 +1359,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case MLEVEL_TL: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_AxisTL, "Top Left"); - } else { Popup_Handler(MoveWait); if (use_probe) { @@ -1426,9 +1380,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case MLEVEL_TR: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_AxisTR, "Top Right"); - } else { Popup_Handler(MoveWait); if (use_probe) { @@ -1448,9 +1401,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case MLEVEL_BR: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_AxisBR, "Bottom Right"); - } else { Popup_Handler(MoveWait); if (use_probe) { @@ -1470,21 +1422,20 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case MLEVEL_C: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_AxisC, "Center"); - } else { Popup_Handler(MoveWait); if (use_probe) { #if HAS_BED_PROBE - sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s"), dtostrf(X_MAX_POS/2.0f - probe.offset.x, 1, 3, str_1), dtostrf(Y_MAX_POS/2.0f - probe.offset.y, 1, 3, str_2)); + sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s"), dtostrf(X_MAX_POS / 2.0f - probe.offset.x, 1, 3, str_1), dtostrf(Y_MAX_POS / 2.0f - probe.offset.y, 1, 3, str_2)); gcode.process_subcommands_now_P(cmd); planner.synchronize(); Popup_Handler(ManualProbing); #endif } else { - sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s\nG0 F300 Z%s"), dtostrf((X_BED_SIZE + X_MIN_POS)/2.0f, 1, 3, str_1), dtostrf((Y_BED_SIZE + Y_MIN_POS)/2.0f, 1, 3, str_2), dtostrf(mlev_z_pos, 1, 3, str_3)); + sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s\nG0 F300 Z%s"), dtostrf((X_BED_SIZE + X_MIN_POS) / 2.0f, 1, 3, str_1), dtostrf((Y_BED_SIZE + Y_MIN_POS) / 2.0f, 1, 3, str_2), dtostrf(mlev_z_pos, 1, 3, str_3)); gcode.process_subcommands_now_P(cmd); planner.synchronize(); Redraw_Menu(); @@ -1496,9 +1447,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_SetZOffset, "Z Position"); Draw_Float(mlev_z_pos, row, false, 100); } - else { + else Modify_Value(mlev_z_pos, 0, MAX_Z_OFFSET, 100); - } break; } break; @@ -1516,21 +1466,17 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case ZOFFSET_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } else { liveadjust = false; - #if HAS_LEVELING - set_bed_leveling_enabled(level_state); - #endif + TERN_(HAS_LEVELING, set_bed_leveling_enabled(level_state)); Draw_Menu(Prepare, PREPARE_ZOFFSET); } break; case ZOFFSET_HOME: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Homing, "Home Z Axis"); - } else { Popup_Handler(Home); gcode.process_subcommands_now_P(PSTR("G28 Z")); @@ -1579,48 +1525,43 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_SetZOffset, "Z Offset"); Draw_Float(zoffsetvalue, row, false, 100); } - else { + else Modify_Value(zoffsetvalue, MIN_Z_OFFSET, MAX_Z_OFFSET, 100); - } break; case ZOFFSET_UP: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Axis, "Microstep Up"); - } else { if (zoffsetvalue < MAX_Z_OFFSET) { - if(liveadjust) { + if (liveadjust) { gcode.process_subcommands_now_P(PSTR("M290 Z0.01")); planner.synchronize(); } zoffsetvalue += 0.01; - Draw_Float(zoffsetvalue, row-1, false, 100); + Draw_Float(zoffsetvalue, row - 1, false, 100); } } break; case ZOFFSET_DOWN: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_AxisD, "Microstep Down"); - } else { if (zoffsetvalue > MIN_Z_OFFSET) { - if(liveadjust) { + if (liveadjust) { gcode.process_subcommands_now_P(PSTR("M290 Z-0.01")); planner.synchronize(); } zoffsetvalue -= 0.01; - Draw_Float(zoffsetvalue, row-2, false, 100); + Draw_Float(zoffsetvalue, row - 2, false, 100); } } break; #if ENABLED(EEPROM_SETTINGS) case ZOFFSET_SAVE: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_WriteEEPROM, "Save"); - } - else { + else AudioFeedback(settings.save()); - } break; #endif } @@ -1640,105 +1581,113 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case PREHEAT_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(Prepare, PREPARE_PREHEAT); - } break; case PREHEAT_MODE: - if (draw) { - Draw_Menu_Item(row, ICON_Homing, "Preheat Mode"); - Draw_Option(preheatmode, preheat_modes, row); - } - else { - Modify_Option(preheatmode, preheat_modes, 2); - } - break; - #if (PREHEAT_COUNT >= 1) + if (draw) { + Draw_Menu_Item(row, ICON_Homing, "Preheat Mode"); + Draw_Option(preheatmode, preheat_modes, row); + } + else + Modify_Option(preheatmode, preheat_modes, 2); + break; + + #if PREHEAT_COUNT >= 1 case PREHEAT_1: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Temperature, PREHEAT_1_LABEL); - } else { thermalManager.disable_all_heaters(); - thermalManager.zero_fan_speeds(); + TERN_(HAS_FAN, thermalManager.zero_fan_speeds()); if (preheatmode == 0 || preheatmode == 1) { - thermalManager.setTargetHotend(ui.material_preset[0].hotend_temp, 0); - thermalManager.set_fan_speed(0, ui.material_preset[0].fan_speed); + TERN_(HAS_HOTEND, thermalManager.setTargetHotend(ui.material_preset[0].hotend_temp, 0)); + TERN_(HAS_FAN, thermalManager.set_fan_speed(0, ui.material_preset[0].fan_speed)); } - if (preheatmode == 0 || preheatmode == 2) thermalManager.setTargetBed(ui.material_preset[0].bed_temp); + #if HAS_HEATED_BED + if (preheatmode == 0 || preheatmode == 2) thermalManager.setTargetBed(ui.material_preset[0].bed_temp); + #endif } break; #endif - #if (PREHEAT_COUNT >= 2) + + #if PREHEAT_COUNT >= 2 case PREHEAT_2: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Temperature, PREHEAT_2_LABEL); - } else { thermalManager.disable_all_heaters(); - thermalManager.zero_fan_speeds(); + TERN_(HAS_FAN, thermalManager.zero_fan_speeds()); if (preheatmode == 0 || preheatmode == 1) { - thermalManager.setTargetHotend(ui.material_preset[1].hotend_temp, 0); - thermalManager.set_fan_speed(0, ui.material_preset[1].fan_speed); + TERN_(HAS_HOTEND, thermalManager.setTargetHotend(ui.material_preset[1].hotend_temp, 0)); + TERN_(HAS_FAN, thermalManager.set_fan_speed(0, ui.material_preset[1].fan_speed)); } - if (preheatmode == 0 || preheatmode == 2) thermalManager.setTargetBed(ui.material_preset[1].bed_temp); + #if HAS_HEATED_BED + if (preheatmode == 0 || preheatmode == 2) thermalManager.setTargetBed(ui.material_preset[1].bed_temp); + #endif } break; #endif - #if (PREHEAT_COUNT >= 3) + + #if PREHEAT_COUNT >= 3 case PREHEAT_3: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Temperature, PREHEAT_3_LABEL); - } else { thermalManager.disable_all_heaters(); - thermalManager.zero_fan_speeds(); + TERN_(HAS_FAN, thermalManager.zero_fan_speeds()); if (preheatmode == 0 || preheatmode == 1) { - thermalManager.setTargetHotend(ui.material_preset[2].hotend_temp, 0); - thermalManager.set_fan_speed(0, ui.material_preset[2].fan_speed); + TERN_(HAS_HOTEND, thermalManager.setTargetHotend(ui.material_preset[2].hotend_temp, 0)); + TERN_(HAS_FAN, thermalManager.set_fan_speed(0, ui.material_preset[2].fan_speed)); } - if (preheatmode == 0 || preheatmode == 2) thermalManager.setTargetBed(ui.material_preset[2].bed_temp); + #if HAS_HEATED_BED + if (preheatmode == 0 || preheatmode == 2) thermalManager.setTargetBed(ui.material_preset[2].bed_temp); + #endif } break; #endif - #if (PREHEAT_COUNT >= 4) + + #if PREHEAT_COUNT >= 4 case PREHEAT_4: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Temperature, PREHEAT_4_LABEL); - } else { thermalManager.disable_all_heaters(); - thermalManager.zero_fan_speeds(); + TERN_(HAS_FAN, thermalManager.zero_fan_speeds()); if (preheatmode == 0 || preheatmode == 1) { - thermalManager.setTargetHotend(ui.material_preset[3].hotend_temp, 0); - thermalManager.set_fan_speed(0, ui.material_preset[3].fan_speed); + TERN_(HAS_HOTEND, thermalManager.setTargetHotend(ui.material_preset[3].hotend_temp, 0)); + TERN_(HAS_FAN, thermalManager.set_fan_speed(0, ui.material_preset[3].fan_speed)); } - if (preheatmode == 0 || preheatmode == 2) thermalManager.setTargetBed(ui.material_preset[3].bed_temp); + #if HAS_HEATED_BED + if (preheatmode == 0 || preheatmode == 2) thermalManager.setTargetBed(ui.material_preset[3].bed_temp); + #endif } break; #endif - #if (PREHEAT_COUNT >= 5) + + #if PREHEAT_COUNT >= 5 case PREHEAT_5: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Temperature, PREHEAT_5_LABEL); - } else { thermalManager.disable_all_heaters(); - thermalManager.zero_fan_speeds(); + TERN_(HAS_FAN, thermalManager.zero_fan_speeds()); if (preheatmode == 0 || preheatmode == 1) { - thermalManager.setTargetHotend(ui.material_preset[4].hotend_temp, 0); - thermalManager.set_fan_speed(0, ui.material_preset[4].fan_speed); + TERN_(HAS_HOTEND, thermalManager.setTargetHotend(ui.material_preset[4].hotend_temp, 0)); + TERN_(HAS_FAN, thermalManager.set_fan_speed(0, ui.material_preset[4].fan_speed)); } - if (preheatmode == 0 || preheatmode == 2) thermalManager.setTargetBed(ui.material_preset[4].bed_temp); + #if HAS_HEATED_BED + if (preheatmode == 0 || preheatmode == 2) thermalManager.setTargetBed(ui.material_preset[4].bed_temp); + #endif } break; #endif } break; #endif + #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES) case ChangeFilament: @@ -1750,23 +1699,19 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case CHANGEFIL_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(Prepare, PREPARE_CHANGEFIL); - } break; case CHANGEFIL_LOAD: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_WriteEEPROM, "Load Filament"); - } else { - if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) { + if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) Popup_Handler(ETemp); - } else { - if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target-2) { + if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) { Popup_Handler(Heating); thermalManager.wait_for_hotend(0); } @@ -1778,15 +1723,14 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case CHANGEFIL_UNLOAD: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_ReadEEPROM, "Unload Filament"); - } else { if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) { Popup_Handler(ETemp); } else { - if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target-2) { + if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) { Popup_Handler(Heating); thermalManager.wait_for_hotend(0); } @@ -1798,15 +1742,13 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case CHANGEFIL_CHANGE: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_ResumeEEPROM, "Change Filament"); - } else { - if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) { + if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) Popup_Handler(ETemp); - } else { - if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target-2) { + if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) { Popup_Handler(Heating); thermalManager.wait_for_hotend(0); } @@ -1818,7 +1760,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ break; } break; - #endif + #endif // FILAMENT_LOAD_UNLOAD_GCODES + case Control: #define CONTROL_BACK 0 @@ -1834,66 +1777,51 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case CONTROL_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Main_Menu(2); - } break; case CONTROL_TEMP: - if (draw) { - Draw_Menu_Item(row, ICON_Temperature, "Temperature", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_Temperature, "Temperature", nullptr, true); + else Draw_Menu(TempMenu); - } break; case CONTROL_MOTION: - if (draw) { - Draw_Menu_Item(row, ICON_Motion, "Motion", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_Motion, "Motion", nullptr, true); + else Draw_Menu(Motion); - } break; case CONTROL_VISUAL: - if (draw) { - Draw_Menu_Item(row, ICON_PrintSize, "Visual", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_PrintSize, "Visual", nullptr, true); + else Draw_Menu(Visual); - } break; case CONTROL_ADVANCED: - if (draw) { - Draw_Menu_Item(row, ICON_Version, "Advanced", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_Version, "Advanced", nullptr, true); + else Draw_Menu(Advanced); - } break; #if ENABLED(EEPROM_SETTINGS) case CONTROL_SAVE: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_WriteEEPROM, "Store Settings"); - } - else { + else AudioFeedback(settings.save()); - } break; case CONTROL_RESTORE: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_ReadEEPROM, "Restore Settings"); - } - else { + else AudioFeedback(settings.load()); - } break; case CONTROL_RESET: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Temperature, "Reset to Defaults"); - } else { settings.reset(); AudioFeedback(); @@ -1901,15 +1829,14 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ break; #endif case CONTROL_INFO: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Info, "Info"); - } - else { + else Draw_Menu(Info); - } break; } break; + case TempMenu: #define TEMP_BACK 0 @@ -1926,12 +1853,10 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case TEMP_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(Control, CONTROL_TEMP); - } break; #if HAS_HOTEND case TEMP_HOTEND: @@ -1939,9 +1864,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_SetEndTemp, "Hotend"); Draw_Float(thermalManager.temp_hotend[0].target, row, false, 1); } - else { + else Modify_Value(thermalManager.temp_hotend[0].target, MIN_E_TEMP, MAX_E_TEMP, 1); - } break; #endif #if HAS_HEATED_BED @@ -1950,9 +1874,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_SetBedTemp, "Bed"); Draw_Float(thermalManager.temp_bed.target, row, false, 1); } - else { + else Modify_Value(thermalManager.temp_bed.target, MIN_BED_TEMP, MAX_BED_TEMP, 1); - } break; #endif #if HAS_FAN @@ -1961,74 +1884,62 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_FanSpeed, "Fan"); Draw_Float(thermalManager.fan_speed[0], row, false, 1); } - else { + else Modify_Value(thermalManager.fan_speed[0], MIN_FAN_SPEED, MAX_FAN_SPEED, 1); - } break; #endif - #if ANY(HAS_HOTEND, HAS_HEATED_BED) + #if HAS_HOTEND || HAS_HEATED_BED case TEMP_PID: - if (draw) { - Draw_Menu_Item(row, ICON_Step, "PID", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_Step, "PID", nullptr, true); + else Draw_Menu(PID); - } break; #endif - #if (PREHEAT_COUNT >= 1) + #if PREHEAT_COUNT >= 1 case TEMP_PREHEAT1: - if (draw) { - Draw_Menu_Item(row, ICON_Step, PREHEAT_1_LABEL, NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_Step, PREHEAT_1_LABEL, nullptr, true); + else Draw_Menu(Preheat1); - } break; #endif - #if (PREHEAT_COUNT >= 2) + #if PREHEAT_COUNT >= 2 case TEMP_PREHEAT2: - if (draw) { - Draw_Menu_Item(row, ICON_Step, PREHEAT_2_LABEL, NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_Step, PREHEAT_2_LABEL, nullptr, true); + else Draw_Menu(Preheat2); - } break; #endif - #if (PREHEAT_COUNT >= 3) + #if PREHEAT_COUNT >= 3 case TEMP_PREHEAT3: - if (draw) { - Draw_Menu_Item(row, ICON_Step, PREHEAT_3_LABEL, NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_Step, PREHEAT_3_LABEL, nullptr, true); + else Draw_Menu(Preheat3); - } break; #endif - #if (PREHEAT_COUNT >= 4) + #if PREHEAT_COUNT >= 4 case TEMP_PREHEAT4: - if (draw) { - Draw_Menu_Item(row, ICON_Step, PREHEAT_4_LABEL, NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_Step, PREHEAT_4_LABEL, nullptr, true); + else Draw_Menu(Preheat4); - } break; #endif - #if (PREHEAT_COUNT >= 5) + #if PREHEAT_COUNT >= 5 case TEMP_PREHEAT5: - if (draw) { - Draw_Menu_Item(row, ICON_Step, PREHEAT_5_LABEL, NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_Step, PREHEAT_5_LABEL, nullptr, true); + else Draw_Menu(Preheat5); - } break; #endif } break; - #if ANY(HAS_HOTEND, HAS_HEATED_BED) + + #if HAS_HOTEND || HAS_HEATED_BED case PID: #define PID_BACK 0 @@ -2041,31 +1952,25 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case PID_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(TempMenu, TEMP_PID); - } break; #if HAS_HOTEND case PID_HOTEND: - if (draw) { - Draw_Menu_Item(row, ICON_HotendTemp, "Hotend", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_HotendTemp, "Hotend", nullptr, true); + else Draw_Menu(HotendPID); - } break; #endif #if HAS_HEATED_BED case PID_BED: - if (draw) { - Draw_Menu_Item(row, ICON_BedTemp, "Bed", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_BedTemp, "Bed", nullptr, true); + else Draw_Menu(BedPID); - } break; #endif case PID_CYCLES: @@ -2073,13 +1978,13 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_FanSpeed, "Cycles"); Draw_Float(PID_cycles, row, false, 1); } - else { + else Modify_Value(PID_cycles, 3, 50, 1); - } break; } break; - #endif + #endif // HAS_HOTEND || HAS_HEATED_BED + #if HAS_HOTEND case HotendPID: @@ -2095,17 +2000,14 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case HOTENDPID_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(PID, PID_HOTEND); - } break; case HOTENDPID_TUNE: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_HotendTemp, "Autotune"); - } else { Popup_Handler(PIDWait); sprintf_P(cmd, PSTR("M303 E0 C%i S%i U1"), PID_cycles, PID_e_temp); @@ -2119,40 +2021,37 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_Temperature, "Temperature"); Draw_Float(PID_e_temp, row, false, 1); } - else { + else Modify_Value(PID_e_temp, MIN_E_TEMP, MAX_E_TEMP, 1); - } break; case HOTENDPID_KP: if (draw) { Draw_Menu_Item(row, ICON_Version, "Kp Value"); Draw_Float(thermalManager.temp_hotend[0].pid.Kp, row, false, 100); } - else { + else Modify_Value(thermalManager.temp_hotend[0].pid.Kp, 0, 5000, 100, thermalManager.updatePID); - } break; case HOTENDPID_KI: if (draw) { Draw_Menu_Item(row, ICON_Version, "Ki Value"); Draw_Float(unscalePID_i(thermalManager.temp_hotend[0].pid.Ki), row, false, 100); } - else { + else Modify_Value(thermalManager.temp_hotend[0].pid.Ki, 0, 5000, 100, thermalManager.updatePID); - } break; case HOTENDPID_KD: if (draw) { Draw_Menu_Item(row, ICON_Version, "Kd Value"); Draw_Float(unscalePID_d(thermalManager.temp_hotend[0].pid.Kd), row, false, 100); } - else { + else Modify_Value(thermalManager.temp_hotend[0].pid.Kd, 0, 5000, 100, thermalManager.updatePID); - } break; } break; - #endif + #endif // HAS_HOTEND + #if HAS_HEATED_BED case BedPID: @@ -2168,17 +2067,14 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case BEDPID_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(PID, PID_BED); - } break; case BEDPID_TUNE: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_HotendTemp, "Autotune"); - } else { Popup_Handler(PIDWait); sprintf_P(cmd, PSTR("M303 E-1 C%i S%i U1"), PID_cycles, PID_bed_temp); @@ -2192,9 +2088,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_Temperature, "Temperature"); Draw_Float(PID_bed_temp, row, false, 1); } - else { + else Modify_Value(PID_bed_temp, MIN_BED_TEMP, MAX_BED_TEMP, 1); - } break; case BEDPID_KP: if (draw) { @@ -2210,23 +2105,22 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_Version, "Ki Value"); Draw_Float(unscalePID_i(thermalManager.temp_bed.pid.Ki), row, false, 100); } - else { + else Modify_Value(thermalManager.temp_bed.pid.Ki, 0, 5000, 100, thermalManager.updatePID); - } break; case BEDPID_KD: if (draw) { Draw_Menu_Item(row, ICON_Version, "Kd Value"); Draw_Float(unscalePID_d(thermalManager.temp_bed.pid.Kd), row, false, 100); } - else { + else Modify_Value(thermalManager.temp_bed.pid.Kd, 0, 5000, 100, thermalManager.updatePID); - } break; } break; - #endif - #if (PREHEAT_COUNT >= 1) + #endif // HAS_HEATED_BED + + #if PREHEAT_COUNT >= 1 case Preheat1: #define PREHEAT1_BACK 0 @@ -2237,12 +2131,10 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case PREHEAT1_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(TempMenu, TEMP_PREHEAT1); - } break; #if HAS_HOTEND case PREHEAT1_HOTEND: @@ -2250,9 +2142,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_SetEndTemp, "Hotend"); Draw_Float(ui.material_preset[0].hotend_temp, row, false, 1); } - else { + else Modify_Value(ui.material_preset[0].hotend_temp, MIN_E_TEMP, MAX_E_TEMP, 1); - } break; #endif #if HAS_HEATED_BED @@ -2261,9 +2152,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_SetBedTemp, "Bed"); Draw_Float(ui.material_preset[0].bed_temp, row, false, 1); } - else { + else Modify_Value(ui.material_preset[0].bed_temp, MIN_BED_TEMP, MAX_BED_TEMP, 1); - } break; #endif #if HAS_FAN @@ -2272,15 +2162,15 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_FanSpeed, "Fan"); Draw_Float(ui.material_preset[0].fan_speed, row, false, 1); } - else { + else Modify_Value(ui.material_preset[0].fan_speed, MIN_FAN_SPEED, MAX_FAN_SPEED, 1); - } break; #endif } break; - #endif - #if (PREHEAT_COUNT >= 2) + #endif // PREHEAT_COUNT >= 1 + + #if PREHEAT_COUNT >= 2 case Preheat2: #define PREHEAT2_BACK 0 @@ -2291,12 +2181,10 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case PREHEAT2_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(TempMenu, TEMP_PREHEAT2); - } break; #if HAS_HOTEND case PREHEAT2_HOTEND: @@ -2304,9 +2192,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_SetEndTemp, "Hotend"); Draw_Float(ui.material_preset[1].hotend_temp, row, false, 1); } - else { + else Modify_Value(ui.material_preset[1].hotend_temp, MIN_E_TEMP, MAX_E_TEMP, 1); - } break; #endif #if HAS_HEATED_BED @@ -2315,9 +2202,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_SetBedTemp, "Bed"); Draw_Float(ui.material_preset[1].bed_temp, row, false, 1); } - else { + else Modify_Value(ui.material_preset[1].bed_temp, MIN_BED_TEMP, MAX_BED_TEMP, 1); - } break; #endif #if HAS_FAN @@ -2326,15 +2212,15 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_FanSpeed, "Fan"); Draw_Float(ui.material_preset[1].fan_speed, row, false, 1); } - else { + else Modify_Value(ui.material_preset[1].fan_speed, MIN_FAN_SPEED, MAX_FAN_SPEED, 1); - } break; #endif } break; - #endif - #if (PREHEAT_COUNT >= 3) + #endif // PREHEAT_COUNT >= 2 + + #if PREHEAT_COUNT >= 3 case Preheat3: #define PREHEAT3_BACK 0 @@ -2345,12 +2231,10 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case PREHEAT3_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(TempMenu, TEMP_PREHEAT3); - } break; #if HAS_HOTEND case PREHEAT3_HOTEND: @@ -2358,9 +2242,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_SetEndTemp, "Hotend"); Draw_Float(ui.material_preset[2].hotend_temp, row, false, 1); } - else { + else Modify_Value(ui.material_preset[2].hotend_temp, MIN_E_TEMP, MAX_E_TEMP, 1); - } break; #endif #if HAS_HEATED_BED @@ -2369,9 +2252,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_SetBedTemp, "Bed"); Draw_Float(ui.material_preset[2].bed_temp, row, false, 1); } - else { + else Modify_Value(ui.material_preset[2].bed_temp, MIN_BED_TEMP, MAX_BED_TEMP, 1); - } break; #endif #if HAS_FAN @@ -2380,15 +2262,15 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_FanSpeed, "Fan"); Draw_Float(ui.material_preset[2].fan_speed, row, false, 1); } - else { + else Modify_Value(ui.material_preset[2].fan_speed, MIN_FAN_SPEED, MAX_FAN_SPEED, 1); - } break; #endif } break; - #endif - #if (PREHEAT_COUNT >= 4) + #endif // PREHEAT_COUNT >= 3 + + #if PREHEAT_COUNT >= 4 case Preheat4: #define PREHEAT4_BACK 0 @@ -2399,12 +2281,10 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case PREHEAT4_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(TempMenu, TEMP_PREHEAT4); - } break; #if HAS_HOTEND case PREHEAT4_HOTEND: @@ -2412,9 +2292,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_SetEndTemp, "Hotend"); Draw_Float(ui.material_preset[3].hotend_temp, row, false, 1); } - else { + else Modify_Value(ui.material_preset[3].hotend_temp, MIN_E_TEMP, MAX_E_TEMP, 1); - } break; #endif #if HAS_HEATED_BED @@ -2423,9 +2302,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_SetBedTemp, "Bed"); Draw_Float(ui.material_preset[3].bed_temp, row, false, 1); } - else { + else Modify_Value(ui.material_preset[3].bed_temp, MIN_BED_TEMP, MAX_BED_TEMP, 1); - } break; #endif #if HAS_FAN @@ -2434,15 +2312,15 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_FanSpeed, "Fan"); Draw_Float(ui.material_preset[3].fan_speed, row, false, 1); } - else { + else Modify_Value(ui.material_preset[3].fan_speed, MIN_FAN_SPEED, MAX_FAN_SPEED, 1); - } break; #endif } break; - #endif - #if (PREHEAT_COUNT >= 5) + #endif // PREHEAT_COUNT >= 4 + + #if PREHEAT_COUNT >= 5 case Preheat5: #define PREHEAT5_BACK 0 @@ -2453,12 +2331,10 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case PREHEAT5_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(TempMenu, TEMP_PREHEAT5); - } break; #if HAS_HOTEND case PREHEAT5_HOTEND: @@ -2466,9 +2342,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_SetEndTemp, "Hotend"); Draw_Float(ui.material_preset[4].hotend_temp, row, false, 1); } - else { + else Modify_Value(ui.material_preset[4].hotend_temp, MIN_E_TEMP, MAX_E_TEMP, 1); - } break; #endif #if HAS_HEATED_BED @@ -2477,9 +2352,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_SetBedTemp, "Bed"); Draw_Float(ui.material_preset[4].bed_temp, row, false, 1); } - else { + else Modify_Value(ui.material_preset[4].bed_temp, MIN_BED_TEMP, MAX_BED_TEMP, 1); - } break; #endif #if HAS_FAN @@ -2488,14 +2362,14 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_FanSpeed, "Fan"); Draw_Float(ui.material_preset[4].fan_speed, row, false, 1); } - else { + else Modify_Value(ui.material_preset[4].fan_speed, MIN_FAN_SPEED, MAX_FAN_SPEED, 1); - } break; #endif } break; - #endif + #endif // PREHEAT_COUNT >= 5 + case Motion: #define MOTION_BACK 0 @@ -2509,54 +2383,42 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case MOTION_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(Control, CONTROL_MOTION); - } break; case MOTION_HOMEOFFSETS: - if (draw) { - Draw_Menu_Item(row, ICON_SetHome, "Home Offsets", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_SetHome, "Home Offsets", nullptr, true); + else Draw_Menu(HomeOffsets); - } break; case MOTION_SPEED: - if (draw) { - Draw_Menu_Item(row, ICON_MaxSpeed, "Max Speed", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_MaxSpeed, "Max Speed", nullptr, true); + else Draw_Menu(MaxSpeed); - } break; case MOTION_ACCEL: - if (draw) { - Draw_Menu_Item(row, ICON_MaxAccelerated, "Max Acceleration", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_MaxAccelerated, "Max Acceleration", nullptr, true); + else Draw_Menu(MaxAcceleration); - } break; #if HAS_CLASSIC_JERK case MOTION_JERK: - if (draw) { - Draw_Menu_Item(row, ICON_MaxJerk, "Max Jerk", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_MaxJerk, "Max Jerk", nullptr, true); + else Draw_Menu(MaxJerk); - } break; #endif case MOTION_STEPS: - if (draw) { - Draw_Menu_Item(row, ICON_Step, "Steps/mm", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_Step, "Steps/mm", nullptr, true); + else Draw_Menu(Steps); - } break; #if HAS_HOTEND case MOTION_FLOW: @@ -2564,13 +2426,13 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_Speed, "Flow Rate"); Draw_Float(planner.flow_percentage[0], row, false, 1); } - else { + else Modify_Value(planner.flow_percentage[0], MIN_FLOW_RATE, MAX_FLOW_RATE, 1); - } break; #endif } break; + case HomeOffsets: #define HOMEOFFSETS_BACK 0 @@ -2580,30 +2442,26 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case HOMEOFFSETS_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(Motion, MOTION_HOMEOFFSETS); - } break; case HOMEOFFSETS_XOFFSET: if (draw) { Draw_Menu_Item(row, ICON_StepX, "X Offset"); Draw_Float(home_offset.x, row, false, 100); } - else { + else Modify_Value(home_offset.x, -MAX_XY_OFFSET, MAX_XY_OFFSET, 100); - } break; case HOMEOFFSETS_YOFFSET: if (draw) { Draw_Menu_Item(row, ICON_StepY, "Y Offset"); Draw_Float(home_offset.y, row, false, 100); } - else { + else Modify_Value(home_offset.y, -MAX_XY_OFFSET, MAX_XY_OFFSET, 100); - } break; } break; @@ -2618,53 +2476,55 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case SPEED_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(Motion, MOTION_SPEED); - } break; case SPEED_X: if (draw) { Draw_Menu_Item(row, ICON_MaxSpeedX, "X Axis"); Draw_Float(planner.settings.max_feedrate_mm_s[X_AXIS], row, false, 1); } - else { - Modify_Value(planner.settings.max_feedrate_mm_s[X_AXIS], 0, default_max_feedrate[X_AXIS]*2, 1); - } - break; - case SPEED_Y: - if (draw) { - Draw_Menu_Item(row, ICON_MaxSpeedY, "Y Axis"); - Draw_Float(planner.settings.max_feedrate_mm_s[Y_AXIS], row, false, 1); - } - else { - Modify_Value(planner.settings.max_feedrate_mm_s[Y_AXIS], 0, default_max_feedrate[Y_AXIS]*2, 1); - } - break; - case SPEED_Z: - if (draw) { - Draw_Menu_Item(row, ICON_MaxSpeedZ, "Z Axis"); - Draw_Float(planner.settings.max_feedrate_mm_s[Z_AXIS], row, false, 1); - } - else { - Modify_Value(planner.settings.max_feedrate_mm_s[Z_AXIS], 0, default_max_feedrate[Z_AXIS]*2, 1); - } + else + Modify_Value(planner.settings.max_feedrate_mm_s[X_AXIS], 0, default_max_feedrate[X_AXIS] * 2, 1); break; + + #if HAS_Y_AXIS + case SPEED_Y: + if (draw) { + Draw_Menu_Item(row, ICON_MaxSpeedY, "Y Axis"); + Draw_Float(planner.settings.max_feedrate_mm_s[Y_AXIS], row, false, 1); + } + else + Modify_Value(planner.settings.max_feedrate_mm_s[Y_AXIS], 0, default_max_feedrate[Y_AXIS] * 2, 1); + break; + #endif + + #if HAS_Z_AXIS + case SPEED_Z: + if (draw) { + Draw_Menu_Item(row, ICON_MaxSpeedZ, "Z Axis"); + Draw_Float(planner.settings.max_feedrate_mm_s[Z_AXIS], row, false, 1); + } + else + Modify_Value(planner.settings.max_feedrate_mm_s[Z_AXIS], 0, default_max_feedrate[Z_AXIS] * 2, 1); + break; + #endif + #if HAS_HOTEND case SPEED_E: if (draw) { Draw_Menu_Item(row, ICON_MaxSpeedE, "Extruder"); Draw_Float(planner.settings.max_feedrate_mm_s[E_AXIS], row, false, 1); } - else { - Modify_Value(planner.settings.max_feedrate_mm_s[E_AXIS], 0, default_max_feedrate[E_AXIS]*2, 1); - } + else + Modify_Value(planner.settings.max_feedrate_mm_s[E_AXIS], 0, default_max_feedrate[E_AXIS] * 2, 1); break; #endif } break; + case MaxAcceleration: #define ACCEL_BACK 0 @@ -2676,39 +2536,34 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case ACCEL_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(Motion, MOTION_ACCEL); - } break; case ACCEL_X: if (draw) { Draw_Menu_Item(row, ICON_MaxAccX, "X Axis"); Draw_Float(planner.settings.max_acceleration_mm_per_s2[X_AXIS], row, false, 1); } - else { - Modify_Value(planner.settings.max_acceleration_mm_per_s2[X_AXIS], 0, default_max_acceleration[X_AXIS]*2, 1); - } + else + Modify_Value(planner.settings.max_acceleration_mm_per_s2[X_AXIS], 0, default_max_acceleration[X_AXIS] * 2, 1); break; case ACCEL_Y: if (draw) { Draw_Menu_Item(row, ICON_MaxAccY, "Y Axis"); Draw_Float(planner.settings.max_acceleration_mm_per_s2[Y_AXIS], row, false, 1); } - else { - Modify_Value(planner.settings.max_acceleration_mm_per_s2[Y_AXIS], 0, default_max_acceleration[Y_AXIS]*2, 1); - } + else + Modify_Value(planner.settings.max_acceleration_mm_per_s2[Y_AXIS], 0, default_max_acceleration[Y_AXIS] * 2, 1); break; case ACCEL_Z: if (draw) { Draw_Menu_Item(row, ICON_MaxAccZ, "Z Axis"); Draw_Float(planner.settings.max_acceleration_mm_per_s2[Z_AXIS], row, false, 1); } - else { - Modify_Value(planner.settings.max_acceleration_mm_per_s2[Z_AXIS], 0, default_max_acceleration[Z_AXIS]*2, 1); - } + else + Modify_Value(planner.settings.max_acceleration_mm_per_s2[Z_AXIS], 0, default_max_acceleration[Z_AXIS] * 2, 1); break; #if HAS_HOTEND case ACCEL_E: @@ -2716,9 +2571,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_MaxAccE, "Extruder"); Draw_Float(planner.settings.max_acceleration_mm_per_s2[E_AXIS], row, false, 1); } - else { - Modify_Value(planner.settings.max_acceleration_mm_per_s2[E_AXIS], 0, default_max_acceleration[E_AXIS]*2, 1); - } + else + Modify_Value(planner.settings.max_acceleration_mm_per_s2[E_AXIS], 0, default_max_acceleration[E_AXIS] * 2, 1); break; #endif } @@ -2735,39 +2589,34 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case JERK_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(Motion, MOTION_JERK); - } break; case JERK_X: if (draw) { Draw_Menu_Item(row, ICON_MaxSpeedJerkX, "X Axis"); Draw_Float(planner.max_jerk[X_AXIS], row, false, 10); } - else { - Modify_Value(planner.max_jerk[X_AXIS], 0, default_max_jerk[X_AXIS]*2, 10); - } + else + Modify_Value(planner.max_jerk[X_AXIS], 0, default_max_jerk[X_AXIS] * 2, 10); break; case JERK_Y: if (draw) { Draw_Menu_Item(row, ICON_MaxSpeedJerkY, "Y Axis"); Draw_Float(planner.max_jerk[Y_AXIS], row, false, 10); } - else { - Modify_Value(planner.max_jerk[Y_AXIS], 0, default_max_jerk[Y_AXIS]*2, 10); - } + else + Modify_Value(planner.max_jerk[Y_AXIS], 0, default_max_jerk[Y_AXIS] * 2, 10); break; case JERK_Z: if (draw) { Draw_Menu_Item(row, ICON_MaxSpeedJerkZ, "Z Axis"); Draw_Float(planner.max_jerk[Z_AXIS], row, false, 10); } - else { - Modify_Value(planner.max_jerk[Z_AXIS], 0, default_max_jerk[Z_AXIS]*2, 10); - } + else + Modify_Value(planner.max_jerk[Z_AXIS], 0, default_max_jerk[Z_AXIS] * 2, 10); break; #if HAS_HOTEND case JERK_E: @@ -2775,9 +2624,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_MaxSpeedJerkE, "Extruder"); Draw_Float(planner.max_jerk[E_AXIS], row, false, 10); } - else { - Modify_Value(planner.max_jerk[E_AXIS], 0, default_max_jerk[E_AXIS]*2, 10); - } + else + Modify_Value(planner.max_jerk[E_AXIS], 0, default_max_jerk[E_AXIS] * 2, 10); break; #endif } @@ -2794,39 +2642,34 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case STEPS_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(Motion, MOTION_STEPS); - } break; case STEPS_X: if (draw) { Draw_Menu_Item(row, ICON_StepX, "X Axis"); Draw_Float(planner.settings.axis_steps_per_mm[X_AXIS], row, false, 10); } - else { - Modify_Value(planner.settings.axis_steps_per_mm[X_AXIS], 0, default_steps[X_AXIS]*2, 10); - } + else + Modify_Value(planner.settings.axis_steps_per_mm[X_AXIS], 0, default_steps[X_AXIS] * 2, 10); break; case STEPS_Y: if (draw) { Draw_Menu_Item(row, ICON_StepY, "Y Axis"); Draw_Float(planner.settings.axis_steps_per_mm[Y_AXIS], row, false, 10); } - else { - Modify_Value(planner.settings.axis_steps_per_mm[Y_AXIS], 0, default_steps[Y_AXIS]*2, 10); - } + else + Modify_Value(planner.settings.axis_steps_per_mm[Y_AXIS], 0, default_steps[Y_AXIS] * 2, 10); break; case STEPS_Z: if (draw) { Draw_Menu_Item(row, ICON_StepZ, "Z Axis"); Draw_Float(planner.settings.axis_steps_per_mm[Z_AXIS], row, false, 10); } - else { - Modify_Value(planner.settings.axis_steps_per_mm[Z_AXIS], 0, default_steps[Z_AXIS]*2, 10); - } + else + Modify_Value(planner.settings.axis_steps_per_mm[Z_AXIS], 0, default_steps[Z_AXIS] * 2, 10); break; #if HAS_HOTEND case STEPS_E: @@ -2834,9 +2677,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_StepE, "Extruder"); Draw_Float(planner.settings.axis_steps_per_mm[E_AXIS], row, false, 10); } - else { + else Modify_Value(planner.settings.axis_steps_per_mm[E_AXIS], 0, 1000, 10); - } break; #endif } @@ -2853,29 +2695,24 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case VISUAL_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(Control, CONTROL_VISUAL); - } break; case VISUAL_BACKLIGHT: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Brightness, "Display Off"); - } - else { + else ui.set_brightness(0); - } break; case VISUAL_BRIGHTNESS: if (draw) { Draw_Menu_Item(row, ICON_Brightness, "LCD Brightness"); Draw_Float(ui.brightness, row, false, 1); } - else { + else Modify_Value(ui.brightness, MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS, 1, ui.refresh_brightness); - } break; case VISUAL_TIME_FORMAT: if (draw) { @@ -2888,141 +2725,128 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case VISUAL_COLOR_THEMES: - if (draw) { - Draw_Menu_Item(row, ICON_MaxSpeed, "UI Color Settings", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_MaxSpeed, "UI Color Settings", nullptr, true); + else Draw_Menu(ColorSettings); - } break; } break; + case ColorSettings: - #define COLORSETTINGS_BACK 0 - #define COLORSETTINGS_CURSOR (COLORSETTINGS_BACK + 1) - #define COLORSETTINGS_SPLIT_LINE (COLORSETTINGS_CURSOR + 1) - #define COLORSETTINGS_MENU_TOP_TXT (COLORSETTINGS_SPLIT_LINE + 1) - #define COLORSETTINGS_MENU_TOP_BG (COLORSETTINGS_MENU_TOP_TXT + 1) - #define COLORSETTINGS_HIGHLIGHT_BORDER (COLORSETTINGS_MENU_TOP_BG + 1) - #define COLORSETTINGS_PROGRESS_PERCENT (COLORSETTINGS_HIGHLIGHT_BORDER + 1) - #define COLORSETTINGS_PROGRESS_TIME (COLORSETTINGS_PROGRESS_PERCENT + 1) - #define COLORSETTINGS_PROGRESS_STATUS_BAR (COLORSETTINGS_PROGRESS_TIME + 1) - #define COLORSETTINGS_PROGRESS_STATUS_AREA (COLORSETTINGS_PROGRESS_STATUS_BAR + 1) - #define COLORSETTINGS_PROGRESS_COORDINATES (COLORSETTINGS_PROGRESS_STATUS_AREA + 1) - #define COLORSETTINGS_PROGRESS_COORDINATES_LINE (COLORSETTINGS_PROGRESS_COORDINATES + 1) - #define COLORSETTINGS_TOTAL COLORSETTINGS_PROGRESS_COORDINATES_LINE + #define COLORSETTINGS_BACK 0 + #define COLORSETTINGS_CURSOR (COLORSETTINGS_BACK + 1) + #define COLORSETTINGS_SPLIT_LINE (COLORSETTINGS_CURSOR + 1) + #define COLORSETTINGS_MENU_TOP_TXT (COLORSETTINGS_SPLIT_LINE + 1) + #define COLORSETTINGS_MENU_TOP_BG (COLORSETTINGS_MENU_TOP_TXT + 1) + #define COLORSETTINGS_HIGHLIGHT_BORDER (COLORSETTINGS_MENU_TOP_BG + 1) + #define COLORSETTINGS_PROGRESS_PERCENT (COLORSETTINGS_HIGHLIGHT_BORDER + 1) + #define COLORSETTINGS_PROGRESS_TIME (COLORSETTINGS_PROGRESS_PERCENT + 1) + #define COLORSETTINGS_PROGRESS_STATUS_BAR (COLORSETTINGS_PROGRESS_TIME + 1) + #define COLORSETTINGS_PROGRESS_STATUS_AREA (COLORSETTINGS_PROGRESS_STATUS_BAR + 1) + #define COLORSETTINGS_PROGRESS_COORDINATES (COLORSETTINGS_PROGRESS_STATUS_AREA + 1) + #define COLORSETTINGS_PROGRESS_COORDINATES_LINE (COLORSETTINGS_PROGRESS_COORDINATES + 1) + #define COLORSETTINGS_TOTAL COLORSETTINGS_PROGRESS_COORDINATES_LINE - switch (item) { + switch (item) { case COLORSETTINGS_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(Visual, VISUAL_COLOR_THEMES); - } break; case COLORSETTINGS_CURSOR: - if (draw) { + if (draw) { Draw_Menu_Item(row, ICON_MaxSpeed, "Cursor"); Draw_Option(eeprom_settings.cursor_color, color_names, row, false, true); } - else { + else Modify_Option(eeprom_settings.cursor_color, color_names, Custom_Colors); - } break; - case COLORSETTINGS_SPLIT_LINE: - if (draw) { + case COLORSETTINGS_SPLIT_LINE: + if (draw) { Draw_Menu_Item(row, ICON_MaxSpeed, "Menu Split Line"); Draw_Option(eeprom_settings.menu_split_line, color_names, row, false, true); } - else { + else Modify_Option(eeprom_settings.menu_split_line, color_names, Custom_Colors); - } break; case COLORSETTINGS_MENU_TOP_TXT: - if (draw) { + if (draw) { Draw_Menu_Item(row, ICON_MaxSpeed, "Menu Header Text"); Draw_Option(eeprom_settings.menu_top_txt, color_names, row, false, true); } - else { + else Modify_Option(eeprom_settings.menu_top_txt, color_names, Custom_Colors); - } break; - case COLORSETTINGS_MENU_TOP_BG: - if (draw) { + case COLORSETTINGS_MENU_TOP_BG: + if (draw) { Draw_Menu_Item(row, ICON_MaxSpeed, "Menu Header Bg"); Draw_Option(eeprom_settings.menu_top_bg, color_names, row, false, true); } - else { + else Modify_Option(eeprom_settings.menu_top_bg, color_names, Custom_Colors); - } break; - case COLORSETTINGS_HIGHLIGHT_BORDER: - if (draw) { + case COLORSETTINGS_HIGHLIGHT_BORDER: + if (draw) { Draw_Menu_Item(row, ICON_MaxSpeed, "Highlight Box"); Draw_Option(eeprom_settings.highlight_box, color_names, row, false, true); } - else { + else Modify_Option(eeprom_settings.highlight_box, color_names, Custom_Colors); - } break; - case COLORSETTINGS_PROGRESS_PERCENT: - if (draw) { + case COLORSETTINGS_PROGRESS_PERCENT: + if (draw) { Draw_Menu_Item(row, ICON_MaxSpeed, "Progress Percent"); Draw_Option(eeprom_settings.progress_percent, color_names, row, false, true); } - else { + else Modify_Option(eeprom_settings.progress_percent, color_names, Custom_Colors); - } break; - case COLORSETTINGS_PROGRESS_TIME: - if (draw) { + case COLORSETTINGS_PROGRESS_TIME: + if (draw) { Draw_Menu_Item(row, ICON_MaxSpeed, "Progress Time"); Draw_Option(eeprom_settings.progress_time, color_names, row, false, true); } - else { + else Modify_Option(eeprom_settings.progress_time, color_names, Custom_Colors); - } break; - case COLORSETTINGS_PROGRESS_STATUS_BAR: - if (draw) { + case COLORSETTINGS_PROGRESS_STATUS_BAR: + if (draw) { Draw_Menu_Item(row, ICON_MaxSpeed, "Status Bar Text"); Draw_Option(eeprom_settings.status_bar_text, color_names, row, false, true); } - else { + else Modify_Option(eeprom_settings.status_bar_text, color_names, Custom_Colors); - } break; - case COLORSETTINGS_PROGRESS_STATUS_AREA: - if (draw) { + case COLORSETTINGS_PROGRESS_STATUS_AREA: + if (draw) { Draw_Menu_Item(row, ICON_MaxSpeed, "Status Area Text"); Draw_Option(eeprom_settings.status_area_text, color_names, row, false, true); } - else { + else Modify_Option(eeprom_settings.status_area_text, color_names, Custom_Colors); - } break; - case COLORSETTINGS_PROGRESS_COORDINATES: - if (draw) { + case COLORSETTINGS_PROGRESS_COORDINATES: + if (draw) { Draw_Menu_Item(row, ICON_MaxSpeed, "Coordinates Text"); Draw_Option(eeprom_settings.coordinates_text, color_names, row, false, true); } - else { + else Modify_Option(eeprom_settings.coordinates_text, color_names, Custom_Colors); - } break; - case COLORSETTINGS_PROGRESS_COORDINATES_LINE: - if (draw) { + case COLORSETTINGS_PROGRESS_COORDINATES_LINE: + if (draw) { Draw_Menu_Item(row, ICON_MaxSpeed, "Coordinates Line"); Draw_Option(eeprom_settings.coordinates_split_line, color_names, row, false, true); } - else { + else Modify_Option(eeprom_settings.coordinates_split_line, color_names, Custom_Colors); - } break; - } - break; + } // switch (item) + break; + case Advanced: #define ADVANCED_BACK 0 @@ -3040,13 +2864,12 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case ADVANCED_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(Control, CONTROL_ADVANCED); - } break; + case ADVANCED_BEEPER: if (draw) { Draw_Menu_Item(row, ICON_Version, "LCD Beeper"); @@ -3057,56 +2880,55 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Checkbox(row, eeprom_settings.beeperenable); } break; + #if HAS_BED_PROBE case ADVANCED_PROBE: - if (draw) { - Draw_Menu_Item(row, ICON_StepX, "Probe", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_StepX, "Probe", nullptr, true); + else Draw_Menu(ProbeMenu); - } break; #endif + case ADVANCED_CORNER: if (draw) { Draw_Menu_Item(row, ICON_MaxAccelerated, "Bed Screw Inset"); Draw_Float(corner_pos, row, false, 10); } - else { - Modify_Value(corner_pos, 1, 100, 10); - } + else + Modify_Value(corner_pos, 1, 100, 10); break; + #if ENABLED(LIN_ADVANCE) case ADVANCED_LA: if (draw) { Draw_Menu_Item(row, ICON_MaxAccelerated, "Lin Advance Kp"); Draw_Float(planner.extruder_advance_K[0], row, false, 100); } - else { + else Modify_Value(planner.extruder_advance_K[0], 0, 10, 100); - } break; #endif + #if ENABLED(ADVANCED_PAUSE_FEATURE) case ADVANCED_LOAD: if (draw) { Draw_Menu_Item(row, ICON_WriteEEPROM, "Load Length"); Draw_Float(fc_settings[0].load_length, row, false, 1); } - else { + else Modify_Value(fc_settings[0].load_length, 0, EXTRUDE_MAXLENGTH, 1); - } break; case ADVANCED_UNLOAD: if (draw) { Draw_Menu_Item(row, ICON_ReadEEPROM, "Unload Length"); Draw_Float(fc_settings[0].unload_length, row, false, 1); } - else { + else Modify_Value(fc_settings[0].unload_length, 0, EXTRUDE_MAXLENGTH, 1); - } break; - #endif + #endif // ADVANCED_PAUSE_FEATURE + #if ENABLED(PREVENT_COLD_EXTRUSION) case ADVANCED_COLD_EXTRUDE: if (draw) { @@ -3119,6 +2941,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; #endif + #if ENABLED(FILAMENT_RUNOUT_SENSOR) case ADVANCED_FILSENSORENABLED: if (draw) { @@ -3130,18 +2953,19 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Checkbox(row, runout.enabled); } break; + #if ENABLED(HAS_FILAMENT_RUNOUT_DISTANCE) case ADVANCED_FILSENSORDISTANCE: if (draw) { Draw_Menu_Item(row, ICON_MaxAccE, "Runout Distance"); Draw_Float(runout.runout_distance(), row, false, 10); } - else { + else Modify_Value(runout.runout_distance(), 0, 999, 10); - } break; #endif - #endif + #endif // FILAMENT_RUNOUT_SENSOR + #if ENABLED(POWER_LOSS_RECOVERY) case ADVANCED_POWER_LOSS: if (draw) { @@ -3156,6 +2980,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ #endif } break; + #if HAS_BED_PROBE case ProbeMenu: @@ -3170,12 +2995,10 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case PROBE_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(Advanced, ADVANCED_PROBE); - } break; case PROBE_XOFFSET: @@ -3183,25 +3006,22 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_StepX, "Probe X Offset"); Draw_Float(probe.offset.x, row, false, 10); } - else { + else Modify_Value(probe.offset.x, -MAX_XY_OFFSET, MAX_XY_OFFSET, 10); - } break; case PROBE_YOFFSET: if (draw) { Draw_Menu_Item(row, ICON_StepY, "Probe Y Offset"); Draw_Float(probe.offset.y, row, false, 10); } - else { + else Modify_Value(probe.offset.y, -MAX_XY_OFFSET, MAX_XY_OFFSET, 10); - } break; case PROBE_TEST: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_StepY, "M48 Probe Test"); - } else { - sprintf_P(cmd, PSTR("G28O\nM48 X%s Y%s P%i"), dtostrf((X_BED_SIZE + X_MIN_POS)/2.0f, 1, 3, str_1), dtostrf((Y_BED_SIZE + Y_MIN_POS)/2.0f, 1, 3, str_2), testcount); + sprintf_P(cmd, PSTR("G28O\nM48 X%s Y%s P%i"), dtostrf((X_BED_SIZE + X_MIN_POS) / 2.0f, 1, 3, str_1), dtostrf((Y_BED_SIZE + Y_MIN_POS) / 2.0f, 1, 3, str_2), testcount); gcode.process_subcommands_now_P(cmd); } break; @@ -3210,9 +3030,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_StepY, "Probe Test Count"); Draw_Float(testcount, row, false, 1); } - else { + else Modify_Value(testcount, 4, 50, 1); - } break; } break; @@ -3238,20 +3057,20 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ char row1[50], row2[50], buf[32]; printStatistics ps = print_job_timer.getStats(); - sprintf(row1, "%i prints, %i finished", ps.totalPrints, ps.finishedPrints); - sprintf(row2, "%s m filament used", dtostrf(ps.filamentUsed / 1000, 1, 2, str_1)); + sprintf_P(row1, PSTR("%i prints, %i finished"), ps.totalPrints, ps.finishedPrints); + sprintf_P(row2, PSTR("%s m filament used"), dtostrf(ps.filamentUsed / 1000, 1, 2, str_1)); Draw_Menu_Item(INFO_PRINTCOUNT, ICON_HotendTemp, row1, row2, false, true); duration_t(print_job_timer.getStats().printTime).toString(buf); - sprintf(row1, "Printed: %s", buf); + sprintf_P(row1, PSTR("Printed: %s"), buf); duration_t(print_job_timer.getStats().longestPrint).toString(buf); - sprintf(row2, "Longest: %s", buf); + sprintf_P(row2, PSTR("Longest: %s"), buf); Draw_Menu_Item(INFO_PRINTTIME, ICON_PrintTime, row1, row2, false, true); #endif - Draw_Menu_Item(INFO_SIZE, ICON_PrintSize, MACHINE_SIZE, NULL, false, true); - Draw_Menu_Item(INFO_VERSION, ICON_Version, SHORT_BUILD_VERSION, "Build Number: v" BUILD_NUMBER, false, true); - Draw_Menu_Item(INFO_CONTACT, ICON_Contact, CORP_WEBSITE_E, NULL, false, true); + Draw_Menu_Item(INFO_SIZE, ICON_PrintSize, MACHINE_SIZE, nullptr, false, true); + Draw_Menu_Item(INFO_VERSION, ICON_Version, SHORT_BUILD_VERSION, nullptr, false, true); + Draw_Menu_Item(INFO_CONTACT, ICON_Contact, CORP_WEBSITE, nullptr, false, true); } else { if (menu == Info) @@ -3262,6 +3081,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ break; } break; + #if HAS_MESH case Leveling: @@ -3279,12 +3099,10 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case LEVELING_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Main_Menu(3); - } break; case LEVELING_ACTIVE: if (draw) { @@ -3299,17 +3117,15 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ break; } } - else { + else set_bed_leveling_enabled(!planner.leveling_active); - } Draw_Checkbox(row, planner.leveling_active); } break; #if BOTH(HAS_BED_PROBE, AUTO_BED_LEVELING_UBL) case LEVELING_GET_TILT: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Tilt, "Autotilt Current Mesh"); - } else { if (ubl.storage_slot < 0) { Popup_Handler(MeshSlot); @@ -3318,12 +3134,10 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Popup_Handler(Home); gcode.home_all_axes(true); Popup_Handler(Level); - if (mesh_conf.tilt_grid > 1) { + if (mesh_conf.tilt_grid > 1) sprintf_P(cmd, PSTR("G29 J%i"), mesh_conf.tilt_grid); - } - else { + else sprintf_P(cmd, PSTR("G29 J")); - } gcode.process_subcommands_now_P(cmd); planner.synchronize(); Redraw_Menu(); @@ -3331,21 +3145,24 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ break; #endif case LEVELING_GET_MESH: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Mesh, "Create New Mesh"); - } else { Popup_Handler(Home); gcode.home_all_axes(true); #if ENABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(PREHEAT_BEFORE_LEVELING) Popup_Handler(Heating); - if (thermalManager.degTargetHotend(0) < LEVELING_NOZZLE_TEMP) - thermalManager.setTargetHotend(LEVELING_NOZZLE_TEMP, 0); - if (thermalManager.degTargetBed() < LEVELING_BED_TEMP) - thermalManager.setTargetBed(LEVELING_BED_TEMP); + #if HAS_HOTEND + if (thermalManager.degTargetHotend(0) < LEVELING_NOZZLE_TEMP) + thermalManager.setTargetHotend(LEVELING_NOZZLE_TEMP, 0); + #endif + #if HAS_HEATED_BED + if (thermalManager.degTargetBed() < LEVELING_BED_TEMP) + thermalManager.setTargetBed(LEVELING_BED_TEMP); + #endif thermalManager.wait_for_hotend(0); - thermalManager.wait_for_bed_heating(); + TERN_(HAS_HEATED_BED, thermalManager.wait_for_bed_heating()); #endif #if HAS_BED_PROBE Popup_Handler(Level); @@ -3380,9 +3197,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case LEVELING_MANUAL: - if (draw) { - Draw_Menu_Item(row, ICON_Mesh, "Manual Tuning", NULL, true); - } + if (draw) + Draw_Menu_Item(row, ICON_Mesh, "Manual Tuning", nullptr, true); else { #if ENABLED(AUTO_BED_LEVELING_BILINEAR) if (!leveling_is_valid()) { @@ -3405,12 +3221,16 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ mesh_conf.goto_mesh_value = false; #if ENABLED(PREHEAT_BEFORE_LEVELING) Popup_Handler(Heating); - if (thermalManager.degTargetHotend(0) < LEVELING_NOZZLE_TEMP) - thermalManager.setTargetHotend(LEVELING_NOZZLE_TEMP, 0); - if (thermalManager.degTargetBed() < LEVELING_BED_TEMP) - thermalManager.setTargetBed(LEVELING_BED_TEMP); - thermalManager.wait_for_hotend(0); - thermalManager.wait_for_bed_heating(); + #if HAS_HOTEND + if (thermalManager.degTargetHotend(0) < LEVELING_NOZZLE_TEMP) + thermalManager.setTargetHotend(LEVELING_NOZZLE_TEMP, 0); + #endif + #if HAS_HEATED_BED + if (thermalManager.degTargetBed() < LEVELING_BED_TEMP) + thermalManager.setTargetBed(LEVELING_BED_TEMP); + #endif + TERN_(HAS_HOTEND, thermalManager.wait_for_hotend(0)); + TERN_(HAS_HEATED_BED, thermalManager.wait_for_bed_heating()); #endif Popup_Handler(MoveWait); mesh_conf.manual_move(); @@ -3418,9 +3238,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case LEVELING_VIEW: - if (draw) { - Draw_Menu_Item(row, ICON_Mesh, "Mesh Viewer", NULL, true); - } + if (draw) + Draw_Menu_Item(row, ICON_Mesh, "Mesh Viewer", nullptr, true); else { #if ENABLED(AUTO_BED_LEVELING_UBL) if (ubl.storage_slot < 0) { @@ -3432,12 +3251,10 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case LEVELING_SETTINGS: - if (draw) { - Draw_Menu_Item(row, ICON_Step, "Leveling Settings", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_Step, "Leveling Settings", nullptr, true); + else Draw_Menu(LevelSettings); - } break; #if ENABLED(AUTO_BED_LEVELING_UBL) case LEVELING_SLOT: @@ -3445,14 +3262,12 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_PrintSize, "Mesh Slot"); Draw_Float(ubl.storage_slot, row, false, 1); } - else { - Modify_Value(ubl.storage_slot, 0, settings.calc_num_meshes()-1, 1); - } + else + Modify_Value(ubl.storage_slot, 0, settings.calc_num_meshes() - 1, 1); break; case LEVELING_LOAD: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_ReadEEPROM, "Load Mesh"); - } else { if (ubl.storage_slot < 0) { Popup_Handler(MeshSlot); @@ -3464,9 +3279,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case LEVELING_SAVE: - if(draw) { + if (draw) Draw_Menu_Item(row, ICON_WriteEEPROM, "Save Mesh"); - } else { if (ubl.storage_slot < 0) { Popup_Handler(MeshSlot); @@ -3480,6 +3294,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ #endif } break; + case LevelView: #define LEVELING_VIEW_BACK 0 @@ -3490,20 +3305,16 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case LEVELING_VIEW_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(Leveling, LEVELING_VIEW); - } break; case LEVELING_VIEW_MESH: - if (draw) { - Draw_Menu_Item(row, ICON_PrintSize, "Mesh Viewer", NULL, true); - } - else { + if (draw) + Draw_Menu_Item(row, ICON_PrintSize, "Mesh Viewer", nullptr, true); + else Draw_Menu(MeshViewer); - } break; case LEVELING_VIEW_TEXT: if (draw) { @@ -3527,6 +3338,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ break; } break; + case LevelSettings: #define LEVELING_SETTINGS_BACK 0 @@ -3539,12 +3351,10 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case LEVELING_SETTINGS_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Menu(Leveling, LEVELING_SETTINGS); - } break; case LEVELING_SETTINGS_FADE: if (draw) { @@ -3557,68 +3367,59 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ set_z_fade_height(planner.z_fade_height); } break; + #if ENABLED(AUTO_BED_LEVELING_UBL) case LEVELING_SETTINGS_TILT: - if (draw) { - Draw_Menu_Item(row, ICON_Tilt, "Tilting Grid Size"); - Draw_Float(mesh_conf.tilt_grid, row, false, 1); - } - else { - Modify_Value(mesh_conf.tilt_grid, 1, 8, 1); - } - break; + if (draw) { + Draw_Menu_Item(row, ICON_Tilt, "Tilting Grid Size"); + Draw_Float(mesh_conf.tilt_grid, row, false, 1); + } + else + Modify_Value(mesh_conf.tilt_grid, 1, 8, 1); + break; case LEVELING_SETTINGS_PLANE: - if (draw) { - Draw_Menu_Item(row, ICON_ResumeEEPROM, "Convert Mesh to Plane"); - } - else { - if (mesh_conf.create_plane_from_mesh()) { - break; - } - gcode.process_subcommands_now_P(PSTR("M420 S1")); - planner.synchronize(); - AudioFeedback(true); - } - break; + if (draw) + Draw_Menu_Item(row, ICON_ResumeEEPROM, "Convert Mesh to Plane"); + else { + if (mesh_conf.create_plane_from_mesh()) break; + gcode.process_subcommands_now_P(PSTR("M420 S1")); + planner.synchronize(); + AudioFeedback(true); + } + break; case LEVELING_SETTINGS_ZERO: - if (draw) { - Draw_Menu_Item(row, ICON_Mesh, "Zero Current Mesh"); - } - else { - ZERO(mesh_conf.mesh_z_values); - } - break; - case LEVELING_SETTINGS_UNDEF: - if (draw) { - Draw_Menu_Item(row, ICON_Mesh, "Clear Current Mesh"); - } - else { - ubl.invalidate(); - } - break; - #endif + if (draw) + Draw_Menu_Item(row, ICON_Mesh, "Zero Current Mesh"); + else + ZERO(mesh_conf.mesh_z_values); + break; + case LEVELING_SETTINGS_UNDEF: + if (draw) + Draw_Menu_Item(row, ICON_Mesh, "Clear Current Mesh"); + else + ubl.invalidate(); + break; + #endif // AUTO_BED_LEVELING_UBL } break; + case MeshViewer: #define MESHVIEW_BACK 0 #define MESHVIEW_TOTAL MESHVIEW_BACK - switch (item) { - case MESHVIEW_BACK: - if (draw) { - Draw_Menu_Item(0, ICON_Back, "Back"); - mesh_conf.Draw_Bed_Mesh(); - mesh_conf.Set_Mesh_Viewer_Status(); - } - else { - if (!mesh_conf.drawing_mesh) { - Draw_Menu(LevelView, LEVELING_VIEW_MESH); - Update_Status(""); - } - } - break; + if (item == MESHVIEW_BACK) { + if (draw) { + Draw_Menu_Item(0, ICON_Back, "Back"); + mesh_conf.Draw_Bed_Mesh(); + mesh_conf.Set_Mesh_Viewer_Status(); + } + else if (!mesh_conf.drawing_mesh) { + Draw_Menu(LevelView, LEVELING_VIEW_MESH); + Update_Status(""); + } } break; + case LevelManual: #define LEVELING_M_BACK 0 @@ -3634,14 +3435,11 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case LEVELING_M_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } else { set_bed_leveling_enabled(level_state); - #if ENABLED(AUTO_BED_LEVELING_BILINEAR) - refresh_bed_level(); - #endif + TERN_(AUTO_BED_LEVELING_BILINEAR, refresh_bed_level()); Draw_Menu(Leveling, LEVELING_MANUAL); } break; @@ -3650,34 +3448,28 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_MoveX, "Mesh Point X"); Draw_Float(mesh_conf.mesh_x, row, 0, 1); } - else { + else Modify_Value(mesh_conf.mesh_x, 0, GRID_MAX_POINTS_X - 1, 1); - } break; case LEVELING_M_Y: if (draw) { Draw_Menu_Item(row, ICON_MoveY, "Mesh Point Y"); Draw_Float(mesh_conf.mesh_y, row, 0, 1); } - else { + else Modify_Value(mesh_conf.mesh_y, 0, GRID_MAX_POINTS_Y - 1, 1); - } break; case LEVELING_M_NEXT: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_More, "Next Point"); - } else { - if (mesh_conf.mesh_x != (GRID_MAX_POINTS_X-1) || mesh_conf.mesh_y != (GRID_MAX_POINTS_Y-1)) { - if ((mesh_conf.mesh_x == (GRID_MAX_POINTS_X-1) && mesh_conf.mesh_y % 2 == 0) || (mesh_conf.mesh_x == 0 && mesh_conf.mesh_y % 2 == 1)) { + if (mesh_conf.mesh_x != (GRID_MAX_POINTS_X - 1) || mesh_conf.mesh_y != (GRID_MAX_POINTS_Y - 1)) { + if ((mesh_conf.mesh_x == (GRID_MAX_POINTS_X - 1) && mesh_conf.mesh_y % 2 == 0) || (mesh_conf.mesh_x == 0 && mesh_conf.mesh_y % 2 == 1)) mesh_conf.mesh_y++; - } - else if (mesh_conf.mesh_y % 2 == 0) { + else if (mesh_conf.mesh_y % 2 == 0) mesh_conf.mesh_x++; - } - else { + else mesh_conf.mesh_x--; - } mesh_conf.manual_move(); } } @@ -3694,33 +3486,27 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case LEVELING_M_UP: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Axis, "Microstep Up"); - } - else { - if (mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) { - mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01; - gcode.process_subcommands_now_P(PSTR("M290 Z0.01")); - planner.synchronize(); - current_position.z += 0.01f; - sync_plan_position(); - Draw_Float(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row-1, false, 100); - } + else if (mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) { + mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01; + gcode.process_subcommands_now_P(PSTR("M290 Z0.01")); + planner.synchronize(); + current_position.z += 0.01f; + sync_plan_position(); + Draw_Float(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100); } break; case LEVELING_M_DOWN: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_AxisD, "Microstep Down"); - } - else { - if (mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) { - mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01; - gcode.process_subcommands_now_P(PSTR("M290 Z-0.01")); - planner.synchronize(); - current_position.z -= 0.01f; - sync_plan_position(); - Draw_Float(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row-2, false, 100); - } + else if (mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) { + mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01; + gcode.process_subcommands_now_P(PSTR("M290 Z-0.01")); + planner.synchronize(); + current_position.z -= 0.01f; + sync_plan_position(); + Draw_Float(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100); } break; case LEVELING_M_GOTO_VALUE: @@ -3737,9 +3523,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ break; #if ENABLED(AUTO_BED_LEVELING_UBL) case LEVELING_M_UNDEF: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_ResumeEEPROM, "Clear Point Value"); - } else { mesh_conf.manual_value_update(true); Redraw_Menu(false); @@ -3748,7 +3533,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ #endif } break; - #endif + #endif // HAS_MESH + #if ENABLED(AUTO_BED_LEVELING_UBL) && !HAS_BED_PROBE case UBLMesh: @@ -3762,9 +3548,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case UBL_M_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } else { set_bed_leveling_enabled(level_state); Draw_Menu(Leveling, LEVELING_GET_MESH); @@ -3772,22 +3557,19 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ break; case UBL_M_NEXT: if (draw) { - if (mesh_conf.mesh_x != (GRID_MAX_POINTS_X-1) || mesh_conf.mesh_y != (GRID_MAX_POINTS_Y-1)) + if (mesh_conf.mesh_x != (GRID_MAX_POINTS_X - 1) || mesh_conf.mesh_y != (GRID_MAX_POINTS_Y - 1)) Draw_Menu_Item(row, ICON_More, "Next Point"); else Draw_Menu_Item(row, ICON_More, "Save Mesh"); } else { - if (mesh_conf.mesh_x != (GRID_MAX_POINTS_X-1) || mesh_conf.mesh_y != (GRID_MAX_POINTS_Y-1)) { - if ((mesh_conf.mesh_x == (GRID_MAX_POINTS_X-1) && mesh_conf.mesh_y % 2 == 0) || (mesh_conf.mesh_x == 0 && mesh_conf.mesh_y % 2 == 1)) { + if (mesh_conf.mesh_x != (GRID_MAX_POINTS_X - 1) || mesh_conf.mesh_y != (GRID_MAX_POINTS_Y - 1)) { + if ((mesh_conf.mesh_x == (GRID_MAX_POINTS_X - 1) && mesh_conf.mesh_y % 2 == 0) || (mesh_conf.mesh_x == 0 && mesh_conf.mesh_y % 2 == 1)) mesh_conf.mesh_y++; - } - else if (mesh_conf.mesh_y % 2 == 0) { + else if (mesh_conf.mesh_y % 2 == 0) mesh_conf.mesh_x++; - } - else { + else mesh_conf.mesh_x--; - } mesh_conf.manual_move(); } else { @@ -3799,20 +3581,16 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case UBL_M_PREV: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_More, "Previous Point"); - } else { if (mesh_conf.mesh_x != 0 || mesh_conf.mesh_y != 0) { - if ((mesh_conf.mesh_x == (GRID_MAX_POINTS_X-1) && mesh_conf.mesh_y % 2 == 1) || (mesh_conf.mesh_x == 0 && mesh_conf.mesh_y % 2 == 0)) { + if ((mesh_conf.mesh_x == (GRID_MAX_POINTS_X - 1) && mesh_conf.mesh_y % 2 == 1) || (mesh_conf.mesh_x == 0 && mesh_conf.mesh_y % 2 == 0)) mesh_conf.mesh_y--; - } - else if (mesh_conf.mesh_y % 2 == 0) { + else if (mesh_conf.mesh_y % 2 == 0) mesh_conf.mesh_x--; - } - else { + else mesh_conf.mesh_x++; - } mesh_conf.manual_move(); } } @@ -3829,38 +3607,33 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case UBL_M_UP: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Axis, "Microstep Up"); - } - else { - if (mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) { - mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01; - gcode.process_subcommands_now_P(PSTR("M290 Z0.01")); - planner.synchronize(); - current_position.z += 0.01f; - sync_plan_position(); - Draw_Float(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row-1, false, 100); - } + else if (mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) { + mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01; + gcode.process_subcommands_now_P(PSTR("M290 Z0.01")); + planner.synchronize(); + current_position.z += 0.01f; + sync_plan_position(); + Draw_Float(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100); } break; case UBL_M_DOWN: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Axis, "Microstep Down"); - } - else { - if (mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) { - mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01; - gcode.process_subcommands_now_P(PSTR("M290 Z-0.01")); - planner.synchronize(); - current_position.z -= 0.01f; - sync_plan_position(); - Draw_Float(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row-2, false, 100); - } + else if (mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) { + mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01; + gcode.process_subcommands_now_P(PSTR("M290 Z-0.01")); + planner.synchronize(); + current_position.z -= 0.01f; + sync_plan_position(); + Draw_Float(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100); } break; } break; - #endif + #endif // AUTO_BED_LEVELING_UBL && !HAS_BED_PROBE + #if ENABLED(PROBE_MANUALLY) case ManualMesh: @@ -3874,9 +3647,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case MMESH_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Cancel"); - } else { gcode.process_subcommands_now_P(PSTR("G29 A")); planner.synchronize(); @@ -3891,20 +3663,18 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ else Draw_Menu_Item(row, ICON_More, "Save Mesh"); } + else if (gridpoint < GRID_MAX_POINTS) { + Popup_Handler(MoveWait); + gcode.process_subcommands_now_P(PSTR("G29")); + planner.synchronize(); + gridpoint++; + Redraw_Menu(); + } else { - if (gridpoint < GRID_MAX_POINTS) { - Popup_Handler(MoveWait); - gcode.process_subcommands_now_P(PSTR("G29")); - planner.synchronize(); - gridpoint++; - Redraw_Menu(); - } - else { - gcode.process_subcommands_now_P(PSTR("G29")); - planner.synchronize(); - AudioFeedback(settings.save()); - Draw_Menu(Leveling, LEVELING_GET_MESH); - } + gcode.process_subcommands_now_P(PSTR("G29")); + planner.synchronize(); + AudioFeedback(settings.save()); + Draw_Menu(Leveling, LEVELING_GET_MESH); } break; case MMESH_OFFSET: @@ -3913,36 +3683,29 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ current_position.z = MANUAL_PROBE_START_Z; Draw_Float(current_position.z, row, false, 100); } - else { + else Modify_Value(current_position.z, MIN_Z_OFFSET, MAX_Z_OFFSET, 100); - } break; case MMESH_UP: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Axis, "Microstep Up"); - } - else { - if (current_position.z < MAX_Z_OFFSET) { - gcode.process_subcommands_now_P(PSTR("M290 Z0.01")); - planner.synchronize(); - current_position.z += 0.01f; - sync_plan_position(); - Draw_Float(current_position.z, row-1, false, 100); - } + else if (current_position.z < MAX_Z_OFFSET) { + gcode.process_subcommands_now_P(PSTR("M290 Z0.01")); + planner.synchronize(); + current_position.z += 0.01f; + sync_plan_position(); + Draw_Float(current_position.z, row - 1, false, 100); } break; case MMESH_DOWN: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_AxisD, "Microstep Down"); - } - else { - if (current_position.z > MIN_Z_OFFSET) { - gcode.process_subcommands_now_P(PSTR("M290 Z-0.01")); - planner.synchronize(); - current_position.z -= 0.01f; - sync_plan_position(); - Draw_Float(current_position.z, row-2, false, 100); - } + else if (current_position.z > MIN_Z_OFFSET) { + gcode.process_subcommands_now_P(PSTR("M290 Z-0.01")); + planner.synchronize(); + current_position.z -= 0.01f; + sync_plan_position(); + Draw_Float(current_position.z, row - 2, false, 100); } break; case MMESH_OLD: @@ -3951,28 +3714,27 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ mesh_y = (gridpoint - 1) / GRID_MAX_POINTS_Y; mesh_x = (gridpoint - 1) % GRID_MAX_POINTS_X; - if (mesh_y % 2 == 1) { + if (mesh_y % 2 == 1) mesh_x = GRID_MAX_POINTS_X - mesh_x - 1; - } const float currval = mesh_conf.mesh_z_values[mesh_x][mesh_y]; if (draw) { Draw_Menu_Item(row, ICON_Zoffset, "Goto Mesh Value"); Draw_Float(currval, row, false, 100); - } else { - if (!isnan(currval)) { - current_position.z = currval; - planner.synchronize(); - planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder); - planner.synchronize(); - Draw_Float(current_position.z, row-3, false, 100); - } + } + else if (!isnan(currval)) { + current_position.z = currval; + planner.synchronize(); + planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder); + planner.synchronize(); + Draw_Float(current_position.z, row - 3, false, 100); } break; } break; - #endif + #endif // PROBE_MANUALLY + case Tune: #define TUNE_BACK 0 @@ -3992,109 +3754,99 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case TUNE_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Back"); - } - else { + else Draw_Print_Screen(); - } break; case TUNE_SPEED: if (draw) { Draw_Menu_Item(row, ICON_Speed, "Print Speed"); Draw_Float(feedrate_percentage, row, false, 1); } - else { + else Modify_Value(feedrate_percentage, MIN_PRINT_SPEED, MAX_PRINT_SPEED, 1); - } break; + #if HAS_HOTEND case TUNE_FLOW: if (draw) { Draw_Menu_Item(row, ICON_Speed, "Flow Rate"); Draw_Float(planner.flow_percentage[0], row, false, 1); } - else { + else Modify_Value(planner.flow_percentage[0], MIN_FLOW_RATE, MAX_FLOW_RATE, 1); - } break; case TUNE_HOTEND: if (draw) { Draw_Menu_Item(row, ICON_SetEndTemp, "Hotend"); Draw_Float(thermalManager.temp_hotend[0].target, row, false, 1); } - else { + else Modify_Value(thermalManager.temp_hotend[0].target, MIN_E_TEMP, MAX_E_TEMP, 1); - } break; #endif + #if HAS_HEATED_BED case TUNE_BED: if (draw) { Draw_Menu_Item(row, ICON_SetBedTemp, "Bed"); Draw_Float(thermalManager.temp_bed.target, row, false, 1); } - else { + else Modify_Value(thermalManager.temp_bed.target, MIN_BED_TEMP, MAX_BED_TEMP, 1); - } break; #endif + #if HAS_FAN case TUNE_FAN: if (draw) { Draw_Menu_Item(row, ICON_FanSpeed, "Fan"); Draw_Float(thermalManager.fan_speed[0], row, false, 1); } - else { + else Modify_Value(thermalManager.fan_speed[0], MIN_FAN_SPEED, MAX_FAN_SPEED, 1); - } break; #endif + #if HAS_ZOFFSET_ITEM case TUNE_ZOFFSET: if (draw) { Draw_Menu_Item(row, ICON_FanSpeed, "Z-Offset"); Draw_Float(zoffsetvalue, row, false, 100); } - else { + else Modify_Value(zoffsetvalue, MIN_Z_OFFSET, MAX_Z_OFFSET, 100); - } break; case TUNE_ZUP: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Axis, "Z-Offset Up"); - } - else { - if (zoffsetvalue < MAX_Z_OFFSET) { - gcode.process_subcommands_now_P(PSTR("M290 Z0.01")); - zoffsetvalue += 0.01; - Draw_Float(zoffsetvalue, row-1, false, 100); - } + else if (zoffsetvalue < MAX_Z_OFFSET) { + gcode.process_subcommands_now_P(PSTR("M290 Z0.01")); + zoffsetvalue += 0.01; + Draw_Float(zoffsetvalue, row - 1, false, 100); } break; case TUNE_ZDOWN: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_AxisD, "Z-Offset Down"); - } - else { - if (zoffsetvalue > MIN_Z_OFFSET) { - gcode.process_subcommands_now_P(PSTR("M290 Z-0.01")); - zoffsetvalue -= 0.01; - Draw_Float(zoffsetvalue, row-2, false, 100); - } + else if (zoffsetvalue > MIN_Z_OFFSET) { + gcode.process_subcommands_now_P(PSTR("M290 Z-0.01")); + zoffsetvalue -= 0.01; + Draw_Float(zoffsetvalue, row - 2, false, 100); } break; #endif + #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES) case TUNE_CHANGEFIL: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_ResumeEEPROM, "Change Filament"); - } - else { + else Popup_Handler(ConfFilChange); - } break; #endif + #if ENABLED(FILAMENT_RUNOUT_SENSOR) case TUNE_FILSENSORENABLED: if (draw) { @@ -4107,25 +3859,24 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; #endif + case TUNE_BACKLIGHT_OFF: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Brightness, "Display Off"); - } - else { + else ui.set_brightness(0); - } break; case TUNE_BACKLIGHT: if (draw) { Draw_Menu_Item(row, ICON_Brightness, "LCD Brightness"); Draw_Float(ui.brightness, row, false, 1); } - else { + else Modify_Value(ui.brightness, MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS, 1, ui.refresh_brightness); - } break; } break; + case PreheatHotend: #define PREHEATHOTEND_BACK 0 @@ -4140,9 +3891,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ switch (item) { case PREHEATHOTEND_BACK: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Back, "Cancel"); - } else { thermalManager.setTargetHotend(0, 0); thermalManager.set_fan_speed(0, 0); @@ -4150,9 +3900,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } break; case PREHEATHOTEND_CONTINUE: - if (draw) { - Draw_Menu_Item(row, ICON_SetEndTemp, (char*)"Continue"); - } + if (draw) + Draw_Menu_Item(row, ICON_SetEndTemp, "Continue"); else { Popup_Handler(Heating); thermalManager.wait_for_hotend(0); @@ -4191,55 +3940,50 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } } break; - #if (PREHEAT_COUNT >= 1) + #if PREHEAT_COUNT >= 1 case PREHEATHOTEND_1: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Temperature, PREHEAT_1_LABEL); - } else { thermalManager.setTargetHotend(ui.material_preset[0].hotend_temp, 0); thermalManager.set_fan_speed(0, ui.material_preset[0].fan_speed); } break; #endif - #if (PREHEAT_COUNT >= 2) + #if PREHEAT_COUNT >= 2 case PREHEATHOTEND_2: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Temperature, PREHEAT_2_LABEL); - } else { thermalManager.setTargetHotend(ui.material_preset[1].hotend_temp, 0); thermalManager.set_fan_speed(0, ui.material_preset[1].fan_speed); } break; #endif - #if (PREHEAT_COUNT >= 3) + #if PREHEAT_COUNT >= 3 case PREHEATHOTEND_3: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Temperature, PREHEAT_3_LABEL); - } else { thermalManager.setTargetHotend(ui.material_preset[2].hotend_temp, 0); thermalManager.set_fan_speed(0, ui.material_preset[2].fan_speed); } break; #endif - #if (PREHEAT_COUNT >= 4) + #if PREHEAT_COUNT >= 4 case PREHEATHOTEND_4: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Temperature, PREHEAT_4_LABEL); - } else { thermalManager.setTargetHotend(ui.material_preset[3].hotend_temp, 0); thermalManager.set_fan_speed(0, ui.material_preset[3].fan_speed); } break; #endif - #if (PREHEAT_COUNT >= 5) + #if PREHEAT_COUNT >= 5 case PREHEATHOTEND_5: - if (draw) { + if (draw) Draw_Menu_Item(row, ICON_Temperature, PREHEAT_5_LABEL); - } else { thermalManager.setTargetHotend(ui.material_preset[4].hotend_temp, 0); thermalManager.set_fan_speed(0, ui.material_preset[4].fan_speed); @@ -4251,9 +3995,8 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ Draw_Menu_Item(row, ICON_Temperature, "Custom"); Draw_Float(thermalManager.temp_hotend[0].target, row, false, 1); } - else { + else Modify_Value(thermalManager.temp_hotend[0].target, EXTRUDE_MINTEMP, MAX_E_TEMP, 1); - } break; } break; @@ -4261,231 +4004,154 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ } const char * CrealityDWINClass::Get_Menu_Title(uint8_t menu) { - switch(menu) { - case MainMenu: - return "Main Menu"; - case Prepare: - return "Prepare"; - case HomeMenu: - return "Homing Menu"; - case Move: - return "Move"; - case ManualLevel: - return "Manual Leveling"; + switch (menu) { + case MainMenu: return "Main Menu"; + case Prepare: return "Prepare"; + case HomeMenu: return "Homing Menu"; + case Move: return "Move"; + case ManualLevel: return "Manual Leveling"; #if HAS_ZOFFSET_ITEM - case ZOffset: - return "Z Offset"; + case ZOffset: return "Z Offset"; #endif #if HAS_PREHEAT - case Preheat: - return "Preheat"; + case Preheat: return "Preheat"; #endif #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES) - case ChangeFilament: - return "Change Filament"; + case ChangeFilament: return "Change Filament"; #endif - case Control: - return "Control"; - case TempMenu: - return "Temperature"; - #if ANY(HAS_HOTEND, HAS_HEATED_BED) - case PID: - return "PID Menu"; + case Control: return "Control"; + case TempMenu: return "Temperature"; + #if HAS_HOTEND || HAS_HEATED_BED + case PID: return "PID Menu"; #endif #if HAS_HOTEND - case HotendPID: - return "Hotend PID Settings"; + case HotendPID: return "Hotend PID Settings"; #endif #if HAS_HEATED_BED - case BedPID: - return "Bed PID Settings"; + case BedPID: return "Bed PID Settings"; #endif - #if (PREHEAT_COUNT >= 1) - case Preheat1: - return (PREHEAT_1_LABEL " Settings"); + #if PREHEAT_COUNT >= 1 + case Preheat1: return (PREHEAT_1_LABEL " Settings"); #endif - #if (PREHEAT_COUNT >= 2) - case Preheat2: - return (PREHEAT_2_LABEL " Settings"); + #if PREHEAT_COUNT >= 2 + case Preheat2: return (PREHEAT_2_LABEL " Settings"); #endif - #if (PREHEAT_COUNT >= 3) - case Preheat3: - return (PREHEAT_3_LABEL " Settings"); + #if PREHEAT_COUNT >= 3 + case Preheat3: return (PREHEAT_3_LABEL " Settings"); #endif - #if (PREHEAT_COUNT >= 4) - case Preheat4: - return (PREHEAT_4_LABEL " Settings"); + #if PREHEAT_COUNT >= 4 + case Preheat4: return (PREHEAT_4_LABEL " Settings"); #endif - #if (PREHEAT_COUNT >= 5) - case Preheat5: - return (PREHEAT_5_LABEL " Settings"); + #if PREHEAT_COUNT >= 5 + case Preheat5: return (PREHEAT_5_LABEL " Settings"); #endif - case Motion: - return "Motion Settings"; - case HomeOffsets: - return "Home Offsets"; - case MaxSpeed: - return "Max Speed"; - case MaxAcceleration: - return "Max Acceleration"; + case Motion: return "Motion Settings"; + case HomeOffsets: return "Home Offsets"; + case MaxSpeed: return "Max Speed"; + case MaxAcceleration: return "Max Acceleration"; #if HAS_CLASSIC_JERK - case MaxJerk: - return "Max Jerk"; + case MaxJerk: return "Max Jerk"; #endif - case Steps: - return "Steps/mm"; - case Visual: - return "Visual Settings"; - case Advanced: - return "Advanced Settings"; + case Steps: return "Steps/mm"; + case Visual: return "Visual Settings"; + case Advanced: return "Advanced Settings"; #if HAS_BED_PROBE - case ProbeMenu: - return "Probe Menu"; + case ProbeMenu: return "Probe Menu"; #endif - case ColorSettings: - return "UI Color Settings"; - case Info: - return "Info"; - case InfoMain: - return "Info"; + case ColorSettings: return "UI Color Settings"; + case Info: return "Info"; + case InfoMain: return "Info"; #if HAS_MESH - case Leveling: - return "Leveling"; - case LevelView: - return "Mesh View"; - case LevelSettings: - return "Leveling Settings"; - case MeshViewer: - return "Mesh Viewer"; - case LevelManual: - return "Manual Tuning"; + case Leveling: return "Leveling"; + case LevelView: return "Mesh View"; + case LevelSettings: return "Leveling Settings"; + case MeshViewer: return "Mesh Viewer"; + case LevelManual: return "Manual Tuning"; #endif #if ENABLED(AUTO_BED_LEVELING_UBL) && !HAS_BED_PROBE - case UBLMesh: - return "UBL Bed Leveling"; + case UBLMesh: return "UBL Bed Leveling"; #endif #if ENABLED(PROBE_MANUALLY) - case ManualMesh: - return "Mesh Bed Leveling"; + case ManualMesh: return "Mesh Bed Leveling"; #endif - case Tune: - return "Tune"; - case PreheatHotend: - return "Preheat Hotend"; + case Tune: return "Tune"; + case PreheatHotend: return "Preheat Hotend"; } return ""; } uint8_t CrealityDWINClass::Get_Menu_Size(uint8_t menu) { - switch(menu) { - case Prepare: - return PREPARE_TOTAL; - case HomeMenu: - return HOME_TOTAL; - case Move: - return MOVE_TOTAL; - case ManualLevel: - return MLEVEL_TOTAL; + switch (menu) { + case Prepare: return PREPARE_TOTAL; + case HomeMenu: return HOME_TOTAL; + case Move: return MOVE_TOTAL; + case ManualLevel: return MLEVEL_TOTAL; #if HAS_ZOFFSET_ITEM - case ZOffset: - return ZOFFSET_TOTAL; + case ZOffset: return ZOFFSET_TOTAL; #endif #if HAS_PREHEAT - case Preheat: - return PREHEAT_TOTAL; + case Preheat: return PREHEAT_TOTAL; #endif #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES) - case ChangeFilament: - return CHANGEFIL_TOTAL; + case ChangeFilament: return CHANGEFIL_TOTAL; #endif - case Control: - return CONTROL_TOTAL; - case TempMenu: - return TEMP_TOTAL; - #if ANY(HAS_HOTEND, HAS_HEATED_BED) - case PID: - return PID_TOTAL; + case Control: return CONTROL_TOTAL; + case TempMenu: return TEMP_TOTAL; + #if HAS_HOTEND || HAS_HEATED_BED + case PID: return PID_TOTAL; #endif #if HAS_HOTEND - case HotendPID: - return HOTENDPID_TOTAL; + case HotendPID: return HOTENDPID_TOTAL; #endif #if HAS_HEATED_BED - case BedPID: - return BEDPID_TOTAL; + case BedPID: return BEDPID_TOTAL; #endif - #if (PREHEAT_COUNT >= 1) - case Preheat1: - return PREHEAT1_TOTAL; + #if PREHEAT_COUNT >= 1 + case Preheat1: return PREHEAT1_TOTAL; #endif - #if (PREHEAT_COUNT >= 2) - case Preheat2: - return PREHEAT2_TOTAL; + #if PREHEAT_COUNT >= 2 + case Preheat2: return PREHEAT2_TOTAL; #endif - #if (PREHEAT_COUNT >= 3) - case Preheat3: - return PREHEAT3_TOTAL; + #if PREHEAT_COUNT >= 3 + case Preheat3: return PREHEAT3_TOTAL; #endif - #if (PREHEAT_COUNT >= 4) - case Preheat4: - return PREHEAT4_TOTAL; + #if PREHEAT_COUNT >= 4 + case Preheat4: return PREHEAT4_TOTAL; #endif - #if (PREHEAT_COUNT >= 5) - case Preheat5: - return PREHEAT5_TOTAL; + #if PREHEAT_COUNT >= 5 + case Preheat5: return PREHEAT5_TOTAL; #endif - case Motion: - return MOTION_TOTAL; - case HomeOffsets: - return HOMEOFFSETS_TOTAL; - case MaxSpeed: - return SPEED_TOTAL; - case MaxAcceleration: - return ACCEL_TOTAL; + case Motion: return MOTION_TOTAL; + case HomeOffsets: return HOMEOFFSETS_TOTAL; + case MaxSpeed: return SPEED_TOTAL; + case MaxAcceleration: return ACCEL_TOTAL; #if HAS_CLASSIC_JERK - case MaxJerk: - return JERK_TOTAL; + case MaxJerk: return JERK_TOTAL; #endif - case Steps: - return STEPS_TOTAL; - case Visual: - return VISUAL_TOTAL; - case Advanced: - return ADVANCED_TOTAL; + case Steps: return STEPS_TOTAL; + case Visual: return VISUAL_TOTAL; + case Advanced: return ADVANCED_TOTAL; #if HAS_BED_PROBE - case ProbeMenu: - return PROBE_TOTAL; + case ProbeMenu: return PROBE_TOTAL; #endif - case Info: - return INFO_TOTAL; - case InfoMain: - return INFO_TOTAL; + case Info: return INFO_TOTAL; + case InfoMain: return INFO_TOTAL; #if ENABLED(AUTO_BED_LEVELING_UBL) && !HAS_BED_PROBE - case UBLMesh: - return UBL_M_TOTAL; + case UBLMesh: return UBL_M_TOTAL; #endif #if ENABLED(PROBE_MANUALLY) - case ManualMesh: - return MMESH_TOTAL; + case ManualMesh: return MMESH_TOTAL; #endif #if HAS_MESH - case Leveling: - return LEVELING_TOTAL; - case LevelView: - return LEVELING_VIEW_TOTAL; - case LevelSettings: - return LEVELING_SETTINGS_TOTAL; - case MeshViewer: - return MESHVIEW_TOTAL; - case LevelManual: - return LEVELING_M_TOTAL; + case Leveling: return LEVELING_TOTAL; + case LevelView: return LEVELING_VIEW_TOTAL; + case LevelSettings: return LEVELING_SETTINGS_TOTAL; + case MeshViewer: return MESHVIEW_TOTAL; + case LevelManual: return LEVELING_M_TOTAL; #endif - case Tune: - return TUNE_TOTAL; - case PreheatHotend: - return PREHEATHOTEND_TOTAL; - case ColorSettings: - return COLORSETTINGS_TOTAL; + case Tune: return TUNE_TOTAL; + case PreheatHotend: return PREHEATHOTEND_TOTAL; + case ColorSettings: return COLORSETTINGS_TOTAL; } return 0; } @@ -4495,88 +4161,38 @@ uint8_t CrealityDWINClass::Get_Menu_Size(uint8_t menu) { void CrealityDWINClass::Popup_Handler(PopupID popupid, bool option/*=false*/) { popup = last_popup = popupid; switch (popupid) { - case Pause: - Draw_Popup("Pause Print", "", "", Popup); - break; - case Stop: - Draw_Popup("Stop Print", "", "", Popup); - break; - case Resume: - Draw_Popup("Resume Print?", "Looks Like the last", "print was interupted.", Popup); - break; - case ConfFilChange: - Draw_Popup("Confirm Filament Change", "", "", Popup); - break; - case PurgeMore: - Draw_Popup("Purge more filament?", "(Cancel to finish process)", "", Popup); - break; - case SaveLevel: - Draw_Popup("Leveling Complete", "Save to EEPROM?", "", Popup); - break; - case MeshSlot: - Draw_Popup("Mesh slot not selected", "(Confirm to select slot 0)", "", Popup); - break; - case ETemp: - Draw_Popup("Nozzle is too cold", "Open Preheat Menu?", "", Popup); - break; - case ManualProbing: - Draw_Popup("Manual Probing", "(Confirm to probe)", "(cancel to exit)", Popup); - break; - case Level: - Draw_Popup("Auto Bed Leveling", "Please wait until done.", "", Wait, ICON_AutoLeveling); - break; - case Home: - Draw_Popup(option ? "Parking" : "Homing", "Please wait until done.", "", Wait, ICON_BLTouch); - break; - case MoveWait: - Draw_Popup("Moving to Point", "Please wait until done.", "", Wait, ICON_BLTouch); - break; - case Heating: - Draw_Popup("Heating", "Please wait until done.", "", Wait, ICON_BLTouch); - break; - case FilLoad: - Draw_Popup(option ? "Unloading Filament" : "Loading Filament", "Please wait until done.", "", Wait, ICON_BLTouch); - break; - case FilChange: - Draw_Popup("Filament Change", "Please wait for prompt.", "", Wait, ICON_BLTouch); - break; - case TempWarn: - Draw_Popup(option ? "Nozzle temp too low!" : "Nozzle temp too high!", "", "", Wait, option ? ICON_TempTooLow : ICON_TempTooHigh); - break; - case Runout: - Draw_Popup("Filament Runout", "", "", Wait, ICON_BLTouch); - break; - case PIDWait: - Draw_Popup("PID Autotune", "in process", "Please wait until done.", Wait, ICON_BLTouch); - break; - case Resuming: - Draw_Popup("Resuming Print", "Please wait until done.", "", Wait, ICON_BLTouch); - break; - default: - break; + case Pause: Draw_Popup(PSTR("Pause Print"), PSTR(""), PSTR(""), Popup); break; + case Stop: Draw_Popup(PSTR("Stop Print"), PSTR(""), PSTR(""), Popup); break; + case Resume: Draw_Popup(PSTR("Resume Print?"), PSTR("Looks Like the last"), PSTR("print was interupted."), Popup); break; + case ConfFilChange: Draw_Popup(PSTR("Confirm Filament Change"), PSTR(""), PSTR(""), Popup); break; + case PurgeMore: Draw_Popup(PSTR("Purge more filament?"), PSTR("(Cancel to finish process)"), PSTR(""), Popup); break; + case SaveLevel: Draw_Popup(PSTR("Leveling Complete"), PSTR("Save to EEPROM?"), PSTR(""), Popup); break; + case MeshSlot: Draw_Popup(PSTR("Mesh slot not selected"), PSTR("(Confirm to select slot 0)"), PSTR(""), Popup); break; + case ETemp: Draw_Popup(PSTR("Nozzle is too cold"), PSTR("Open Preheat Menu?"), PSTR(""), Popup); break; + case ManualProbing: Draw_Popup(PSTR("Manual Probing"), PSTR("(Confirm to probe)"), PSTR("(cancel to exit)"), Popup); break; + case Level: Draw_Popup(PSTR("Auto Bed Leveling"), PSTR("Please wait until done."), PSTR(""), Wait, ICON_AutoLeveling); break; + case Home: Draw_Popup(option ? PSTR("Parking") : PSTR("Homing"), PSTR("Please wait until done."), PSTR(""), Wait, ICON_BLTouch); break; + case MoveWait: Draw_Popup(PSTR("Moving to Point"), PSTR("Please wait until done."), PSTR(""), Wait, ICON_BLTouch); break; + case Heating: Draw_Popup(PSTR("Heating"), PSTR("Please wait until done."), PSTR(""), Wait, ICON_BLTouch); break; + case FilLoad: Draw_Popup(option ? PSTR("Unloading Filament") : PSTR("Loading Filament"), PSTR("Please wait until done."), PSTR(""), Wait, ICON_BLTouch); break; + case FilChange: Draw_Popup(PSTR("Filament Change"), PSTR("Please wait for prompt."), PSTR(""), Wait, ICON_BLTouch); break; + case TempWarn: Draw_Popup(option ? PSTR("Nozzle temp too low!") : PSTR("Nozzle temp too high!"), PSTR(""), PSTR(""), Wait, option ? ICON_TempTooLow : ICON_TempTooHigh); break; + case Runout: Draw_Popup(PSTR("Filament Runout"), PSTR(""), PSTR(""), Wait, ICON_BLTouch); break; + case PIDWait: Draw_Popup(PSTR("PID Autotune"), PSTR("in process"), PSTR("Please wait until done."), Wait, ICON_BLTouch); break; + case Resuming: Draw_Popup(PSTR("Resuming Print"), PSTR("Please wait until done."), PSTR(""), Wait, ICON_BLTouch); break; + default: break; } } void CrealityDWINClass::Confirm_Handler(PopupID popupid) { popup = popupid; switch (popupid) { - case FilInsert: - Draw_Popup("Insert Filament", "Press to Continue", "", Confirm); - break; - case HeaterTime: - Draw_Popup("Heater Timed Out", "Press to Reheat", "", Confirm); - break; - case UserInput: - Draw_Popup("Waiting for Input", "Press to Continue", "", Confirm); - break; - case LevelError: - Draw_Popup("Couldn't enable Leveling", "(Valid mesh must exist)", "", Confirm); - break; - case InvalidMesh: - Draw_Popup("Valid mesh must exist", "before tuning can be", "performed", Confirm); - break; - default: - break; + case FilInsert: Draw_Popup(PSTR("Insert Filament"), PSTR("Press to Continue"), PSTR(""), Confirm); break; + case HeaterTime: Draw_Popup(PSTR("Heater Timed Out"), PSTR("Press to Reheat"), PSTR(""), Confirm); break; + case UserInput: Draw_Popup(PSTR("Waiting for Input"), PSTR("Press to Continue"), PSTR(""), Confirm); break; + case LevelError: Draw_Popup(PSTR("Couldn't enable Leveling"), PSTR("(Valid mesh must exist)"), PSTR(""), Confirm); break; + case InvalidMesh: Draw_Popup(PSTR("Valid mesh must exist"), PSTR("before tuning can be"), PSTR("performed"), Confirm); break; + default: break; } } @@ -4594,24 +4210,11 @@ void CrealityDWINClass::Main_Menu_Control() { Main_Menu_Icons(); } else if (encoder_diffState == ENCODER_DIFF_ENTER) - switch(selection) { - case 0: - card.mount(); - Draw_SD_List(); - break; - case 1: - Draw_Menu(Prepare); - break; - case 2: - Draw_Menu(Control); - break; - case 3: - #if HAS_MESH - Draw_Menu(Leveling); - #else - Draw_Menu(InfoMain); - #endif - break; + switch (selection) { + case 0: card.mount(); Draw_SD_List(); break; + case 1: Draw_Menu(Prepare); break; + case 2: Draw_Menu(Control); break; + case 3: Draw_Menu(TERN(HAS_MESH, Leveling, InfoMain)); break; } DWIN_UpdateLCD(); } @@ -4620,24 +4223,24 @@ void CrealityDWINClass::Menu_Control() { ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze(); if (encoder_diffState == ENCODER_DIFF_NO) return; if (encoder_diffState == ENCODER_DIFF_CW && selection < Get_Menu_Size(active_menu)) { - DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection-scrollpos) - 18, 14, MBASE(selection-scrollpos) + 33); + DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33); selection++; // Select Down if (selection > scrollpos+MROWS) { scrollpos++; DWIN_Frame_AreaMove(1, 2, MLINE, Color_Bg_Black, 0, 31, DWIN_WIDTH, 349); Menu_Item_Handler(active_menu, selection); } - DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(selection-scrollpos) - 18, 14, MBASE(selection-scrollpos) + 33); + DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33); } else if (encoder_diffState == ENCODER_DIFF_CCW && selection > 0) { - DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection-scrollpos) - 18, 14, MBASE(selection-scrollpos) + 33); + DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33); selection--; // Select Up if (selection < scrollpos) { scrollpos--; DWIN_Frame_AreaMove(1, 3, MLINE, Color_Bg_Black, 0, 31, DWIN_WIDTH, 349); Menu_Item_Handler(active_menu, selection); } - DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(selection-scrollpos) - 18, 14, MBASE(selection-scrollpos) + 33); + DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33); } else if (encoder_diffState == ENCODER_DIFF_ENTER) Menu_Item_Handler(active_menu, selection, false); @@ -4647,44 +4250,42 @@ void CrealityDWINClass::Menu_Control() { void CrealityDWINClass::Value_Control() { ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze(); if (encoder_diffState == ENCODER_DIFF_NO) return; - if (encoder_diffState == ENCODER_DIFF_CW) { + if (encoder_diffState == ENCODER_DIFF_CW) tempvalue += EncoderRate.encoderMoveValue; - } - else if (encoder_diffState == ENCODER_DIFF_CCW) { + else if (encoder_diffState == ENCODER_DIFF_CCW) tempvalue -= EncoderRate.encoderMoveValue; - } else if (encoder_diffState == ENCODER_DIFF_ENTER) { process = Menu; EncoderRate.enabled = false; - Draw_Float(tempvalue/valueunit, selection-scrollpos, false, valueunit); + Draw_Float(tempvalue / valueunit, selection - scrollpos, false, valueunit); DWIN_UpdateLCD(); if (active_menu == ZOffset && liveadjust) { planner.synchronize(); - current_position.z += (tempvalue/valueunit - zoffsetvalue); + current_position.z += (tempvalue / valueunit - zoffsetvalue); planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder); current_position.z = 0; sync_plan_position(); } else if (active_menu == Tune && selection == TUNE_ZOFFSET) { - sprintf_P(cmd, PSTR("M290 Z%s"), dtostrf((tempvalue/valueunit - zoffsetvalue), 1, 3, str_1)); + sprintf_P(cmd, PSTR("M290 Z%s"), dtostrf((tempvalue / valueunit - zoffsetvalue), 1, 3, str_1)); gcode.process_subcommands_now_P(cmd); } - if (valuepointer == &thermalManager.temp_hotend[0].pid.Ki || valuepointer == &thermalManager.temp_bed.pid.Ki) + if (TERN0(HAS_HOTEND, valuepointer == &thermalManager.temp_hotend[0].pid.Ki) || TERN0(HAS_HEATED_BED, valuepointer == &thermalManager.temp_bed.pid.Ki)) tempvalue = scalePID_i(tempvalue); - if (valuepointer == &thermalManager.temp_hotend[0].pid.Kd || valuepointer == &thermalManager.temp_bed.pid.Kd) + if (TERN0(HAS_HOTEND, valuepointer == &thermalManager.temp_hotend[0].pid.Kd) || TERN0(HAS_HEATED_BED, valuepointer == &thermalManager.temp_bed.pid.Kd)) tempvalue = scalePID_d(tempvalue); switch (valuetype) { - case 0: *(float*)valuepointer = tempvalue/valueunit; break; - case 1: *(uint8_t*)valuepointer = tempvalue/valueunit; break; - case 2: *(uint16_t*)valuepointer = tempvalue/valueunit; break; - case 3: *(int16_t*)valuepointer = tempvalue/valueunit; break; - case 4: *(uint32_t*)valuepointer = tempvalue/valueunit; break; - case 5: *(int8_t*)valuepointer = tempvalue/valueunit; break; + case 0: *(float*)valuepointer = tempvalue / valueunit; break; + case 1: *(uint8_t*)valuepointer = tempvalue / valueunit; break; + case 2: *(uint16_t*)valuepointer = tempvalue / valueunit; break; + case 3: *(int16_t*)valuepointer = tempvalue / valueunit; break; + case 4: *(uint32_t*)valuepointer = tempvalue / valueunit; break; + case 5: *(int8_t*)valuepointer = tempvalue / valueunit; break; } switch (active_menu) { case Move: planner.synchronize(); - planner.buffer_line(current_position, manual_feedrate_mm_s[selection-1], active_extruder); + planner.buffer_line(current_position, manual_feedrate_mm_s[selection - 1], active_extruder); break; #if HAS_MESH case ManualMesh: @@ -4692,44 +4293,37 @@ void CrealityDWINClass::Value_Control() { planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder); planner.synchronize(); break; - case UBLMesh: - mesh_conf.manual_move(true); - break; - case LevelManual: - mesh_conf.manual_move(selection == LEVELING_M_OFFSET); - break; + case UBLMesh: mesh_conf.manual_move(true); break; + case LevelManual: mesh_conf.manual_move(selection == LEVELING_M_OFFSET); break; #endif } - if (valuepointer == &planner.flow_percentage[0]) { + if (valuepointer == &planner.flow_percentage[0]) planner.refresh_e_factor(0); - } if (funcpointer) funcpointer(); return; } NOLESS(tempvalue, (valuemin * valueunit)); NOMORE(tempvalue, (valuemax * valueunit)); - Draw_Float(tempvalue/valueunit, selection-scrollpos, true, valueunit); + Draw_Float(tempvalue / valueunit, selection - scrollpos, true, valueunit); DWIN_UpdateLCD(); if (active_menu == Move && livemove) { - *(float*)valuepointer = tempvalue/valueunit; - planner.buffer_line(current_position, manual_feedrate_mm_s[selection-1], active_extruder); + *(float*)valuepointer = tempvalue / valueunit; + planner.buffer_line(current_position, manual_feedrate_mm_s[selection - 1], active_extruder); } } void CrealityDWINClass::Option_Control() { ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze(); if (encoder_diffState == ENCODER_DIFF_NO) return; - if (encoder_diffState == ENCODER_DIFF_CW) { + if (encoder_diffState == ENCODER_DIFF_CW) tempvalue += EncoderRate.encoderMoveValue; - } - else if (encoder_diffState == ENCODER_DIFF_CCW) { + else if (encoder_diffState == ENCODER_DIFF_CCW) tempvalue -= EncoderRate.encoderMoveValue; - } else if (encoder_diffState == ENCODER_DIFF_ENTER) { process = Menu; EncoderRate.enabled = false; if (valuepointer == &color_names) { - switch(selection) { + switch (selection) { case COLORSETTINGS_CURSOR: eeprom_settings.cursor_color = tempvalue; break; case COLORSETTINGS_SPLIT_LINE: eeprom_settings.menu_split_line = tempvalue; break; case COLORSETTINGS_MENU_TOP_BG: eeprom_settings.menu_top_bg = tempvalue; break; @@ -4744,16 +4338,16 @@ void CrealityDWINClass::Option_Control() { } Redraw_Screen(); } - else if (valuepointer == &preheat_modes) { + else if (valuepointer == &preheat_modes) preheatmode = tempvalue; - } - Draw_Option(tempvalue, static_cast(valuepointer), selection-scrollpos, false, (valuepointer == &color_names)); + + Draw_Option(tempvalue, static_cast(valuepointer), selection - scrollpos, false, (valuepointer == &color_names)); DWIN_UpdateLCD(); return; } NOLESS(tempvalue, valuemin); NOMORE(tempvalue, valuemax); - Draw_Option(tempvalue, static_cast(valuepointer), selection-scrollpos, true); + Draw_Option(tempvalue, static_cast(valuepointer), selection - scrollpos, true); DWIN_UpdateLCD(); } @@ -4762,7 +4356,7 @@ void CrealityDWINClass::File_Control() { static uint8_t filescrl = 0; if (encoder_diffState == ENCODER_DIFF_NO) { if (selection > 0) { - card.getfilename_sorted(SD_ORDER(selection-1, card.get_num_Files())); + card.getfilename_sorted(SD_ORDER(selection - 1, card.get_num_Files())); char * const filename = card.longest_filename(); size_t len = strlen(filename); int8_t pos = len; @@ -4773,22 +4367,19 @@ void CrealityDWINClass::File_Control() { if (PENDING(millis(), time)) return; time = millis() + 200; pos -= filescrl; - len = pos; - if (len > MENU_CHAR_LIMIT) - len = MENU_CHAR_LIMIT; - char name[len+1]; + len = _MIN(pos, MENU_CHAR_LIMIT); + char name[len + 1]; if (pos >= 0) { - LOOP_L_N(i, len) name[i] = filename[i+filescrl]; + LOOP_L_N(i, len) name[i] = filename[i + filescrl]; } else { - LOOP_L_N(i, MENU_CHAR_LIMIT+pos) name[i] = ' '; - LOOP_S_L_N(i, MENU_CHAR_LIMIT+pos, MENU_CHAR_LIMIT) name[i] = filename[i-(MENU_CHAR_LIMIT+pos)]; + LOOP_L_N(i, MENU_CHAR_LIMIT + pos) name[i] = ' '; + LOOP_S_L_N(i, MENU_CHAR_LIMIT + pos, MENU_CHAR_LIMIT) name[i] = filename[i - (MENU_CHAR_LIMIT + pos)]; } name[len] = '\0'; - DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection-scrollpos) - 14, 271, MBASE(selection-scrollpos) + 28); - Draw_Menu_Item(selection-scrollpos, card.flag.filenameIsDir ? ICON_More : ICON_File, name); - if (-pos >= MENU_CHAR_LIMIT) - filescrl = 0; + DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28); + Draw_Menu_Item(selection - scrollpos, card.flag.filenameIsDir ? ICON_More : ICON_File, name); + if (-pos >= MENU_CHAR_LIMIT) filescrl = 0; filescrl++; DWIN_UpdateLCD(); } @@ -4796,36 +4387,36 @@ void CrealityDWINClass::File_Control() { return; } if (encoder_diffState == ENCODER_DIFF_CW && selection < card.get_num_Files()) { - DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection-scrollpos) - 18, 14, MBASE(selection-scrollpos) + 33); + DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33); if (selection > 0) { - DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection-scrollpos) - 14, 271, MBASE(selection-scrollpos) + 28); - Draw_SD_Item(selection, selection-scrollpos); + DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28); + Draw_SD_Item(selection, selection - scrollpos); } filescrl = 0; selection++; // Select Down - if (selection > scrollpos+MROWS) { + if (selection > scrollpos + MROWS) { scrollpos++; DWIN_Frame_AreaMove(1, 2, MLINE, Color_Bg_Black, 0, 31, DWIN_WIDTH, 349); - Draw_SD_Item(selection, selection-scrollpos); + Draw_SD_Item(selection, selection - scrollpos); } - DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(selection-scrollpos) - 18, 14, MBASE(selection-scrollpos) + 33); + DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33); } else if (encoder_diffState == ENCODER_DIFF_CCW && selection > 0) { - DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection-scrollpos) - 18, 14, MBASE(selection-scrollpos) + 33); - DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection-scrollpos) - 14, 271, MBASE(selection-scrollpos) + 28); - Draw_SD_Item(selection, selection-scrollpos); + DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33); + DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28); + Draw_SD_Item(selection, selection - scrollpos); filescrl = 0; selection--; // Select Up if (selection < scrollpos) { scrollpos--; DWIN_Frame_AreaMove(1, 3, MLINE, Color_Bg_Black, 0, 31, DWIN_WIDTH, 349); - Draw_SD_Item(selection, selection-scrollpos); + Draw_SD_Item(selection, selection - scrollpos); } - DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(selection-scrollpos) - 18, 14, MBASE(selection-scrollpos) + 33); + DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33); } else if (encoder_diffState == ENCODER_DIFF_ENTER) { if (selection == 0) { - if(card.flag.workDirIsRoot) { + if (card.flag.workDirIsRoot) { process = Main; Draw_Main_Menu(); } @@ -4835,7 +4426,7 @@ void CrealityDWINClass::File_Control() { } } else { - card.getfilename_sorted(SD_ORDER(selection-1, card.get_num_Files())); + card.getfilename_sorted(SD_ORDER(selection - 1, card.get_num_Files())); if (card.flag.filenameIsDir) { card.cd(card.filename); Draw_SD_List(); @@ -4859,8 +4450,8 @@ void CrealityDWINClass::Print_Screen_Control() { selection--; // Select Up Print_Screen_Icons(); } - else if (encoder_diffState == ENCODER_DIFF_ENTER) - switch(selection) { + else if (encoder_diffState == ENCODER_DIFF_ENTER) { + switch (selection) { case 0: Draw_Menu(Tune); Update_Status_Bar(true); @@ -4874,19 +4465,21 @@ void CrealityDWINClass::Print_Screen_Control() { TERN_(POWER_LOSS_RECOVERY, recovery.prepare()); #else char cmnd[20]; - cmnd[sprintf_P(cmnd, PSTR("M140 S%i"), pausebed)] = '\0'; - gcode.process_subcommands_now_P(PSTR(cmnd)); - cmnd[sprintf_P(cmnd, PSTR("M109 S%i"), pausetemp)] = '\0'; - gcode.process_subcommands_now_P(PSTR(cmnd)); - thermalManager.fan_speed[0] = pausefan; + #if HAS_HEATED_BED + cmnd[sprintf_P(cmnd, PSTR("M140 S%i"), pausebed)] = '\0'; + gcode.process_subcommands_now_P(PSTR(cmnd)); + #endif + #if HAS_EXTRUDERS + cmnd[sprintf_P(cmnd, PSTR("M109 S%i"), pausetemp)] = '\0'; + gcode.process_subcommands_now_P(PSTR(cmnd)); + #endif + TERN_(HAS_FAN, thermalManager.fan_speed[0] = pausefan); planner.synchronize(); - queue.inject_P(PSTR("M24")); + TERN_(SDSUPPORT, queue.inject_P(PSTR("M24"))); #endif } else { - #if ENABLED(HOST_ACTION_COMMANDS) - host_action_resume(); - #endif + TERN_(HOST_ACTION_COMMANDS, host_action_resume()); } Draw_Print_Screen(); } @@ -4897,6 +4490,7 @@ void CrealityDWINClass::Print_Screen_Control() { Popup_Handler(Stop); break; } + } DWIN_UpdateLCD(); } @@ -4911,10 +4505,10 @@ void CrealityDWINClass::Popup_Control() { selection--; Popup_Select(); } - else if (encoder_diffState == ENCODER_DIFF_ENTER) - switch(popup) { + else if (encoder_diffState == ENCODER_DIFF_ENTER) { + switch (popup) { case Pause: - if (selection==0) { + if (selection == 0) { if (sdprint) { #if ENABLED(POWER_LOSS_RECOVERY) if (recovery.enabled) recovery.save(true); @@ -4929,66 +4523,60 @@ void CrealityDWINClass::Popup_Control() { planner.synchronize(); #else queue.inject_P(PSTR("M25")); - pausetemp = thermalManager.temp_hotend[0].target; - pausebed = thermalManager.temp_bed.target; - pausefan = thermalManager.fan_speed[0]; + TERN_(HAS_HOTEND, pausetemp = thermalManager.temp_hotend[0].target); + TERN_(HAS_HEATED_BED, pausebed = thermalManager.temp_bed.target); + TERN_(HAS_FAN, pausefan = thermalManager.fan_speed[0]); thermalManager.disable_all_heaters(); - thermalManager.zero_fan_speeds(); + TERN_(HAS_FAN, thermalManager.zero_fan_speeds()); #endif } else { - #if ENABLED(HOST_ACTION_COMMANDS) - host_action_pause(); - #endif + TERN_(HOST_ACTION_COMMANDS, host_action_pause()); } } Draw_Print_Screen(); break; case Stop: - if (selection==0) { + if (selection == 0) { if (sdprint) { ui.abort_print(); - thermalManager.zero_fan_speeds(); + TERN_(HAS_FAN, thermalManager.zero_fan_speeds()); thermalManager.disable_all_heaters(); } else { - #if ENABLED(HOST_ACTION_COMMANDS) - host_action_cancel(); - #endif + TERN_(HOST_ACTION_COMMANDS, host_action_cancel()); } } - else { + else Draw_Print_Screen(); - } break; case Resume: - if (selection==0) { + if (selection == 0) queue.inject_P(PSTR("M1000")); - } else { queue.inject_P(PSTR("M1000 C")); Draw_Main_Menu(); } break; - case ETemp: - if (selection==0) { - thermalManager.setTargetHotend(EXTRUDE_MINTEMP, 0); - thermalManager.set_fan_speed(0, MAX_FAN_SPEED); - Draw_Menu(PreheatHotend); - } - else { - Redraw_Menu(true, true, false); - } - break; + + #if HAS_HOTEND + case ETemp: + if (selection == 0) { + thermalManager.setTargetHotend(EXTRUDE_MINTEMP, 0); + thermalManager.set_fan_speed(0, MAX_FAN_SPEED); + Draw_Menu(PreheatHotend); + } + else + Redraw_Menu(true, true, false); + break; + #endif + #if HAS_BED_PROBE case ManualProbing: - if (selection==0) { + if (selection == 0) { char buf[80]; const float dif = probe.probe_at_point(current_position.x, current_position.y, PROBE_PT_STOW, 0, false) - corner_avg; - if (dif > 0) - sprintf(buf, "Corner is %smm high", dtostrf(abs(dif), 1, 3, str_1)); - else - sprintf(buf, "Corner is %smm low", dtostrf(abs(dif), 1, 3, str_1)); + sprintf_P(buf, dif > 0 ? PSTR("Corner is %smm high") : PSTR("Corner is %smm low"), dtostrf(abs(dif), 1, 3, str_1)); Update_Status(buf); } else { @@ -4997,14 +4585,14 @@ void CrealityDWINClass::Popup_Control() { } break; #endif + #if ENABLED(ADVANCED_PAUSE_FEATURE) case ConfFilChange: - if (selection==0) { - if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) { + if (selection == 0) { + if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) Popup_Handler(ETemp); - } else { - if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target-2) { + if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) { Popup_Handler(Heating); thermalManager.wait_for_hotend(0); } @@ -5012,24 +4600,26 @@ void CrealityDWINClass::Popup_Control() { sprintf_P(cmd, PSTR("M600 B1 R%i"), thermalManager.temp_hotend[0].target); gcode.process_subcommands_now_P(cmd); } - } else { - Redraw_Menu(true, true, false); } + else + Redraw_Menu(true, true, false); break; case PurgeMore: - if (selection==0) { + if (selection == 0) { pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE; Popup_Handler(FilChange); - } else { + } + else { pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; if (printing) Popup_Handler(Resuming); else Redraw_Menu(true, true, (active_menu==PreheatHotend)); } break; - #endif + #endif // ADVANCED_PAUSE_FEATURE + #if HAS_MESH case SaveLevel: - if (selection==0) { + if (selection == 0) { #if ENABLED(AUTO_BED_LEVELING_UBL) gcode.process_subcommands_now_P(PSTR("G29 S")); planner.synchronize(); @@ -5041,16 +4631,16 @@ void CrealityDWINClass::Popup_Control() { Draw_Menu(Leveling, LEVELING_GET_MESH); break; #endif + #if ENABLED(AUTO_BED_LEVELING_UBL) case MeshSlot: - if (selection==0) - ubl.storage_slot = 0; + if (selection == 0) ubl.storage_slot = 0; Redraw_Menu(true, true); break; #endif - default: - break; + default: break; } + } DWIN_UpdateLCD(); } @@ -5058,7 +4648,7 @@ void CrealityDWINClass::Confirm_Control() { ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze(); if (encoder_diffState == ENCODER_DIFF_NO) return; if (encoder_diffState == ENCODER_DIFF_ENTER) { - switch(popup) { + switch (popup) { case Complete: Draw_Main_Menu(); break; @@ -5082,9 +4672,9 @@ void CrealityDWINClass::Confirm_Control() { /* In-Menu Value Modification */ void CrealityDWINClass::Setup_Value(float value, float min, float max, float unit, uint8_t type) { - if (valuepointer == &thermalManager.temp_hotend[0].pid.Ki || valuepointer == &thermalManager.temp_bed.pid.Ki) + if (TERN0(HAS_HOTEND, valuepointer == &thermalManager.temp_hotend[0].pid.Ki) || TERN0(HAS_HEATED_BED, valuepointer == &thermalManager.temp_bed.pid.Ki)) tempvalue = unscalePID_i(value) * unit; - else if (valuepointer == &thermalManager.temp_hotend[0].pid.Kd || valuepointer == &thermalManager.temp_bed.pid.Kd) + else if (TERN0(HAS_HOTEND, valuepointer == &thermalManager.temp_hotend[0].pid.Kd) || TERN0(HAS_HEATED_BED, valuepointer == &thermalManager.temp_bed.pid.Kd)) tempvalue = unscalePID_d(value) * unit; else tempvalue = value * unit; @@ -5094,41 +4684,40 @@ void CrealityDWINClass::Setup_Value(float value, float min, float max, float uni valuetype = type; process = Value; EncoderRate.enabled = true; - Draw_Float(tempvalue/unit, selection-scrollpos, true, valueunit); + Draw_Float(tempvalue / unit, selection - scrollpos, true, valueunit); } -void CrealityDWINClass::Modify_Value(float &value, float min, float max, float unit, void (*f)()/*=NULL*/) { +void CrealityDWINClass::Modify_Value(float &value, float min, float max, float unit, void (*f)()/*=nullptr*/) { valuepointer = &value; funcpointer = f; Setup_Value((float)value, min, max, unit, 0); } -void CrealityDWINClass::Modify_Value(uint8_t &value, float min, float max, float unit, void (*f)()/*=NULL*/) { +void CrealityDWINClass::Modify_Value(uint8_t &value, float min, float max, float unit, void (*f)()/*=nullptr*/) { valuepointer = &value; funcpointer = f; Setup_Value((float)value, min, max, unit, 1); } -void CrealityDWINClass::Modify_Value(uint16_t &value, float min, float max, float unit, void (*f)()/*=NULL*/) { +void CrealityDWINClass::Modify_Value(uint16_t &value, float min, float max, float unit, void (*f)()/*=nullptr*/) { valuepointer = &value; funcpointer = f; Setup_Value((float)value, min, max, unit, 2); } -void CrealityDWINClass::Modify_Value(int16_t &value, float min, float max, float unit, void (*f)()/*=NULL*/) { +void CrealityDWINClass::Modify_Value(int16_t &value, float min, float max, float unit, void (*f)()/*=nullptr*/) { valuepointer = &value; funcpointer = f; Setup_Value((float)value, min, max, unit, 3); } -void CrealityDWINClass::Modify_Value(uint32_t &value, float min, float max, float unit, void (*f)()/*=NULL*/) { +void CrealityDWINClass::Modify_Value(uint32_t &value, float min, float max, float unit, void (*f)()/*=nullptr*/) { valuepointer = &value; funcpointer = f; Setup_Value((float)value, min, max, unit, 4); } -void CrealityDWINClass::Modify_Value(int8_t &value, float min, float max, float unit, void (*f)()/*=NULL*/) { +void CrealityDWINClass::Modify_Value(int8_t &value, float min, float max, float unit, void (*f)()/*=nullptr*/) { valuepointer = &value; funcpointer = f; Setup_Value((float)value, min, max, unit, 5); } - void CrealityDWINClass::Modify_Option(uint8_t value, const char * const * options, uint8_t max) { tempvalue = value; valuepointer = const_cast(options); @@ -5136,7 +4725,7 @@ void CrealityDWINClass::Modify_Option(uint8_t value, const char * const * option valuemax = max; process = Option; EncoderRate.enabled = true; - Draw_Option(value, options, selection-scrollpos, true); + Draw_Option(value, options, selection - scrollpos, true); } /* Main Functions */ @@ -5145,9 +4734,9 @@ void CrealityDWINClass::Update_Status(const char * const text) { char header[4]; LOOP_L_N(i, 3) header[i] = text[i]; header[3] = '\0'; - if (strcmp_P(header,"")==0) { - LOOP_L_N(i, _MIN((size_t)LONG_FILENAME_LENGTH, strlen(text))) filename[i] = text[i+3]; - filename[_MIN((size_t)LONG_FILENAME_LENGTH-1, strlen(text))] = '\0'; + if (strcmp_P(header,"") == 0) { + LOOP_L_N(i, _MIN((size_t)LONG_FILENAME_LENGTH, strlen(text))) filename[i] = text[i + 3]; + filename[_MIN((size_t)LONG_FILENAME_LENGTH - 1, strlen(text))] = '\0'; Draw_Print_Filename(true); } else { @@ -5171,8 +4760,8 @@ void CrealityDWINClass::Start_Print(bool sd) { } else strcpy_P(filename, "Host Print"); - ui.set_progress(0); - ui.set_remaining_time(0); + TERN_(LCD_SET_PROGRESS_MANUALLY, ui.set_progress(0)); + TERN_(USE_M73_REMAINING_TIME, ui.set_remaining_time(0)); Draw_Print_Screen(); } } @@ -5180,42 +4769,25 @@ void CrealityDWINClass::Start_Print(bool sd) { void CrealityDWINClass::Stop_Print() { printing = false; sdprint = false; - thermalManager.zero_fan_speeds(); + TERN_(HAS_FAN, thermalManager.zero_fan_speeds()); thermalManager.disable_all_heaters(); - ui.set_progress(100 * (PROGRESS_SCALE)); - ui.set_remaining_time(0); + TERN_(LCD_SET_PROGRESS_MANUALLY, ui.set_progress(100 * (PROGRESS_SCALE))); + TERN_(USE_M73_REMAINING_TIME, ui.set_remaining_time(0)); Draw_Print_confirm(); } void CrealityDWINClass::Update() { State_Update(); Screen_Update(); - - switch(process) { - case Main: - Main_Menu_Control(); - break; - case Menu: - Menu_Control(); - break; - case Value: - Value_Control(); - break; - case Option: - Option_Control(); - break; - case File: - File_Control(); - break; - case Print: - Print_Screen_Control(); - break; - case Popup: - Popup_Control(); - break; - case Confirm: - Confirm_Control(); - break; + switch (process) { + case Main: Main_Menu_Control(); break; + case Menu: Menu_Control(); break; + case Value: Value_Control(); break; + case Option: Option_Control(); break; + case File: File_Control(); break; + case Print: Print_Screen_Control(); break; + case Popup: Popup_Control(); break; + case Confirm: Confirm_Control(); break; } } @@ -5229,14 +4801,12 @@ void CrealityDWINClass::State_Update() { if (process == Print) Print_Screen_Icons(); if (process == Wait && !paused) Redraw_Menu(true, true); } - if (wait_for_user && !(process == Confirm) && !print_job_timer.isPaused()) { + if (wait_for_user && !(process == Confirm) && !print_job_timer.isPaused()) Confirm_Handler(UserInput); - } #if ENABLED(ADVANCED_PAUSE_FEATURE) if (process == Popup && popup == PurgeMore) { - if (pause_menu_response == PAUSE_RESPONSE_EXTRUDE_MORE) { + if (pause_menu_response == PAUSE_RESPONSE_EXTRUDE_MORE) Popup_Handler(FilChange); - } else if (pause_menu_response == PAUSE_RESPONSE_RESUME_PRINT) { if (printing) Popup_Handler(Resuming); else Redraw_Menu(true, true, (active_menu==PreheatHotend)); @@ -5257,8 +4827,7 @@ void CrealityDWINClass::Screen_Update() { if (ELAPSED(millis(), scrltime)) { scrltime = millis() + 200; Update_Status_Bar(); - if (process==Print) - Draw_Print_Filename(); + if (process == Print) Draw_Print_Filename(); } static millis_t statustime = 0; @@ -5273,7 +4842,7 @@ void CrealityDWINClass::Screen_Update() { if (process == Print) { Draw_Print_ProgressBar(); Draw_Print_ProgressElapsed(); - Draw_Print_ProgressRemain(); + TERN_(USE_M73_REMAINING_TIME, Draw_Print_ProgressRemain()); } } @@ -5293,6 +4862,7 @@ void CrealityDWINClass::Screen_Update() { #if HAS_FAN static int16_t fanspeed = -1; #endif + #if HAS_ZOFFSET_ITEM static float lastzoffset = zoffsetvalue; if (zoffsetvalue != lastzoffset) { @@ -5305,25 +4875,23 @@ void CrealityDWINClass::Screen_Update() { } #if HAS_BED_PROBE - if (probe.offset.z != lastzoffset) { + if (probe.offset.z != lastzoffset) zoffsetvalue = lastzoffset = probe.offset.z; - } #else - if (-home_offset.z != lastzoffset) { + if (-home_offset.z != lastzoffset) zoffsetvalue = lastzoffset = -home_offset.z; - } #endif - #endif + #endif // HAS_ZOFFSET_ITEM if (process == Menu || process == Value) { - switch(active_menu) { + switch (active_menu) { case TempMenu: #if HAS_HOTEND if (thermalManager.temp_hotend[0].target != hotendtarget) { hotendtarget = thermalManager.temp_hotend[0].target; if (scrollpos <= TEMP_HOTEND && TEMP_HOTEND <= scrollpos + MROWS) { - if (process != Value || selection != TEMP_HOTEND-scrollpos) - Draw_Float(thermalManager.temp_hotend[0].target, TEMP_HOTEND-scrollpos, false, 1); + if (process != Value || selection != TEMP_HOTEND - scrollpos) + Draw_Float(thermalManager.temp_hotend[0].target, TEMP_HOTEND - scrollpos, false, 1); } } #endif @@ -5331,8 +4899,8 @@ void CrealityDWINClass::Screen_Update() { if (thermalManager.temp_bed.target != bedtarget) { bedtarget = thermalManager.temp_bed.target; if (scrollpos <= TEMP_BED && TEMP_BED <= scrollpos + MROWS) { - if (process != Value || selection != TEMP_HOTEND-scrollpos) - Draw_Float(thermalManager.temp_bed.target, TEMP_BED-scrollpos, false, 1); + if (process != Value || selection != TEMP_HOTEND - scrollpos) + Draw_Float(thermalManager.temp_bed.target, TEMP_BED - scrollpos, false, 1); } } #endif @@ -5340,8 +4908,8 @@ void CrealityDWINClass::Screen_Update() { if (thermalManager.fan_speed[0] != fanspeed) { fanspeed = thermalManager.fan_speed[0]; if (scrollpos <= TEMP_FAN && TEMP_FAN <= scrollpos + MROWS) { - if (process != Value || selection != TEMP_HOTEND-scrollpos) - Draw_Float(thermalManager.fan_speed[0], TEMP_FAN-scrollpos, false, 1); + if (process != Value || selection != TEMP_HOTEND - scrollpos) + Draw_Float(thermalManager.fan_speed[0], TEMP_FAN - scrollpos, false, 1); } } #endif @@ -5351,8 +4919,8 @@ void CrealityDWINClass::Screen_Update() { if (thermalManager.temp_hotend[0].target != hotendtarget) { hotendtarget = thermalManager.temp_hotend[0].target; if (scrollpos <= TUNE_HOTEND && TUNE_HOTEND <= scrollpos + MROWS) { - if (process != Value || selection != TEMP_HOTEND-scrollpos) - Draw_Float(thermalManager.temp_hotend[0].target, TUNE_HOTEND-scrollpos, false, 1); + if (process != Value || selection != TEMP_HOTEND - scrollpos) + Draw_Float(thermalManager.temp_hotend[0].target, TUNE_HOTEND - scrollpos, false, 1); } } #endif @@ -5360,8 +4928,8 @@ void CrealityDWINClass::Screen_Update() { if (thermalManager.temp_bed.target != bedtarget) { bedtarget = thermalManager.temp_bed.target; if (scrollpos <= TUNE_BED && TUNE_BED <= scrollpos + MROWS) { - if (process != Value || selection != TEMP_HOTEND-scrollpos) - Draw_Float(thermalManager.temp_bed.target, TUNE_BED-scrollpos, false, 1); + if (process != Value || selection != TEMP_HOTEND - scrollpos) + Draw_Float(thermalManager.temp_bed.target, TUNE_BED - scrollpos, false, 1); } } #endif @@ -5369,8 +4937,8 @@ void CrealityDWINClass::Screen_Update() { if (thermalManager.fan_speed[0] != fanspeed) { fanspeed = thermalManager.fan_speed[0]; if (scrollpos <= TUNE_FAN && TUNE_FAN <= scrollpos + MROWS) { - if (process != Value || selection != TEMP_HOTEND-scrollpos) - Draw_Float(thermalManager.fan_speed[0], TUNE_FAN-scrollpos, false, 1); + if (process != Value || selection != TEMP_HOTEND - scrollpos) + Draw_Float(thermalManager.fan_speed[0], TUNE_FAN - scrollpos, false, 1); } } #endif @@ -5382,47 +4950,43 @@ void CrealityDWINClass::Screen_Update() { void CrealityDWINClass::AudioFeedback(const bool success/*=true*/) { if (success) { if (eeprom_settings.beeperenable) { - buzzer.tone(100, 659); - buzzer.tone(10, 0); - buzzer.tone(100, 698); + BUZZ(100, 659); + BUZZ( 10, 0); + BUZZ(100, 698); } else Update_Status("Success"); } + else if (eeprom_settings.beeperenable) + BUZZ(40, 440); else - if (eeprom_settings.beeperenable) - buzzer.tone(40, 440); - else Update_Status("Failed"); + Update_Status("Failed"); } void CrealityDWINClass::Save_Settings(char *buff) { - #if ENABLED(AUTO_BED_LEVELING_UBL) - eeprom_settings.tilt_grid_size = mesh_conf.tilt_grid-1; - #endif + TERN_(AUTO_BED_LEVELING_UBL, eeprom_settings.tilt_grid_size = mesh_conf.tilt_grid - 1); eeprom_settings.corner_pos = corner_pos * 10; memcpy(buff, &eeprom_settings, min(sizeof(eeprom_settings), eeprom_data_size)); } void CrealityDWINClass::Load_Settings(const char *buff) { memcpy(&eeprom_settings, buff, min(sizeof(eeprom_settings), eeprom_data_size)); - #if ENABLED(AUTO_BED_LEVELING_UBL) - mesh_conf.tilt_grid = eeprom_settings.tilt_grid_size+1; - #endif + TERN_(AUTO_BED_LEVELING_UBL, mesh_conf.tilt_grid = eeprom_settings.tilt_grid_size + 1); if (eeprom_settings.corner_pos == 0) eeprom_settings.corner_pos = 325; corner_pos = eeprom_settings.corner_pos / 10.0f; Redraw_Screen(); - static bool init = true; - if (init) { - init = false; - queue.inject_P(PSTR("M1000 S")); - } + #if ENABLED(POWER_LOSS_RECOVERY) + static bool init = true; + if (init) { + init = false; + queue.inject_P(PSTR("M1000 S")); + } + #endif } void CrealityDWINClass::Reset_Settings() { eeprom_settings.time_format_textual = false; eeprom_settings.beeperenable = true; - #if ENABLED(AUTO_BED_LEVELING_UBL) - eeprom_settings.tilt_grid_size = 0; - #endif + TERN_(AUTO_BED_LEVELING_UBL, eeprom_settings.tilt_grid_size = 0); eeprom_settings.corner_pos = 325; eeprom_settings.cursor_color = 0; eeprom_settings.menu_split_line = 0; @@ -5435,9 +4999,7 @@ void CrealityDWINClass::Reset_Settings() { eeprom_settings.status_area_text = 0; eeprom_settings.coordinates_text = 0; eeprom_settings.coordinates_split_line = 0; - #if ENABLED(AUTO_BED_LEVELING_UBL) - mesh_conf.tilt_grid = eeprom_settings.tilt_grid_size+1; - #endif + TERN_(AUTO_BED_LEVELING_UBL, mesh_conf.tilt_grid = eeprom_settings.tilt_grid_size + 1); corner_pos = eeprom_settings.corner_pos / 10.0f; Redraw_Screen(); } diff --git a/Marlin/src/lcd/dwin/e3v2/dwin.h b/Marlin/src/lcd/dwin/e3v2/dwin.h index bb053b6f00e1..bb90bcb89977 100644 --- a/Marlin/src/lcd/dwin/e3v2/dwin.h +++ b/Marlin/src/lcd/dwin/e3v2/dwin.h @@ -23,7 +23,7 @@ /** * DWIN by Creality3D - * Rewrite and Extui Port by Jacob Myers + * Rewrite by Jacob Myers */ #include "../dwin_lcd.h" @@ -83,7 +83,6 @@ enum menuID : uint8_t { PreheatHotend }; - #define Start_Process 0 #define Language_English 1 #define Language_Chinese 2 @@ -215,7 +214,6 @@ enum menuID : uint8_t { #define ICON_AxisC ICON_Axis #endif - #define font6x12 0x00 #define font8x16 0x01 #define font10x20 0x02 @@ -267,10 +265,9 @@ enum colorID : uint8_t { #define Cancel_Color 0x3186 class CrealityDWINClass { - public: static constexpr size_t eeprom_data_size = 48; - struct EEPROM_Settings { // use bit fields to save space, max 48 bytes + static struct EEPROM_Settings { // use bit fields to save space, max 48 bytes bool time_format_textual : 1; bool beeperenable : 1; #if ENABLED(AUTO_BED_LEVELING_UBL) @@ -290,82 +287,78 @@ class CrealityDWINClass { uint8_t coordinates_split_line : 4; } eeprom_settings; - const char * const color_names[11] = {"Default", "White", "Green", "Cyan", "Blue", "Magenta", "Red", "Orange", "Yellow", "Brown", "Black"}; - const char * const preheat_modes[3] = {"Both", "Hotend", "Bed"}; - - - void Clear_Screen(uint8_t e=3); - void Draw_Float(float value, uint8_t row, bool selected=false, uint8_t minunit=10); - void Draw_Option(uint8_t value, const char * const * options, uint8_t row, bool selected=false, bool color=false); - uint16_t GetColor(uint8_t color, uint16_t original, bool light=false); - void Draw_Checkbox(uint8_t row, bool value); - void Draw_Title(const char * title); - void Draw_Menu_Item(uint8_t row, uint8_t icon=0, const char * const label1=NULL, const char * const label2=NULL, bool more=false, bool centered=false); - void Draw_Menu(uint8_t menu, uint8_t select=0, uint8_t scroll=0); - void Redraw_Menu(bool lastprocess=true, bool lastselection=false, bool lastmenu=false); - void Redraw_Screen(); - - void Main_Menu_Icons(); - void Draw_Main_Menu(uint8_t select=0); - void Print_Screen_Icons(); - void Draw_Print_Screen(); - void Draw_Print_Filename(bool reset=false); - void Draw_Print_ProgressBar(); - void Draw_Print_ProgressRemain(); - void Draw_Print_ProgressElapsed(); - void Draw_Print_confirm(); - void Draw_SD_Item(uint8_t item, uint8_t row); - void Draw_SD_List(bool removed=false); - void Draw_Status_Area(bool icons=false); - void Draw_Popup(const char * line1, const char * line2, const char * line3, uint8_t mode, uint8_t icon=0); - void Popup_Select(); - void Update_Status_Bar(bool refresh=false); + static constexpr const char * const color_names[11] = { "Default", "White", "Green", "Cyan", "Blue", "Magenta", "Red", "Orange", "Yellow", "Brown", "Black" }; + static constexpr const char * const preheat_modes[3] = { "Both", "Hotend", "Bed" }; + + static void Clear_Screen(uint8_t e=3); + static void Draw_Float(float value, uint8_t row, bool selected=false, uint8_t minunit=10); + static void Draw_Option(uint8_t value, const char * const * options, uint8_t row, bool selected=false, bool color=false); + static uint16_t GetColor(uint8_t color, uint16_t original, bool light=false); + static void Draw_Checkbox(uint8_t row, bool value); + static void Draw_Title(const char * title); + static void Draw_Menu_Item(uint8_t row, uint8_t icon=0, const char * const label1=nullptr, const char * const label2=nullptr, bool more=false, bool centered=false); + static void Draw_Menu(uint8_t menu, uint8_t select=0, uint8_t scroll=0); + static void Redraw_Menu(bool lastprocess=true, bool lastselection=false, bool lastmenu=false); + static void Redraw_Screen(); + + static void Main_Menu_Icons(); + static void Draw_Main_Menu(uint8_t select=0); + static void Print_Screen_Icons(); + static void Draw_Print_Screen(); + static void Draw_Print_Filename(const bool reset=false); + static void Draw_Print_ProgressBar(); + #if ENABLED(USE_M73_REMAINING_TIME) + static void Draw_Print_ProgressRemain(); + #endif + static void Draw_Print_ProgressElapsed(); + static void Draw_Print_confirm(); + static void Draw_SD_Item(uint8_t item, uint8_t row); + static void Draw_SD_List(bool removed=false); + static void Draw_Status_Area(bool icons=false); + static void Draw_Popup(PGM_P const line1, PGM_P const line2, PGM_P const line3, uint8_t mode, uint8_t icon=0); + static void Popup_Select(); + static void Update_Status_Bar(bool refresh=false); #if ENABLED(AUTO_BED_LEVELING_UBL) - void Draw_Bed_Mesh(int16_t selected = -1, uint8_t gridline_width = 1, uint16_t padding_x = 8, uint16_t padding_y_top = 40 + 53 - 7); - void Set_Mesh_Viewer_Status(); + static void Draw_Bed_Mesh(int16_t selected = -1, uint8_t gridline_width = 1, uint16_t padding_x = 8, uint16_t padding_y_top = 40 + 53 - 7); + static void Set_Mesh_Viewer_Status(); #endif - const char * Get_Menu_Title(uint8_t menu); - uint8_t Get_Menu_Size(uint8_t menu); - void Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw=true); - - - void Popup_Handler(PopupID popupid, bool option = false); - void Confirm_Handler(PopupID popupid); - - - void Main_Menu_Control(); - void Menu_Control(); - void Value_Control(); - void Option_Control(); - void File_Control(); - void Print_Screen_Control(); - void Popup_Control(); - void Confirm_Control(); - - - void Setup_Value(float value, float min, float max, float unit, uint8_t type); - void Modify_Value(float &value, float min, float max, float unit, void (*f)()=NULL); - void Modify_Value(uint8_t &value, float min, float max, float unit, void (*f)()=NULL); - void Modify_Value(uint16_t &value, float min, float max, float unit, void (*f)()=NULL); - void Modify_Value(int16_t &value, float min, float max, float unit, void (*f)()=NULL); - void Modify_Value(uint32_t &value, float min, float max, float unit, void (*f)()=NULL); - void Modify_Value(int8_t &value, float min, float max, float unit, void (*f)()=NULL); - void Modify_Option(uint8_t value, const char * const * options, uint8_t max); - - - void Update_Status(const char * const text); - void Start_Print(bool sd); - void Stop_Print(); - void Update(); - void State_Update(); - void Screen_Update(); - void AudioFeedback(const bool success=true); - void Save_Settings(char *buff); - void Load_Settings(const char *buff); - void Reset_Settings(); - + static const char * Get_Menu_Title(uint8_t menu); + static uint8_t Get_Menu_Size(uint8_t menu); + static void Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw=true); + + static void Popup_Handler(PopupID popupid, bool option = false); + static void Confirm_Handler(PopupID popupid); + + static void Main_Menu_Control(); + static void Menu_Control(); + static void Value_Control(); + static void Option_Control(); + static void File_Control(); + static void Print_Screen_Control(); + static void Popup_Control(); + static void Confirm_Control(); + + static void Setup_Value(float value, float min, float max, float unit, uint8_t type); + static void Modify_Value(float &value, float min, float max, float unit, void (*f)()=nullptr); + static void Modify_Value(uint8_t &value, float min, float max, float unit, void (*f)()=nullptr); + static void Modify_Value(uint16_t &value, float min, float max, float unit, void (*f)()=nullptr); + static void Modify_Value(int16_t &value, float min, float max, float unit, void (*f)()=nullptr); + static void Modify_Value(uint32_t &value, float min, float max, float unit, void (*f)()=nullptr); + static void Modify_Value(int8_t &value, float min, float max, float unit, void (*f)()=nullptr); + static void Modify_Option(uint8_t value, const char * const * options, uint8_t max); + + static void Update_Status(const char * const text); + static void Start_Print(bool sd); + static void Stop_Print(); + static void Update(); + static void State_Update(); + static void Screen_Update(); + static void AudioFeedback(const bool success=true); + static void Save_Settings(char *buff); + static void Load_Settings(const char *buff); + static void Reset_Settings(); }; extern CrealityDWINClass CrealityDWIN; diff --git a/Marlin/src/lcd/dwin/e3v2/rotary_encoder.cpp b/Marlin/src/lcd/dwin/e3v2/rotary_encoder.cpp index fe8321ea85a6..0b02928c0b9e 100644 --- a/Marlin/src/lcd/dwin/e3v2/rotary_encoder.cpp +++ b/Marlin/src/lcd/dwin/e3v2/rotary_encoder.cpp @@ -97,12 +97,8 @@ ENCODER_DiffState Encoder_ReceiveAnalyze() { #if PIN_EXISTS(LCD_LED) //LED_Action(); #endif - if (!ui.backlight) { - ui.refresh_brightness(); - } - else { - return ENCODER_DIFF_ENTER; - } + if (ui.backlight) return ENCODER_DIFF_ENTER; + ui.refresh_brightness(); } else return ENCODER_DIFF_NO; } diff --git a/Marlin/src/lcd/extui/ui_api.h b/Marlin/src/lcd/extui/ui_api.h index faa6c8f41a85..d2af25c918fc 100644 --- a/Marlin/src/lcd/extui/ui_api.h +++ b/Marlin/src/lcd/extui/ui_api.h @@ -194,11 +194,7 @@ namespace ExtUI { void setHostResponse(const uint8_t); #endif - inline void simulateUserClick() { - #if EITHER(HAS_LCD_MENU, EXTENSIBLE_UI) - ui.lcd_clicked = true; - #endif - } + inline void simulateUserClick() { ui.lcd_clicked = true; } #if ENABLED(PRINTCOUNTER) char* getFailedPrints_str(char buffer[21]); diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index 799108d13de1..99a078a83844 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -47,7 +47,7 @@ MarlinUI ui; #endif #if ENABLED(DWIN_CREALITY_LCD) - #include "dwin/creality_dwin.h" + #include "dwin/e3v2/dwin.h" #endif #if ENABLED(LCD_PROGRESS_BAR) && !IS_TFTGLCD_PANEL @@ -98,6 +98,18 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP; } #endif +#if HAS_LCD_BRIGHTNESS + uint8_t MarlinUI::brightness = DEFAULT_LCD_BRIGHTNESS; + bool MarlinUI::backlight = true; + + void MarlinUI::set_brightness(const uint8_t value) { + backlight = !!value; + if (backlight) + brightness = constrain(value, MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS); + DWIN_Backlight_SetLuminance(backlight ? brightness : 0); + } +#endif + #if ENABLED(SOUND_MENU_ITEM) bool MarlinUI::buzzer_enabled = true; #endif diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index cc775a42391c..0dc00bb5fbea 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -55,7 +55,7 @@ #include "../module/printcounter.h" #endif -#if ENABLED(ADVANCED_PAUSE_FEATURE) && EITHER(HAS_LCD_MENU, EXTENSIBLE_UI) || BOTH(DWIN_CREALITY_LCD, ADVANCED_PAUSE_FEATURE) +#if ENABLED(ADVANCED_PAUSE_FEATURE) && ANY(HAS_LCD_MENU, EXTENSIBLE_UI, DWIN_CREALITY_LCD) #include "../feature/pause.h" #include "../module/motion.h" // for active_extruder #endif @@ -552,7 +552,7 @@ class MarlinUI { static inline bool use_click() { return false; } #endif - #if ENABLED(ADVANCED_PAUSE_FEATURE) && EITHER(HAS_LCD_MENU, EXTENSIBLE_UI) || BOTH(DWIN_CREALITY_LCD, ADVANCED_PAUSE_FEATURE) + #if ENABLED(ADVANCED_PAUSE_FEATURE) && ANY(HAS_LCD_MENU, EXTENSIBLE_UI, DWIN_CREALITY_LCD) static void pause_show_message(const PauseMessage message, const PauseMode mode=PAUSE_MODE_SAME, const uint8_t extruder=active_extruder); #else static inline void _pause_show_message() {} diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index 6cdabfb9744a..f499f35695c5 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -36,7 +36,7 @@ */ // Change EEPROM version if the structure changes -#define EEPROM_VERSION "V83" +#define EEPROM_VERSION "V84" #define EEPROM_OFFSET 100 // Check the integrity of data offsets. @@ -74,7 +74,7 @@ #endif #if ENABLED(DWIN_CREALITY_LCD) - #include "../lcd/dwin/creality_dwin.h" + #include "../lcd/dwin/e3v2/dwin.h" #endif #if HAS_SERVOS @@ -360,7 +360,7 @@ typedef struct SettingsDataStruct { // // HAS_LCD_BRIGHTNESS // - uint8_t lcd_brightness; // M251 B + uint8_t lcd_brightness; // M251 B // // Controller fan settings @@ -1015,14 +1015,7 @@ void MarlinSettings::postprocess() { // { _FIELD_TEST(lcd_contrast); - - const int16_t lcd_contrast = - #if HAS_LCD_CONTRAST - ui.contrast - #else - 127 - #endif - ; + const int16_t lcd_contrast = TERN(HAS_LCD_CONTRAST, ui.contrast, 127); EEPROM_WRITE(lcd_contrast); } @@ -1031,14 +1024,7 @@ void MarlinSettings::postprocess() { // { _FIELD_TEST(lcd_brightness); - - const uint8_t lcd_brightness = - #if HAS_LCD_BRIGHTNESS - ui.brightness - #else - 255 - #endif - ; + const uint8_t lcd_brightness = TERN(HAS_LCD_BRIGHTNESS, ui.brightness, 255); EEPROM_WRITE(lcd_brightness); } @@ -1363,25 +1349,25 @@ void MarlinSettings::postprocess() { // Extensible UI User Data // #if ENABLED(EXTENSIBLE_UI) - { - char extui_data[ExtUI::eeprom_data_size] = { 0 }; - ExtUI::onStoreSettings(extui_data); - _FIELD_TEST(extui_data); - EEPROM_WRITE(extui_data); - } + { + char extui_data[ExtUI::eeprom_data_size] = { 0 }; + ExtUI::onStoreSettings(extui_data); + _FIELD_TEST(extui_data); + EEPROM_WRITE(extui_data); + } #endif // // Creality UI Settings // #if ENABLED(DWIN_CREALITY_LCD) - { - char dwin_settings[CrealityDWIN.eeprom_data_size] = { 0 }; - CrealityDWIN.Save_Settings(dwin_settings); - _FIELD_TEST(dwin_settings); - EEPROM_WRITE(dwin_settings); - } - #endif + { + char dwin_settings[CrealityDWIN.eeprom_data_size] = { 0 }; + CrealityDWIN.Save_Settings(dwin_settings); + _FIELD_TEST(dwin_settings); + EEPROM_WRITE(dwin_settings); + } + #endif // // Case Light Brightness @@ -1897,9 +1883,7 @@ void MarlinSettings::postprocess() { _FIELD_TEST(lcd_brightness); uint8_t lcd_brightness; EEPROM_READ(lcd_brightness); - if (!validating) { - TERN_(HAS_LCD_BRIGHTNESS, ui.set_brightness(lcd_brightness)); - } + TERN_(HAS_LCD_BRIGHTNESS, if (!validating) ui.set_brightness(lcd_brightness)); } // @@ -2256,25 +2240,24 @@ void MarlinSettings::postprocess() { // Extensible UI User Data // #if ENABLED(EXTENSIBLE_UI) - // This is a significant hardware change; don't reserve EEPROM space when not present - { - const char extui_data[ExtUI::eeprom_data_size] = { 0 }; - _FIELD_TEST(extui_data); - EEPROM_READ(extui_data); - if (!validating) ExtUI::onLoadSettings(extui_data); - } + { // This is a significant hardware change; don't reserve EEPROM space when not present + const char extui_data[ExtUI::eeprom_data_size] = { 0 }; + _FIELD_TEST(extui_data); + EEPROM_READ(extui_data); + if (!validating) ExtUI::onLoadSettings(extui_data); + } #endif // // Creality UI Settings // #if ENABLED(DWIN_CREALITY_LCD) - { - const char dwin_settings[CrealityDWIN.eeprom_data_size] = { 0 }; - _FIELD_TEST(dwin_settings); - EEPROM_READ(dwin_settings); - if (!validating) CrealityDWIN.Load_Settings(dwin_settings); - } + { + const char dwin_settings[CrealityDWIN.eeprom_data_size] = { 0 }; + _FIELD_TEST(dwin_settings); + EEPROM_READ(dwin_settings); + if (!validating) CrealityDWIN.Load_Settings(dwin_settings); + } #endif // diff --git a/Marlin/src/module/stepper/trinamic.cpp b/Marlin/src/module/stepper/trinamic.cpp index a5d7e5ad6b3d..f9ed43acbfe2 100644 --- a/Marlin/src/module/stepper/trinamic.cpp +++ b/Marlin/src/module/stepper/trinamic.cpp @@ -1008,7 +1008,7 @@ void reset_trinamic_drivers() { TMC_SW_DETAIL(Y), TMC_SW_DETAIL(Y2), TMC_SW_DETAIL(Z), TMC_SW_DETAIL(Z2), TMC_SW_DETAIL(Z3), TMC_SW_DETAIL(Z4), TMC_SW_DETAIL(I), TMC_SW_DETAIL(J), TMC_SW_DETAIL(K), - TMC_SW_DETAIL(E0), TMC_SW_DETAIL(E1), TMC_SW_DETAIL(E2), TMC_SW_DETAIL(E3), TMC_SW_DETAIL(E4), TMC_SW_DETAIL(E5), TMC_SW_DETAIL(E6), TMC_SW_DETAIL(E7) + TMC_SW_DETAIL(E0), TMC_SW_DETAIL(E1), TMC_SW_DETAIL(E2), TMC_SW_DETAIL(E3), TMC_SW_DETAIL(E4), TMC_SW_DETAIL(E5), TMC_SW_DETAIL(E6), TMC_SW_DETAIL(E7) }; constexpr bool sc_sw_done(size_t start, size_t end) { return start == end; } diff --git a/Marlin/src/pins/stm32f1/pins_CREALITY_V452.h b/Marlin/src/pins/stm32f1/pins_CREALITY_V452.h index ad4ddff0cea2..64e07a0bc832 100644 --- a/Marlin/src/pins/stm32f1/pins_CREALITY_V452.h +++ b/Marlin/src/pins/stm32f1/pins_CREALITY_V452.h @@ -29,7 +29,7 @@ #error "Creality v4.5.2 only supports one hotend / E-stepper. Comment out this line to continue." #endif -#define BOARD_NAME "Creality v4.5.2" +#define BOARD_INFO_NAME "Creality v4.5.2" #define HEATER_0_PIN PA1 // HEATER1 #define HEATER_BED_PIN PA2 // HOT BED diff --git a/Marlin/src/pins/stm32f1/pins_CREALITY_V453.h b/Marlin/src/pins/stm32f1/pins_CREALITY_V453.h index cdb87adece47..ca437312c8e1 100644 --- a/Marlin/src/pins/stm32f1/pins_CREALITY_V453.h +++ b/Marlin/src/pins/stm32f1/pins_CREALITY_V453.h @@ -29,7 +29,7 @@ #error "Creality v4.5.3 only supports one hotend / E-stepper. Comment out this line to continue." #endif -#define BOARD_NAME "Creality v4.5.3" +#define BOARD_INFO_NAME "Creality v4.5.3" #define HEATER_0_PIN PB14 // HEATER1 #define HEATER_BED_PIN PB13 // HOT BED diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index 448a594fb220..2ff8c387a660 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -560,7 +560,7 @@ void CardReader::startOrResumeFilePrinting() { // void CardReader::endFilePrintNow(TERN_(SD_RESORT, const bool re_sort/*=false*/)) { TERN_(ADVANCED_PAUSE_FEATURE, did_pause_print = 0); - flag.sdprinting = flag.abort_sd_printing = false; + flag.abort_sd_printing = false; if (isFileOpen()) file.close(); TERN_(SD_RESORT, if (re_sort) presort()); }