From 46f272b66945e4f2fb6e191b83cebeaa57e496f5 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Fri, 23 Apr 2021 22:29:15 -0300 Subject: [PATCH] Fix Celsius precision, current temp accessors (#21678) --- Marlin/src/module/temperature.cpp | 14 +++++++------- Marlin/src/module/temperature.h | 24 ++++++++++++------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 3c8d55c630..8e2b2d6b91 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -500,7 +500,7 @@ volatile bool Temperature::raw_temps_ready = false; * temperature to succeed. */ void Temperature::PID_autotune(const celsius_t target, const heater_id_t heater_id, const int8_t ncycles, const bool set_result/*=false*/) { - float current_temp = 0.0; + celsius_float_t current_temp = 0.0; int cycles = 0; bool heating = true; @@ -1668,7 +1668,7 @@ void Temperature::manage_heater() { SERIAL_EOL(); } - celsius_t Temperature::user_thermistor_to_deg_c(const uint8_t t_index, const int raw) { + celsius_float_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; @@ -1717,7 +1717,7 @@ void Temperature::manage_heater() { #if HAS_HOTEND // Derived from RepRap FiveD extruder::getTemperature() // For hot end temperature measurement. - celsius_t Temperature::analog_to_celsius_hotend(const int raw, const uint8_t e) { + celsius_float_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); @@ -1826,7 +1826,7 @@ void Temperature::manage_heater() { #if HAS_HEATED_BED // For bed temperature measurement. - celsius_t Temperature::analog_to_celsius_bed(const int raw) { + celsius_float_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 @@ -1844,7 +1844,7 @@ void Temperature::manage_heater() { #if HAS_TEMP_CHAMBER // For chamber temperature measurement. - celsius_t Temperature::analog_to_celsius_chamber(const int raw) { + celsius_float_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 @@ -1862,7 +1862,7 @@ void Temperature::manage_heater() { #if HAS_TEMP_COOLER // For cooler temperature measurement. - celsius_t Temperature::analog_to_celsius_cooler(const int raw) { + celsius_float_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 @@ -1880,7 +1880,7 @@ void Temperature::manage_heater() { #if HAS_TEMP_PROBE // For probe temperature measurement. - celsius_t Temperature::analog_to_celsius_probe(const int raw) { + celsius_float_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 diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index a7d41b36f9..b7d52e8a08 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; - celsius_t celsius; + celsius_float_t celsius; inline void reset() { acc = 0; } inline void sample(const uint16_t s) { acc += s; } inline void update() { raw = acc; } @@ -501,7 +501,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 celsius_t user_thermistor_to_deg_c(const uint8_t t_index, const int raw); + static celsius_float_t user_thermistor_to_deg_c(const uint8_t t_index, const int raw); static inline 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; @@ -529,19 +529,19 @@ class Temperature { #endif #if HAS_HOTEND - static celsius_t analog_to_celsius_hotend(const int raw, const uint8_t e); + static celsius_float_t analog_to_celsius_hotend(const int raw, const uint8_t e); #endif #if HAS_HEATED_BED - static celsius_t analog_to_celsius_bed(const int raw); + static celsius_float_t analog_to_celsius_bed(const int raw); #endif #if HAS_TEMP_PROBE - static celsius_t analog_to_celsius_probe(const int raw); + static celsius_float_t analog_to_celsius_probe(const int raw); #endif #if HAS_TEMP_CHAMBER - static celsius_t analog_to_celsius_chamber(const int raw); + static celsius_float_t analog_to_celsius_chamber(const int raw); #endif #if HAS_TEMP_COOLER - static celsius_t analog_to_celsius_cooler(const int raw); + static celsius_float_t analog_to_celsius_cooler(const int raw); #endif #if HAS_FAN @@ -627,7 +627,7 @@ class Temperature { //inline so that there is no performance decrease. //deg=degreeCelsius - static inline celsius_t degHotend(const uint8_t E_NAME) { + static inline celsius_float_t degHotend(const uint8_t E_NAME) { return TERN0(HAS_HOTEND, temp_hotend[HOTEND_INDEX].celsius); } @@ -701,7 +701,7 @@ class Temperature { #if ENABLED(SHOW_TEMP_ADC_VALUES) static inline int16_t rawBedTemp() { return temp_bed.raw; } #endif - static inline celsius_t degBed() { return temp_bed.celsius; } + static inline celsius_float_t degBed() { return temp_bed.celsius; } static inline celsius_t wholeDegBed() { return static_cast(degBed() + 0.5f); } static inline celsius_t degTargetBed() { return temp_bed.target; } static inline bool isHeatingBed() { return temp_bed.target > temp_bed.celsius; } @@ -737,7 +737,7 @@ class Temperature { #if ENABLED(SHOW_TEMP_ADC_VALUES) static inline int16_t rawProbeTemp() { return temp_probe.raw; } #endif - static inline celsius_t degProbe() { return temp_probe.celsius; } + static inline celsius_float_t degProbe() { return temp_probe.celsius; } static inline celsius_t wholeDegProbe() { return static_cast(degProbe() + 0.5f); } static inline bool isProbeBelowTemp(const celsius_t target_temp) { return wholeDegProbe() < target_temp; } static inline bool isProbeAboveTemp(const celsius_t target_temp) { return wholeDegProbe() > target_temp; } @@ -754,7 +754,7 @@ class Temperature { #if ENABLED(SHOW_TEMP_ADC_VALUES) static inline int16_t rawChamberTemp() { return temp_chamber.raw; } #endif - static inline celsius_t degChamber() { return temp_chamber.celsius; } + static inline celsius_float_t degChamber() { return temp_chamber.celsius; } static inline celsius_t wholeDegChamber() { return static_cast(degChamber() + 0.5f); } #if HAS_HEATED_CHAMBER static inline celsius_t degTargetChamber() { return temp_chamber.target; } @@ -781,7 +781,7 @@ class Temperature { #if ENABLED(SHOW_TEMP_ADC_VALUES) static inline int16_t rawCoolerTemp() { return temp_cooler.raw; } #endif - static inline celsius_t degCooler() { return temp_cooler.celsius; } + static inline celsius_float_t degCooler() { return temp_cooler.celsius; } static inline celsius_t wholeDegCooler() { return static_cast(temp_cooler.celsius + 0.5f); } #if HAS_COOLER static inline celsius_t degTargetCooler() { return temp_cooler.target; }