Add typedef celsius_t (#21374)
This commit is contained in:
@@ -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::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);
|
||||
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)
|
||||
@@ -368,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
|
||||
@@ -383,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
|
||||
@@ -400,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
|
||||
@@ -419,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:
|
||||
@@ -429,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
|
||||
|
||||
@@ -474,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
|
||||
@@ -1566,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
|
||||
@@ -1663,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;
|
||||
@@ -1712,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);
|
||||
@@ -1821,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
|
||||
@@ -1839,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
|
||||
@@ -1857,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
|
||||
@@ -1875,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
|
||||
@@ -2191,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); \
|
||||
@@ -2257,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);
|
||||
@@ -2345,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
|
||||
@@ -2554,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)
|
||||
|
||||
Reference in New Issue
Block a user