Skip to content

Commit

Permalink
Fix Celsius precision, current temp accessors (#21678)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhapsodyv authored and thinkyhead committed Apr 29, 2021
1 parent 899fcf5 commit 1570005
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
14 changes: 7 additions & 7 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
24 changes: 12 additions & 12 deletions Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<celsius_t>(degBed() + 0.5f); }
static inline celsius_t degTargetBed() { return temp_bed.target; }
static inline bool isHeatingBed() { return temp_bed.target > temp_bed.celsius; }
Expand Down Expand Up @@ -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<celsius_t>(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; }
Expand All @@ -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<celsius_t>(degChamber() + 0.5f); }
#if HAS_HEATED_CHAMBER
static inline celsius_t degTargetChamber() { return temp_chamber.target; }
Expand All @@ -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<celsius_t>(temp_cooler.celsius + 0.5f); }
#if HAS_COOLER
static inline celsius_t degTargetCooler() { return temp_cooler.target; }
Expand Down

0 comments on commit 1570005

Please sign in to comment.