From 90bcb22da3bb8d3e78566a13db50e3237801d236 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 6 Mar 2021 05:59:27 -0600 Subject: [PATCH] Temperature cleanup --- Marlin/src/core/types.h | 6 + Marlin/src/feature/mmu/mmu2.cpp | 2 +- Marlin/src/feature/pause.cpp | 5 +- Marlin/src/feature/pause.h | 2 +- Marlin/src/feature/powerloss.cpp | 8 +- Marlin/src/feature/powerloss.h | 4 +- Marlin/src/gcode/bedlevel/G26.cpp | 4 +- Marlin/src/gcode/host/M360.cpp | 2 +- Marlin/src/gcode/lcd/M145.cpp | 6 +- Marlin/src/gcode/parser.h | 61 ++-- Marlin/src/gcode/temp/M104_M109.cpp | 6 +- Marlin/src/gcode/temp/M140_M190.cpp | 6 +- Marlin/src/lcd/HD44780/marlinui_HD44780.cpp | 16 +- Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp | 19 +- Marlin/src/lcd/dogm/status_screen_DOGM.cpp | 22 +- .../lcd/dogm/status_screen_lite_ST7920.cpp | 32 +- Marlin/src/lcd/dwin/e3v2/dwin.cpp | 106 +++--- Marlin/src/lcd/dwin/e3v2/dwin.h | 4 +- .../lcd/extui/lib/dgus/DGUSScreenHandler.cpp | 10 +- .../extui/lib/dgus/fysetc/DGUSDisplayDef.cpp | 6 +- .../extui/lib/dgus/hiprecy/DGUSDisplayDef.cpp | 6 +- .../lcd/extui/lib/dgus/mks/DGUSDisplayDef.cpp | 10 +- .../extui/lib/dgus/mks/DGUSScreenHandler.cpp | 325 +++++++----------- .../extui/lib/dgus/mks/DGUSScreenHandler.h | 1 + .../extui/lib/dgus/origin/DGUSDisplayDef.cpp | 4 +- .../src/lcd/extui/lib/mks_ui/draw_dialog.cpp | 29 +- .../extui/lib/mks_ui/draw_filament_change.cpp | 12 +- .../lib/mks_ui/draw_filament_settings.cpp | 2 +- .../lcd/extui/lib/mks_ui/draw_number_key.cpp | 4 +- Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp | 2 +- Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h | 46 ++- Marlin/src/lcd/extui/ui_api.cpp | 6 +- Marlin/src/lcd/marlinui.h | 6 +- Marlin/src/lcd/menu/menu_advanced.cpp | 6 +- Marlin/src/lcd/menu/menu_configuration.cpp | 4 +- Marlin/src/lcd/menu/menu_filament.cpp | 2 +- Marlin/src/lcd/menu/menu_item.h | 2 +- Marlin/src/lcd/menu/menu_temperature.cpp | 16 +- Marlin/src/lcd/menu/menu_tune.cpp | 6 +- Marlin/src/lcd/menu/menu_ubl.cpp | 2 +- Marlin/src/lcd/tft/touch.cpp | 10 +- Marlin/src/lcd/tft/ui_320x240.cpp | 6 +- Marlin/src/lcd/tft/ui_480x320.cpp | 6 +- Marlin/src/module/motion.cpp | 6 +- Marlin/src/module/motion.h | 14 +- Marlin/src/module/planner.cpp | 8 +- Marlin/src/module/planner.h | 3 +- Marlin/src/module/temperature.cpp | 136 ++++---- Marlin/src/module/temperature.h | 134 +++----- Marlin/src/module/thermistor/thermistors.h | 2 +- 50 files changed, 499 insertions(+), 644 deletions(-) diff --git a/Marlin/src/core/types.h b/Marlin/src/core/types.h index 20519e1888b51..d77dba38d9771 100644 --- a/Marlin/src/core/types.h +++ b/Marlin/src/core/types.h @@ -72,6 +72,12 @@ struct IF { typedef L type; }; // typedef float feedRate_t; +// +// celsius_t is the native unit of temperature. Signed to handle a disconnected thermistor value (-14). +// For more resolition (e.g., for a chocolate printer) this may later be changed to Celsius x 100 +// +typedef int16_t celsius_t; + // Conversion macros #define MMM_TO_MMS(MM_M) feedRate_t(float(MM_M) / 60.0f) #define MMS_TO_MMM(MM_S) (float(MM_S) * 60.0f) diff --git a/Marlin/src/feature/mmu/mmu2.cpp b/Marlin/src/feature/mmu/mmu2.cpp index a1bec36e45783..d4238400c73a7 100644 --- a/Marlin/src/feature/mmu/mmu2.cpp +++ b/Marlin/src/feature/mmu/mmu2.cpp @@ -775,7 +775,7 @@ void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) { bool response = false; mmu_print_saved = false; xyz_pos_t resume_position; - int16_t resume_hotend_temp = thermalManager.degTargetHotend(active_extruder); + celsius_t resume_hotend_temp = thermalManager.degTargetHotend(active_extruder); KEEPALIVE_STATE(PAUSED_FOR_USER); diff --git a/Marlin/src/feature/pause.cpp b/Marlin/src/feature/pause.cpp index a6a28925edaf5..5f3338139a57c 100644 --- a/Marlin/src/feature/pause.cpp +++ b/Marlin/src/feature/pause.cpp @@ -555,7 +555,7 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep * - Send host action for resume, if configured * - Resume the current SD print job, if any */ -void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_length/*=0*/, const float &purge_length/*=ADVANCED_PAUSE_PURGE_LENGTH*/, const int8_t max_beep_count/*=0*/, int16_t targetTemp/*=0*/ DXC_ARGS) { +void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_length/*=0*/, const float &purge_length/*=ADVANCED_PAUSE_PURGE_LENGTH*/, const int8_t max_beep_count/*=0*/, const celsius_t targetTemp/*=0*/ DXC_ARGS) { DEBUG_SECTION(rp, "resume_print", true); DEBUG_ECHOLNPAIR("... slowlen:", slow_load_length, " fastlen:", fast_load_length, " purgelen:", purge_length, " maxbeep:", max_beep_count, " targetTemp:", targetTemp DXC_SAY); @@ -577,9 +577,8 @@ void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_le thermalManager.reset_hotend_idle_timer(e); } - if (targetTemp > thermalManager.degTargetHotend(active_extruder)) { + if (targetTemp > thermalManager.degTargetHotend(active_extruder)) thermalManager.setTargetHotend(targetTemp, active_extruder); - } // Load the new filament load_filament(slow_load_length, fast_load_length, purge_length, max_beep_count, true, nozzle_timed_out, PAUSE_MODE_SAME DXC_PASS); diff --git a/Marlin/src/feature/pause.h b/Marlin/src/feature/pause.h index 7e58d4564ebb5..4ab33ac5191ba 100644 --- a/Marlin/src/feature/pause.h +++ b/Marlin/src/feature/pause.h @@ -90,7 +90,7 @@ bool pause_print(const float &retract, const xyz_pos_t &park_point, const float void wait_for_confirmation(const bool is_reload=false, const int8_t max_beep_count=0 DXC_PARAMS); void resume_print(const float &slow_load_length=0, const float &fast_load_length=0, const float &extrude_length=ADVANCED_PAUSE_PURGE_LENGTH, - const int8_t max_beep_count=0, int16_t targetTemp=0 DXC_PARAMS); + const int8_t max_beep_count=0, const celsius_t targetTemp=0 DXC_PARAMS); bool load_filament(const float &slow_load_length=0, const float &fast_load_length=0, const float &extrude_length=0, const int8_t max_beep_count=0, const bool show_lcd=false, const bool pause_for_user=false, const PauseMode mode=PAUSE_MODE_PAUSE_PRINT DXC_PARAMS); diff --git a/Marlin/src/feature/powerloss.cpp b/Marlin/src/feature/powerloss.cpp index 1bb3a7e91531a..cc45d6ecf0718 100644 --- a/Marlin/src/feature/powerloss.cpp +++ b/Marlin/src/feature/powerloss.cpp @@ -201,10 +201,10 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=0*/ #endif #if EXTRUDERS - HOTEND_LOOP() info.target_temperature[e] = thermalManager.temp_hotend[e].target; + HOTEND_LOOP() info.target_temperature[e] = thermalManager.degTargetHotend(e); #endif - TERN_(HAS_HEATED_BED, info.target_temperature_bed = thermalManager.temp_bed.target); + TERN_(HAS_HEATED_BED, info.target_temperature_bed = thermalManager.degTargetBed()); #if HAS_FAN COPY(info.fan_speed, thermalManager.fan_speed); @@ -343,7 +343,7 @@ void PrintJobRecovery::resume() { #endif #if HAS_HEATED_BED - const int16_t bt = info.target_temperature_bed; + const celsius_t bt = info.target_temperature_bed; if (bt) { // Restore the bed temperature sprintf_P(cmd, PSTR("M190 S%i"), bt); @@ -354,7 +354,7 @@ void PrintJobRecovery::resume() { // Restore all hotend temperatures #if HAS_HOTEND HOTEND_LOOP() { - const int16_t et = info.target_temperature[e]; + const celsius_t et = info.target_temperature[e]; if (et) { #if HAS_MULTI_HOTEND sprintf_P(cmd, PSTR("T%i S"), e); diff --git a/Marlin/src/feature/powerloss.h b/Marlin/src/feature/powerloss.h index 25581e17230d1..12d11b141e3e9 100644 --- a/Marlin/src/feature/powerloss.h +++ b/Marlin/src/feature/powerloss.h @@ -66,8 +66,8 @@ typedef struct { float filament_size[EXTRUDERS]; #endif - TERN_(HAS_HOTEND, int16_t target_temperature[HOTENDS]); - TERN_(HAS_HEATED_BED, int16_t target_temperature_bed); + TERN_(HAS_HOTEND, celsius_t target_temperature[HOTENDS]); + TERN_(HAS_HEATED_BED, celsius_t target_temperature_bed); TERN_(HAS_FAN, uint8_t fan_speed[FAN_COUNT]); TERN_(HAS_LEVELING, float fade); diff --git a/Marlin/src/gcode/bedlevel/G26.cpp b/Marlin/src/gcode/bedlevel/G26.cpp index ed2995905589a..0468b79363bb8 100644 --- a/Marlin/src/gcode/bedlevel/G26.cpp +++ b/Marlin/src/gcode/bedlevel/G26.cpp @@ -533,7 +533,7 @@ void GcodeSuite::G26() { #if HAS_HEATED_BED // Get a temperature from 'I' or 'B' - int16_t bedtemp = 0; + celsius_t bedtemp = 0; // Use the 'I' index if temperature presets are defined #if PREHEAT_COUNT @@ -616,7 +616,7 @@ void GcodeSuite::G26() { g26_extrusion_multiplier *= g26_filament_diameter * sq(g26_nozzle) / sq(0.3); // Scale up by nozzle size // Get a temperature from 'I' or 'H' - int16_t noztemp = 0; + celsius_t noztemp = 0; // Accept 'I' if temperature presets are defined #if PREHEAT_COUNT diff --git a/Marlin/src/gcode/host/M360.cpp b/Marlin/src/gcode/host/M360.cpp index 50a4e45426596..f3c242526dd55 100644 --- a/Marlin/src/gcode/host/M360.cpp +++ b/Marlin/src/gcode/host/M360.cpp @@ -177,7 +177,7 @@ void GcodeSuite::M360() { config_line_e(e, PSTR("MaxSpeed"), planner.settings.max_feedrate_mm_s[E_AXIS_N(e)]); config_line_e(e, PSTR("Acceleration"), planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(e)]); config_line_e(e, PSTR("Diameter"), TERN(NO_VOLUMETRICS, DEFAULT_NOMINAL_FILAMENT_DIA, planner.filament_size[e])); - config_line_e(e, PSTR("MaxTemp"), thermalManager.heater_maxtemp[e]); + config_line_e(e, PSTR("MaxTemp"), thermalManager.hotend_maxtemp[e]); } #endif } diff --git a/Marlin/src/gcode/lcd/M145.cpp b/Marlin/src/gcode/lcd/M145.cpp index 84a7e75aa4407..d6a57d22157e1 100644 --- a/Marlin/src/gcode/lcd/M145.cpp +++ b/Marlin/src/gcode/lcd/M145.cpp @@ -27,6 +27,10 @@ #include "../gcode.h" #include "../../lcd/marlinui.h" +#if HAS_HOTEND + #include "../../module/temperature.h" +#endif + /** * M145: Set the heatup state for a material in the LCD menu * @@ -43,7 +47,7 @@ void GcodeSuite::M145() { preheat_t &mat = ui.material_preset[material]; #if HAS_HOTEND if (parser.seenval('H')) - mat.hotend_temp = constrain(parser.value_int(), EXTRUDE_MINTEMP, (HEATER_0_MAXTEMP) - (HOTEND_OVERSHOOT)); + mat.hotend_temp = constrain(parser.value_int(), EXTRUDE_MINTEMP, thermalManager.hotend_max_target(0)); #endif #if HAS_HEATED_BED if (parser.seenval('B')) diff --git a/Marlin/src/gcode/parser.h b/Marlin/src/gcode/parser.h index 5a31a9943e293..44fa7fa4f7d8a 100644 --- a/Marlin/src/gcode/parser.h +++ b/Marlin/src/gcode/parser.h @@ -352,50 +352,45 @@ class GCodeParser { static inline PGM_P temp_units_name() { return input_temp_units == TEMPUNIT_K ? PSTR("Kelvin") : input_temp_units == TEMPUNIT_F ? PSTR("Fahrenheit") : PSTR("Celsius"); } - static inline float to_temp_units(const float &f) { + static inline float to_temp_units(celsius_t c) { switch (input_temp_units) { - case TEMPUNIT_F: - return f * 0.5555555556f + 32; - case TEMPUNIT_K: - return f + 273.15f; - case TEMPUNIT_C: default: - return f; + case TEMPUNIT_C: return c; + case TEMPUNIT_K: return c + 273.15f; + case TEMPUNIT_F: return c * 0.5555555556f + 32; } } #endif // HAS_LCD_MENU && !DISABLE_M503 - static inline float value_celsius() { - const float f = value_float(); + static inline celsius_t value_celsius() { + float f = value_float(); switch (input_temp_units) { - case TEMPUNIT_F: - return (f - 32) * 0.5555555556f; - case TEMPUNIT_K: - return f - 273.15f; - case TEMPUNIT_C: default: - return f; + case TEMPUNIT_C: break; + case TEMPUNIT_K: f -= 273.15f; + case TEMPUNIT_F: f = (f - 32) * 0.5555555556f; } + return celsius_t(f + 0.5f); } - static inline float value_celsius_diff() { + static inline celsius_t value_celsius_diff() { + float f = value_float(); switch (input_temp_units) { - case TEMPUNIT_F: - return value_float() * 0.5555555556f; - case TEMPUNIT_C: - case TEMPUNIT_K: default: - return value_float(); + case TEMPUNIT_C: + case TEMPUNIT_K: break; + case TEMPUNIT_F: f *= 0.5555555556f; } + return celsius_t(f + 0.5f); } #define TEMP_UNIT(N) parser.to_temp_units(N) #else // !TEMPERATURE_UNITS_SUPPORT - static inline float value_celsius() { return value_float(); } - static inline float value_celsius_diff() { return value_float(); } + static inline celsius_t value_celsius() { return value_int(); } + static inline celsius_t value_celsius_diff() { return value_int(); } #define TEMP_UNIT(N) (N) @@ -406,16 +401,16 @@ class GCodeParser { void unknown_command_warning(); // Provide simple value accessors with default option - static inline char* stringval(const char c, char * const dval=nullptr) { return seenval(c) ? value_string() : dval; } - static inline float floatval(const char c, const float dval=0.0) { return seenval(c) ? value_float() : dval; } - static inline bool boolval(const char c, const bool dval=false) { return seenval(c) ? value_bool() : (seen(c) ? true : dval); } - static inline uint8_t byteval(const char c, const uint8_t dval=0) { return seenval(c) ? value_byte() : dval; } - static inline int16_t intval(const char c, const int16_t dval=0) { return seenval(c) ? value_int() : dval; } - static inline uint16_t ushortval(const char c, const uint16_t dval=0) { return seenval(c) ? value_ushort() : dval; } - static inline int32_t longval(const char c, const int32_t dval=0) { return seenval(c) ? value_long() : dval; } - static inline uint32_t ulongval(const char c, const uint32_t dval=0) { return seenval(c) ? value_ulong() : dval; } - static inline float linearval(const char c, const float dval=0) { return seenval(c) ? value_linear_units() : dval; } - static inline float celsiusval(const char c, const float dval=0) { return seenval(c) ? value_celsius() : dval; } + static inline char* stringval(const char c, char * const dval=nullptr) { return seenval(c) ? value_string() : dval; } + static inline float floatval(const char c, const float dval=0.0) { return seenval(c) ? value_float() : dval; } + static inline bool boolval(const char c, const bool dval=false) { return seenval(c) ? value_bool() : (seen(c) ? true : dval); } + static inline uint8_t byteval(const char c, const uint8_t dval=0) { return seenval(c) ? value_byte() : dval; } + static inline int16_t intval(const char c, const int16_t dval=0) { return seenval(c) ? value_int() : dval; } + static inline uint16_t ushortval(const char c, const uint16_t dval=0) { return seenval(c) ? value_ushort() : dval; } + static inline int32_t longval(const char c, const int32_t dval=0) { return seenval(c) ? value_long() : dval; } + static inline uint32_t ulongval(const char c, const uint32_t dval=0) { return seenval(c) ? value_ulong() : dval; } + static inline float linearval(const char c, const float dval=0) { return seenval(c) ? value_linear_units() : dval; } + static inline celsius_t celsiusval(const char c, const float dval=0) { return seenval(c) ? value_celsius() : dval; } #if ENABLED(MARLIN_DEV_MODE) diff --git a/Marlin/src/gcode/temp/M104_M109.cpp b/Marlin/src/gcode/temp/M104_M109.cpp index 07e46e177571f..fe1e834656d9b 100644 --- a/Marlin/src/gcode/temp/M104_M109.cpp +++ b/Marlin/src/gcode/temp/M104_M109.cpp @@ -69,7 +69,7 @@ void GcodeSuite::M104() { #endif bool got_temp = false; - int16_t temp = 0; + celsius_t temp = 0; // Accept 'I' if temperature presets are defined #if PREHEAT_COUNT @@ -145,7 +145,7 @@ void GcodeSuite::M109() { #endif bool got_temp = false; - int16_t temp = 0; + celsius_t temp = 0; // Accept 'I' if temperature presets are defined #if PREHEAT_COUNT @@ -161,7 +161,7 @@ void GcodeSuite::M109() { if (!got_temp) { no_wait_for_cooling = parser.seenval('S'); got_temp = no_wait_for_cooling || parser.seenval('R'); - if (got_temp) temp = int16_t(parser.value_celsius()); + if (got_temp) temp = parser.value_celsius(); } if (got_temp) { diff --git a/Marlin/src/gcode/temp/M140_M190.cpp b/Marlin/src/gcode/temp/M140_M190.cpp index 9a1a0287d9f95..3aed878a0385d 100644 --- a/Marlin/src/gcode/temp/M140_M190.cpp +++ b/Marlin/src/gcode/temp/M140_M190.cpp @@ -44,7 +44,7 @@ void GcodeSuite::M140() { if (DEBUGGING(DRYRUN)) return; bool got_temp = false; - int16_t temp = 0; + celsius_t temp = 0; // Accept 'I' if temperature presets are defined #if PREHEAT_COUNT @@ -94,7 +94,7 @@ void GcodeSuite::M190() { if (DEBUGGING(DRYRUN)) return; bool got_temp = false; - int16_t temp = 0; + celsius_t temp = 0; // Accept 'I' if temperature presets are defined #if PREHEAT_COUNT @@ -110,7 +110,7 @@ void GcodeSuite::M190() { if (!got_temp) { no_wait_for_cooling = parser.seenval('S'); got_temp = no_wait_for_cooling || parser.seenval('R'); - if (got_temp) temp = int16_t(parser.value_celsius()); + if (got_temp) temp = parser.value_celsius(); } if (!got_temp) return; diff --git a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp index 15b3d8bfb321a..3f4cc23abad6b 100644 --- a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp +++ b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp @@ -520,15 +520,15 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char prefix, const bool blink) { #if HAS_HEATED_BED const bool isBed = TERN(HAS_HEATED_CHAMBER, heater_id == H_BED, heater_id < 0); - const float t1 = (isBed ? thermalManager.degBed() : thermalManager.degHotend(heater_id)), - t2 = (isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater_id)); + const celsius_t t1 = (isBed ? thermalManager.degBed() : thermalManager.degHotend(heater_id)), + t2 = (isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater_id)); #else - const float t1 = thermalManager.degHotend(heater_id), t2 = thermalManager.degTargetHotend(heater_id); + const celsius_t t1 = thermalManager.degHotend(heater_id), t2 = thermalManager.degTargetHotend(heater_id); #endif if (prefix >= 0) lcd_put_wchar(prefix); - lcd_put_u8str(i16tostr3rj(t1 + 0.5)); + lcd_put_u8str(i16tostr3rj(t1)); lcd_put_wchar('/'); #if !HEATER_IDLE_HANDLER @@ -541,7 +541,7 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char pr } else #endif - lcd_put_u8str(i16tostr3left(t2 + 0.5)); + lcd_put_u8str(i16tostr3left(t2)); if (prefix >= 0) { lcd_put_wchar(LCD_STR_DEGREE[0]); @@ -571,9 +571,9 @@ FORCE_INLINE void _draw_bed_status(const bool blink) { #if ENABLED(LCD_PROGRESS_BAR) void MarlinUI::draw_progress_bar(const uint8_t percent) { - const int16_t tix = (int16_t)(percent * (LCD_WIDTH) * 3) / 100, - cel = tix / 3, - rem = tix % 3; + const int16_t tix = int16_t(percent * (LCD_WIDTH) * 3) / 100, + cel = tix / 3, + rem = tix % 3; uint8_t i = LCD_WIDTH; char msg[LCD_WIDTH + 1], b = ' '; msg[LCD_WIDTH] = '\0'; diff --git a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp index 44128cc9f8d16..fd72f94862d12 100644 --- a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp +++ b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp @@ -434,33 +434,32 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char *p uint8_t pic_hot_bits; #if HAS_HEATED_BED const bool isBed = heater_id < 0; - const float t1 = (isBed ? thermalManager.degBed() : thermalManager.degHotend(heater_id)); - const float t2 = (isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater_id)); + const celsius_t t1 = (isBed ? thermalManager.degBed() : thermalManager.degHotend(heater_id)), + t2 = (isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater_id)); #else - const float t1 = thermalManager.degHotend(heater_id); - const float t2 = thermalManager.degTargetHotend(heater_id); + const celsius_t t1 = thermalManager.degHotend(heater_id), t2 = thermalManager.degTargetHotend(heater_id); #endif #if HOTENDS < 2 if (heater_id == H_E0) { lcd.setCursor(2, 5); lcd.print(prefix); //HE - lcd.setCursor(1, 6); lcd.print(i16tostr3rj(t1 + 0.5)); + lcd.setCursor(1, 6); lcd.print(i16tostr3rj(t1)); lcd.setCursor(1, 7); } else { lcd.setCursor(6, 5); lcd.print(prefix); //BED - lcd.setCursor(6, 6); lcd.print(i16tostr3rj(t1 + 0.5)); + lcd.setCursor(6, 6); lcd.print(i16tostr3rj(t1)); lcd.setCursor(6, 7); } #else if (heater_id > H_BED) { - lcd.setCursor(heater_id * 4, 5); lcd.print(prefix); //HE1 or HE2 or HE3 - lcd.setCursor(heater_id * 4, 6); lcd.print(i16tostr3rj(t1 + 0.5)); + lcd.setCursor(heater_id * 4, 5); lcd.print(prefix); // HE1 or HE2 or HE3 + lcd.setCursor(heater_id * 4, 6); lcd.print(i16tostr3rj(t1)); lcd.setCursor(heater_id * 4, 7); } else { lcd.setCursor(13, 5); lcd.print(prefix); //BED - lcd.setCursor(13, 6); lcd.print(i16tostr3rj(t1 + 0.5)); + lcd.setCursor(13, 6); lcd.print(i16tostr3rj(t1)); lcd.setCursor(13, 7); } #endif // HOTENDS <= 1 @@ -475,7 +474,7 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char *p } else #endif // !HEATER_IDLE_HANDLER - lcd.print(i16tostr3rj(t2 + 0.5)); + lcd.print(i16tostr3rj(t2)); switch (heater_id) { case H_BED: pic_hot_bits = ICON_BED; break; diff --git a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp index 892ab5218b83a..7d97a1cdcfb5d 100644 --- a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp +++ b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp @@ -187,7 +187,7 @@ #define PROGRESS_BAR_Y (EXTRAS_BASELINE + 1) #define PROGRESS_BAR_WIDTH (LCD_PIXEL_WIDTH - PROGRESS_BAR_X) -FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t tx, const uint8_t ty) { +FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, const uint8_t ty) { const char *str = i16tostr3rj(temp); const uint8_t len = str[0] != ' ' ? 3 : str[1] != ' ' ? 2 : 1; lcd_put_u8str(tx - len * (INFO_FONT_WIDTH) / 2 + 1, ty, &str[3-len]); @@ -206,8 +206,8 @@ FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t tx, cons const uint8_t tx = STATUS_HOTEND_TEXT_X(heater_id); - const float temp = thermalManager.degHotend(heater_id), - target = thermalManager.degTargetHotend(heater_id); + const celsius_t temp = thermalManager.degHotend(heater_id), + target = thermalManager.degTargetHotend(heater_id); #if DISABLED(STATUS_HOTEND_ANIM) #define STATIC_HOTEND true @@ -277,11 +277,11 @@ FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t tx, cons #else constexpr bool dodraw = true; #endif - if (dodraw) _draw_centered_temp(target + 0.5, tx, 7); + if (dodraw) _draw_centered_temp(target, tx, 7); } if (PAGE_CONTAINS(28 - INFO_FONT_ASCENT, 28 - 1)) - _draw_centered_temp(temp + 0.5f, tx, 28); + _draw_centered_temp(temp, tx, 28); if (STATIC_HOTEND && HOTEND_DOT && PAGE_CONTAINS(17, 19)) { u8g.setColorIndex(0); // set to white on black @@ -303,8 +303,8 @@ FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t tx, cons const uint8_t tx = STATUS_BED_TEXT_X; - const float temp = thermalManager.degBed(), - target = thermalManager.degTargetBed(); + const celsius_t temp = thermalManager.degBed(), + target = thermalManager.degTargetBed(); #if ENABLED(STATUS_HEAT_PERCENT) || DISABLED(STATUS_BED_ANIM) const bool isHeat = BED_ALT(); @@ -350,11 +350,11 @@ FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t tx, cons #else constexpr bool dodraw = true; #endif - if (dodraw) _draw_centered_temp(target + 0.5, tx, 7); + if (dodraw) _draw_centered_temp(target, tx, 7); } if (PAGE_CONTAINS(28 - INFO_FONT_ASCENT, 28 - 1)) - _draw_centered_temp(temp + 0.5f, tx, 28); + _draw_centered_temp(temp, tx, 28); if (STATIC_BED && BED_DOT && PAGE_CONTAINS(17, 19)) { u8g.setColorIndex(0); // set to white on black @@ -370,10 +370,10 @@ FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t tx, cons FORCE_INLINE void _draw_chamber_status() { #if HAS_HEATED_CHAMBER if (PAGE_UNDER(7)) - _draw_centered_temp(thermalManager.degTargetChamber() + 0.5f, STATUS_CHAMBER_TEXT_X, 7); + _draw_centered_temp(thermalManager.degTargetChamber(), STATUS_CHAMBER_TEXT_X, 7); #endif if (PAGE_CONTAINS(28 - INFO_FONT_ASCENT, 28 - 1)) - _draw_centered_temp(thermalManager.degChamber() + 0.5f, STATUS_CHAMBER_TEXT_X, 28); + _draw_centered_temp(thermalManager.degChamber(), STATUS_CHAMBER_TEXT_X, 28); } #endif diff --git a/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp b/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp index a538121d2cf6f..dcb65f676d40a 100644 --- a/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp +++ b/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp @@ -691,15 +691,15 @@ bool ST7920_Lite_Status_Screen::indicators_changed() { // We only add the target temperatures to the checksum // because the actual temps fluctuate so by updating // them only during blinks we gain a bit of stability. - const bool blink = ui.get_blink(); - const uint16_t feedrate_perc = feedrate_percentage; - const uint16_t fs = thermalManager.scaledFanSpeed(0); - const int16_t extruder_1_target = thermalManager.degTargetHotend(0); + const bool blink = ui.get_blink(); + const uint16_t feedrate_perc = feedrate_percentage; + const uint16_t fs = thermalManager.scaledFanSpeed(0); + const celsius_t extruder_1_target = thermalManager.degTargetHotend(0); #if HAS_MULTI_HOTEND - const int16_t extruder_2_target = thermalManager.degTargetHotend(1); + const celsius_t extruder_2_target = thermalManager.degTargetHotend(1); #endif #if HAS_HEATED_BED - const int16_t bed_target = thermalManager.degTargetBed(); + const celsius_t bed_target = thermalManager.degTargetBed(); #endif static uint16_t last_checksum = 0; const uint16_t checksum = blink ^ feedrate_perc ^ fs ^ extruder_1_target @@ -712,19 +712,19 @@ bool ST7920_Lite_Status_Screen::indicators_changed() { void ST7920_Lite_Status_Screen::update_indicators(const bool forceUpdate) { if (forceUpdate || indicators_changed()) { - const bool blink = ui.get_blink(); - const duration_t elapsed = print_job_timer.duration(); - duration_t remaining = TERN0(USE_M73_REMAINING_TIME, ui.get_remaining_time()); - const uint16_t feedrate_perc = feedrate_percentage; - const int16_t extruder_1_temp = thermalManager.degHotend(0), - extruder_1_target = thermalManager.degTargetHotend(0); + const bool blink = ui.get_blink(); + const duration_t elapsed = print_job_timer.duration(); + duration_t remaining = TERN0(USE_M73_REMAINING_TIME, ui.get_remaining_time()); + const uint16_t feedrate_perc = feedrate_percentage; + const celsius_t extruder_1_temp = thermalManager.degHotend(0), + extruder_1_target = thermalManager.degTargetHotend(0); #if HAS_MULTI_HOTEND - const int16_t extruder_2_temp = thermalManager.degHotend(1), - extruder_2_target = thermalManager.degTargetHotend(1); + const celsius_t extruder_2_temp = thermalManager.degHotend(1), + extruder_2_target = thermalManager.degTargetHotend(1); #endif #if HAS_HEATED_BED - const int16_t bed_temp = thermalManager.degBed(), - bed_target = thermalManager.degTargetBed(); + const celsius_t bed_temp = thermalManager.degBed(), + bed_target = thermalManager.degTargetBed(); #endif draw_extruder_1_temp(extruder_1_temp, extruder_1_target, forceUpdate); diff --git a/Marlin/src/lcd/dwin/e3v2/dwin.cpp b/Marlin/src/lcd/dwin/e3v2/dwin.cpp index 97a9fbd4da3a9..d7a2cef7ee04f 100644 --- a/Marlin/src/lcd/dwin/e3v2/dwin.cpp +++ b/Marlin/src/lcd/dwin/e3v2/dwin.cpp @@ -102,25 +102,11 @@ #define DWIN_FONT_HEAD font10x20 #define MENU_CHAR_LIMIT 24 -#define STATUS_Y 360 - -// Fan speed limit -#define FANON 255 -#define FANOFF 0 +#define STATUS_Y 360 // Print speed limit -#define MAX_PRINT_SPEED 999 -#define MIN_PRINT_SPEED 10 - -// Temp limits -#if HAS_HOTEND - #define MAX_E_TEMP (HEATER_0_MAXTEMP - (HOTEND_OVERSHOOT)) - #define MIN_E_TEMP HEATER_0_MINTEMP -#endif - -#if HAS_HEATED_BED - #define MIN_BED_TEMP BED_MINTEMP -#endif +#define MIN_PRINT_SPEED 10 +#define MAX_PRINT_SPEED 999 // Feedspeed limit (max feedspeed = DEFAULT_MAX_FEEDRATE * 2) #define MIN_MAXFEEDSPEED 1 @@ -889,11 +875,11 @@ void Draw_Tune_Menu() { #if HAS_HOTEND Draw_Menu_Line(TUNE_CASE_TEMP, ICON_HotendTemp); - DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(TUNE_CASE_TEMP), thermalManager.temp_hotend[0].target); + DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(TUNE_CASE_TEMP), thermalManager.degTargetHotend(0)); #endif #if HAS_HEATED_BED Draw_Menu_Line(TUNE_CASE_BED, ICON_BedTemp); - DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(TUNE_CASE_BED), thermalManager.temp_bed.target); + DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(TUNE_CASE_BED), thermalManager.degTargetBed()); #endif #if HAS_FAN Draw_Menu_Line(TUNE_CASE_FAN, ICON_FanSpeed); @@ -1357,7 +1343,7 @@ void HMI_Move_Z() { return; } // E_Temp limit - LIMIT(HMI_ValueStruct.E_Temp, MIN_E_TEMP, MAX_E_TEMP); + LIMIT(HMI_ValueStruct.E_Temp, HEATER_0_MINTEMP, hotend_max_target(0)); // E_Temp value DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 216, MBASE(temp_line), HMI_ValueStruct.E_Temp); } @@ -1400,7 +1386,7 @@ void HMI_Move_Z() { return; } // Bed_Temp limit - LIMIT(HMI_ValueStruct.Bed_Temp, MIN_BED_TEMP, BED_MAX_TARGET); + LIMIT(HMI_ValueStruct.Bed_Temp, BED_MINTEMP, BED_MAX_TARGET); // Bed_Temp value DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 216, MBASE(bed_line), HMI_ValueStruct.Bed_Temp); } @@ -1444,7 +1430,7 @@ void HMI_Move_Z() { return; } // Fan_speed limit - LIMIT(HMI_ValueStruct.Fan_speed, FANOFF, FANON); + LIMIT(HMI_ValueStruct.Fan_speed, 0, 255); // Fan_speed value DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 216, MBASE(fan_line), HMI_ValueStruct.Fan_speed); } @@ -1592,20 +1578,22 @@ void _draw_xyz_position(const bool force) { void update_variable() { #if HAS_HOTEND - static float _hotendtemp = 0; - const bool _new_hotend_temp = _hotendtemp != thermalManager.temp_hotend[0].celsius; - if (_new_hotend_temp) _hotendtemp = thermalManager.temp_hotend[0].celsius; - static int16_t _hotendtarget = 0; - const bool _new_hotend_target = _hotendtarget != thermalManager.temp_hotend[0].target; - if (_new_hotend_target) _hotendtarget = thermalManager.temp_hotend[0].target; + static celsius_t _hotendtemp = 0, _hotendtarget = 0; + const celsius_t hc = thermalManager.degHotend(0), + ht = thermalManager.degTargetHotend(0); + const bool _new_hotend_temp = _hotendtemp != hc, + _new_hotend_target = _hotendtarget != ht; + if (_new_hotend_temp) _hotendtemp = hc; + if (_new_hotend_target) _hotendtarget = ht; #endif #if HAS_HEATED_BED - static float _bedtemp = 0; - const bool _new_bed_temp = _bedtemp != thermalManager.temp_bed.celsius; - if (_new_bed_temp) _bedtemp = thermalManager.temp_bed.celsius; - static int16_t _bedtarget = 0; - const bool _new_bed_target = _bedtarget != thermalManager.temp_bed.target; - if (_new_bed_target) _bedtarget = thermalManager.temp_bed.target; + static celsius_t _bedtemp = 0, _bedtarget = 0; + const celsius_t bc = thermalManager.degBed(), + bt = thermalManager.degTargetBed(); + const bool _new_bed_temp = _bedtemp != bc, + _new_bed_target = _bedtarget != bt; + if (_new_bed_temp) _bedtemp = bc; + if (_new_bed_target) _bedtarget = bt; #endif #if HAS_FAN static uint8_t _fanspeed = 0; @@ -1888,9 +1876,9 @@ void Draw_Status_Area(const bool with_update) { #if HAS_HOTEND DWIN_ICON_Show(ICON, ICON_HotendTemp, 10, 383); - DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 28, 384, thermalManager.temp_hotend[0].celsius); + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 28, 384, thermalManager.degHotend(0)); DWIN_Draw_String(false, false, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 25 + 3 * STAT_CHR_W + 5, 384, F("/")); - DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 25 + 4 * STAT_CHR_W + 6, 384, thermalManager.temp_hotend[0].target); + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 25 + 4 * STAT_CHR_W + 6, 384, thermalManager.degTargetHotend(0)); DWIN_ICON_Show(ICON, ICON_StepE, 112, 417); DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 116 + 2 * STAT_CHR_W, 417, planner.flow_percentage[0]); @@ -1899,9 +1887,9 @@ void Draw_Status_Area(const bool with_update) { #if HAS_HEATED_BED DWIN_ICON_Show(ICON, ICON_BedTemp, 10, 416); - DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 28, 417, thermalManager.temp_bed.celsius); + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 28, 417, thermalManager.degBed()); DWIN_Draw_String(false, false, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 25 + 3 * STAT_CHR_W + 5, 417, F("/")); - DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 25 + 4 * STAT_CHR_W + 6, 417, thermalManager.temp_bed.target); + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 25 + 4 * STAT_CHR_W + 6, 417, thermalManager.degTargetBed()); #endif DWIN_ICON_Show(ICON, ICON_Speed, 113, 383); @@ -2163,8 +2151,8 @@ void HMI_SelectFile() { #if FAN_COUNT > 0 // All fans on for Ender 3 v2 ? // The slicer should manage this for us. - // for (uint8_t i = 0; i < FAN_COUNT; i++) - // thermalManager.fan_speed[i] = FANON; + //for (uint8_t i = 0; i < FAN_COUNT; i++) + // thermalManager.fan_speed[i] = 255; #endif Goto_PrintProcess(); @@ -2545,11 +2533,11 @@ void Draw_Temperature_Menu() { #define _TMENU_ICON(N) Draw_Menu_Line(++i, ICON_SetEndTemp + (N) - 1) #if HAS_HOTEND _TMENU_ICON(TEMP_CASE_TEMP); - DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(i), thermalManager.temp_hotend[0].target); + DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(i), thermalManager.degTargetHotend(0)); #endif #if HAS_HEATED_BED _TMENU_ICON(TEMP_CASE_BED); - DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(i), thermalManager.temp_bed.target); + DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(i), thermalManager.degTargetBed()); #endif #if HAS_FAN _TMENU_ICON(TEMP_CASE_FAN); @@ -2717,7 +2705,7 @@ void HMI_AxisMove() { case 4: // Extruder // window tips #ifdef PREVENT_COLD_EXTRUSION - if (thermalManager.temp_hotend[0].celsius < EXTRUDE_MINTEMP) { + if (thermalManager.degHotend(0) < EXTRUDE_MINTEMP) { HMI_flag.ETempTooLow_flag = true; Popup_Window_ETempTooLow(); DWIN_UpdateLCD(); @@ -2758,16 +2746,16 @@ void HMI_Temperature() { #if HAS_HOTEND case TEMP_CASE_TEMP: // Nozzle temperature checkkey = ETemp; - HMI_ValueStruct.E_Temp = thermalManager.temp_hotend[0].target; - DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 216, MBASE(1), thermalManager.temp_hotend[0].target); + HMI_ValueStruct.E_Temp = thermalManager.degTargetHotend(0); + DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 216, MBASE(1), HMI_ValueStruct.E_Temp); EncoderRate.enabled = true; break; #endif #if HAS_HEATED_BED case TEMP_CASE_BED: // Bed temperature checkkey = BedTemp; - HMI_ValueStruct.Bed_Temp = thermalManager.temp_bed.target; - DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 216, MBASE(2), thermalManager.temp_bed.target); + HMI_ValueStruct.Bed_Temp = thermalManager.degTargetBed(); + DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 216, MBASE(2), HMI_ValueStruct.Bed_Temp); EncoderRate.enabled = true; break; #endif @@ -2775,7 +2763,7 @@ void HMI_Temperature() { case TEMP_CASE_FAN: // Fan speed checkkey = FanSpeed; HMI_ValueStruct.Fan_speed = thermalManager.fan_speed[0]; - DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 216, MBASE(3), thermalManager.fan_speed[0]); + DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 216, MBASE(3), HMI_ValueStruct.Fan_speed); EncoderRate.enabled = true; break; #endif @@ -2807,7 +2795,7 @@ void HMI_Temperature() { #ifdef USE_STRING_HEADINGS Draw_Title("PLA Settings"); // TODO: GET_TEXT_F #else - DWIN_Frame_TitleCopy(1, 56, 16, 141, 28); // "PLA Settings" + DWIN_Frame_TitleCopy(1, 56, 16, 141, 28); // "PLA Settings" #endif #ifdef USE_STRING_TITLES DWIN_Draw_Label(MBASE(PREHEAT_CASE_TEMP), F("Nozzle Temp")); @@ -2823,7 +2811,7 @@ void HMI_Temperature() { #else DWIN_Frame_AreaCopy(1, 157, 76, 181, 86, LBLX, MBASE(PREHEAT_CASE_TEMP)); DWIN_Frame_AreaCopy(1, 197, 104, 238, 114, LBLX + 27, MBASE(PREHEAT_CASE_TEMP)); - DWIN_Frame_AreaCopy(1, 1, 89, 83, 101, LBLX + 71, MBASE(PREHEAT_CASE_TEMP)); // PLA nozzle temp + DWIN_Frame_AreaCopy(1, 1, 89, 83, 101, LBLX + 71, MBASE(PREHEAT_CASE_TEMP)); // PLA nozzle temp #if HAS_HEATED_BED DWIN_Frame_AreaCopy(1, 157, 76, 181, 86, LBLX, MBASE(PREHEAT_CASE_BED) + 3); DWIN_Frame_AreaCopy(1, 240, 104, 264, 114, LBLX + 27, MBASE(PREHEAT_CASE_BED) + 3); @@ -2834,7 +2822,7 @@ void HMI_Temperature() { DWIN_Frame_AreaCopy(1, 0, 119, 64, 132, LBLX + 27, MBASE(PREHEAT_CASE_FAN)); // PLA fan speed #endif #if ENABLED(EEPROM_SETTINGS) - DWIN_Frame_AreaCopy(1, 97, 165, 229, 177, LBLX, MBASE(PREHEAT_CASE_SAVE)); // Save PLA configuration + DWIN_Frame_AreaCopy(1, 97, 165, 229, 177, LBLX, MBASE(PREHEAT_CASE_SAVE)); // Save PLA configuration #endif #endif } @@ -3291,22 +3279,22 @@ void HMI_Tune() { case TUNE_CASE_SPEED: // Print speed checkkey = PrintSpeed; HMI_ValueStruct.print_speed = feedrate_percentage; - DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 216, MBASE(TUNE_CASE_SPEED + MROWS - index_tune), feedrate_percentage); + DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 216, MBASE(TUNE_CASE_SPEED + MROWS - index_tune), HMI_ValueStruct.print_speed); EncoderRate.enabled = true; break; #if HAS_HOTEND case TUNE_CASE_TEMP: // Nozzle temp checkkey = ETemp; - HMI_ValueStruct.E_Temp = thermalManager.temp_hotend[0].target; - DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 216, MBASE(TUNE_CASE_TEMP + MROWS - index_tune), thermalManager.temp_hotend[0].target); + HMI_ValueStruct.E_Temp = thermalManager.degTargetHotend(0); + DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 216, MBASE(TUNE_CASE_TEMP + MROWS - index_tune), HMI_ValueStruct.E_Temp); EncoderRate.enabled = true; break; #endif #if HAS_HEATED_BED case TUNE_CASE_BED: // Bed temp checkkey = BedTemp; - HMI_ValueStruct.Bed_Temp = thermalManager.temp_bed.target; - DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 216, MBASE(TUNE_CASE_BED + MROWS - index_tune), thermalManager.temp_bed.target); + HMI_ValueStruct.Bed_Temp = thermalManager.degTargetBed(); + DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 216, MBASE(TUNE_CASE_BED + MROWS - index_tune), HMI_ValueStruct.Bed_Temp); EncoderRate.enabled = true; break; #endif @@ -3314,7 +3302,7 @@ void HMI_Tune() { case TUNE_CASE_FAN: // Fan speed checkkey = FanSpeed; HMI_ValueStruct.Fan_speed = thermalManager.fan_speed[0]; - DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 216, MBASE(TUNE_CASE_FAN + MROWS - index_tune), thermalManager.fan_speed[0]); + DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 216, MBASE(TUNE_CASE_FAN + MROWS - index_tune), HMI_ValueStruct.Fan_speed); EncoderRate.enabled = true; break; #endif @@ -3632,8 +3620,8 @@ void EachMomentUpdate() { if (HMI_flag.pause_action && printingIsPaused() && !planner.has_blocks_queued()) { HMI_flag.pause_action = false; #if ENABLED(PAUSE_HEAT) - TERN_(HAS_HOTEND, resume_hotend_temp = thermalManager.temp_hotend[0].target); - TERN_(HAS_HEATED_BED, resume_bed_temp = thermalManager.temp_bed.target); + TERN_(HAS_HOTEND, resume_hotend_temp = thermalManager.degTargetHotend(0)); + TERN_(HAS_HEATED_BED, resume_bed_temp = thermalManager.degTargetBed()); thermalManager.disable_all_heaters(); #endif queue.inject_P(PSTR("G1 F1200 X0 Y0")); diff --git a/Marlin/src/lcd/dwin/e3v2/dwin.h b/Marlin/src/lcd/dwin/e3v2/dwin.h index 217127ed11b13..9e0cda86c29eb 100644 --- a/Marlin/src/lcd/dwin/e3v2/dwin.h +++ b/Marlin/src/lcd/dwin/e3v2/dwin.h @@ -234,8 +234,8 @@ extern char print_filename[16]; extern millis_t dwin_heat_time; typedef struct { - TERN_(HAS_HOTEND, int16_t E_Temp = 0); - TERN_(HAS_HEATED_BED, int16_t Bed_Temp = 0); + TERN_(HAS_HOTEND, celsius_t E_Temp = 0); + TERN_(HAS_HEATED_BED, celsius_t Bed_Temp = 0); TERN_(HAS_FAN, int16_t Fan_speed = 0); int16_t print_speed = 100; float Max_Feedspeed = 0; diff --git a/Marlin/src/lcd/extui/lib/dgus/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/lib/dgus/DGUSScreenHandler.cpp index 93a7de14a1997..473fcb954c088 100644 --- a/Marlin/src/lcd/extui/lib/dgus/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/lib/dgus/DGUSScreenHandler.cpp @@ -388,28 +388,28 @@ void DGUSScreenHandler::HandleAllHeatersOff(DGUS_VP_Variable &var, void *val_ptr } void DGUSScreenHandler::HandleTemperatureChanged(DGUS_VP_Variable &var, void *val_ptr) { - uint16_t newvalue = swap16(*(uint16_t*)val_ptr); - uint16_t acceptedvalue; + celsius_t newvalue = swap16(*(uint16_t*)val_ptr); + celsius_t acceptedvalue; switch (var.VP) { default: return; #if HOTENDS >= 1 case VP_T_E0_Set: - NOMORE(newvalue, (uint16_t)HEATER_0_MAXTEMP); + NOMORE(newvalue, HEATER_0_MAXTEMP); thermalManager.setTargetHotend(newvalue, 0); acceptedvalue = thermalManager.degTargetHotend(0); break; #endif #if HOTENDS >= 2 case VP_T_E1_Set: - NOMORE(newvalue, (uint16_t)HEATER_1_MAXTEMP); + NOMORE(newvalue, HEATER_1_MAXTEMP); thermalManager.setTargetHotend(newvalue, 1); acceptedvalue = thermalManager.degTargetHotend(1); break; #endif #if HAS_HEATED_BED case VP_T_Bed_Set: - NOMORE(newvalue, (uint16_t)BED_MAXTEMP); + NOMORE(newvalue, BED_MAXTEMP); thermalManager.setTargetBed(newvalue); acceptedvalue = thermalManager.degTargetBed(); break; diff --git a/Marlin/src/lcd/extui/lib/dgus/fysetc/DGUSDisplayDef.cpp b/Marlin/src/lcd/extui/lib/dgus/fysetc/DGUSDisplayDef.cpp index 467444c214596..ee0a1c749faba 100644 --- a/Marlin/src/lcd/extui/lib/dgus/fysetc/DGUSDisplayDef.cpp +++ b/Marlin/src/lcd/extui/lib/dgus/fysetc/DGUSDisplayDef.cpp @@ -367,7 +367,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { // Temperature Data #if HOTENDS >= 1 - VPHELPER(VP_T_E0_Is, &thermalManager.temp_hotend[0].celsius, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<0>), + VPHELPER(VP_T_E0_Is, &thermalManager.temp_hotend[0].celsius, nullptr, ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_T_E0_Set, &thermalManager.temp_hotend[0].target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_Flowrate_E0, &planner.flow_percentage[ExtUI::extruder_t::E0], ScreenHandler.HandleFlowRateChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_EPos, &destination.e, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>), @@ -388,7 +388,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { #endif #endif #if HOTENDS >= 2 - VPHELPER(VP_T_E1_Is, &thermalManager.temp_hotend[1].celsius, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<0>), + VPHELPER(VP_T_E1_Is, &thermalManager.temp_hotend[1].celsius, nullptr, ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_T_E1_Set, &thermalManager.temp_hotend[1].target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_Flowrate_E1, &planner.flow_percentage[ExtUI::extruder_t::E1], ScreenHandler.HandleFlowRateChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_MOVE_E1, nullptr, &ScreenHandler.HandleManualExtrude, nullptr), @@ -400,7 +400,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { VPHELPER(VP_E1_FILAMENT_LOAD_UNLOAD, nullptr, &ScreenHandler.HandleFilamentOption, &ScreenHandler.HandleFilamentLoadUnload), #endif #if HAS_HEATED_BED - VPHELPER(VP_T_Bed_Is, &thermalManager.temp_bed.celsius, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<0>), + VPHELPER(VP_T_Bed_Is, &thermalManager.temp_bed.celsius, nullptr, ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_T_Bed_Set, &thermalManager.temp_bed.target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_BED_CONTROL, &thermalManager.temp_bed.target, &ScreenHandler.HandleHeaterControl, nullptr), VPHELPER(VP_BED_STATUS, &thermalManager.temp_bed.target, nullptr, &ScreenHandler.DGUSLCD_SendHeaterStatusToDisplay), diff --git a/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSDisplayDef.cpp b/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSDisplayDef.cpp index 536640ec95260..5de3f302fddb7 100644 --- a/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSDisplayDef.cpp +++ b/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSDisplayDef.cpp @@ -370,7 +370,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { // Temperature Data #if HOTENDS >= 1 - VPHELPER(VP_T_E0_Is, &thermalManager.temp_hotend[0].celsius, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<0>), + VPHELPER(VP_T_E0_Is, &thermalManager.temp_hotend[0].celsius, nullptr, ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_T_E0_Set, &thermalManager.temp_hotend[0].target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_Flowrate_E0, &planner.flow_percentage[ExtUI::extruder_t::E0], ScreenHandler.HandleFlowRateChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_EPos, &destination.e, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>), @@ -391,7 +391,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { #endif #endif #if HOTENDS >= 2 - VPHELPER(VP_T_E1_Is, &thermalManager.temp_hotend[1].celsius, nullptr, DGUSLCD_SendFloatAsLongValueToDisplay<0>), + VPHELPER(VP_T_E1_Is, &thermalManager.temp_hotend[1].celsius, nullptr, DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_T_E1_Set, &thermalManager.temp_hotend[1].target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_Flowrate_E1, nullptr, ScreenHandler.HandleFlowRateChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_MOVE_E1, nullptr, &ScreenHandler.HandleManualExtrude, nullptr), @@ -399,7 +399,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { VPHELPER(VP_E1_STATUS, &thermalManager.temp_hotend[1].target, nullptr, &ScreenHandler.DGUSLCD_SendHeaterStatusToDisplay), #endif #if HAS_HEATED_BED - VPHELPER(VP_T_Bed_Is, &thermalManager.temp_bed.celsius, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<0>), + VPHELPER(VP_T_Bed_Is, &thermalManager.temp_bed.celsius, nullptr, ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_T_Bed_Set, &thermalManager.temp_bed.target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_BED_CONTROL, &thermalManager.temp_bed.target, &ScreenHandler.HandleHeaterControl, nullptr), VPHELPER(VP_BED_STATUS, &thermalManager.temp_bed.target, nullptr, &ScreenHandler.DGUSLCD_SendHeaterStatusToDisplay), diff --git a/Marlin/src/lcd/extui/lib/dgus/mks/DGUSDisplayDef.cpp b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSDisplayDef.cpp index bfa518446d594..3cd3c5fa65d1f 100644 --- a/Marlin/src/lcd/extui/lib/dgus/mks/DGUSDisplayDef.cpp +++ b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSDisplayDef.cpp @@ -548,7 +548,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { // Temperature Data #if HOTENDS >= 1 - VPHELPER(VP_T_E0_Is, &thermalManager.temp_hotend[0].celsius, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<0>), + VPHELPER(VP_T_E0_Is, &thermalManager.temp_hotend[0].celsius, nullptr, ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_T_E0_Set, &thermalManager.temp_hotend[0].target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_Flowrate_E0, &planner.flow_percentage[ExtUI::extruder_t::E0], ScreenHandler.HandleFlowRateChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_EPos, &destination.e, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>), @@ -573,7 +573,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { #endif #if HOTENDS >= 2 - VPHELPER(VP_T_E1_Is, &thermalManager.temp_hotend[1].celsius, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<0>), + VPHELPER(VP_T_E1_Is, &thermalManager.temp_hotend[1].celsius, nullptr, ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_T_E1_Set, &thermalManager.temp_hotend[1].target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_Flowrate_E1, &planner.flow_percentage[ExtUI::extruder_t::E1], ScreenHandler.HandleFlowRateChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_MOVE_E1, nullptr, &ScreenHandler.HandleManualExtrude, nullptr), @@ -593,7 +593,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { #endif #if HAS_HEATED_BED - VPHELPER(VP_T_Bed_Is, &thermalManager.temp_bed.celsius, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<0>), + VPHELPER(VP_T_Bed_Is, &thermalManager.temp_bed.celsius, nullptr, ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_T_Bed_Set, &thermalManager.temp_bed.target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_BED_CONTROL, &thermalManager.temp_bed.target, &ScreenHandler.HandleHeaterControl, nullptr), VPHELPER(VP_BED_STATUS, &thermalManager.temp_bed.target, nullptr, &ScreenHandler.DGUSLCD_SendHeaterStatusToDisplay), @@ -764,8 +764,8 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { VPHELPER(VP_SD_AbortPrintConfirmed, nullptr, ScreenHandler.DGUSLCD_SD_ReallyAbort, nullptr), VPHELPER(VP_SD_Print_Setting, nullptr, ScreenHandler.DGUSLCD_SD_PrintTune, nullptr), #if ENABLED(BABYSTEPPING) - VPHELPER(VP_SD_Print_LiveAdjustZ,nullptr, ScreenHandler.HandleLiveAdjustZ, &ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<2>), - VPHELPER(VP_ZOffset_DE_DIS,&z_offset_add,nullptr, &ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_SD_Print_LiveAdjustZ, nullptr, ScreenHandler.HandleLiveAdjustZ, &ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<2>), + VPHELPER(VP_ZOffset_DE_DIS, &z_offset_add, nullptr, &ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>), #endif #if HAS_BED_PROBE VPHELPER(VP_OFFSET_X, &probe.offset.x, ScreenHandler.GetOffsetValue,ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>), diff --git a/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.cpp index 577171a135811..17329ae44e6d7 100644 --- a/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.cpp @@ -111,7 +111,7 @@ void DGUSScreenHandler::DGUSLCD_SendPrintTimeToDisplay_MKS(DGUS_VP_Variable &var void DGUSScreenHandler::DGUSLCD_SetUint8(DGUS_VP_Variable &var, void *val_ptr) { if (var.memadr) { - uint16_t value = swap16(*(uint16_t*)val_ptr); + const uint16_t value = swap16(*(uint16_t*)val_ptr); DEBUG_ECHOLNPAIR("FAN value get:", value); *(uint8_t*)var.memadr = map(constrain(value, 0, 255), 0, 255, 0, 255); DEBUG_ECHOLNPAIR("FAN value change:", *(uint8_t*)var.memadr); @@ -314,7 +314,7 @@ void DGUSScreenHandler::ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr) { } void DGUSScreenHandler::ScreenBackChange(DGUS_VP_Variable &var, void *val_ptr) { - uint16_t target = swap16(*(uint16_t *)val_ptr); + const uint16_t target = swap16(*(uint16_t *)val_ptr); DEBUG_ECHOLNPAIR(" back = 0x%x", target); switch (target) { } @@ -330,7 +330,7 @@ void DGUSScreenHandler::ZoffsetConfirm(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandler::GetTurnOffCtrl(DGUS_VP_Variable &var, void *val_ptr) { DEBUG_ECHOLNPGM("ctrl turn off\n"); - uint16_t value = swap16(*(uint16_t *)val_ptr); + const uint16_t value = swap16(*(uint16_t *)val_ptr); switch (value) { case 0 ... 1: DGUSAutoTurnOff = (bool)value; break; default: break; @@ -339,7 +339,7 @@ void DGUSScreenHandler::GetTurnOffCtrl(DGUS_VP_Variable &var, void *val_ptr) { void DGUSScreenHandler::GetMinExtrudeTemp(DGUS_VP_Variable &var, void *val_ptr) { DEBUG_ECHOLNPGM("MinExtrudeTempChange DistanceChange"); - uint16_t value = swap16(*(uint16_t *)val_ptr); + const uint16_t value = swap16(*(uint16_t *)val_ptr); thermalManager.extrude_min_temp = value; min_ex_temp = value; settings.save(); @@ -347,7 +347,7 @@ void DGUSScreenHandler::GetMinExtrudeTemp(DGUS_VP_Variable &var, void *val_ptr) void DGUSScreenHandler::GetZoffsetDistance(DGUS_VP_Variable &var, void *val_ptr) { DEBUG_ECHOLNPGM("Zoffset DistanceChange"); - uint16_t value = swap16(*(uint16_t *)val_ptr); + const uint16_t value = swap16(*(uint16_t *)val_ptr); float val_distance = 0; switch (value) { case 0: val_distance = 0.01; break; @@ -365,7 +365,7 @@ void DGUSScreenHandler::GetManualMovestep(DGUS_VP_Variable &var, void *val_ptr) } void DGUSScreenHandler::EEPROM_CTRL(DGUS_VP_Variable &var, void *val_ptr) { - uint16_t eep_flag = swap16(*(uint16_t *)val_ptr); + const uint16_t eep_flag = swap16(*(uint16_t *)val_ptr); switch (eep_flag) { case 0: settings.save(); @@ -383,7 +383,7 @@ void DGUSScreenHandler::EEPROM_CTRL(DGUS_VP_Variable &var, void *val_ptr) { } void DGUSScreenHandler::Z_offset_select(DGUS_VP_Variable &var, void *val_ptr) { - uint16_t z_value = swap16(*(uint16_t *)val_ptr); + const uint16_t z_value = swap16(*(uint16_t *)val_ptr); switch (z_value) { case 0: Z_distance = 0.01; break; case 1: Z_distance = 0.1; break; @@ -410,7 +410,7 @@ void DGUSScreenHandler::GetOffsetValue(DGUS_VP_Variable &var, void *val_ptr) { } void DGUSScreenHandler::LanguageChange_MKS(DGUS_VP_Variable &var, void *val_ptr) { - uint16_t lag_flag = swap16(*(uint16_t *)val_ptr); + const uint16_t lag_flag = swap16(*(uint16_t *)val_ptr); switch (lag_flag) { case MKS_SimpleChinese: DGUS_LanguageDisplay(MKS_SimpleChinese); @@ -435,7 +435,7 @@ void DGUSScreenHandler::LanguageChange_MKS(DGUS_VP_Variable &var, void *val_ptr) #endif void DGUSScreenHandler::Level_Ctrl_MKS(DGUS_VP_Variable &var, void *val_ptr) { - uint16_t lev_but = swap16(*(uint16_t *)val_ptr); + const uint16_t lev_but = swap16(*(uint16_t *)val_ptr); #if ENABLED(MESH_BED_LEVELING) auto cs = getCurrentScreen(); #endif @@ -482,7 +482,7 @@ void DGUSScreenHandler::Level_Ctrl_MKS(DGUS_VP_Variable &var, void *val_ptr) { } void DGUSScreenHandler::MeshLevelDistanceConfig(DGUS_VP_Variable &var, void *val_ptr) { - uint16_t mesh_dist = swap16(*(uint16_t *)val_ptr); + const uint16_t mesh_dist = swap16(*(uint16_t *)val_ptr); switch (mesh_dist) { case 0: mesh_adj_distance = 0.01; break; case 1: mesh_adj_distance = 0.1; break; @@ -493,7 +493,7 @@ void DGUSScreenHandler::MeshLevelDistanceConfig(DGUS_VP_Variable &var, void *val void DGUSScreenHandler::MeshLevel(DGUS_VP_Variable &var, void *val_ptr) { #if ENABLED(MESH_BED_LEVELING) - uint16_t mesh_value = swap16(*(uint16_t *)val_ptr); + const uint16_t mesh_value = swap16(*(uint16_t *)val_ptr); // static uint8_t a_first_level = 1; char cmd_buf[30]; float offset = mesh_adj_distance; @@ -586,20 +586,16 @@ void DGUSScreenHandler::MeshLevel(DGUS_VP_Variable &var, void *val_ptr) { } void DGUSScreenHandler::LCD_BLK_Adjust(DGUS_VP_Variable &var, void *val_ptr) { + const uint16_t lcd_value = swap16(*(uint16_t *)val_ptr); - uint16_t lcd_value = swap16(*(uint16_t *)val_ptr); + lcd_default_light = constrain(lcd_value, 10, 100); - if (lcd_value > 100) lcd_value = 100; - else if (lcd_value < 10) lcd_value = 10; - - lcd_default_light = lcd_value; - - const uint16_t lcd_data[2] = {lcd_default_light, lcd_default_light}; + const uint16_t lcd_data[2] = { lcd_default_light, lcd_default_light }; dgusdisplay.WriteVariable(0x0082, &lcd_data, 5, true); } void DGUSScreenHandler::ManualAssistLeveling(DGUS_VP_Variable &var, void *val_ptr) { - int16_t point_value = swap16(*(uint16_t *)val_ptr); + const int16_t point_value = swap16(*(uint16_t *)val_ptr); int16_t level_x_pos, level_y_pos; char buf_level[32] = {0}; @@ -686,7 +682,7 @@ void DGUSScreenHandler::ManualAssistLeveling(DGUS_VP_Variable &var, void *val_pt #define mks_max(a, b) ((a) > (b)) ? (a) : (b) void DGUSScreenHandler::TMC_ChangeConfig(DGUS_VP_Variable &var, void *val_ptr) { #if EITHER(HAS_TRINAMIC_CONFIG, HAS_STEALTHCHOP) - uint16_t tmc_value = swap16(*(uint16_t*)val_ptr); + const uint16_t tmc_value = swap16(*(uint16_t*)val_ptr); #endif switch (var.VP) { @@ -930,7 +926,7 @@ void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { } void DGUSScreenHandler::GetParkPos_MKS(DGUS_VP_Variable &var, void *val_ptr) { - int16_t value_pos = swap16(*(int16_t*)val_ptr); + const int16_t value_pos = swap16(*(int16_t*)val_ptr); switch (var.VP) { case VP_X_PARK_POS: x_park_pos = value_pos; break; @@ -939,75 +935,76 @@ void DGUSScreenHandler::GetParkPos_MKS(DGUS_VP_Variable &var, void *val_ptr) { default: break; } skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel - return; } void DGUSScreenHandler::HandleChangeLevelPoint_MKS(DGUS_VP_Variable &var, void *val_ptr) { DEBUG_ECHOLNPGM("HandleStepPerMMChanged"); - int16_t value_raw = swap16(*(int16_t*)val_ptr); - - DEBUG_ECHOLNPAIR_F("value:", value_raw); + const int16_t value_raw = swap16(*(int16_t*)val_ptr); + DEBUG_ECHOLNPAIR_F("value_raw:", value_raw); *(int16_t*)var.memadr = value_raw; settings.save(); skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel - return; } void DGUSScreenHandler::HandleStepPerMMChanged_MKS(DGUS_VP_Variable &var, void *val_ptr) { DEBUG_ECHOLNPGM("HandleStepPerMMChanged"); - uint16_t value_raw = swap16(*(uint16_t*)val_ptr); + const uint16_t value_raw = swap16(*(uint16_t*)val_ptr); + const float value = (float)value_raw; DEBUG_ECHOLNPAIR("value_raw:", value_raw); - float value = (float)value_raw; + DEBUG_ECHOLNPAIR_F("value:", value); + ExtUI::axis_t axis; switch (var.VP) { + default: return; case VP_X_STEP_PER_MM: axis = ExtUI::axis_t::X; break; case VP_Y_STEP_PER_MM: axis = ExtUI::axis_t::Y; break; case VP_Z_STEP_PER_MM: axis = ExtUI::axis_t::Z; break; - default: return; } - DEBUG_ECHOLNPAIR_F("value:", value); ExtUI::setAxisSteps_per_mm(value, axis); DEBUG_ECHOLNPAIR_F("value_set:", ExtUI::getAxisSteps_per_mm(axis)); settings.save(); skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel - return; } void DGUSScreenHandler::HandleStepPerMMExtruderChanged_MKS(DGUS_VP_Variable &var, void *val_ptr) { DEBUG_ECHOLNPGM("HandleStepPerMMExtruderChanged"); - uint16_t value_raw = swap16(*(uint16_t*)val_ptr); + const uint16_t value_raw = swap16(*(uint16_t*)val_ptr); + const float value = (float)value_raw; + DEBUG_ECHOLNPAIR("value_raw:", value_raw); - float value = (float)value_raw; + DEBUG_ECHOLNPAIR_F("value:", value); + ExtUI::extruder_t extruder; switch (var.VP) { default: return; - #if HOTENDS >= 1 - case VP_E0_STEP_PER_MM: extruder = ExtUI::extruder_t::E0; break; - #endif - #if HOTENDS >= 2 - #endif - case VP_E1_STEP_PER_MM: extruder = ExtUI::extruder_t::E1; break; + #if HAS_HOTEND + case VP_E0_STEP_PER_MM: extruder = ExtUI::extruder_t::E0; break; + #endif + #if HAS_MULTI_HOTEND + case VP_E1_STEP_PER_MM: extruder = ExtUI::extruder_t::E1; break; + #endif } - DEBUG_ECHOLNPAIR_F("value:", value); ExtUI::setAxisSteps_per_mm(value, extruder); DEBUG_ECHOLNPAIR_F("value_set:", ExtUI::getAxisSteps_per_mm(extruder)); settings.save(); skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel - return; } void DGUSScreenHandler::HandleMaxSpeedChange_MKS(DGUS_VP_Variable &var, void *val_ptr) { DEBUG_ECHOLNPGM("HandleMaxSpeedChange_MKS"); - uint16_t value_raw = swap16(*(uint16_t*)val_ptr); + const uint16_t value_raw = swap16(*(uint16_t*)val_ptr); + const float value = (float)value_raw; + DEBUG_ECHOLNPAIR("value_raw:", value_raw); - float value = (float)value_raw; + DEBUG_ECHOLNPAIR_F("value:", value); + ExtUI::axis_t axis; switch (var.VP) { case VP_X_MAX_SPEED: axis = ExtUI::axis_t::X; break; @@ -1015,59 +1012,57 @@ void DGUSScreenHandler::HandleMaxSpeedChange_MKS(DGUS_VP_Variable &var, void *va case VP_Z_MAX_SPEED: axis = ExtUI::axis_t::Z; break; default: return; } - DEBUG_ECHOLNPAIR_F("value:", value); - // ExtUI::setAxisSteps_per_mm(value,extruder); ExtUI::setAxisMaxFeedrate_mm_s(value, axis); DEBUG_ECHOLNPAIR_F("value_set:", ExtUI::getAxisMaxFeedrate_mm_s(axis)); settings.save(); skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel - return; } void DGUSScreenHandler::HandleExtruderMaxSpeedChange_MKS(DGUS_VP_Variable &var, void *val_ptr) { DEBUG_ECHOLNPGM("HandleMaxSpeedChange_MKS"); - uint16_t value_raw = swap16(*(uint16_t*)val_ptr); + const uint16_t value_raw = swap16(*(uint16_t*)val_ptr); + const float value = (float)value_raw; + DEBUG_ECHOLNPAIR("value_raw:", value_raw); - float value = (float)value_raw; + DEBUG_ECHOLNPAIR_F("value:", value); + ExtUI::extruder_t extruder; switch (var.VP) { default: return; - #if HOTENDS >= 1 + #if HAS_HOTEND case VP_E0_MAX_SPEED: extruder = ExtUI::extruder_t::E0; break; #endif - #if HOTENDS >= 2 + #if HAS_MULTI_HOTEND #endif case VP_E1_MAX_SPEED: extruder = ExtUI::extruder_t::E1; break; } - DEBUG_ECHOLNPAIR_F("value:", value); - // ExtUI::setAxisSteps_per_mm(value,extruder); ExtUI::setAxisMaxFeedrate_mm_s(value, extruder); DEBUG_ECHOLNPAIR_F("value_set:", ExtUI::getAxisMaxFeedrate_mm_s(extruder)); settings.save(); skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel - return; } void DGUSScreenHandler::HandleMaxAccChange_MKS(DGUS_VP_Variable &var, void *val_ptr) { DEBUG_ECHOLNPGM("HandleMaxSpeedChange_MKS"); - uint16_t value_raw = swap16(*(uint16_t*)val_ptr); + const uint16_t value_raw = swap16(*(uint16_t*)val_ptr); + const float value = (float)value_raw; + DEBUG_ECHOLNPAIR("value_raw:", value_raw); - float value = (float)value_raw; + DEBUG_ECHOLNPAIR_F("value:", value); + ExtUI::axis_t axis; switch (var.VP) { + default: return; case VP_X_ACC_MAX_SPEED: axis = ExtUI::axis_t::X; break; case VP_Y_ACC_MAX_SPEED: axis = ExtUI::axis_t::Y; break; case VP_Z_ACC_MAX_SPEED: axis = ExtUI::axis_t::Z; break; - default: return; } - DEBUG_ECHOLNPAIR_F("value:", value); ExtUI::setAxisMaxAcceleration_mm_s2(value, axis); DEBUG_ECHOLNPAIR_F("value_set:", ExtUI::getAxisMaxAcceleration_mm_s2(axis)); settings.save(); skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel - return; } void DGUSScreenHandler::HandleExtruderAccChange_MKS(DGUS_VP_Variable &var, void *val_ptr) { @@ -1079,76 +1074,66 @@ void DGUSScreenHandler::HandleExtruderAccChange_MKS(DGUS_VP_Variable &var, void ExtUI::extruder_t extruder; switch (var.VP) { default: return; - #if HOTENDS >= 1 - case VP_E0_ACC_MAX_SPEED: extruder = ExtUI::extruder_t::E0; settings.load(); break; - #endif - #if HOTENDS >= 2 - #endif - case VP_E1_ACC_MAX_SPEED: extruder = ExtUI::extruder_t::E1; settings.load(); break; + #if HAS_HOTEND + case VP_E0_ACC_MAX_SPEED: extruder = ExtUI::extruder_t::E0; settings.load(); break; + #endif + #if HAS_MULTI_HOTEND + case VP_E1_ACC_MAX_SPEED: extruder = ExtUI::extruder_t::E1; settings.load(); break; + #endif } DEBUG_ECHOLNPAIR_F("value:", value); - // ExtUI::setAxisSteps_per_mm(value,extruder); ExtUI::setAxisMaxAcceleration_mm_s2(value, extruder); DEBUG_ECHOLNPAIR_F("value_set:", ExtUI::getAxisMaxAcceleration_mm_s2(extruder)); settings.save(); skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel - return; } void DGUSScreenHandler::HandleTravelAccChange_MKS(DGUS_VP_Variable &var, void *val_ptr) { uint16_t value_travel = swap16(*(uint16_t*)val_ptr); - float value = (float)value_travel; - planner.settings.travel_acceleration = value; + planner.settings.travel_acceleration = (float)value_travel; skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel - return; } void DGUSScreenHandler::HandleFeedRateMinChange_MKS(DGUS_VP_Variable &var, void *val_ptr) { uint16_t value_t = swap16(*(uint16_t*)val_ptr); - float value = (float)value_t; - planner.settings.min_feedrate_mm_s = value; + planner.settings.min_feedrate_mm_s = (float)value_t; skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel - return; } void DGUSScreenHandler::HandleMin_T_F_MKS(DGUS_VP_Variable &var, void *val_ptr) { uint16_t value_t_f = swap16(*(uint16_t*)val_ptr); - float value = (float)value_t_f; - planner.settings.min_travel_feedrate_mm_s = value; + planner.settings.min_travel_feedrate_mm_s = (float)value_t_f; skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel - return; } void DGUSScreenHandler::HandleAccChange_MKS(DGUS_VP_Variable &var, void *val_ptr) { uint16_t value_acc = swap16(*(uint16_t*)val_ptr); - float value = (float)value_acc; - planner.settings.acceleration = value; + planner.settings.acceleration = (float)value_acc; skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel - return; } void DGUSScreenHandler::HandleGetExMinTemp_MKS(DGUS_VP_Variable &var, void *val_ptr) { - uint16_t value_ex_min_temp = swap16(*(uint16_t*)val_ptr); + const uint16_t value_ex_min_temp = swap16(*(uint16_t*)val_ptr); thermalManager.extrude_min_temp = value_ex_min_temp; skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel } #if HAS_PID_HEATING void DGUSScreenHandler::HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr) { - uint16_t rawvalue = swap16(*(uint16_t*)val_ptr); + const uint16_t rawvalue = swap16(*(uint16_t*)val_ptr); DEBUG_ECHOLNPAIR("V1:", rawvalue); - float value = (float)rawvalue / 10; + const float value = 1.0f * rawvalue; DEBUG_ECHOLNPAIR("V2:", value); float newvalue = 0; switch (var.VP) { default: return; - #if HOTENDS >= 1 + #if HAS_HOTEND case VP_E0_PID_P: newvalue = value; break; case VP_E0_PID_I: newvalue = scalePID_i(value); break; case VP_E0_PID_D: newvalue = scalePID_d(value); break; #endif - #if HOTENDS >= 2 + #if HAS_MULTI_HOTEND case VP_E1_PID_P: newvalue = value; break; case VP_E1_PID_I: newvalue = scalePID_i(value); break; case VP_E1_PID_D: newvalue = scalePID_d(value); break; @@ -1224,7 +1209,6 @@ void DGUSScreenHandler::GetManualFilament(DGUS_VP_Variable &var, void *val_ptr) distanceFilament = value; skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel - return; } void DGUSScreenHandler::GetManualFilamentSpeed(DGUS_VP_Variable &var, void *val_ptr) { @@ -1237,134 +1221,62 @@ void DGUSScreenHandler::GetManualFilamentSpeed(DGUS_VP_Variable &var, void *val_ FilamentSpeed = value_len; skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel - return; } -void DGUSScreenHandler::MKS_FilamentLoad(DGUS_VP_Variable &var, void *val_ptr) { - DEBUG_ECHOLNPGM("Load Filament"); - char buf[40]; - - uint16_t val_t = swap16(*(uint16_t*)val_ptr); +void DGUSScreenHandler::MKS_FilamentLoadUnload(DGUS_VP_Variable &var, void *val_ptr, const int filamentDir) { + #if EITHER(HAS_MULTI_HOTEND, SINGLENOZZLE) + uint8_t swap_tool = 0; + #endif + #if HAS_HOTEND + uint8_t hotend_too_cold = 0; + #endif + char buf[40]; + const uint16_t val_t = swap16(*(uint16_t*)val_ptr); switch (val_t) { + default: break; case 0: - #if HOTENDS >= 1 - if (thermalManager.degHotend(0) < thermalManager.extrude_min_temp) { - if (thermalManager.degTargetHotend(0) < thermalManager.extrude_min_temp) - thermalManager.setTargetHotend(thermalManager.extrude_min_temp, 0); - sendinfoscreen(PSTR("NOTICE"), nullptr, PSTR("Please wait."), PSTR("Nozzle heating!"), true, true, true, true); - SetupConfirmAction(nullptr); - GotoScreen(DGUSLCD_SCREEN_POPUP); - } - else { - queue.enqueue_now_P(PSTR("T0")); - queue.enqueue_now_P(PSTR("G91")); - snprintf_P(buf,40,PSTR("G1 E%d F%d"),(int)distanceFilament,FilamentSpeed * 60); - queue.enqueue_one_now(buf); - queue.enqueue_now_P(PSTR("G90")); - } + #if HAS_HOTEND + if (thermalManager.tooColdToExtrude(0)) hotend_too_cold = 1; else swap_tool = 1; #endif break; - case 1: - #if HOTENDS >= 2 - if (thermalManager.degHotend(1) < thermalManager.extrude_min_temp) { - if (thermalManager.degTargetHotend(1) < thermalManager.extrude_min_temp) - thermalManager.setTargetHotend(thermalManager.extrude_min_temp, 1); - sendinfoscreen(PSTR("NOTICE"), nullptr, PSTR("Please wait."), PSTR("Nozzle heating!"), true, true, true, true); - SetupConfirmAction(nullptr); - GotoScreen(DGUSLCD_SCREEN_POPUP); - } - else { - queue.enqueue_now_P(PSTR("T1")); - queue.enqueue_now_P(PSTR("G91")); - snprintf_P(buf,40,PSTR("G1 E%d F%d"),(int)distanceFilament,FilamentSpeed * 60); - queue.enqueue_one_now(buf); - queue.enqueue_now_P(PSTR("G90")); - } - #endif - #if ENABLED(SINGLENOZZLE) - if (thermalManager.degHotend(0) < thermalManager.extrude_min_temp) { - if (thermalManager.degTargetHotend(0) < thermalManager.extrude_min_temp) - thermalManager.setTargetHotend(thermalManager.extrude_min_temp, 0); - sendinfoscreen(PSTR("NOTICE"), nullptr, PSTR("Please wait."), PSTR("Nozzle heating!"), true, true, true, true); - SetupConfirmAction(nullptr); - GotoScreen(DGUSLCD_SCREEN_POPUP); - } - else { - queue.enqueue_now_P(PSTR("T1")); - queue.enqueue_now_P(PSTR("G91")); - snprintf_P(buf,40,PSTR("G1 E%d F%d"),(int)distanceFilament,FilamentSpeed * 60); - queue.enqueue_one_now(buf); - queue.enqueue_now_P(PSTR("G90")); - } + #if HAS_MULTI_HOTEND + if (thermalManager.tooColdToExtrude(1)) hotend_too_cold = 2; else swap_tool = 2; + #elif ENABLED(SINGLENOZZLE) + if (thermalManager.tooColdToExtrude(0)) hotend_too_cold = 1; else swap_tool = 2; #endif break; - - default: - break; } + + #if HAS_HOTEND + if (hotend_too_cold) { + if (thermalManager.targetTooColdToExtrude(hotend_too_cold - 1)) thermalManager.setTargetHotend(thermalManager.extrude_min_temp, hotend_too_cold - 1); + sendinfoscreen(PSTR("NOTICE"), nullptr, PSTR("Please wait."), PSTR("Nozzle heating!"), true, true, true, true); + SetupConfirmAction(nullptr); + GotoScreen(DGUSLCD_SCREEN_POPUP); + } + #endif + + #if EITHER(HAS_MULTI_HOTEND, SINGLENOZZLE) + if (swap_tool) { + queue.enqueue_now_P(swap_tool == 2 ? PSTR("T1") : PSTR("T0")); + queue.enqueue_now_P(PSTR("G91")); + snprintf_P(buf, 40, PSTR("G1 E%d F%d"), (int)distanceFilament * filamentDir, FilamentSpeed * 60); + queue.enqueue_one_now(buf); + queue.enqueue_now_P(PSTR("G90")); + } + #endif +} + +void DGUSScreenHandler::MKS_FilamentLoad(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("Load Filament"); + MKS_FilamentLoadUnload(var, val_ptr, 1); } void DGUSScreenHandler::MKS_FilamentUnLoad(DGUS_VP_Variable &var, void *val_ptr) { DEBUG_ECHOLNPGM("UnLoad Filament"); - char buf[40]; - uint16_t val_t = swap16(*(uint16_t*)val_ptr); - switch (val_t) { - case 0: - #if HOTENDS >= 1 - if (thermalManager.degHotend(0) < thermalManager.extrude_min_temp) { - if (thermalManager.degTargetHotend(0) < thermalManager.extrude_min_temp) - thermalManager.setTargetHotend(thermalManager.extrude_min_temp, 0); - sendinfoscreen(PSTR("NOTICE"), nullptr, PSTR("Please wait."), PSTR("Nozzle heating!"), true, true, true, true); - SetupConfirmAction(nullptr); - GotoScreen(DGUSLCD_SCREEN_POPUP); - } - else { - queue.enqueue_now_P(PSTR("T0")); - queue.enqueue_now_P(PSTR("G91")); - snprintf_P(buf,40,PSTR("G1 E-%d F%d"),(int)distanceFilament,FilamentSpeed * 60); - queue.enqueue_one_now(buf); - queue.enqueue_now_P(PSTR("G90")); - } - #endif - break; - case 1: - #if HOTENDS >= 2 - if (thermalManager.degHotend(1) < thermalManager.extrude_min_temp) { - if (thermalManager.degTargetHotend(1) < thermalManager.extrude_min_temp) - thermalManager.setTargetHotend(thermalManager.extrude_min_temp, 1); - sendinfoscreen(PSTR("NOTICE"), nullptr, PSTR("Please wait."), PSTR("Nozzle heating!"), true, true, true, true); - SetupConfirmAction(nullptr); - GotoScreen(DGUSLCD_SCREEN_POPUP); - } - else { - queue.enqueue_now_P(PSTR("T1")); - queue.enqueue_now_P(PSTR("G91")); - snprintf_P(buf,40,PSTR("G1 E-%d F%d"),(int)distanceFilament,FilamentSpeed * 60); - queue.enqueue_one_now(buf); - queue.enqueue_now_P(PSTR("G90")); - } - #endif - - #if ENABLED(SINGLENOZZLE) - if (thermalManager.degHotend(0) < thermalManager.extrude_min_temp) { - if (thermalManager.degTargetHotend(0) < thermalManager.extrude_min_temp) - thermalManager.setTargetHotend(thermalManager.extrude_min_temp, 0); - sendinfoscreen(PSTR("NOTICE"), nullptr, PSTR("Please wait."), PSTR("Nozzle heating!"), true, true, true, true); - SetupConfirmAction(nullptr); - GotoScreen(DGUSLCD_SCREEN_POPUP); - } - else { - queue.enqueue_now_P(PSTR("T1")); - queue.enqueue_now_P(PSTR("G91")); - snprintf_P(buf,40,PSTR("G1 E-%d F%d"),(int)distanceFilament,FilamentSpeed * 60); - queue.enqueue_one_now(buf); - queue.enqueue_now_P(PSTR("G90")); - } - #endif - break; - } + MKS_FilamentLoadUnload(var, val_ptr, -1); } #if ENABLED(DGUS_FILAMENT_LOADUNLOAD) @@ -1375,17 +1287,15 @@ void DGUSScreenHandler::MKS_FilamentUnLoad(DGUS_VP_Variable &var, void *val_ptr) uint8_t e_temp = 0; filament_data.heated = false; uint16_t preheat_option = swap16(*(uint16_t*)val_ptr); - if (preheat_option <= 8) { // Load filament type - filament_data.action = 1; - } - else if (preheat_option >= 10) { // Unload filament type + if (preheat_option >= 10) { // Unload filament type preheat_option -= 10; filament_data.action = 2; filament_data.purge_length = DGUS_FILAMENT_PURGE_LENGTH; } - else { // Cancel filament operation + else if (preheat_option <= 8) // Load filament type + filament_data.action = 1; + else // Cancel filament operation filament_data.action = 0; - } switch (preheat_option) { case 0: // Load PLA @@ -1413,10 +1323,10 @@ void DGUSScreenHandler::MKS_FilamentUnLoad(DGUS_VP_Variable &var, void *val_ptr) } if (filament_data.action == 0) { // Go back to utility screen - #if HOTENDS >= 1 + #if HAS_HOTEND thermalManager.setTargetHotend(e_temp, ExtUI::extruder_t::E0); #endif - #if HOTENDS >= 2 + #if HAS_MULTI_HOTEND thermalManager.setTargetHotend(e_temp, ExtUI::extruder_t::E1); #endif GotoScreen(DGUSLCD_SCREEN_UTILITY); @@ -1424,13 +1334,13 @@ void DGUSScreenHandler::MKS_FilamentUnLoad(DGUS_VP_Variable &var, void *val_ptr) else { // Go to the preheat screen to show the heating progress switch (var.VP) { default: return; - #if HOTENDS >= 1 + #if HAS_HOTEND case VP_E0_FILAMENT_LOAD_UNLOAD: filament_data.extruder = ExtUI::extruder_t::E0; thermalManager.setTargetHotend(e_temp, filament_data.extruder); break; #endif - #if HOTENDS >= 2 + #if HAS_MULTI_HOTEND case VP_E1_FILAMENT_LOAD_UNLOAD: filament_data.extruder = ExtUI::extruder_t::E1; thermalManager.setTargetHotend(e_temp, filament_data.extruder); @@ -1472,6 +1382,7 @@ void DGUSScreenHandler::MKS_FilamentUnLoad(DGUS_VP_Variable &var, void *val_ptr) ExtUI::setAxisPosition_mm(movevalue, filament_data.extruder); } } + #endif // DGUS_FILAMENT_LOADUNLOAD bool DGUSScreenHandler::loop() { diff --git a/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.h b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.h index 15e232e413b50..bfec3c4572476 100644 --- a/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.h +++ b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.h @@ -149,6 +149,7 @@ class DGUSScreenHandler { // Hook for filament load and unload static void HandleFilamentLoadUnload(DGUS_VP_Variable &var); + static void MKS_FilamentLoadUnload(DGUS_VP_Variable &var, void *val_ptr, const int filamentDir); static void MKS_FilamentLoad(DGUS_VP_Variable &var, void *val_ptr); static void MKS_FilamentUnLoad(DGUS_VP_Variable &var, void *val_ptr); static void MKS_LOAD_UNLOAD_IDLE(); diff --git a/Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.cpp b/Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.cpp index 8d89de3e335d4..e232bf9b969d3 100644 --- a/Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.cpp +++ b/Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.cpp @@ -216,7 +216,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { #endif #endif #if HOTENDS >= 2 - VPHELPER(VP_T_E1_Is, &thermalManager.temp_hotend[1].celsius, nullptr, DGUSLCD_SendFloatAsLongValueToDisplay<0>), + VPHELPER(VP_T_E1_Is, &thermalManager.temp_hotend[1].celsius, nullptr, DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_T_E1_Set, &thermalManager.temp_hotend[1].target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_Flowrate_E1, nullptr, ScreenHandler.HandleFlowRateChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_MOVE_E1, nullptr, &ScreenHandler.HandleManualExtrude, nullptr), @@ -227,7 +227,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { #endif #endif #if HAS_HEATED_BED - VPHELPER(VP_T_Bed_Is, &thermalManager.temp_bed.celsius, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<0>), + VPHELPER(VP_T_Bed_Is, &thermalManager.temp_bed.celsius, nullptr, ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_T_Bed_Set, &thermalManager.temp_bed.target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), VPHELPER(VP_BED_CONTROL, &thermalManager.temp_bed.target, &ScreenHandler.HandleHeaterControl, nullptr), VPHELPER(VP_BED_STATUS, &thermalManager.temp_bed.target, nullptr, &ScreenHandler.DGUSLCD_SendHeaterStatusToDisplay), diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp index 5d02f79fd1fb9..3fed4cc385330 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp @@ -514,13 +514,13 @@ void filament_dialog_handle() { queue.inject(public_buf_m); } - if ( ((abs((int)((int)thermalManager.degHotend(uiCfg.extruderIndex) - gCfgItems.filament_limit_temper)) <= 1) - || ((int)thermalManager.degHotend(uiCfg.extruderIndex) > gCfgItems.filament_limit_temper)) - && uiCfg.filament_load_heat_flg - ) { - uiCfg.filament_load_heat_flg = false; - lv_clear_dialog(); - lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED); + if (uiCfg.filament_load_heat_flg) { + const celsius_t diff = thermalManager.degHotend(uiCfg.extruderIndex) - gCfgItems.filament_limit_temp; + if (abs(diff) < 2 || diff > 0) { + uiCfg.filament_load_heat_flg = false; + lv_clear_dialog(); + lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED); + } } if (uiCfg.filament_loading_completed) { @@ -529,13 +529,14 @@ void filament_dialog_handle() { lv_clear_dialog(); lv_draw_dialog(DIALOG_TYPE_FILAMENT_LOAD_COMPLETED); } - if (((abs((int)((int)thermalManager.degHotend(uiCfg.extruderIndex) - gCfgItems.filament_limit_temper)) <= 1) - || ((int)thermalManager.degHotend(uiCfg.extruderIndex) > gCfgItems.filament_limit_temper)) - && uiCfg.filament_unload_heat_flg - ) { - uiCfg.filament_unload_heat_flg = false; - lv_clear_dialog(); - lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED); + + if (uiCfg.filament_unload_heat_flg) { + const celsius_t diff = thermalManager.degHotend(uiCfg.extruderIndex) - gCfgItems.filament_limit_temp; + if (abs(diff) < 2 || diff > 0) { + uiCfg.filament_unload_heat_flg = false; + lv_clear_dialog(); + lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED); + } } if (uiCfg.filament_unloading_completed) { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_change.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_change.cpp index e12a4b82cf28b..56a776c79e30e 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_change.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_change.cpp @@ -51,15 +51,15 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { case ID_FILAMNT_IN: uiCfg.filament_load_heat_flg = true; if ((abs(thermalManager.degTargetHotend(uiCfg.extruderIndex) - thermalManager.degHotend(uiCfg.extruderIndex)) <= 1) - || (gCfgItems.filament_limit_temper <= thermalManager.degHotend(uiCfg.extruderIndex))) { + || (gCfgItems.filament_limit_temp <= thermalManager.degHotend(uiCfg.extruderIndex))) { lv_clear_filament_change(); lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED); } else { lv_clear_filament_change(); lv_draw_dialog(DIALOG_TYPE_FILAMENT_LOAD_HEAT); - if (thermalManager.degTargetHotend(uiCfg.extruderIndex) < gCfgItems.filament_limit_temper) { - thermalManager.setTargetHotend(gCfgItems.filament_limit_temper, uiCfg.extruderIndex); + if (thermalManager.degTargetHotend(uiCfg.extruderIndex) < gCfgItems.filament_limit_temp) { + thermalManager.setTargetHotend(gCfgItems.filament_limit_temp, uiCfg.extruderIndex); thermalManager.start_watching_hotend(uiCfg.extruderIndex); } } @@ -68,7 +68,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { uiCfg.filament_unload_heat_flg = true; if (thermalManager.degTargetHotend(uiCfg.extruderIndex) && ((abs((int)((int)thermalManager.degTargetHotend(uiCfg.extruderIndex) - thermalManager.degHotend(uiCfg.extruderIndex))) <= 1) - || ((int)thermalManager.degHotend(uiCfg.extruderIndex) >= gCfgItems.filament_limit_temper)) + || ((int)thermalManager.degHotend(uiCfg.extruderIndex) >= gCfgItems.filament_limit_temp)) ) { lv_clear_filament_change(); lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED); @@ -76,8 +76,8 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { else { lv_clear_filament_change(); lv_draw_dialog(DIALOG_TYPE_FILAMENT_UNLOAD_HEAT); - if (thermalManager.degTargetHotend(uiCfg.extruderIndex) < gCfgItems.filament_limit_temper) { - thermalManager.setTargetHotend(gCfgItems.filament_limit_temper, uiCfg.extruderIndex); + if (thermalManager.degTargetHotend(uiCfg.extruderIndex) < gCfgItems.filament_limit_temp) { + thermalManager.setTargetHotend(gCfgItems.filament_limit_temp, uiCfg.extruderIndex); thermalManager.start_watching_hotend(uiCfg.extruderIndex); } filament_sprayer_temp(); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_settings.cpp index 128989a27cff2..553cb29895e0c 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_settings.cpp @@ -107,7 +107,7 @@ void lv_draw_filament_settings() { lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.next, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_FILAMENT_SET_DOWN, true); } else { - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filament_limit_temper); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filament_limit_temp); lv_screen_menu_item_1_edit(scr, machine_menu.FilamentTemperature, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_FILAMENT_SET_TEMP, 0, public_buf_l); lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.previous, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_FILAMENT_SET_UP, true); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_number_key.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_number_key.cpp index d001175915f1c..91a1fce28d225 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_number_key.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_number_key.cpp @@ -261,7 +261,7 @@ static void disp_key_value() { sprintf_P(public_buf_m, PSTR("%d"), gCfgItems.filamentchange_unload_speed); break; case filament_temp: - sprintf_P(public_buf_m, PSTR("%d"), gCfgItems.filament_limit_temper); + sprintf_P(public_buf_m, PSTR("%d"), gCfgItems.filament_limit_temp); break; case x_sensitivity: #if X_SENSORLESS @@ -505,7 +505,7 @@ static void set_value_confirm() { update_spi_flash(); break; case filament_temp: - gCfgItems.filament_limit_temper = atoi(key_value); + gCfgItems.filament_limit_temp = atoi(key_value); update_spi_flash(); break; case x_sensitivity: diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp index 9b7fea0a45e1b..d96e23461c9fa 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp @@ -143,7 +143,7 @@ void gCfgItems_init() { gCfgItems.filamentchange_load_speed = 1000; gCfgItems.filamentchange_unload_length = 200; gCfgItems.filamentchange_unload_speed = 1000; - gCfgItems.filament_limit_temper = 200; + gCfgItems.filament_limit_temp = 200; gCfgItems.encoder_enable = true; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h index 4b0ce2b4d810e..3098a6666cf5a 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h @@ -184,29 +184,27 @@ extern char public_buf_m[100]; extern char public_buf_l[30]; typedef struct { - uint32_t spi_flash_flag; - uint8_t disp_rotation_180; - bool multiple_language; - uint8_t language; - uint8_t leveling_mode; - bool from_flash_pic; - bool finish_power_off; - bool pause_reprint; - uint8_t wifi_mode_sel; - uint8_t fileSysType; - uint8_t wifi_type; - bool cloud_enable, - encoder_enable; - int levelingPos[5][2]; - int filamentchange_load_length, - filamentchange_load_speed, - filamentchange_unload_length, - filamentchange_unload_speed, - filament_limit_temper; - float pausePosX, - pausePosY, - pausePosZ; - uint32_t curFilesize; + uint32_t spi_flash_flag; + uint8_t disp_rotation_180; + bool multiple_language; + uint8_t language; + uint8_t leveling_mode; + bool from_flash_pic; + bool finish_power_off; + bool pause_reprint; + uint8_t wifi_mode_sel; + uint8_t fileSysType; + uint8_t wifi_type; + bool cloud_enable, + encoder_enable; + int levelingPos[5][2]; + int filamentchange_load_length, + filamentchange_load_speed, + filamentchange_unload_length, + filamentchange_unload_speed; + celsius_t filament_limit_temp; + float pausePosX, pausePosY, pausePosZ; + uint32_t curFilesize; } CFG_ITMES; typedef struct { @@ -246,7 +244,7 @@ typedef struct { filament_loading_time_cnt, filament_unloading_time_cnt; float move_dist; - float hotendTargetTempBak; + celsius_t hotendTargetTempBak; float current_x_position_bak, current_y_position_bak, current_z_position_bak, diff --git a/Marlin/src/lcd/extui/ui_api.cpp b/Marlin/src/lcd/extui/ui_api.cpp index 73e5bc092d459..ea7b6a12caec8 100644 --- a/Marlin/src/lcd/extui/ui_api.cpp +++ b/Marlin/src/lcd/extui/ui_api.cpp @@ -904,7 +904,7 @@ namespace ExtUI { enableHeater(heater); switch (heater) { #if HAS_HEATED_CHAMBER - case CHAMBER: thermalManager.setTargetChamber(LROUND(constrain(value, 0, CHAMBER_MAXTEMP - 10))); break; + case CHAMBER: thermalManager.setTargetChamber(LROUND(constrain(value, 0, CHAMBER_MAX_TARGET))); break; #endif #if HAS_COOLER case COOLER: thermalManager.setTargetCooler(LROUND(constrain(value, 0, COOLER_MAXTEMP))); break; @@ -915,7 +915,7 @@ namespace ExtUI { default: { #if HAS_HOTEND const int16_t e = heater - H0; - thermalManager.setTargetHotend(LROUND(constrain(value, 0, thermalManager.heater_maxtemp[e] - HOTEND_OVERSHOOT)), e); + thermalManager.setTargetHotend(LROUND(constrain(value, 0, thermalManager.hotend_max_target(e))), e); #endif } break; } @@ -929,7 +929,7 @@ namespace ExtUI { #if HAS_HOTEND const int16_t e = extruder - E0; enableHeater(extruder); - thermalManager.setTargetHotend(LROUND(constrain(value, 0, thermalManager.heater_maxtemp[e] - HOTEND_OVERSHOOT)), e); + thermalManager.setTargetHotend(LROUND(constrain(value, 0, thermalManager.hotend_max_target(e))), e); #endif } diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index 1c9e80c75e8e2..6f5703e6225fb 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -110,9 +110,9 @@ #if PREHEAT_COUNT typedef struct { - TERN_(HAS_HOTEND, uint16_t hotend_temp); - TERN_(HAS_HEATED_BED, uint16_t bed_temp ); - TERN_(HAS_FAN, uint16_t fan_speed ); + TERN_(HAS_HOTEND, celsius_t hotend_temp); + TERN_(HAS_HEATED_BED, celsius_t bed_temp ); + TERN_(HAS_FAN, uint16_t fan_speed ); } preheat_t; #endif diff --git a/Marlin/src/lcd/menu/menu_advanced.cpp b/Marlin/src/lcd/menu/menu_advanced.cpp index aab93c3bdda53..463433685ecf4 100644 --- a/Marlin/src/lcd/menu/menu_advanced.cpp +++ b/Marlin/src/lcd/menu/menu_advanced.cpp @@ -261,8 +261,8 @@ void menu_backlash(); // #if BOTH(AUTOTEMP, HAS_TEMP_HOTEND) EDIT_ITEM(bool, MSG_AUTOTEMP, &planner.autotemp_enabled); - EDIT_ITEM(float3, MSG_MIN, &planner.autotemp_min, 0, float(HEATER_0_MAXTEMP) - HOTEND_OVERSHOOT); - EDIT_ITEM(float3, MSG_MAX, &planner.autotemp_max, 0, float(HEATER_0_MAXTEMP) - HOTEND_OVERSHOOT); + EDIT_ITEM(int3, MSG_MIN, &planner.autotemp_min, 0, thermalManager.hotend_max_target(0)); + EDIT_ITEM(int3, MSG_MAX, &planner.autotemp_max, 0, thermalManager.hotend_max_target(0)); EDIT_ITEM(float42_52, MSG_FACTOR, &planner.autotemp_factor, 0, 10); #endif @@ -315,7 +315,7 @@ void menu_backlash(); #if ENABLED(PID_AUTOTUNE_MENU) #define HOTEND_PID_EDIT_MENU_ITEMS(N) \ _HOTEND_PID_EDIT_MENU_ITEMS(N); \ - EDIT_ITEM_FAST_N(int3, N, MSG_PID_AUTOTUNE_E, &autotune_temp[N], 150, thermalManager.heater_maxtemp[N] - HOTEND_OVERSHOOT, []{ _lcd_autotune(heater_id_t(MenuItemBase::itemIndex)); }); + EDIT_ITEM_FAST_N(int3, N, MSG_PID_AUTOTUNE_E, &autotune_temp[N], 150, thermalManager.hotend_max_target(N), []{ _lcd_autotune(heater_id_t(MenuItemBase::itemIndex)); }); #else #define HOTEND_PID_EDIT_MENU_ITEMS(N) _HOTEND_PID_EDIT_MENU_ITEMS(N); #endif diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index 179a2c2d558c6..df67e8f9edbfb 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -325,10 +325,10 @@ void menu_advanced_settings(); EDIT_ITEM_N(percent, m, MSG_FAN_SPEED, &editable.uint8, 0, 255, []{ ui.material_preset[MenuItemBase::itemIndex].fan_speed = editable.uint8; }); #endif #if HAS_TEMP_HOTEND - EDIT_ITEM(uint16_3, MSG_NOZZLE, &ui.material_preset[m].hotend_temp, MINTEMP_ALL, MAXTEMP_ALL - HOTEND_OVERSHOOT); + EDIT_ITEM(int3, MSG_NOZZLE, &ui.material_preset[m].hotend_temp, MINTEMP_ALL, MAXTEMP_ALL - (HOTEND_OVERSHOOT)); #endif #if HAS_HEATED_BED - EDIT_ITEM(uint16_3, MSG_BED, &ui.material_preset[m].bed_temp, BED_MINTEMP, BED_MAX_TARGET); + EDIT_ITEM(int3, MSG_BED, &ui.material_preset[m].bed_temp, BED_MINTEMP, BED_MAX_TARGET); #endif #if ENABLED(EEPROM_SETTINGS) ACTION_ITEM(MSG_STORE_EEPROM, ui.store_settings); diff --git a/Marlin/src/lcd/menu/menu_filament.cpp b/Marlin/src/lcd/menu/menu_filament.cpp index 19601d678e050..8df2af1dd085a 100644 --- a/Marlin/src/lcd/menu/menu_filament.cpp +++ b/Marlin/src/lcd/menu/menu_filament.cpp @@ -95,7 +95,7 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) { ACTION_ITEM_N_S(m, ui.get_preheat_label(m), MSG_PREHEAT_M, _change_filament_with_preset); #endif EDIT_ITEM_FAST_N(int3, extruder, MSG_PREHEAT_CUSTOM, &thermalManager.temp_hotend[extruder].target, - EXTRUDE_MINTEMP, thermalManager.heater_maxtemp[extruder] - HOTEND_OVERSHOOT, + EXTRUDE_MINTEMP, thermalManager.hotend_max_target(extruder), _change_filament_with_custom ); END_MENU(); diff --git a/Marlin/src/lcd/menu/menu_item.h b/Marlin/src/lcd/menu/menu_item.h index 6873f209b4805..945a892799184 100644 --- a/Marlin/src/lcd/menu/menu_item.h +++ b/Marlin/src/lcd/menu/menu_item.h @@ -473,7 +473,7 @@ class MenuItem_bool : public MenuEditItemBase { #define _FAN_EDIT_ITEMS(F,L) do{ \ editable.uint8 = thermalManager.fan_speed[F]; \ EDIT_ITEM_FAST_N(percent, F, MSG_##L, &editable.uint8, 0, 255, on_fan_update); \ - EDIT_EXTRA_FAN_SPEED(percent, F, MSG_EXTRA_##L, &thermalManager.new_fan_speed[F], 3, 255); \ + EDIT_EXTRA_FAN_SPEED(percent, F, MSG_EXTRA_##L, &thermalManager.extra_fan_speed[F].speed, 3, 255); \ }while(0) #if FAN_COUNT > 1 diff --git a/Marlin/src/lcd/menu/menu_temperature.cpp b/Marlin/src/lcd/menu/menu_temperature.cpp index 3a9906ddeb5b9..e040f2f412480 100644 --- a/Marlin/src/lcd/menu/menu_temperature.cpp +++ b/Marlin/src/lcd/menu/menu_temperature.cpp @@ -47,11 +47,11 @@ // "Temperature" submenu items // -void Temperature::lcd_preheat(const int16_t e, const int8_t indh, const int8_t indb) { +void Temperature::lcd_preheat(const uint8_t e, const int8_t indh, const int8_t indb) { UNUSED(e); UNUSED(indh); UNUSED(indb); #if HAS_HOTEND if (indh >= 0 && ui.material_preset[indh].hotend_temp > 0) - setTargetHotend(_MIN(thermalManager.heater_maxtemp[e] - HOTEND_OVERSHOOT, ui.material_preset[indh].hotend_temp), e); + setTargetHotend(_MIN(thermalManager.hotend_max_target(e), ui.material_preset[indh].hotend_temp), e); #endif #if HAS_HEATED_BED if (indb >= 0 && ui.material_preset[indb].bed_temp > 0) setTargetBed(ui.material_preset[indb].bed_temp); @@ -70,7 +70,7 @@ void Temperature::lcd_preheat(const int16_t e, const int8_t indh, const int8_t i void do_preheat_end_m() { _preheat_end(editable.int8, 0); } #endif #if HAS_HEATED_BED - inline void _preheat_bed(const uint8_t m) { thermalManager.lcd_preheat(-1, -1, m); } + inline void _preheat_bed(const uint8_t m) { thermalManager.lcd_preheat(0, -1, m); } #endif #if HAS_COOLER inline void _precool_laser(const uint8_t m, const uint8_t e) { thermalManager.lcd_preheat(e, m, -1); } @@ -163,15 +163,15 @@ void menu_temperature() { // Nozzle [1-5]: // #if HOTENDS == 1 - EDIT_ITEM_FAST(int3, MSG_NOZZLE, &thermalManager.temp_hotend[0].target, 0, HEATER_0_MAXTEMP - (HOTEND_OVERSHOOT), []{ thermalManager.start_watching_hotend(0); }); + EDIT_ITEM_FAST(int3, MSG_NOZZLE, &thermalManager.temp_hotend[0].target, 0, thermalManager.hotend_max_target(0), []{ thermalManager.start_watching_hotend(0); }); #elif HAS_MULTI_HOTEND HOTEND_LOOP() - EDIT_ITEM_FAST_N(int3, e, MSG_NOZZLE_N, &thermalManager.temp_hotend[e].target, 0, thermalManager.heater_maxtemp[e] - (HOTEND_OVERSHOOT), []{ thermalManager.start_watching_hotend(MenuItemBase::itemIndex); }); + EDIT_ITEM_FAST_N(int3, e, MSG_NOZZLE_N, &thermalManager.temp_hotend[e].target, 0, thermalManager.hotend_max_target(e), []{ thermalManager.start_watching_hotend(MenuItemBase::itemIndex); }); #endif #if ENABLED(SINGLENOZZLE_STANDBY_TEMP) LOOP_S_L_N(e, 1, EXTRUDERS) - EDIT_ITEM_FAST_N(uint16_3, e, MSG_NOZZLE_STANDBY, &thermalManager.singlenozzle_temp[e], 0, thermalManager.heater_maxtemp[0] - (HOTEND_OVERSHOOT)); + EDIT_ITEM_FAST_N(uint16_3, e, MSG_NOZZLE_STANDBY, &thermalManager.singlenozzle_temp[e], 0, thermalManager.hotend_max_target(0)); #endif // @@ -185,7 +185,7 @@ void menu_temperature() { // Chamber: // #if HAS_HEATED_CHAMBER - EDIT_ITEM_FAST(int3, MSG_CHAMBER, &thermalManager.temp_chamber.target, 0, CHAMBER_MAXTEMP - 10, thermalManager.start_watching_chamber); + EDIT_ITEM_FAST(int3, MSG_CHAMBER, &thermalManager.temp_chamber.target, 0, CHAMBER_MAX_TARGET, thermalManager.start_watching_chamber); #endif // @@ -194,7 +194,7 @@ void menu_temperature() { #if HAS_COOLER editable.state = cooler.is_enabled(); EDIT_ITEM(bool, MSG_COOLER(TOGGLE), &cooler.state, []{ if (editable.state) cooler.disable(); else cooler.enable(); }); - EDIT_ITEM_FAST(int3, MSG_COOLER, &thermalManager.temp_cooler.target, COOLER_MINTEMP + 2, COOLER_MAXTEMP - 2, thermalManager.start_watching_cooler); + EDIT_ITEM_FAST(int3, MSG_COOLER, &thermalManager.temp_cooler.target, COOLER_MINTEMP + 2, COOLER_MAXTEMP, thermalManager.start_watching_cooler); #endif // diff --git a/Marlin/src/lcd/menu/menu_tune.cpp b/Marlin/src/lcd/menu/menu_tune.cpp index 0fbb57f2ac171..feabae437dace 100644 --- a/Marlin/src/lcd/menu/menu_tune.cpp +++ b/Marlin/src/lcd/menu/menu_tune.cpp @@ -126,15 +126,15 @@ void menu_tune() { // Nozzle [1-4]: // #if HOTENDS == 1 - EDIT_ITEM_FAST(int3, MSG_NOZZLE, &thermalManager.temp_hotend[0].target, 0, HEATER_0_MAXTEMP - HOTEND_OVERSHOOT, []{ thermalManager.start_watching_hotend(0); }); + EDIT_ITEM_FAST(int3, MSG_NOZZLE, &thermalManager.temp_hotend[0].target, 0, thermalManager.hotend_max_target(0), []{ thermalManager.start_watching_hotend(0); }); #elif HAS_MULTI_HOTEND HOTEND_LOOP() - EDIT_ITEM_FAST_N(int3, e, MSG_NOZZLE_N, &thermalManager.temp_hotend[e].target, 0, thermalManager.heater_maxtemp[e] - HOTEND_OVERSHOOT, []{ thermalManager.start_watching_hotend(MenuItemBase::itemIndex); }); + EDIT_ITEM_FAST_N(int3, e, MSG_NOZZLE_N, &thermalManager.temp_hotend[e].target, 0, thermalManager.hotend_max_target(e), []{ thermalManager.start_watching_hotend(MenuItemBase::itemIndex); }); #endif #if ENABLED(SINGLENOZZLE_STANDBY_TEMP) LOOP_S_L_N(e, 1, EXTRUDERS) - EDIT_ITEM_FAST_N(uint16_3, e, MSG_NOZZLE_STANDBY, &thermalManager.singlenozzle_temp[e], 0, thermalManager.heater_maxtemp[0] - HOTEND_OVERSHOOT); + EDIT_ITEM_FAST_N(uint16_3, e, MSG_NOZZLE_STANDBY, &thermalManager.singlenozzle_temp[e], 0, thermalManager.hotend_max_target(0)); #endif // diff --git a/Marlin/src/lcd/menu/menu_ubl.cpp b/Marlin/src/lcd/menu/menu_ubl.cpp index 79bedb9ea522e..6c6076cf7467b 100644 --- a/Marlin/src/lcd/menu/menu_ubl.cpp +++ b/Marlin/src/lcd/menu/menu_ubl.cpp @@ -126,7 +126,7 @@ void _lcd_ubl_custom_mesh() { START_MENU(); BACK_ITEM(MSG_UBL_BUILD_MESH_MENU); #if HAS_HOTEND - EDIT_ITEM(int3, MSG_UBL_HOTEND_TEMP_CUSTOM, &custom_hotend_temp, EXTRUDE_MINTEMP, HEATER_0_MAXTEMP - HOTEND_OVERSHOOT); + EDIT_ITEM(int3, MSG_UBL_HOTEND_TEMP_CUSTOM, &custom_hotend_temp, EXTRUDE_MINTEMP, thermalManager.hotend_max_target(0)); #endif #if HAS_HEATED_BED EDIT_ITEM(int3, MSG_UBL_BED_TEMP_CUSTOM, &custom_bed_temp, BED_MINTEMP, BED_MAX_TARGET); diff --git a/Marlin/src/lcd/tft/touch.cpp b/Marlin/src/lcd/tft/touch.cpp index 29dd088c99bbf..2e0a681fc55cb 100644 --- a/Marlin/src/lcd/tft/touch.cpp +++ b/Marlin/src/lcd/tft/touch.cpp @@ -186,25 +186,25 @@ void Touch::touch(touch_control_t *control) { ui.clear_lcd(); if (heater >= 0) { // HotEnd #if HOTENDS == 1 - MenuItem_int3::action((const char *)GET_TEXT_F(MSG_NOZZLE), &thermalManager.temp_hotend[0].target, 0, thermalManager.heater_maxtemp[0] - 15, []{ thermalManager.start_watching_hotend(0); }); + MenuItem_int3::action((const char *)GET_TEXT_F(MSG_NOZZLE), &thermalManager.temp_hotend[0].target, 0, thermalManager.hotend_max_target(0), []{ thermalManager.start_watching_hotend(0); }); #else MenuItemBase::itemIndex = heater; - MenuItem_int3::action((const char *)GET_TEXT_F(MSG_NOZZLE_N), &thermalManager.temp_hotend[heater].target, 0, thermalManager.heater_maxtemp[heater] - 15, []{ thermalManager.start_watching_hotend(MenuItemBase::itemIndex); }); + MenuItem_int3::action((const char *)GET_TEXT_F(MSG_NOZZLE_N), &thermalManager.temp_hotend[heater].target, 0, thermalManager.hotend_max_target(heater), []{ thermalManager.start_watching_hotend(MenuItemBase::itemIndex); }); #endif } #if HAS_HEATED_BED else if (heater == H_BED) { - MenuItem_int3::action((const char *)GET_TEXT_F(MSG_BED), &thermalManager.temp_bed.target, 0, BED_MAXTEMP - 10, thermalManager.start_watching_bed); + MenuItem_int3::action((const char *)GET_TEXT_F(MSG_BED), &thermalManager.temp_bed.target, 0, BED_MAX_TARGET, thermalManager.start_watching_bed); } #endif #if HAS_HEATED_CHAMBER else if (heater == H_CHAMBER) { - MenuItem_int3::action((const char *)GET_TEXT_F(MSG_CHAMBER), &thermalManager.temp_chamber.target, 0, CHAMBER_MAXTEMP - 10, thermalManager.start_watching_chamber); + MenuItem_int3::action((const char *)GET_TEXT_F(MSG_CHAMBER), &thermalManager.temp_chamber.target, 0, CHAMBER_MAX_TARGET, thermalManager.start_watching_chamber); } #endif #if HAS_COOLER else if (heater == H_COOLER) { - MenuItem_int3::action((const char *)GET_TEXT_F(MSG_COOLER), &thermalManager.temp_cooler.target, 0, COOLER_MAXTEMP - 8, thermalManager.start_watching_cooler); + MenuItem_int3::action((const char *)GET_TEXT_F(MSG_COOLER), &thermalManager.temp_cooler.target, 0, COOLER_MAXTEMP, thermalManager.start_watching_cooler); } #endif diff --git a/Marlin/src/lcd/tft/ui_320x240.cpp b/Marlin/src/lcd/tft/ui_320x240.cpp index fb821886451e0..37a44f51b40a8 100644 --- a/Marlin/src/lcd/tft/ui_320x240.cpp +++ b/Marlin/src/lcd/tft/ui_320x240.cpp @@ -114,7 +114,7 @@ void MarlinUI::draw_kill_screen() { void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) { MarlinImage image = imgHotEnd; uint16_t Color; - float currentTemperature, targetTemperature; + celsius_t currentTemperature, targetTemperature; if (Heater >= 0) { // HotEnd currentTemperature = thermalManager.degHotend(Heater); @@ -175,13 +175,13 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) { tft.add_image(0, 18, image, Color); - tft_string.set((uint8_t *)i16tostr3rj(currentTemperature + 0.5)); + tft_string.set((uint8_t *)i16tostr3rj(currentTemperature)); tft_string.add(LCD_STR_DEGREE); tft_string.trim(); tft.add_text(tft_string.center(64) + 2, 72, Color, tft_string); if (targetTemperature >= 0) { - tft_string.set((uint8_t *)i16tostr3rj(targetTemperature + 0.5)); + tft_string.set((uint8_t *)i16tostr3rj(targetTemperature)); tft_string.add(LCD_STR_DEGREE); tft_string.trim(); tft.add_text(tft_string.center(64) + 2, 8, Color, tft_string); diff --git a/Marlin/src/lcd/tft/ui_480x320.cpp b/Marlin/src/lcd/tft/ui_480x320.cpp index 164785a229645..81e4603ea4a45 100644 --- a/Marlin/src/lcd/tft/ui_480x320.cpp +++ b/Marlin/src/lcd/tft/ui_480x320.cpp @@ -114,7 +114,7 @@ void MarlinUI::draw_kill_screen() { void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) { MarlinImage image = imgHotEnd; uint16_t Color; - float currentTemperature, targetTemperature; + celsius_t currentTemperature, targetTemperature; if (Heater >= 0) { // HotEnd currentTemperature = thermalManager.degHotend(Heater); @@ -168,13 +168,13 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) { tft.add_image(8, 28, image, Color); - tft_string.set((uint8_t *)i16tostr3rj(currentTemperature + 0.5)); + tft_string.set((uint8_t *)i16tostr3rj(currentTemperature)); tft_string.add(LCD_STR_DEGREE); tft_string.trim(); tft.add_text(tft_string.center(80) + 2, 82, Color, tft_string); if (targetTemperature >= 0) { - tft_string.set((uint8_t *)i16tostr3rj(targetTemperature + 0.5)); + tft_string.set((uint8_t *)i16tostr3rj(targetTemperature)); tft_string.add(LCD_STR_DEGREE); tft_string.trim(); tft.add_text(tft_string.center(80) + 2, 8, Color, tft_string); diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index 2f4f5e283a34c..b0a4890e07006 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -940,11 +940,11 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) { DualXMode dual_x_carriage_mode = DEFAULT_DUAL_X_CARRIAGE_MODE; float inactive_extruder_x = X2_MAX_POS, // Used in mode 0 & 1 - duplicate_extruder_x_offset = DEFAULT_DUPLICATION_X_OFFSET; // Used in mode 2 + duplicate_extruder_x_offset = DEFAULT_DUPLICATION_X_OFFSET; // Used in mode 2 & 3 xyz_pos_t raised_parked_position; // Used in mode 1 - bool active_extruder_parked = false; // Used in mode 1 & 2 + bool active_extruder_parked = false; // Used in mode 1, 2 & 3 millis_t delayed_move_time = 0; // Used in mode 1 - int16_t duplicate_extruder_temp_offset = 0; // Used in mode 2 + celsius_t duplicate_extruder_temp_offset = 0; // Used in mode 2 & 3 bool idex_mirrored_mode = false; // Used in mode 3 float x_home_pos(const uint8_t extruder) { diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h index 0328d015a49db..7b8d2f20182bb 100644 --- a/Marlin/src/module/motion.h +++ b/Marlin/src/module/motion.h @@ -463,13 +463,13 @@ FORCE_INLINE bool all_axes_trusted() { return xyz_bits == }; extern DualXMode dual_x_carriage_mode; - extern float inactive_extruder_x, // Used in mode 0 & 1 - duplicate_extruder_x_offset; // Used in mode 2 & 3 - extern xyz_pos_t raised_parked_position; // Used in mode 1 - extern bool active_extruder_parked; // Used in mode 1, 2 & 3 - extern millis_t delayed_move_time; // Used in mode 1 - extern int16_t duplicate_extruder_temp_offset; // Used in mode 2 & 3 - extern bool idex_mirrored_mode; // Used in mode 3 + extern float inactive_extruder_x, // Used in mode 0 & 1 + duplicate_extruder_x_offset; // Used in mode 2 & 3 + extern xyz_pos_t raised_parked_position; // Used in mode 1 + extern bool active_extruder_parked; // Used in mode 1, 2 & 3 + extern millis_t delayed_move_time; // Used in mode 1 + extern celsius_t duplicate_extruder_temp_offset; // Used in mode 2 & 3 + extern bool idex_mirrored_mode; // Used in mode 3 FORCE_INLINE bool idex_is_duplicating() { return dual_x_carriage_mode >= DXC_DUPLICATION_MODE; } diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 594671f87ae49..8c320925be90c 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -197,9 +197,9 @@ float Planner::steps_to_mm[XYZE_N]; // (mm) Millimeters per step skew_factor_t Planner::skew_factor; // Initialized by settings.load() #if ENABLED(AUTOTEMP) - float Planner::autotemp_max = 250, - Planner::autotemp_min = 210, - Planner::autotemp_factor = 0.1f; + celsius_t Planner::autotemp_max = 250, + Planner::autotemp_min = 210; + float Planner::autotemp_factor = 0.1f; bool Planner::autotemp_enabled = false; #endif @@ -1376,7 +1376,7 @@ void Planner::check_axes_activity() { #if ENABLED(AUTOTEMP_PROPORTIONAL) void Planner::_autotemp_update_from_hotend() { - const int16_t target = thermalManager.degTargetHotend(active_extruder); + const celsius_t target = thermalManager.degTargetHotend(active_extruder); autotemp_min = target + AUTOTEMP_MIN_P; autotemp_max = target + AUTOTEMP_MAX_P; } diff --git a/Marlin/src/module/planner.h b/Marlin/src/module/planner.h index 7ebba1e342f4a..769967d4a6e4d 100644 --- a/Marlin/src/module/planner.h +++ b/Marlin/src/module/planner.h @@ -896,7 +896,8 @@ class Planner { #endif #if ENABLED(AUTOTEMP) - static float autotemp_min, autotemp_max, autotemp_factor; + static celsius_t autotemp_min, autotemp_max; + static float autotemp_factor; static bool autotemp_enabled; static void autotemp_update(); static void autotemp_M104_M109(); diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index a000a31de7ec7..53f5193f409d6 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -253,7 +253,7 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY, #if HAS_HOTEND hotend_info_t Temperature::temp_hotend[HOTEND_TEMPS]; // = { 0 } - const uint16_t Temperature::heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP, HEATER_5_MAXTEMP, HEATER_6_MAXTEMP, HEATER_7_MAXTEMP); + const celsius_t Temperature::hotend_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP, HEATER_5_MAXTEMP, HEATER_6_MAXTEMP, HEATER_7_MAXTEMP); #endif #if ENABLED(AUTO_POWER_E_FANS) @@ -267,24 +267,32 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY, #if ENABLED(AUTO_POWER_COOLER_FAN) uint8_t Temperature::coolerfan_speed; // = 0 #endif + #if HAS_FAN uint8_t Temperature::fan_speed[FAN_COUNT]; // = { 0 } #if ENABLED(EXTRA_FAN_SPEED) - uint8_t Temperature::old_fan_speed[FAN_COUNT], Temperature::new_fan_speed[FAN_COUNT]; - void Temperature::set_temp_fan_speed(const uint8_t fan, const uint16_t tmp_temp) { - switch (tmp_temp) { + Temperature::extra_fan_t Temperature::extra_fan_speed[FAN_COUNT]; + + /** + * Handle the M106 P T command: + * T1 = Restore fan speed saved on the last T2 + * T2 = Save the fan speed, then set to the last T<3-255> value + * T<3-255> = Set the "extra fan speed" + */ + void Temperature::set_temp_fan_speed(const uint8_t fan, const uint16_t command_or_speed) { + switch (command_or_speed) { case 1: - set_fan_speed(fan, old_fan_speed[fan]); + set_fan_speed(fan, extra_fan_speed[fan].saved); break; case 2: - old_fan_speed[fan] = fan_speed[fan]; - set_fan_speed(fan, new_fan_speed[fan]); + extra_fan_speed[fan].saved = fan_speed[fan]; + set_fan_speed(fan, extra_fan_speed[fan].speed); break; default: - new_fan_speed[fan] = _MIN(tmp_temp, 255U); + extra_fan_speed[fan].speed = _MIN(command_or_speed, 255U); break; } } @@ -360,12 +368,8 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY, #if HAS_HEATED_BED bed_info_t Temperature::temp_bed; // = { 0 } // Init min and max temp with extreme values to prevent false errors during startup - #ifdef BED_MINTEMP - int16_t Temperature::mintemp_raw_BED = TEMP_SENSOR_BED_RAW_LO_TEMP; - #endif - #ifdef BED_MAXTEMP - int16_t Temperature::maxtemp_raw_BED = TEMP_SENSOR_BED_RAW_HI_TEMP; - #endif + int16_t Temperature::mintemp_raw_BED = TEMP_SENSOR_BED_RAW_LO_TEMP, + Temperature::maxtemp_raw_BED = TEMP_SENSOR_BED_RAW_HI_TEMP; TERN_(WATCH_BED, bed_watch_t Temperature::watch_bed); // = { 0 } IF_DISABLED(PIDTEMPBED, millis_t Temperature::next_bed_check_ms); #endif @@ -375,12 +379,8 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY, #if HAS_HEATED_CHAMBER millis_t next_cool_check_ms_2 = 0; float old_temp = 9999; - #ifdef CHAMBER_MINTEMP - int16_t Temperature::mintemp_raw_CHAMBER = TEMP_SENSOR_CHAMBER_RAW_LO_TEMP; - #endif - #ifdef CHAMBER_MAXTEMP - int16_t Temperature::maxtemp_raw_CHAMBER = TEMP_SENSOR_CHAMBER_RAW_HI_TEMP; - #endif + int16_t Temperature::mintemp_raw_CHAMBER = TEMP_SENSOR_CHAMBER_RAW_LO_TEMP, + Temperature::maxtemp_raw_CHAMBER = TEMP_SENSOR_CHAMBER_RAW_HI_TEMP; TERN_(WATCH_CHAMBER, chamber_watch_t Temperature::watch_chamber{0}); IF_DISABLED(PIDTEMPCHAMBER, millis_t Temperature::next_chamber_check_ms); #endif @@ -392,12 +392,8 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY, bool flag_cooler_state; //bool flag_cooler_excess = false; float previous_temp = 9999; - #ifdef COOLER_MINTEMP - int16_t Temperature::mintemp_raw_COOLER = TEMP_SENSOR_COOLER_RAW_LO_TEMP; - #endif - #ifdef COOLER_MAXTEMP - int16_t Temperature::maxtemp_raw_COOLER = TEMP_SENSOR_COOLER_RAW_HI_TEMP; - #endif + int16_t Temperature::mintemp_raw_COOLER = TEMP_SENSOR_COOLER_RAW_LO_TEMP, + Temperature::maxtemp_raw_COOLER = TEMP_SENSOR_COOLER_RAW_HI_TEMP; #if WATCH_COOLER cooler_watch_t Temperature::watch_cooler{0}; #endif @@ -411,7 +407,7 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY, #if ENABLED(PREVENT_COLD_EXTRUSION) bool Temperature::allow_cold_extrude = false; - int16_t Temperature::extrude_min_temp = EXTRUDE_MINTEMP; + celsius_t Temperature::extrude_min_temp = EXTRUDE_MINTEMP; #endif // private: @@ -421,7 +417,7 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY, #endif #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT) - uint16_t Temperature::redundant_temperature_raw = 0; + celsius_t Temperature::redundant_temperature_raw = 0; float Temperature::redundant_temperature = 0.0; #endif @@ -466,7 +462,7 @@ volatile bool Temperature::raw_temps_ready = false; #endif #if ENABLED(SINGLENOZZLE_STANDBY_TEMP) - uint16_t Temperature::singlenozzle_temp[EXTRUDERS]; + celsius_t Temperature::singlenozzle_temp[EXTRUDERS]; #if HAS_FAN uint8_t Temperature::singlenozzle_fan_speed[EXTRUDERS]; #endif @@ -552,7 +548,7 @@ volatile bool Temperature::raw_temps_ready = false; TERN_(HAS_AUTO_FAN, next_auto_fan_check_ms = next_temp_ms + 2500UL); - if (target > GHV(CHAMBER_MAX_TARGET, BED_MAX_TARGET, temp_range[heater_id].maxtemp - HOTEND_OVERSHOOT)) { + if (target > GHV(CHAMBER_MAX_TARGET, BED_MAX_TARGET, temp_range[heater_id].maxtemp - (HOTEND_OVERSHOOT))) { SERIAL_ECHOLNPGM(STR_PID_TEMP_TOO_HIGH); TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_TEMP_TOO_HIGH)); return; @@ -1512,7 +1508,7 @@ void Temperature::manage_heater() { if (cooler.is_enabled()) { flag_cooler_state = true; // used to allow M106 fan control when cooler is disabled - if (temp_cooler.target == 0) temp_cooler.target = COOLER_MINTEMP; + if (temp_cooler.target == 0) temp_cooler.target = COOLER_MINTEMP + 2; if (ELAPSED(ms, next_cooler_check_ms)) { next_cooler_check_ms = ms + COOLER_CHECK_INTERVAL; if (temp_cooler.celsius > temp_cooler.target) { @@ -1558,22 +1554,22 @@ void Temperature::manage_heater() { * Bisect search for the range of the 'raw' value, then interpolate * proportionally between the under and over values. */ -#define SCAN_THERMISTOR_TABLE(TBL,LEN) do{ \ - uint8_t l = 0, r = LEN, m; \ - for (;;) { \ - m = (l + r) >> 1; \ - if (!m) return int16_t(pgm_read_word(&TBL[0].celsius)); \ - if (m == l || m == r) return int16_t(pgm_read_word(&TBL[LEN-1].celsius)); \ - int16_t v00 = pgm_read_word(&TBL[m-1].value), \ - v10 = pgm_read_word(&TBL[m-0].value); \ - if (raw < v00) r = m; \ - else if (raw > v10) l = m; \ - else { \ - const int16_t v01 = int16_t(pgm_read_word(&TBL[m-1].celsius)), \ - v11 = int16_t(pgm_read_word(&TBL[m-0].celsius)); \ - return v01 + (raw - v00) * float(v11 - v01) / float(v10 - v00); \ - } \ - } \ +#define SCAN_THERMISTOR_TABLE(TBL,LEN) do{ \ + uint8_t l = 0, r = LEN, m; \ + for (;;) { \ + m = (l + r) >> 1; \ + if (!m) return celsius_t(pgm_read_word(&TBL[0].celsius)); \ + if (m == l || m == r) return celsius_t(pgm_read_word(&TBL[LEN-1].celsius)); \ + int16_t v00 = pgm_read_word(&TBL[m-1].value), \ + v10 = pgm_read_word(&TBL[m-0].value); \ + if (raw < v00) r = m; \ + else if (raw > v10) l = m; \ + else { \ + const celsius_t v01 = celsius_t(pgm_read_word(&TBL[m-1].celsius)), \ + v11 = celsius_t(pgm_read_word(&TBL[m-0].celsius)); \ + return v01 + (raw - v00) * float(v11 - v01) / float(v10 - v00); \ + } \ + } \ }while(0) #if HAS_USER_THERMISTORS @@ -1655,7 +1651,7 @@ void Temperature::manage_heater() { SERIAL_EOL(); } - float Temperature::user_thermistor_to_deg_c(const uint8_t t_index, const int raw) { + celsius_t Temperature::user_thermistor_to_deg_c(const uint8_t t_index, const int raw) { //#if (MOTHERBOARD == BOARD_RAMPS_14_EFB) // static uint32_t clocks_total = 0; // static uint32_t calls = 0; @@ -1704,7 +1700,7 @@ void Temperature::manage_heater() { #if HAS_HOTEND // Derived from RepRap FiveD extruder::getTemperature() // For hot end temperature measurement. - float Temperature::analog_to_celsius_hotend(const int raw, const uint8_t e) { + celsius_t Temperature::analog_to_celsius_hotend(const int raw, const uint8_t e) { if (e > HOTENDS - DISABLED(TEMP_SENSOR_1_AS_REDUNDANT)) { SERIAL_ERROR_START(); SERIAL_ECHO(e); @@ -1813,7 +1809,7 @@ void Temperature::manage_heater() { #if HAS_HEATED_BED // For bed temperature measurement. - float Temperature::analog_to_celsius_bed(const int raw) { + celsius_t Temperature::analog_to_celsius_bed(const int raw) { #if TEMP_SENSOR_BED_IS_CUSTOM return user_thermistor_to_deg_c(CTI_BED, raw); #elif TEMP_SENSOR_BED_IS_THERMISTOR @@ -1831,7 +1827,7 @@ void Temperature::manage_heater() { #if HAS_TEMP_CHAMBER // For chamber temperature measurement. - float Temperature::analog_to_celsius_chamber(const int raw) { + celsius_t Temperature::analog_to_celsius_chamber(const int raw) { #if TEMP_SENSOR_CHAMBER_IS_CUSTOM return user_thermistor_to_deg_c(CTI_CHAMBER, raw); #elif TEMP_SENSOR_CHAMBER_IS_THERMISTOR @@ -1849,7 +1845,7 @@ void Temperature::manage_heater() { #if HAS_TEMP_COOLER // For cooler temperature measurement. - float Temperature::analog_to_celsius_cooler(const int raw) { + celsius_t Temperature::analog_to_celsius_cooler(const int raw) { #if TEMP_SENSOR_COOLER_IS_CUSTOM return user_thermistor_to_deg_c(CTI_COOLER, raw); #elif TEMP_SENSOR_COOLER_IS_THERMISTOR @@ -1867,7 +1863,7 @@ void Temperature::manage_heater() { #if HAS_TEMP_PROBE // For probe temperature measurement. - float Temperature::analog_to_celsius_probe(const int raw) { + celsius_t Temperature::analog_to_celsius_probe(const int raw) { #if TEMP_SENSOR_PROBE_IS_CUSTOM return user_thermistor_to_deg_c(CTI_PROBE, raw); #elif TEMP_SENSOR_PROBE_IS_THERMISTOR @@ -2183,13 +2179,13 @@ void Temperature::init() { #if HAS_HOTEND #define _TEMP_MIN_E(NR) do{ \ - const int16_t tmin = _MAX(HEATER_##NR##_MINTEMP, TERN(TEMP_SENSOR_##NR##_IS_CUSTOM, 0, (int16_t)pgm_read_word(&TEMPTABLE_##NR [TEMP_SENSOR_##NR##_MINTEMP_IND].celsius))); \ + const celsius_t tmin = _MAX(HEATER_##NR##_MINTEMP, TERN(TEMP_SENSOR_##NR##_IS_CUSTOM, 0, pgm_read_word(&TEMPTABLE_##NR [TEMP_SENSOR_##NR##_MINTEMP_IND].celsius))); \ temp_range[NR].mintemp = tmin; \ while (analog_to_celsius_hotend(temp_range[NR].raw_min, NR) < tmin) \ temp_range[NR].raw_min += TEMPDIR(NR) * (OVERSAMPLENR); \ }while(0) #define _TEMP_MAX_E(NR) do{ \ - const int16_t tmax = _MIN(HEATER_##NR##_MAXTEMP, TERN(TEMP_SENSOR_##NR##_IS_CUSTOM, 2000, (int16_t)pgm_read_word(&TEMPTABLE_##NR [TEMP_SENSOR_##NR##_MAXTEMP_IND].celsius) - 1)); \ + const celsius_t tmax = _MIN(HEATER_##NR##_MAXTEMP, TERN(TEMP_SENSOR_##NR##_IS_CUSTOM, 2000, pgm_read_word(&TEMPTABLE_##NR [TEMP_SENSOR_##NR##_MAXTEMP_IND].celsius) - 1)); \ temp_range[NR].maxtemp = tmax; \ while (analog_to_celsius_hotend(temp_range[NR].raw_max, NR) > tmax) \ temp_range[NR].raw_max -= TEMPDIR(NR) * (OVERSAMPLENR); \ @@ -2249,30 +2245,18 @@ void Temperature::init() { #endif // HAS_HOTEND #if HAS_HEATED_BED - #ifdef BED_MINTEMP - while (analog_to_celsius_bed(mintemp_raw_BED) < BED_MINTEMP) mintemp_raw_BED += TEMPDIR(BED) * (OVERSAMPLENR); - #endif - #ifdef BED_MAXTEMP - while (analog_to_celsius_bed(maxtemp_raw_BED) > BED_MAXTEMP) maxtemp_raw_BED -= TEMPDIR(BED) * (OVERSAMPLENR); - #endif - #endif // HAS_HEATED_BED + while (analog_to_celsius_bed(mintemp_raw_BED) < BED_MINTEMP) mintemp_raw_BED += TEMPDIR(BED) * (OVERSAMPLENR); + while (analog_to_celsius_bed(maxtemp_raw_BED) > BED_MAXTEMP) maxtemp_raw_BED -= TEMPDIR(BED) * (OVERSAMPLENR); + #endif #if HAS_HEATED_CHAMBER - #ifdef CHAMBER_MINTEMP - while (analog_to_celsius_chamber(mintemp_raw_CHAMBER) < CHAMBER_MINTEMP) mintemp_raw_CHAMBER += TEMPDIR(CHAMBER) * (OVERSAMPLENR); - #endif - #ifdef CHAMBER_MAXTEMP - while (analog_to_celsius_chamber(maxtemp_raw_CHAMBER) > CHAMBER_MAXTEMP) maxtemp_raw_CHAMBER -= TEMPDIR(CHAMBER) * (OVERSAMPLENR); - #endif + while (analog_to_celsius_chamber(mintemp_raw_CHAMBER) < CHAMBER_MINTEMP) mintemp_raw_CHAMBER += TEMPDIR(CHAMBER) * (OVERSAMPLENR); + while (analog_to_celsius_chamber(maxtemp_raw_CHAMBER) > CHAMBER_MAXTEMP) maxtemp_raw_CHAMBER -= TEMPDIR(CHAMBER) * (OVERSAMPLENR); #endif #if HAS_COOLER - #ifdef COOLER_MINTEMP - while (analog_to_celsius_cooler(mintemp_raw_COOLER) > COOLER_MINTEMP) mintemp_raw_COOLER += TEMPDIR(COOLER) * (OVERSAMPLENR); - #endif - #ifdef COOLER_MAXTEMP - while (analog_to_celsius_cooler(maxtemp_raw_COOLER) < COOLER_MAXTEMP) maxtemp_raw_COOLER -= TEMPDIR(COOLER) * (OVERSAMPLENR); - #endif + while (analog_to_celsius_cooler(mintemp_raw_COOLER) > COOLER_MINTEMP) mintemp_raw_COOLER += TEMPDIR(COOLER) * (OVERSAMPLENR); + while (analog_to_celsius_cooler(maxtemp_raw_COOLER) < COOLER_MAXTEMP) maxtemp_raw_COOLER -= TEMPDIR(COOLER) * (OVERSAMPLENR); #endif TERN_(PROBING_HEATERS_OFF, paused = false); @@ -2337,7 +2321,7 @@ void Temperature::init() { * * TODO: Embed the last 3 parameters during init, if not less optimal */ - void Temperature::tr_state_machine_t::run(const float ¤t, const float &target, const heater_id_t heater_id, const uint16_t period_seconds, const uint16_t hysteresis_degc) { + void Temperature::tr_state_machine_t::run(const float ¤t, const float &target, const heater_id_t heater_id, const uint16_t period_seconds, const celsius_t hysteresis_degc) { #if HEATER_IDLE_HANDLER // Convert the given heater_id_t to an idle array index @@ -2546,7 +2530,7 @@ void Temperature::disable_all_heaters() { #if HAS_MULTI_MAX_TC // Needed to return the correct temp when this is called between readings - static uint16_t max_tc_temp_previous[MAX_TC_COUNT] = { 0 }; + static celsius_t max_tc_temp_previous[MAX_TC_COUNT] = { 0 }; #define THERMO_TEMP(I) max_tc_temp_previous[I] #define THERMO_SEL(A,B) (hindex ? (B) : (A)) #define MAX6675_WRITE(V) do{ switch (hindex) { case 1: WRITE(MAX6675_SS2_PIN, V); break; default: WRITE(MAX6675_SS_PIN, V); } }while(0) diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index e69183f6f5e4d..8bf6fe493468f 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -179,7 +179,7 @@ enum ADCSensorState : char { typedef struct TempInfo { uint16_t acc; int16_t raw; - float celsius; + celsius_t celsius; inline void reset() { acc = 0; } inline void sample(const uint16_t s) { acc += s; } inline void update() { raw = acc; } @@ -187,7 +187,7 @@ typedef struct TempInfo { // A PWM heater with temperature sensor typedef struct HeaterInfo : public TempInfo { - int16_t target; + celsius_t target; uint8_t soft_pwm_amount; } heater_info_t; @@ -228,14 +228,14 @@ struct PIDHeaterInfo : public HeaterInfo { // Heater watch handling template struct HeaterWatch { - uint16_t target; + celsius_t target; millis_t next_ms; inline bool elapsed(const millis_t &ms) { return next_ms && ELAPSED(ms, next_ms); } inline bool elapsed() { return elapsed(millis()); } - inline void restart(const int16_t curr, const int16_t tgt) { + inline void restart(const celsius_t curr, const celsius_t tgt) { if (tgt) { - const int16_t newtarget = curr + INCREASE; + const celsius_t newtarget = curr + INCREASE; if (newtarget < tgt - HYSTERESIS - 1) { target = newtarget; next_ms = millis() + SEC_TO_MS(PERIOD); @@ -261,8 +261,8 @@ struct HeaterWatch { // Temperature sensor read value ranges typedef struct { int16_t raw_min, raw_max; } raw_range_t; -typedef struct { int16_t mintemp, maxtemp; } celsius_range_t; -typedef struct { int16_t raw_min, raw_max, mintemp, maxtemp; } temp_range_t; +typedef struct { celsius_t mintemp, maxtemp; } celsius_range_t; +typedef struct { int16_t raw_min, raw_max; celsius_t mintemp, maxtemp; } temp_range_t; #define THERMISTOR_ABS_ZERO_C -273.15f // bbbbrrrrr cold ! #define THERMISTOR_RESISTANCE_NOMINAL_C 25.0f // mmmmm comfortable @@ -323,7 +323,8 @@ class Temperature { #if HAS_HOTEND #define HOTEND_TEMPS (HOTENDS + ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)) static hotend_info_t temp_hotend[HOTEND_TEMPS]; - static const uint16_t heater_maxtemp[HOTENDS]; + static const celsius_t hotend_maxtemp[HOTENDS]; + FORCE_INLINE static celsius_t hotend_max_target(const uint8_t e) { return hotend_maxtemp[e] - (HOTEND_OVERSHOOT); } #endif TERN_(HAS_HEATED_BED, static bed_info_t temp_bed); TERN_(HAS_TEMP_PROBE, static probe_info_t temp_probe); @@ -341,8 +342,8 @@ class Temperature { #if ENABLED(PREVENT_COLD_EXTRUSION) static bool allow_cold_extrude; - static int16_t extrude_min_temp; - FORCE_INLINE static bool tooCold(const int16_t temp) { return allow_cold_extrude ? false : temp < extrude_min_temp - (TEMP_WINDOW); } + static celsius_t extrude_min_temp; + FORCE_INLINE static bool tooCold(const celsius_t temp) { return allow_cold_extrude ? false : temp < extrude_min_temp - (TEMP_WINDOW); } FORCE_INLINE static bool tooColdToExtrude(const uint8_t E_NAME) { return tooCold(degHotend(HOTEND_INDEX)); } @@ -358,7 +359,7 @@ class Temperature { FORCE_INLINE static bool targetHotEnoughToExtrude(const uint8_t e) { return !targetTooColdToExtrude(e); } #if ENABLED(SINGLENOZZLE_STANDBY_FAN) - static uint16_t singlenozzle_temp[EXTRUDERS]; + static celsius_t singlenozzle_temp[EXTRUDERS]; #if HAS_FAN static uint8_t singlenozzle_fan_speed[EXTRUDERS]; #endif @@ -410,7 +411,7 @@ class Temperature { #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT) static uint16_t redundant_temperature_raw; - static float redundant_temperature; + static celsius_t redundant_temperature; #endif #if ENABLED(PID_EXTRUSION_SCALING) @@ -423,34 +424,19 @@ class Temperature { #if HAS_HEATED_BED TERN_(WATCH_BED, static bed_watch_t watch_bed); IF_DISABLED(PIDTEMPBED, static millis_t next_bed_check_ms); - #ifdef BED_MINTEMP - static int16_t mintemp_raw_BED; - #endif - #ifdef BED_MAXTEMP - static int16_t maxtemp_raw_BED; - #endif + static int16_t mintemp_raw_BED, maxtemp_raw_BED; #endif #if HAS_HEATED_CHAMBER TERN_(WATCH_CHAMBER, static chamber_watch_t watch_chamber); TERN(PIDTEMPCHAMBER,,static millis_t next_chamber_check_ms); - #ifdef CHAMBER_MINTEMP - static int16_t mintemp_raw_CHAMBER; - #endif - #ifdef CHAMBER_MAXTEMP - static int16_t maxtemp_raw_CHAMBER; - #endif + static int16_t mintemp_raw_CHAMBER, maxtemp_raw_CHAMBER; #endif #if HAS_COOLER TERN_(WATCH_COOLER, static cooler_watch_t watch_cooler); static millis_t next_cooler_check_ms, cooler_fan_flush_ms; - #ifdef COOLER_MINTEMP - static int16_t mintemp_raw_COOLER; - #endif - #ifdef COOLER_MAXTEMP - static int16_t maxtemp_raw_COOLER; - #endif + static int16_t mintemp_raw_COOLER, maxtemp_raw_COOLER; #endif #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED @@ -487,7 +473,7 @@ class Temperature { static user_thermistor_t user_thermistor[USER_THERMISTORS]; static void log_user_thermistor(const uint8_t t_index, const bool eprom=false); static void reset_user_thermistors(); - static float user_thermistor_to_deg_c(const uint8_t t_index, const int raw); + static celsius_t user_thermistor_to_deg_c(const uint8_t t_index, const int raw); static bool set_pull_up_res(int8_t t_index, float value) { //if (!WITHIN(t_index, 0, USER_THERMISTORS - 1)) return false; if (!WITHIN(value, 1, 1000000)) return false; @@ -515,19 +501,19 @@ class Temperature { #endif #if HAS_HOTEND - static float analog_to_celsius_hotend(const int raw, const uint8_t e); + static celsius_t analog_to_celsius_hotend(const int raw, const uint8_t e); #endif #if HAS_HEATED_BED - static float analog_to_celsius_bed(const int raw); + static celsius_t analog_to_celsius_bed(const int raw); #endif #if HAS_TEMP_PROBE - static float analog_to_celsius_probe(const int raw); + static celsius_t analog_to_celsius_probe(const int raw); #endif #if HAS_TEMP_CHAMBER - static float analog_to_celsius_chamber(const int raw); + static celsius_t analog_to_celsius_chamber(const int raw); #endif #if HAS_TEMP_COOLER - static float analog_to_celsius_cooler(const int raw); + static celsius_t analog_to_celsius_cooler(const int raw); #endif #if HAS_FAN @@ -560,8 +546,9 @@ class Temperature { } #if ENABLED(EXTRA_FAN_SPEED) - static uint8_t old_fan_speed[FAN_COUNT], new_fan_speed[FAN_COUNT]; - static void set_temp_fan_speed(const uint8_t fan, const uint16_t tmp_temp); + typedef struct { uint8_t saved, speed; } extra_fan_t; + static extra_fan_t extra_fan_speed[FAN_COUNT]; + static void set_temp_fan_speed(const uint8_t fan, const uint16_t command_or_speed); #endif #if EITHER(PROBING_FANS_OFF, ADVANCED_PAUSE_FANS_PAUSE) @@ -618,7 +605,7 @@ class Temperature { } #endif - FORCE_INLINE static int16_t degTargetHotend(const uint8_t E_NAME) { + FORCE_INLINE static celsius_t degTargetHotend(const uint8_t E_NAME) { return TERN0(HAS_HOTEND, temp_hotend[HOTEND_INDEX].target); } @@ -630,7 +617,7 @@ class Temperature { #if HAS_HOTEND - static void setTargetHotend(const int16_t celsius, const uint8_t E_NAME) { + static void setTargetHotend(const celsius_t celsius, const uint8_t E_NAME) { const uint8_t ee = HOTEND_INDEX; #ifdef MILLISECONDS_PREHEAT_TIME if (celsius == 0) @@ -639,7 +626,7 @@ class Temperature { start_preheat_time(ee); #endif TERN_(AUTO_POWER_CONTROL, if (celsius) powerManager.power_on()); - temp_hotend[ee].target = _MIN(celsius, temp_range[ee].maxtemp - HOTEND_OVERSHOOT); + temp_hotend[ee].target = _MIN(celsius, hotend_max_target(ee)); start_watching_hotend(ee); } @@ -676,12 +663,12 @@ class Temperature { #if HAS_HEATED_BED #if ENABLED(SHOW_TEMP_ADC_VALUES) - FORCE_INLINE static int16_t rawBedTemp() { return temp_bed.raw; } + FORCE_INLINE static int16_t rawBedTemp() { return temp_bed.raw; } #endif - FORCE_INLINE static float degBed() { return temp_bed.celsius; } - FORCE_INLINE static int16_t degTargetBed() { return temp_bed.target; } - FORCE_INLINE static bool isHeatingBed() { return temp_bed.target > temp_bed.celsius; } - FORCE_INLINE static bool isCoolingBed() { return temp_bed.target < temp_bed.celsius; } + FORCE_INLINE static celsius_t degBed() { return temp_bed.celsius; } + FORCE_INLINE static celsius_t degTargetBed() { return temp_bed.target; } + FORCE_INLINE static bool isHeatingBed() { return temp_bed.target > temp_bed.celsius; } + FORCE_INLINE static bool isCoolingBed() { return temp_bed.target < temp_bed.celsius; } #if WATCH_BED static void start_watching_bed(); @@ -689,15 +676,9 @@ class Temperature { static inline void start_watching_bed() {} #endif - static void setTargetBed(const int16_t celsius) { + static void setTargetBed(const celsius_t celsius) { TERN_(AUTO_POWER_CONTROL, if (celsius) powerManager.power_on()); - temp_bed.target = - #ifdef BED_MAX_TARGET - _MIN(celsius, BED_MAX_TARGET) - #else - celsius - #endif - ; + temp_bed.target = _MIN(celsius, BED_MAX_TARGET); start_watching_bed(); } @@ -733,14 +714,13 @@ class Temperature { #if HAS_TEMP_CHAMBER #if ENABLED(SHOW_TEMP_ADC_VALUES) - FORCE_INLINE static int16_t rawChamberTemp() { return temp_chamber.raw; } + FORCE_INLINE static int16_t rawChamberTemp() { return temp_chamber.raw; } #endif - FORCE_INLINE static float degChamber() { return temp_chamber.celsius; } + FORCE_INLINE static float degChamber() { return temp_chamber.celsius; } #if HAS_HEATED_CHAMBER - FORCE_INLINE static int16_t degTargetChamber() { return temp_chamber.target; } - FORCE_INLINE static bool isHeatingChamber() { return temp_chamber.target > temp_chamber.celsius; } - FORCE_INLINE static bool isCoolingChamber() { return temp_chamber.target < temp_chamber.celsius; } - + FORCE_INLINE static celsius_t degTargetChamber() { return temp_chamber.target; } + FORCE_INLINE static bool isHeatingChamber() { return temp_chamber.target > temp_chamber.celsius; } + FORCE_INLINE static bool isCoolingChamber() { return temp_chamber.target < temp_chamber.celsius; } static bool wait_for_chamber(const bool no_wait_for_cooling=true); #endif #endif @@ -752,27 +732,21 @@ class Temperature { #endif #if HAS_HEATED_CHAMBER - static void setTargetChamber(const int16_t celsius) { - temp_chamber.target = - #ifdef CHAMBER_MAXTEMP - _MIN(celsius, CHAMBER_MAXTEMP - 10) - #else - celsius - #endif - ; + static void setTargetChamber(const celsius_t celsius) { + temp_chamber.target = _MIN(celsius, CHAMBER_MAX_TARGET); start_watching_chamber(); } #endif #if HAS_TEMP_COOLER #if ENABLED(SHOW_TEMP_ADC_VALUES) - FORCE_INLINE static int16_t rawCoolerTemp() { return temp_cooler.raw; } + FORCE_INLINE static int16_t rawCoolerTemp() { return temp_cooler.raw; } #endif - FORCE_INLINE static float degCooler() { return temp_cooler.celsius; } + FORCE_INLINE static float degCooler() { return temp_cooler.celsius; } #if HAS_COOLER - FORCE_INLINE static int16_t degTargetCooler() { return temp_cooler.target; } - FORCE_INLINE static bool isLaserHeating() { return temp_cooler.target > temp_cooler.celsius; } - FORCE_INLINE static bool isLaserCooling() { return temp_cooler.target < temp_cooler.celsius; } + FORCE_INLINE static celsius_t degTargetCooler() { return temp_cooler.target; } + FORCE_INLINE static bool isLaserHeating() { return temp_cooler.target > temp_cooler.celsius; } + FORCE_INLINE static bool isLaserCooling() { return temp_cooler.target < temp_cooler.celsius; } static bool wait_for_cooler(const bool no_wait_for_cooling=true); #endif #endif @@ -784,14 +758,8 @@ class Temperature { #endif #if HAS_COOLER - static void setTargetCooler(const int16_t celsius) { - temp_cooler.target = - #ifdef COOLER_MAXTEMP - _MIN(celsius, COOLER_MAXTEMP - 10) - #else - celsius - #endif - ; + static void setTargetCooler(const celsius_t celsius) { + temp_cooler.target = constrain(celsius, COOLER_MINTEMP + 2, COOLER_MAXTEMP); start_watching_cooler(); } #endif @@ -878,7 +846,7 @@ class Temperature { TERN_(HAS_DISPLAY, static void set_heating_message(const uint8_t e)); #if HAS_LCD_MENU && HAS_TEMPERATURE - static void lcd_preheat(const int16_t e, const int8_t indh, const int8_t indb); + static void lcd_preheat(const uint8_t e, const int8_t indh, const int8_t indb); #endif private: @@ -949,7 +917,7 @@ class Temperature { millis_t timer = 0; TRState state = TRInactive; float running_temp; - void run(const float ¤t, const float &target, const heater_id_t heater_id, const uint16_t period_seconds, const uint16_t hysteresis_degc); + void run(const float ¤t, const float &target, const heater_id_t heater_id, const uint16_t period_seconds, const celsius_t hysteresis_degc); } tr_state_machine_t; static tr_state_machine_t tr_state_machine[NR_HEATER_RUNAWAY]; diff --git a/Marlin/src/module/thermistor/thermistors.h b/Marlin/src/module/thermistor/thermistors.h index f0ec289dfefdb..0871844e39218 100644 --- a/Marlin/src/module/thermistor/thermistors.h +++ b/Marlin/src/module/thermistor/thermistors.h @@ -44,7 +44,7 @@ #define ANY_THERMISTOR_IS(n) (TEMP_SENSOR_0_THERMISTOR_ID == n || TEMP_SENSOR_1_THERMISTOR_ID == n || TEMP_SENSOR_2_THERMISTOR_ID == n || TEMP_SENSOR_3_THERMISTOR_ID == n || TEMP_SENSOR_4_THERMISTOR_ID == n || TEMP_SENSOR_5_THERMISTOR_ID == n || TEMP_SENSOR_6_THERMISTOR_ID == n || TEMP_SENSOR_7_THERMISTOR_ID == n || TEMP_SENSOR_BED_THERMISTOR_ID == n || TEMP_SENSOR_CHAMBER_THERMISTOR_ID == n || TEMP_SENSOR_COOLER_THERMISTOR_ID == n || TEMP_SENSOR_PROBE_THERMISTOR_ID == n) -typedef struct { int16_t value, celsius; } temp_entry_t; +typedef struct { int16_t value; celsius_t celsius; } temp_entry_t; // Pt1000 and Pt100 handling //