From 72e3d2492f2085efe9c5fb0b33d67c24baf8a4bc Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 23 Apr 2021 19:14:49 -0500 Subject: [PATCH] Update temperature types --- Marlin/src/core/types.h | 20 ++++---- Marlin/src/feature/probe_temp_comp.cpp | 6 +-- Marlin/src/feature/probe_temp_comp.h | 4 +- Marlin/src/gcode/calibrate/G76_M192_M871.cpp | 12 ++--- Marlin/src/gcode/temp/M303.cpp | 4 +- .../extui/lib/anycubic_chiron/chiron_tft.cpp | 3 +- .../anycubic_i3mega/anycubic_i3mega_lcd.cpp | 18 ++++--- .../screens/string_format.cpp | 8 +-- .../ftdi_eve_touch_ui/screens/string_format.h | 8 +-- .../src/lcd/extui/lib/nextion/nextion_tft.cpp | 4 +- Marlin/src/lcd/extui/ui_api.cpp | 8 +-- Marlin/src/lcd/extui/ui_api.h | 8 +-- Marlin/src/module/probe.cpp | 8 +-- Marlin/src/module/probe.h | 2 +- Marlin/src/module/temperature.cpp | 49 +++++++++++-------- Marlin/src/module/temperature.h | 2 +- 16 files changed, 88 insertions(+), 76 deletions(-) diff --git a/Marlin/src/core/types.h b/Marlin/src/core/types.h index 687ec867d..79a79b739 100644 --- a/Marlin/src/core/types.h +++ b/Marlin/src/core/types.h @@ -77,6 +77,7 @@ typedef float feedRate_t; // For more resolition (e.g., for a chocolate printer) this may later be changed to Celsius x 100 // typedef int16_t celsius_t; +typedef float celsius_float_t; // // On AVR pointers are only 2 bytes so use 'const float &' for 'const float' @@ -87,17 +88,18 @@ typedef int16_t celsius_t; typedef const float const_float_t; #endif typedef const_float_t const_feedRate_t; +typedef const_float_t const_celsius_float_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) +#define MMM_TO_MMS(MM_M) feedRate_t(static_cast(MM_M) / 60.0f) +#define MMS_TO_MMM(MM_S) (static_cast(MM_S) * 60.0f) // // Coordinates structures for XY, XYZ, XYZE... // // Helpers -#define _RECIP(N) ((N) ? 1.0f / float(N) : 0.0f) +#define _RECIP(N) ((N) ? 1.0f / static_cast(N) : 0.0f) #define _ABS(N) ((N) < 0 ? -(N) : (N)) #define _LS(N) (N = (T)(uint32_t(N) << v)) #define _RS(N) (N = (T)(uint32_t(N) >> v)) @@ -214,8 +216,8 @@ struct XYval { FI XYval asLong() const { return { int32_t(x), int32_t(y) }; } FI XYval ROUNDL() { return { int32_t(LROUND(x)), int32_t(LROUND(y)) }; } FI XYval ROUNDL() const { return { int32_t(LROUND(x)), int32_t(LROUND(y)) }; } - FI XYval asFloat() { return { float(x), float(y) }; } - FI XYval asFloat() const { return { float(x), float(y) }; } + FI XYval asFloat() { return { static_cast(x), static_cast(y) }; } + FI XYval asFloat() const { return { static_cast(x), static_cast(y) }; } FI XYval reciprocal() const { return { _RECIP(x), _RECIP(y) }; } FI XYval asLogical() const { XYval o = asFloat(); toLogical(o); return o; } FI XYval asNative() const { XYval o = asFloat(); toNative(o); return o; } @@ -325,8 +327,8 @@ struct XYZval { FI XYZval asLong() const { return { int32_t(x), int32_t(y), int32_t(z) }; } FI XYZval ROUNDL() { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)) }; } FI XYZval ROUNDL() const { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)) }; } - FI XYZval asFloat() { return { float(x), float(y), float(z) }; } - FI XYZval asFloat() const { return { float(x), float(y), float(z) }; } + FI XYZval asFloat() { return { static_cast(x), static_cast(y), static_cast(z) }; } + FI XYZval asFloat() const { return { static_cast(x), static_cast(y), static_cast(z) }; } FI XYZval reciprocal() const { return { _RECIP(x), _RECIP(y), _RECIP(z) }; } FI XYZval asLogical() const { XYZval o = asFloat(); toLogical(o); return o; } FI XYZval asNative() const { XYZval o = asFloat(); toNative(o); return o; } @@ -436,8 +438,8 @@ struct XYZEval { FI XYZEval asLong() const { return { int32_t(x), int32_t(y), int32_t(z), int32_t(e) }; } FI XYZEval ROUNDL() { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)), int32_t(LROUND(e)) }; } FI XYZEval ROUNDL() const { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)), int32_t(LROUND(e)) }; } - FI XYZEval asFloat() { return { float(x), float(y), float(z), float(e) }; } - FI XYZEval asFloat() const { return { float(x), float(y), float(z), float(e) }; } + FI XYZEval asFloat() { return { static_cast(x), static_cast(y), static_cast(z), static_cast(e) }; } + FI XYZEval asFloat() const { return { static_cast(x), static_cast(y), static_cast(z), static_cast(e) }; } FI XYZEval reciprocal() const { return { _RECIP(x), _RECIP(y), _RECIP(z), _RECIP(e) }; } FI XYZEval asLogical() const { XYZEval o = asFloat(); toLogical(o); return o; } FI XYZEval asNative() const { XYZEval o = asFloat(); toNative(o); return o; } diff --git a/Marlin/src/feature/probe_temp_comp.cpp b/Marlin/src/feature/probe_temp_comp.cpp index b0867817b..68e669224 100644 --- a/Marlin/src/feature/probe_temp_comp.cpp +++ b/Marlin/src/feature/probe_temp_comp.cpp @@ -52,7 +52,7 @@ const temp_calib_t ProbeTempComp::cali_info[TSI_COUNT] = { constexpr xyz_pos_t ProbeTempComp::park_point; constexpr xy_pos_t ProbeTempComp::measure_point; -constexpr int ProbeTempComp::probe_calib_bed_temp; +constexpr celsius_t ProbeTempComp::probe_calib_bed_temp; uint8_t ProbeTempComp::calib_idx; // = 0 float ProbeTempComp::init_measurement; // = 0.0 @@ -126,7 +126,7 @@ bool ProbeTempComp::finish_calibration(const TempSensorID tsi) { SERIAL_ECHOPGM("Applying linear extrapolation"); calib_idx--; for (; calib_idx < measurements; ++calib_idx) { - const float temp = start_temp + float(calib_idx) * res_temp; + const celsius_float_t temp = start_temp + float(calib_idx) * res_temp; data[calib_idx] = static_cast(k * temp + d); } } @@ -174,7 +174,7 @@ float ProbeTempComp::get_offset_for_temperature(const TempSensorID tsi, const_fl return xy_float_t({start_temp + i*res_temp, static_cast(data[i])}); }; - auto linear_interp = [](float x, xy_float_t p1, xy_float_t p2) { + auto linear_interp = [](const_float_t x, xy_float_t p1, xy_float_t p2) { return (p2.y - p1.y) / (p2.x - p2.y) * (x - p1.x) + p1.y; }; diff --git a/Marlin/src/feature/probe_temp_comp.h b/Marlin/src/feature/probe_temp_comp.h index e29da7ece..5fb637a17 100644 --- a/Marlin/src/feature/probe_temp_comp.h +++ b/Marlin/src/feature/probe_temp_comp.h @@ -100,8 +100,8 @@ class ProbeTempComp { static constexpr xy_pos_t measure_point = PTC_PROBE_POS; // Coordinates to probe //measure_point = { 12.0f, 7.3f }; // Coordinates for the MK52 magnetic heatbed - static constexpr int probe_calib_bed_temp = BED_MAX_TARGET, // Bed temperature while calibrating probe - bed_calib_probe_temp = BTC_PROBE_TEMP; // Probe temperature while calibrating bed + static constexpr celsius_t probe_calib_bed_temp = BED_MAX_TARGET, // Bed temperature while calibrating probe + bed_calib_probe_temp = BTC_PROBE_TEMP; // Probe temperature while calibrating bed static int16_t *sensor_z_offsets[TSI_COUNT], z_offsets_probe[cali_info_init[TSI_PROBE].measurements], // (µm) diff --git a/Marlin/src/gcode/calibrate/G76_M192_M871.cpp b/Marlin/src/gcode/calibrate/G76_M192_M871.cpp index 8cfe6fee7..9fc30b794 100644 --- a/Marlin/src/gcode/calibrate/G76_M192_M871.cpp +++ b/Marlin/src/gcode/calibrate/G76_M192_M871.cpp @@ -110,7 +110,7 @@ void GcodeSuite::G76() { return false; }; - auto g76_probe = [](const TempSensorID sid, uint16_t &targ, const xy_pos_t &nozpos) { + auto g76_probe = [](const TempSensorID sid, celsius_t &targ, const xy_pos_t &nozpos) { do_z_clearance(5.0); // Raise nozzle before probing const float measured_z = probe.probe_at_point(nozpos, PROBE_PT_STOW, 0, false); // verbose=0, probe_relative=false if (isnan(measured_z)) @@ -170,14 +170,14 @@ void GcodeSuite::G76() { // Report temperatures every second and handle heating timeouts millis_t next_temp_report = millis() + 1000; - auto report_targets = [&](const uint16_t tb, const uint16_t tp) { + auto report_targets = [&](const celsius_t tb, const celsius_t tp) { SERIAL_ECHOLNPAIR("Target Bed:", tb, " Probe:", tp); }; if (do_bed_cal) { - uint16_t target_bed = cali_info_init[TSI_BED].start_temp, - target_probe = temp_comp.bed_calib_probe_temp; + celsius_t target_bed = cali_info_init[TSI_BED].start_temp, + target_probe = temp_comp.bed_calib_probe_temp; say_waiting_for(); SERIAL_ECHOLNPGM(" cooling."); while (thermalManager.degBed() > target_bed || thermalManager.degProbe() > target_probe) @@ -236,10 +236,10 @@ void GcodeSuite::G76() { do_blocking_move_to(parkpos); // Initialize temperatures - const uint16_t target_bed = temp_comp.probe_calib_bed_temp; + const celsius_t target_bed = temp_comp.probe_calib_bed_temp; thermalManager.setTargetBed(target_bed); - uint16_t target_probe = cali_info_init[TSI_PROBE].start_temp; + celsius_t target_probe = cali_info_init[TSI_PROBE].start_temp; report_targets(target_bed, target_probe); diff --git a/Marlin/src/gcode/temp/M303.cpp b/Marlin/src/gcode/temp/M303.cpp index 0934e04e7..e49381cdf 100644 --- a/Marlin/src/gcode/temp/M303.cpp +++ b/Marlin/src/gcode/temp/M303.cpp @@ -57,7 +57,7 @@ void GcodeSuite::M303() { #endif const heater_id_t hid = (heater_id_t)parser.intval('E'); - int16_t default_temp; + celsius_t default_temp; switch (hid) { #if ENABLED(PIDTEMP) case 0 ... HOTENDS - 1: default_temp = PREHEAT_1_TEMP_HOTEND; break; @@ -74,7 +74,7 @@ void GcodeSuite::M303() { return; } - const int16_t temp = parser.celsiusval('S', default_temp); + const celsius_t temp = parser.celsiusval('S', default_temp); const int c = parser.intval('C', 5); const bool u = parser.boolval('U'); diff --git a/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp b/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp index 08160d52f..ee8f18cd8 100644 --- a/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp +++ b/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp @@ -373,10 +373,9 @@ int8_t ChironTFT::FindToken(char c) { void ChironTFT::CheckHeaters() { uint8_t faultDuration = 0; - float temp = 0; // if the hotend temp is abnormal, confirm state before signalling panel - temp = getActualTemp_celsius(E0); + celsius_float_t temp = getActualTemp_celsius(E0); while (!WITHIN(temp, HEATER_0_MINTEMP, HEATER_0_MAXTEMP)) { faultDuration++; if (faultDuration >= AC_HEATER_FAULT_VALIDATION_TIME) { diff --git a/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp b/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp index ecc516108..acd4d202b 100644 --- a/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp +++ b/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp @@ -534,6 +534,8 @@ void AnycubicTFTClass::OnPrintTimerStopped() { #endif } +#define ROUND(val) int((val)+0.5f) + void AnycubicTFTClass::GetCommandFromTFT() { char *starpos = nullptr; while (LCD_SERIAL.available() > 0 && TFTbuflen < TFTBUFSIZE) { @@ -560,26 +562,26 @@ void AnycubicTFTClass::GetCommandFromTFT() { switch (a_command) { case 0: { // A0 GET HOTEND TEMP - const float hotendActualTemp = getActualTemp_celsius(E0); - SEND_PGM_VAL("A0V ", int(hotendActualTemp + 0.5)); + const celsius_float_t hotendActualTemp = getActualTemp_celsius(E0); + SEND_PGM_VAL("A0V ", ROUND(hotendActualTemp)); } break; case 1: { // A1 GET HOTEND TARGET TEMP - const float hotendTargetTemp = getTargetTemp_celsius(E0); - SEND_PGM_VAL("A1V ", int(hotendTargetTemp + 0.5)); + const celsius_float_t hotendTargetTemp = getTargetTemp_celsius(E0); + SEND_PGM_VAL("A1V ", ROUND(hotendTargetTemp)); } break; case 2: { // A2 GET HOTBED TEMP - const float heatedBedActualTemp = getActualTemp_celsius(BED); - SEND_PGM_VAL("A2V ", int(heatedBedActualTemp + 0.5)); + const celsius_float_t heatedBedActualTemp = getActualTemp_celsius(BED); + SEND_PGM_VAL("A2V ", ROUND(heatedBedActualTemp)); } break; case 3: { // A3 GET HOTBED TARGET TEMP - const float heatedBedTargetTemp = getTargetTemp_celsius(BED); - SEND_PGM_VAL("A3V ", int(heatedBedTargetTemp + 0.5)); + const celsius_float_t heatedBedTargetTemp = getTargetTemp_celsius(BED); + SEND_PGM_VAL("A3V ", ROUND(heatedBedTargetTemp)); } break; case 4: { // A4 GET FAN SPEED diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/string_format.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/string_format.cpp index c3114a392..ac423c2d0 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/string_format.cpp +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/string_format.cpp @@ -33,28 +33,28 @@ /** * Formats a temperature string (e.g. "100°C") */ -void format_temp(char *str, float t1) { +void format_temp(char *str, const_celsius_float_t t1) { sprintf_P(str, PSTR("%3d" S_FMT), ROUND(t1), GET_TEXT(MSG_UNITS_C)); } /** * Formats a temperature string for an idle heater (e.g. "100 °C / idle") */ -void format_temp_and_idle(char *str, float t1) { +void format_temp_and_idle(char *str, const_celsius_float_t t1) { sprintf_P(str, PSTR("%3d" S_FMT " / " S_FMT), ROUND(t1), GET_TEXT(MSG_UNITS_C), GET_TEXT(MSG_IDLE)); } /** * Formats a temperature string for an active heater (e.g. "100 / 200°C") */ -void format_temp_and_temp(char *str, float t1, float t2) { +void format_temp_and_temp(char *str, const_celsius_float_t t1, const_celsius_float_t t2) { sprintf_P(str, PSTR("%3d / %3d" S_FMT), ROUND(t1), ROUND(t2), GET_TEXT(MSG_UNITS_C)); } /** * Formats a temperature string for a material (e.g. "100°C (PLA)") */ -void format_temp_and_material(char *str, float t1, const char *material) { +void format_temp_and_material(char *str, const_celsius_float_t t1, const char *material) { sprintf_P(str, PSTR("%3d" S_FMT " (" S_FMT ")"), ROUND(t1), GET_TEXT(MSG_UNITS_C), material); } diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/string_format.h b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/string_format.h index 545c70170..44583f08e 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/string_format.h +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/string_format.h @@ -21,9 +21,9 @@ #pragma once -void format_temp(char *str, float t1); -void format_temp_and_idle(char *str, float t1); -void format_temp_and_temp(char *str, float t1, float t2); -void format_temp_and_material(char *str, float t1, const char *material); +void format_temp(char *str, const_celsius_float_t t1); +void format_temp_and_idle(char *str, const_celsius_float_t t1); +void format_temp_and_temp(char *str, const_celsius_float_t t1, const_celsius_float_t t2); +void format_temp_and_material(char *str, const_celsius_float_t t1, const char *material); void format_position(char *str, float p, uint8_t decimals = 1); void format_position(char *str, float x, float y, float z); diff --git a/Marlin/src/lcd/extui/lib/nextion/nextion_tft.cpp b/Marlin/src/lcd/extui/lib/nextion/nextion_tft.cpp index 3cd99b316..679f66d80 100644 --- a/Marlin/src/lcd/extui/lib/nextion/nextion_tft.cpp +++ b/Marlin/src/lcd/extui/lib/nextion/nextion_tft.cpp @@ -595,8 +595,8 @@ void NextionTFT::PanelAction(uint8_t req) { void NextionTFT::UpdateOnChange() { const millis_t ms = millis(); static millis_t next_event_ms = 0; - static float last_degBed = 999, last_degHotend0 = 999, last_degHotend1 = 999, - last_degTargetBed = 999, last_degTargetHotend0 = 999, last_degTargetHotend1 = 999; + static celsius_float_t last_degBed = 999, last_degHotend0 = 999, last_degHotend1 = 999, + last_degTargetBed = 999, last_degTargetHotend0 = 999, last_degTargetHotend1 = 999; // tmppage Temperature if (!WITHIN(last_degHotend0 - getActualTemp_celsius(E0), -0.2, 0.2) || !WITHIN(last_degTargetHotend0 - getTargetTemp_celsius(E0), -0.5, 0.5)) { diff --git a/Marlin/src/lcd/extui/ui_api.cpp b/Marlin/src/lcd/extui/ui_api.cpp index 66bc10c41..c2f51b326 100644 --- a/Marlin/src/lcd/extui/ui_api.cpp +++ b/Marlin/src/lcd/extui/ui_api.cpp @@ -263,7 +263,7 @@ namespace ExtUI { #define GET_TEMP_ADJUSTMENT(A) A #endif - float getActualTemp_celsius(const heater_t heater) { + celsius_float_t getActualTemp_celsius(const heater_t heater) { switch (heater) { #if ENABLED(HAS_HEATED_BED) case BED: return GET_TEMP_ADJUSTMENT(thermalManager.degBed()); @@ -275,11 +275,11 @@ namespace ExtUI { } } - float getActualTemp_celsius(const extruder_t extruder) { + celsius_float_t getActualTemp_celsius(const extruder_t extruder) { return GET_TEMP_ADJUSTMENT(thermalManager.degHotend(extruder - E0)); } - float getTargetTemp_celsius(const heater_t heater) { + celsius_float_t getTargetTemp_celsius(const heater_t heater) { switch (heater) { #if ENABLED(HAS_HEATED_BED) case BED: return GET_TEMP_ADJUSTMENT(thermalManager.degTargetBed()); @@ -291,7 +291,7 @@ namespace ExtUI { } } - float getTargetTemp_celsius(const extruder_t extruder) { + celsius_float_t getTargetTemp_celsius(const extruder_t extruder) { return GET_TEMP_ADJUSTMENT(thermalManager.degTargetHotend(extruder - E0)); } diff --git a/Marlin/src/lcd/extui/ui_api.h b/Marlin/src/lcd/extui/ui_api.h index c59fe0bd1..bd017c6bd 100644 --- a/Marlin/src/lcd/extui/ui_api.h +++ b/Marlin/src/lcd/extui/ui_api.h @@ -109,10 +109,10 @@ namespace ExtUI { void setTMCBumpSensitivity(const_float_t , const axis_t); #endif - float getActualTemp_celsius(const heater_t); - float getActualTemp_celsius(const extruder_t); - float getTargetTemp_celsius(const heater_t); - float getTargetTemp_celsius(const extruder_t); + celsius_float_t getActualTemp_celsius(const heater_t); + celsius_float_t getActualTemp_celsius(const extruder_t); + celsius_float_t getTargetTemp_celsius(const heater_t); + celsius_float_t getTargetTemp_celsius(const extruder_t); float getTargetFan_percent(const fan_t); float getActualFan_percent(const fan_t); float getAxisPosition_mm(const axis_t); diff --git a/Marlin/src/module/probe.cpp b/Marlin/src/module/probe.cpp index d4b8409ef..910db87f5 100644 --- a/Marlin/src/module/probe.cpp +++ b/Marlin/src/module/probe.cpp @@ -352,7 +352,7 @@ FORCE_INLINE void probe_specific_action(const bool deploy) { * - If a preheat input is higher than the current target, raise the target temperature. * - If a preheat input is higher than the current temperature, wait for stabilization. */ - void Probe::preheat_for_probing(const int16_t hotend_temp, const int16_t bed_temp) { + void Probe::preheat_for_probing(const celsius_t hotend_temp, const celsius_t bed_temp) { #if HAS_HOTEND && (PROBING_NOZZLE_TEMP || LEVELING_NOZZLE_TEMP) #define WAIT_FOR_NOZZLE_HEAT #endif @@ -363,17 +363,17 @@ FORCE_INLINE void probe_specific_action(const bool deploy) { DEBUG_ECHOPGM("Preheating "); #if ENABLED(WAIT_FOR_NOZZLE_HEAT) - const int16_t hotendPreheat = hotend_temp > thermalManager.degTargetHotend(0) ? hotend_temp : 0; + const celsius_t hotendPreheat = hotend_temp > thermalManager.degTargetHotend(0) ? hotend_temp : 0; if (hotendPreheat) { DEBUG_ECHOPAIR("hotend (", hotendPreheat, ")"); thermalManager.setTargetHotend(hotendPreheat, 0); } #elif ENABLED(WAIT_FOR_BED_HEAT) - constexpr int16_t hotendPreheat = 0; + constexpr celsius_t hotendPreheat = 0; #endif #if ENABLED(WAIT_FOR_BED_HEAT) - const int16_t bedPreheat = bed_temp > thermalManager.degTargetBed() ? bed_temp : 0; + const celsius_t bedPreheat = bed_temp > thermalManager.degTargetBed() ? bed_temp : 0; if (bedPreheat) { if (hotendPreheat) DEBUG_ECHOPGM(" and "); DEBUG_ECHOPAIR("bed (", bedPreheat, ")"); diff --git a/Marlin/src/module/probe.h b/Marlin/src/module/probe.h index 75aba76ef..7438a5661 100644 --- a/Marlin/src/module/probe.h +++ b/Marlin/src/module/probe.h @@ -61,7 +61,7 @@ public: static xyz_pos_t offset; #if EITHER(PREHEAT_BEFORE_PROBING, PREHEAT_BEFORE_LEVELING) - static void preheat_for_probing(const int16_t hotend_temp, const int16_t bed_temp); + static void preheat_for_probing(const celsius_t hotend_temp, const celsius_t bed_temp); #endif static bool set_deployed(const bool deploy); diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 08583676d..cd93ec1fc 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -382,7 +382,7 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY, chamber_info_t Temperature::temp_chamber; // = { 0 } #if HAS_HEATED_CHAMBER millis_t next_cool_check_ms_2 = 0; - float old_temp = 9999; + celsius_float_t old_temp = 9999; 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}); @@ -395,7 +395,7 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY, #if HAS_COOLER bool flag_cooler_state; //bool flag_cooler_excess = false; - float previous_temp = 9999; + celsius_float_t previous_temp = 9999; 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 @@ -421,8 +421,8 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY, #endif #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT) - celsius_t Temperature::redundant_temperature_raw = 0; - float Temperature::redundant_temperature = 0.0; + int16_t Temperature::redundant_temperature_raw = 0; + celsius_float_t Temperature::redundant_temperature = 0.0; #endif volatile bool Temperature::raw_temps_ready = false; @@ -508,7 +508,7 @@ volatile bool Temperature::raw_temps_ready = false; long t_high = 0, t_low = 0; PID_t tune_pid = { 0, 0, 0 }; - float maxT = 0, minT = 10000; + celsius_float_t maxT = 0, minT = 10000; const bool isbed = (heater_id == H_BED); const bool ischamber = (heater_id == H_CHAMBER); @@ -544,9 +544,9 @@ volatile bool Temperature::raw_temps_ready = false; #define GTV(C,B,H) C_GTV(ischamber, C, B_GTV(isbed, B, H)) const uint16_t watch_temp_period = GTV(WATCH_CHAMBER_TEMP_PERIOD, WATCH_BED_TEMP_PERIOD, WATCH_TEMP_PERIOD); const uint8_t watch_temp_increase = GTV(WATCH_CHAMBER_TEMP_INCREASE, WATCH_BED_TEMP_INCREASE, WATCH_TEMP_INCREASE); - const float watch_temp_target = target - float(watch_temp_increase + GTV(TEMP_CHAMBER_HYSTERESIS, TEMP_BED_HYSTERESIS, TEMP_HYSTERESIS) + 1); + const celsius_float_t watch_temp_target = celsius_float_t(target - watch_temp_increase + GTV(TEMP_CHAMBER_HYSTERESIS, TEMP_BED_HYSTERESIS, TEMP_HYSTERESIS) + 1); millis_t temp_change_ms = next_temp_ms + SEC_TO_MS(watch_temp_period); - float next_watch_temp = 0.0; + celsius_float_t next_watch_temp = 0.0; bool heated = false; #endif @@ -567,7 +567,7 @@ volatile bool Temperature::raw_temps_ready = false; SHV(bias); #if ENABLED(PRINTER_EVENT_LEDS) - const float start_temp = GHV(temp_chamber.celsius, temp_bed.celsius, temp_hotend[heater_id].celsius); + const celsius_float_t start_temp = GHV(temp_chamber.celsius, temp_bed.celsius, temp_hotend[heater_id].celsius); LEDColor color = ONHEATINGSTART(); #endif @@ -2338,7 +2338,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 current, const_float_t target, const heater_id_t heater_id, const uint16_t period_seconds, const celsius_t hysteresis_degc) { + void Temperature::tr_state_machine_t::run(const_celsius_float_t current, const_celsius_float_t 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 @@ -3373,7 +3373,16 @@ void Temperature::isr() { #include "../gcode/gcode.h" - static void print_heater_state(const_float_t c, const_float_t t + /** + * Print a single heater state in the form: + * Bed: " B:nnn.nn /nnn.nn" + * Chamber: " C:nnn.nn /nnn.nn" + * Probe: " P:nnn.nn /nnn.nn" + * Cooler: " L:nnn.nn /nnn.nn" + * Extruder: " T0:nnn.nn /nnn.nn" + * With ADC: " T0:nnn.nn /nnn.nn (nnn.nn)" + */ + static void print_heater_state(const_celsius_float_t c, const_celsius_float_t t #if ENABLED(SHOW_TEMP_ADC_VALUES) , const float r #endif @@ -3557,12 +3566,12 @@ void Temperature::isr() { #endif #if ENABLED(PRINTER_EVENT_LEDS) - const float start_temp = degHotend(target_extruder); + const celsius_float_t start_temp = degHotend(target_extruder); printerEventLEDs.onHotendHeatingStart(); #endif bool wants_to_cool = false; - float target_temp = -1.0, old_temp = 9999.0; + celsius_float_t target_temp = -1.0, old_temp = 9999.0; millis_t now, next_temp_ms = 0, next_cool_check_ms = 0; wait_for_heatup = true; do { @@ -3592,7 +3601,7 @@ void Temperature::isr() { idle(); gcode.reset_stepper_timeout(); // Keep steppers powered - const float temp = degHotend(target_extruder); + const celsius_float_t temp = degHotend(target_extruder); #if ENABLED(PRINTER_EVENT_LEDS) // Gradually change LED strip from violet to red as nozzle heats up @@ -3601,7 +3610,7 @@ void Temperature::isr() { #if TEMP_RESIDENCY_TIME > 0 - const float temp_diff = ABS(target_temp - temp); + const celsius_float_t temp_diff = ABS(target_temp - temp); if (!residency_start_ms) { // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time. @@ -3695,12 +3704,12 @@ void Temperature::isr() { #endif #if ENABLED(PRINTER_EVENT_LEDS) - const float start_temp = degBed(); + const celsius_float_t start_temp = degBed(); printerEventLEDs.onBedHeatingStart(); #endif bool wants_to_cool = false; - float target_temp = -1, old_temp = 9999; + celsius_float_t target_temp = -1, old_temp = 9999; millis_t now, next_temp_ms = 0, next_cool_check_ms = 0; wait_for_heatup = true; do { @@ -3730,7 +3739,7 @@ void Temperature::isr() { idle(); gcode.reset_stepper_timeout(); // Keep steppers powered - const float temp = degBed(); + const celsius_float_t temp = degBed(); #if ENABLED(PRINTER_EVENT_LEDS) // Gradually change LED strip from blue to violet as bed heats up @@ -3739,7 +3748,7 @@ void Temperature::isr() { #if TEMP_BED_RESIDENCY_TIME > 0 - const float temp_diff = ABS(target_temp - temp); + const celsius_float_t temp_diff = ABS(target_temp - temp); if (!residency_start_ms) { // Start the TEMP_BED_RESIDENCY_TIME timer when we reach target temp for the first time. @@ -4021,11 +4030,11 @@ void Temperature::isr() { idle(); gcode.reset_stepper_timeout(); // Keep steppers powered - const float current_temp = degCooler(); + const celsius_float_t current_temp = degCooler(); #if TEMP_COOLER_RESIDENCY_TIME > 0 - const float temp_diff = ABS(target_temp - temp); + const celsius_float_t temp_diff = ABS(target_temp - temp); if (!residency_start_ms) { // Start the TEMP_COOLER_RESIDENCY_TIME timer when we reach target temp for the first time. diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index d2b3db874..033573392 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -961,7 +961,7 @@ class Temperature { millis_t timer = 0; TRState state = TRInactive; float running_temp; - void run(const_float_t current, const_float_t target, const heater_id_t heater_id, const uint16_t period_seconds, const celsius_t hysteresis_degc); + void run(const_celsius_float_t current, const_celsius_float_t 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];