Update temperature types

This commit is contained in:
Scott Lahteine 2021-04-23 19:14:49 -05:00 committed by Scott Lahteine
parent ecc419fce0
commit 4ab19e7882
16 changed files with 88 additions and 76 deletions

View File

@ -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 // For more resolition (e.g., for a chocolate printer) this may later be changed to Celsius x 100
// //
typedef int16_t celsius_t; typedef int16_t celsius_t;
typedef float celsius_float_t;
// //
// On AVR pointers are only 2 bytes so use 'const float &' for 'const float' // 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; typedef const float const_float_t;
#endif #endif
typedef const_float_t const_feedRate_t; typedef const_float_t const_feedRate_t;
typedef const_float_t const_celsius_float_t;
// Conversion macros // Conversion macros
#define MMM_TO_MMS(MM_M) feedRate_t(float(MM_M) / 60.0f) #define MMM_TO_MMS(MM_M) feedRate_t(static_cast<float>(MM_M) / 60.0f)
#define MMS_TO_MMM(MM_S) (float(MM_S) * 60.0f) #define MMS_TO_MMM(MM_S) (static_cast<float>(MM_S) * 60.0f)
// //
// Coordinates structures for XY, XYZ, XYZE... // Coordinates structures for XY, XYZ, XYZE...
// //
// Helpers // Helpers
#define _RECIP(N) ((N) ? 1.0f / float(N) : 0.0f) #define _RECIP(N) ((N) ? 1.0f / static_cast<float>(N) : 0.0f)
#define _ABS(N) ((N) < 0 ? -(N) : (N)) #define _ABS(N) ((N) < 0 ? -(N) : (N))
#define _LS(N) (N = (T)(uint32_t(N) << v)) #define _LS(N) (N = (T)(uint32_t(N) << v))
#define _RS(N) (N = (T)(uint32_t(N) >> v)) #define _RS(N) (N = (T)(uint32_t(N) >> v))
@ -214,8 +216,8 @@ struct XYval {
FI XYval<int32_t> asLong() const { return { int32_t(x), int32_t(y) }; } FI XYval<int32_t> asLong() const { return { int32_t(x), int32_t(y) }; }
FI XYval<int32_t> ROUNDL() { return { int32_t(LROUND(x)), int32_t(LROUND(y)) }; } FI XYval<int32_t> ROUNDL() { return { int32_t(LROUND(x)), int32_t(LROUND(y)) }; }
FI XYval<int32_t> ROUNDL() const { return { int32_t(LROUND(x)), int32_t(LROUND(y)) }; } FI XYval<int32_t> ROUNDL() const { return { int32_t(LROUND(x)), int32_t(LROUND(y)) }; }
FI XYval<float> asFloat() { return { float(x), float(y) }; } FI XYval<float> asFloat() { return { static_cast<float>(x), static_cast<float>(y) }; }
FI XYval<float> asFloat() const { return { float(x), float(y) }; } FI XYval<float> asFloat() const { return { static_cast<float>(x), static_cast<float>(y) }; }
FI XYval<float> reciprocal() const { return { _RECIP(x), _RECIP(y) }; } FI XYval<float> reciprocal() const { return { _RECIP(x), _RECIP(y) }; }
FI XYval<float> asLogical() const { XYval<float> o = asFloat(); toLogical(o); return o; } FI XYval<float> asLogical() const { XYval<float> o = asFloat(); toLogical(o); return o; }
FI XYval<float> asNative() const { XYval<float> o = asFloat(); toNative(o); return o; } FI XYval<float> asNative() const { XYval<float> o = asFloat(); toNative(o); return o; }
@ -325,8 +327,8 @@ struct XYZval {
FI XYZval<int32_t> asLong() const { return { int32_t(x), int32_t(y), int32_t(z) }; } FI XYZval<int32_t> asLong() const { return { int32_t(x), int32_t(y), int32_t(z) }; }
FI XYZval<int32_t> ROUNDL() { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)) }; } FI XYZval<int32_t> ROUNDL() { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)) }; }
FI XYZval<int32_t> ROUNDL() const { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)) }; } FI XYZval<int32_t> ROUNDL() const { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)) }; }
FI XYZval<float> asFloat() { return { float(x), float(y), float(z) }; } FI XYZval<float> asFloat() { return { static_cast<float>(x), static_cast<float>(y), static_cast<float>(z) }; }
FI XYZval<float> asFloat() const { return { float(x), float(y), float(z) }; } FI XYZval<float> asFloat() const { return { static_cast<float>(x), static_cast<float>(y), static_cast<float>(z) }; }
FI XYZval<float> reciprocal() const { return { _RECIP(x), _RECIP(y), _RECIP(z) }; } FI XYZval<float> reciprocal() const { return { _RECIP(x), _RECIP(y), _RECIP(z) }; }
FI XYZval<float> asLogical() const { XYZval<float> o = asFloat(); toLogical(o); return o; } FI XYZval<float> asLogical() const { XYZval<float> o = asFloat(); toLogical(o); return o; }
FI XYZval<float> asNative() const { XYZval<float> o = asFloat(); toNative(o); return o; } FI XYZval<float> asNative() const { XYZval<float> o = asFloat(); toNative(o); return o; }
@ -436,8 +438,8 @@ struct XYZEval {
FI XYZEval<int32_t> asLong() const { return { int32_t(x), int32_t(y), int32_t(z), int32_t(e) }; } FI XYZEval<int32_t> asLong() const { return { int32_t(x), int32_t(y), int32_t(z), int32_t(e) }; }
FI XYZEval<int32_t> ROUNDL() { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)), int32_t(LROUND(e)) }; } FI XYZEval<int32_t> ROUNDL() { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)), int32_t(LROUND(e)) }; }
FI XYZEval<int32_t> ROUNDL() const { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)), int32_t(LROUND(e)) }; } FI XYZEval<int32_t> ROUNDL() const { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)), int32_t(LROUND(e)) }; }
FI XYZEval<float> asFloat() { return { float(x), float(y), float(z), float(e) }; } FI XYZEval<float> asFloat() { return { static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), static_cast<float>(e) }; }
FI XYZEval<float> asFloat() const { return { float(x), float(y), float(z), float(e) }; } FI XYZEval<float> asFloat() const { return { static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), static_cast<float>(e) }; }
FI XYZEval<float> reciprocal() const { return { _RECIP(x), _RECIP(y), _RECIP(z), _RECIP(e) }; } FI XYZEval<float> reciprocal() const { return { _RECIP(x), _RECIP(y), _RECIP(z), _RECIP(e) }; }
FI XYZEval<float> asLogical() const { XYZEval<float> o = asFloat(); toLogical(o); return o; } FI XYZEval<float> asLogical() const { XYZEval<float> o = asFloat(); toLogical(o); return o; }
FI XYZEval<float> asNative() const { XYZEval<float> o = asFloat(); toNative(o); return o; } FI XYZEval<float> asNative() const { XYZEval<float> o = asFloat(); toNative(o); return o; }

View File

@ -52,7 +52,7 @@ const temp_calib_t ProbeTempComp::cali_info[TSI_COUNT] = {
constexpr xyz_pos_t ProbeTempComp::park_point; constexpr xyz_pos_t ProbeTempComp::park_point;
constexpr xy_pos_t ProbeTempComp::measure_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 uint8_t ProbeTempComp::calib_idx; // = 0
float ProbeTempComp::init_measurement; // = 0.0 float ProbeTempComp::init_measurement; // = 0.0
@ -126,7 +126,7 @@ bool ProbeTempComp::finish_calibration(const TempSensorID tsi) {
SERIAL_ECHOPGM("Applying linear extrapolation"); SERIAL_ECHOPGM("Applying linear extrapolation");
calib_idx--; calib_idx--;
for (; calib_idx < measurements; ++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<int16_t>(k * temp + d); data[calib_idx] = static_cast<int16_t>(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<float>(data[i])}); return xy_float_t({start_temp + i*res_temp, static_cast<float>(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; return (p2.y - p1.y) / (p2.x - p2.y) * (x - p1.x) + p1.y;
}; };

View File

@ -100,7 +100,7 @@ class ProbeTempComp {
static constexpr xy_pos_t measure_point = PTC_PROBE_POS; // Coordinates to probe 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 //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 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 bed_calib_probe_temp = BTC_PROBE_TEMP; // Probe temperature while calibrating bed
static int16_t *sensor_z_offsets[TSI_COUNT], static int16_t *sensor_z_offsets[TSI_COUNT],

View File

@ -110,7 +110,7 @@ void GcodeSuite::G76() {
return false; 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 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 const float measured_z = probe.probe_at_point(nozpos, PROBE_PT_STOW, 0, false); // verbose=0, probe_relative=false
if (isnan(measured_z)) if (isnan(measured_z))
@ -170,13 +170,13 @@ void GcodeSuite::G76() {
// Report temperatures every second and handle heating timeouts // Report temperatures every second and handle heating timeouts
millis_t next_temp_report = millis() + 1000; 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); SERIAL_ECHOLNPAIR("Target Bed:", tb, " Probe:", tp);
}; };
if (do_bed_cal) { if (do_bed_cal) {
uint16_t target_bed = cali_info_init[TSI_BED].start_temp, celsius_t target_bed = cali_info_init[TSI_BED].start_temp,
target_probe = temp_comp.bed_calib_probe_temp; target_probe = temp_comp.bed_calib_probe_temp;
say_waiting_for(); SERIAL_ECHOLNPGM(" cooling."); say_waiting_for(); SERIAL_ECHOLNPGM(" cooling.");
@ -236,10 +236,10 @@ void GcodeSuite::G76() {
do_blocking_move_to(parkpos); do_blocking_move_to(parkpos);
// Initialize temperatures // 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); 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); report_targets(target_bed, target_probe);

View File

@ -57,7 +57,7 @@ void GcodeSuite::M303() {
#endif #endif
const heater_id_t hid = (heater_id_t)parser.intval('E'); const heater_id_t hid = (heater_id_t)parser.intval('E');
int16_t default_temp; celsius_t default_temp;
switch (hid) { switch (hid) {
#if ENABLED(PIDTEMP) #if ENABLED(PIDTEMP)
case 0 ... HOTENDS - 1: default_temp = PREHEAT_1_TEMP_HOTEND; break; case 0 ... HOTENDS - 1: default_temp = PREHEAT_1_TEMP_HOTEND; break;
@ -74,7 +74,7 @@ void GcodeSuite::M303() {
return; 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 int c = parser.intval('C', 5);
const bool u = parser.boolval('U'); const bool u = parser.boolval('U');

View File

@ -373,10 +373,9 @@ int8_t ChironTFT::FindToken(char c) {
void ChironTFT::CheckHeaters() { void ChironTFT::CheckHeaters() {
uint8_t faultDuration = 0; uint8_t faultDuration = 0;
float temp = 0;
// if the hotend temp is abnormal, confirm state before signalling panel // 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)) { while (!WITHIN(temp, HEATER_0_MINTEMP, HEATER_0_MAXTEMP)) {
faultDuration++; faultDuration++;
if (faultDuration >= AC_HEATER_FAULT_VALIDATION_TIME) { if (faultDuration >= AC_HEATER_FAULT_VALIDATION_TIME) {

View File

@ -534,6 +534,8 @@ void AnycubicTFTClass::OnPrintTimerStopped() {
#endif #endif
} }
#define ROUND(val) int((val)+0.5f)
void AnycubicTFTClass::GetCommandFromTFT() { void AnycubicTFTClass::GetCommandFromTFT() {
char *starpos = nullptr; char *starpos = nullptr;
while (LCD_SERIAL.available() > 0 && TFTbuflen < TFTBUFSIZE) { while (LCD_SERIAL.available() > 0 && TFTbuflen < TFTBUFSIZE) {
@ -560,26 +562,26 @@ void AnycubicTFTClass::GetCommandFromTFT() {
switch (a_command) { switch (a_command) {
case 0: { // A0 GET HOTEND TEMP case 0: { // A0 GET HOTEND TEMP
const float hotendActualTemp = getActualTemp_celsius(E0); const celsius_float_t hotendActualTemp = getActualTemp_celsius(E0);
SEND_PGM_VAL("A0V ", int(hotendActualTemp + 0.5)); SEND_PGM_VAL("A0V ", ROUND(hotendActualTemp));
} }
break; break;
case 1: { // A1 GET HOTEND TARGET TEMP case 1: { // A1 GET HOTEND TARGET TEMP
const float hotendTargetTemp = getTargetTemp_celsius(E0); const celsius_float_t hotendTargetTemp = getTargetTemp_celsius(E0);
SEND_PGM_VAL("A1V ", int(hotendTargetTemp + 0.5)); SEND_PGM_VAL("A1V ", ROUND(hotendTargetTemp));
} }
break; break;
case 2: { // A2 GET HOTBED TEMP case 2: { // A2 GET HOTBED TEMP
const float heatedBedActualTemp = getActualTemp_celsius(BED); const celsius_float_t heatedBedActualTemp = getActualTemp_celsius(BED);
SEND_PGM_VAL("A2V ", int(heatedBedActualTemp + 0.5)); SEND_PGM_VAL("A2V ", ROUND(heatedBedActualTemp));
} }
break; break;
case 3: { // A3 GET HOTBED TARGET TEMP case 3: { // A3 GET HOTBED TARGET TEMP
const float heatedBedTargetTemp = getTargetTemp_celsius(BED); const celsius_float_t heatedBedTargetTemp = getTargetTemp_celsius(BED);
SEND_PGM_VAL("A3V ", int(heatedBedTargetTemp + 0.5)); SEND_PGM_VAL("A3V ", ROUND(heatedBedTargetTemp));
} break; } break;
case 4: { // A4 GET FAN SPEED case 4: { // A4 GET FAN SPEED

View File

@ -33,28 +33,28 @@
/** /**
* Formats a temperature string (e.g. "100°C") * 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)); 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") * 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)); 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") * 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)); 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)") * 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); sprintf_P(str, PSTR("%3d" S_FMT " (" S_FMT ")"), ROUND(t1), GET_TEXT(MSG_UNITS_C), material);
} }

View File

@ -21,9 +21,9 @@
#pragma once #pragma once
void format_temp(char *str, float t1); void format_temp(char *str, const_celsius_float_t t1);
void format_temp_and_idle(char *str, float t1); void format_temp_and_idle(char *str, const_celsius_float_t t1);
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);
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);
void format_position(char *str, float p, uint8_t decimals = 1); void format_position(char *str, float p, uint8_t decimals = 1);
void format_position(char *str, float x, float y, float z); void format_position(char *str, float x, float y, float z);

View File

@ -595,7 +595,7 @@ void NextionTFT::PanelAction(uint8_t req) {
void NextionTFT::UpdateOnChange() { void NextionTFT::UpdateOnChange() {
const millis_t ms = millis(); const millis_t ms = millis();
static millis_t next_event_ms = 0; static millis_t next_event_ms = 0;
static float last_degBed = 999, last_degHotend0 = 999, last_degHotend1 = 999, static celsius_float_t last_degBed = 999, last_degHotend0 = 999, last_degHotend1 = 999,
last_degTargetBed = 999, last_degTargetHotend0 = 999, last_degTargetHotend1 = 999; last_degTargetBed = 999, last_degTargetHotend0 = 999, last_degTargetHotend1 = 999;
// tmppage Temperature // tmppage Temperature

View File

@ -263,7 +263,7 @@ namespace ExtUI {
#define GET_TEMP_ADJUSTMENT(A) A #define GET_TEMP_ADJUSTMENT(A) A
#endif #endif
float getActualTemp_celsius(const heater_t heater) { celsius_float_t getActualTemp_celsius(const heater_t heater) {
switch (heater) { switch (heater) {
#if ENABLED(HAS_HEATED_BED) #if ENABLED(HAS_HEATED_BED)
case BED: return GET_TEMP_ADJUSTMENT(thermalManager.degBed()); 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)); 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) { switch (heater) {
#if ENABLED(HAS_HEATED_BED) #if ENABLED(HAS_HEATED_BED)
case BED: return GET_TEMP_ADJUSTMENT(thermalManager.degTargetBed()); 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)); return GET_TEMP_ADJUSTMENT(thermalManager.degTargetHotend(extruder - E0));
} }

View File

@ -109,10 +109,10 @@ namespace ExtUI {
void setTMCBumpSensitivity(const_float_t , const axis_t); void setTMCBumpSensitivity(const_float_t , const axis_t);
#endif #endif
float getActualTemp_celsius(const heater_t); celsius_float_t getActualTemp_celsius(const heater_t);
float getActualTemp_celsius(const extruder_t); celsius_float_t getActualTemp_celsius(const extruder_t);
float getTargetTemp_celsius(const heater_t); celsius_float_t getTargetTemp_celsius(const heater_t);
float getTargetTemp_celsius(const extruder_t); celsius_float_t getTargetTemp_celsius(const extruder_t);
float getTargetFan_percent(const fan_t); float getTargetFan_percent(const fan_t);
float getActualFan_percent(const fan_t); float getActualFan_percent(const fan_t);
float getAxisPosition_mm(const axis_t); float getAxisPosition_mm(const axis_t);

View File

@ -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 target, raise the target temperature.
* - If a preheat input is higher than the current temperature, wait for stabilization. * - 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) #if HAS_HOTEND && (PROBING_NOZZLE_TEMP || LEVELING_NOZZLE_TEMP)
#define WAIT_FOR_NOZZLE_HEAT #define WAIT_FOR_NOZZLE_HEAT
#endif #endif
@ -363,17 +363,17 @@ FORCE_INLINE void probe_specific_action(const bool deploy) {
DEBUG_ECHOPGM("Preheating "); DEBUG_ECHOPGM("Preheating ");
#if ENABLED(WAIT_FOR_NOZZLE_HEAT) #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) { if (hotendPreheat) {
DEBUG_ECHOPAIR("hotend (", hotendPreheat, ")"); DEBUG_ECHOPAIR("hotend (", hotendPreheat, ")");
thermalManager.setTargetHotend(hotendPreheat, 0); thermalManager.setTargetHotend(hotendPreheat, 0);
} }
#elif ENABLED(WAIT_FOR_BED_HEAT) #elif ENABLED(WAIT_FOR_BED_HEAT)
constexpr int16_t hotendPreheat = 0; constexpr celsius_t hotendPreheat = 0;
#endif #endif
#if ENABLED(WAIT_FOR_BED_HEAT) #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 (bedPreheat) {
if (hotendPreheat) DEBUG_ECHOPGM(" and "); if (hotendPreheat) DEBUG_ECHOPGM(" and ");
DEBUG_ECHOPAIR("bed (", bedPreheat, ")"); DEBUG_ECHOPAIR("bed (", bedPreheat, ")");

View File

@ -61,7 +61,7 @@ public:
static xyz_pos_t offset; static xyz_pos_t offset;
#if EITHER(PREHEAT_BEFORE_PROBING, PREHEAT_BEFORE_LEVELING) #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 #endif
static bool set_deployed(const bool deploy); static bool set_deployed(const bool deploy);

View File

@ -382,7 +382,7 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY,
chamber_info_t Temperature::temp_chamber; // = { 0 } chamber_info_t Temperature::temp_chamber; // = { 0 }
#if HAS_HEATED_CHAMBER #if HAS_HEATED_CHAMBER
millis_t next_cool_check_ms_2 = 0; 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, int16_t Temperature::mintemp_raw_CHAMBER = TEMP_SENSOR_CHAMBER_RAW_LO_TEMP,
Temperature::maxtemp_raw_CHAMBER = TEMP_SENSOR_CHAMBER_RAW_HI_TEMP; Temperature::maxtemp_raw_CHAMBER = TEMP_SENSOR_CHAMBER_RAW_HI_TEMP;
TERN_(WATCH_CHAMBER, chamber_watch_t Temperature::watch_chamber{0}); 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 #if HAS_COOLER
bool flag_cooler_state; bool flag_cooler_state;
//bool flag_cooler_excess = false; //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, int16_t Temperature::mintemp_raw_COOLER = TEMP_SENSOR_COOLER_RAW_LO_TEMP,
Temperature::maxtemp_raw_COOLER = TEMP_SENSOR_COOLER_RAW_HI_TEMP; Temperature::maxtemp_raw_COOLER = TEMP_SENSOR_COOLER_RAW_HI_TEMP;
#if WATCH_COOLER #if WATCH_COOLER
@ -421,8 +421,8 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY,
#endif #endif
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT) #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
celsius_t Temperature::redundant_temperature_raw = 0; int16_t Temperature::redundant_temperature_raw = 0;
float Temperature::redundant_temperature = 0.0; celsius_float_t Temperature::redundant_temperature = 0.0;
#endif #endif
volatile bool Temperature::raw_temps_ready = false; 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; long t_high = 0, t_low = 0;
PID_t tune_pid = { 0, 0, 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 isbed = (heater_id == H_BED);
const bool ischamber = (heater_id == H_CHAMBER); 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)) #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 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 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); 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; bool heated = false;
#endif #endif
@ -567,7 +567,7 @@ volatile bool Temperature::raw_temps_ready = false;
SHV(bias); SHV(bias);
#if ENABLED(PRINTER_EVENT_LEDS) #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(); LEDColor color = ONHEATINGSTART();
#endif #endif
@ -2338,7 +2338,7 @@ void Temperature::init() {
* *
* TODO: Embed the last 3 parameters during init, if not less optimal * 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 #if HEATER_IDLE_HANDLER
// Convert the given heater_id_t to an idle array index // Convert the given heater_id_t to an idle array index
@ -3373,7 +3373,16 @@ void Temperature::isr() {
#include "../gcode/gcode.h" #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) #if ENABLED(SHOW_TEMP_ADC_VALUES)
, const float r , const float r
#endif #endif
@ -3557,12 +3566,12 @@ void Temperature::isr() {
#endif #endif
#if ENABLED(PRINTER_EVENT_LEDS) #if ENABLED(PRINTER_EVENT_LEDS)
const float start_temp = degHotend(target_extruder); const celsius_float_t start_temp = degHotend(target_extruder);
printerEventLEDs.onHotendHeatingStart(); printerEventLEDs.onHotendHeatingStart();
#endif #endif
bool wants_to_cool = false; 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; millis_t now, next_temp_ms = 0, next_cool_check_ms = 0;
wait_for_heatup = true; wait_for_heatup = true;
do { do {
@ -3592,7 +3601,7 @@ void Temperature::isr() {
idle(); idle();
gcode.reset_stepper_timeout(); // Keep steppers powered 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) #if ENABLED(PRINTER_EVENT_LEDS)
// Gradually change LED strip from violet to red as nozzle heats up // Gradually change LED strip from violet to red as nozzle heats up
@ -3601,7 +3610,7 @@ void Temperature::isr() {
#if TEMP_RESIDENCY_TIME > 0 #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) { if (!residency_start_ms) {
// Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time. // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
@ -3695,12 +3704,12 @@ void Temperature::isr() {
#endif #endif
#if ENABLED(PRINTER_EVENT_LEDS) #if ENABLED(PRINTER_EVENT_LEDS)
const float start_temp = degBed(); const celsius_float_t start_temp = degBed();
printerEventLEDs.onBedHeatingStart(); printerEventLEDs.onBedHeatingStart();
#endif #endif
bool wants_to_cool = false; 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; millis_t now, next_temp_ms = 0, next_cool_check_ms = 0;
wait_for_heatup = true; wait_for_heatup = true;
do { do {
@ -3730,7 +3739,7 @@ void Temperature::isr() {
idle(); idle();
gcode.reset_stepper_timeout(); // Keep steppers powered gcode.reset_stepper_timeout(); // Keep steppers powered
const float temp = degBed(); const celsius_float_t temp = degBed();
#if ENABLED(PRINTER_EVENT_LEDS) #if ENABLED(PRINTER_EVENT_LEDS)
// Gradually change LED strip from blue to violet as bed heats up // 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 #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) { if (!residency_start_ms) {
// Start the TEMP_BED_RESIDENCY_TIME timer when we reach target temp for the first time. // Start the TEMP_BED_RESIDENCY_TIME timer when we reach target temp for the first time.
@ -4021,11 +4030,11 @@ void Temperature::isr() {
idle(); idle();
gcode.reset_stepper_timeout(); // Keep steppers powered 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 #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) { if (!residency_start_ms) {
// Start the TEMP_COOLER_RESIDENCY_TIME timer when we reach target temp for the first time. // Start the TEMP_COOLER_RESIDENCY_TIME timer when we reach target temp for the first time.

View File

@ -961,7 +961,7 @@ class Temperature {
millis_t timer = 0; millis_t timer = 0;
TRState state = TRInactive; TRState state = TRInactive;
float running_temp; 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; } tr_state_machine_t;
static tr_state_machine_t tr_state_machine[NR_HEATER_RUNAWAY]; static tr_state_machine_t tr_state_machine[NR_HEATER_RUNAWAY];