Skip to content

Commit 72c7874

Browse files
committed
πŸ§‘β€πŸ’» Use raw temp accessors
1 parent 3ce3586 commit 72c7874

File tree

2 files changed

+33
-50
lines changed

2 files changed

+33
-50
lines changed

β€ŽMarlin/src/module/temperature.cppβ€Ž

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,16 +2876,16 @@ void Temperature::updateTemperaturesFromRawValues() {
28762876
#endif
28772877

28782878
#if HAS_HOTEND
2879-
HOTEND_LOOP() temp_hotend[e].celsius = analog_to_celsius_hotend(temp_hotend[e].getraw(), e);
2879+
HOTEND_LOOP() temp_hotend[e].celsius = analog_to_celsius_hotend(rawHotendTemp(e), e);
28802880
#endif
28812881

2882-
TERN_(HAS_HEATED_BED, temp_bed.celsius = analog_to_celsius_bed(temp_bed.getraw()));
2883-
TERN_(HAS_TEMP_CHAMBER, temp_chamber.celsius = analog_to_celsius_chamber(temp_chamber.getraw()));
2884-
TERN_(HAS_TEMP_COOLER, temp_cooler.celsius = analog_to_celsius_cooler(temp_cooler.getraw()));
2885-
TERN_(HAS_TEMP_PROBE, temp_probe.celsius = analog_to_celsius_probe(temp_probe.getraw()));
2886-
TERN_(HAS_TEMP_BOARD, temp_board.celsius = analog_to_celsius_board(temp_board.getraw()));
2887-
TERN_(HAS_TEMP_SOC, temp_soc.celsius = analog_to_celsius_soc(temp_soc.getraw()));
2888-
TERN_(HAS_TEMP_REDUNDANT, temp_redundant.celsius = analog_to_celsius_redundant(temp_redundant.getraw()));
2882+
TERN_(HAS_HEATED_BED, temp_bed.celsius = analog_to_celsius_bed(rawBedTemp()));
2883+
TERN_(HAS_TEMP_CHAMBER, temp_chamber.celsius = analog_to_celsius_chamber(rawChamberTemp()));
2884+
TERN_(HAS_TEMP_COOLER, temp_cooler.celsius = analog_to_celsius_cooler(rawCoolerTemp()));
2885+
TERN_(HAS_TEMP_PROBE, temp_probe.celsius = analog_to_celsius_probe(rawProbeTemp()));
2886+
TERN_(HAS_TEMP_BOARD, temp_board.celsius = analog_to_celsius_board(rawBoardTemp()));
2887+
TERN_(HAS_TEMP_SOC, temp_soc.celsius = analog_to_celsius_soc(rawSocTemp()));
2888+
TERN_(HAS_TEMP_REDUNDANT, temp_redundant.celsius = analog_to_celsius_redundant(rawRedundantTemp()));
28892889

28902890
TERN_(FILAMENT_WIDTH_SENSOR, filwidth.update_measured_mm());
28912891
TERN_(HAS_POWER_MONITOR, power_monitor.capture_values());
@@ -2895,7 +2895,7 @@ void Temperature::updateTemperaturesFromRawValues() {
28952895
static constexpr int8_t temp_dir[HOTENDS] = { REPEAT(HOTENDS, _TEMPDIR) };
28962896

28972897
HOTEND_LOOP() {
2898-
const raw_adc_t r = temp_hotend[e].getraw();
2898+
const raw_adc_t r = rawHotendTemp(e);
28992899
const bool neg = temp_dir[e] < 0, pos = temp_dir[e] > 0;
29002900
if ((neg && r < temp_range[e].raw_max) || (pos && r > temp_range[e].raw_max))
29012901
MAXTEMP_ERROR(e, temp_hotend[e].celsius);
@@ -2920,35 +2920,35 @@ void Temperature::updateTemperaturesFromRawValues() {
29202920
#endif // HAS_HOTEND
29212921

29222922
#if ENABLED(THERMAL_PROTECTION_BED)
2923-
if (TP_CMP(BED, temp_bed.getraw(), temp_sensor_range_bed.raw_max))
2923+
if (TP_CMP(BED, rawBedTemp(), temp_sensor_range_bed.raw_max))
29242924
MAXTEMP_ERROR(H_BED, temp_bed.celsius);
2925-
if (temp_bed.target > 0 && !is_bed_preheating() && TP_CMP(BED, temp_sensor_range_bed.raw_min, temp_bed.getraw()))
2925+
if (temp_bed.target > 0 && !is_bed_preheating() && TP_CMP(BED, temp_sensor_range_bed.raw_min, rawBedTemp()))
29262926
MINTEMP_ERROR(H_BED, temp_bed.celsius);
29272927
#endif
29282928

29292929
#if ALL(HAS_HEATED_CHAMBER, THERMAL_PROTECTION_CHAMBER)
2930-
if (TP_CMP(CHAMBER, temp_chamber.getraw(), temp_sensor_range_chamber.raw_max))
2930+
if (TP_CMP(CHAMBER, rawChamberTemp(), temp_sensor_range_chamber.raw_max))
29312931
MAXTEMP_ERROR(H_CHAMBER, temp_chamber.celsius);
2932-
if (temp_chamber.target > 0 && TP_CMP(CHAMBER, temp_sensor_range_chamber.raw_min, temp_chamber.getraw()))
2932+
if (temp_chamber.target > 0 && TP_CMP(CHAMBER, temp_sensor_range_chamber.raw_min, rawChamberTemp()))
29332933
MINTEMP_ERROR(H_CHAMBER, temp_chamber.celsius);
29342934
#endif
29352935

29362936
#if ALL(HAS_COOLER, THERMAL_PROTECTION_COOLER)
2937-
if (cutter.unitPower > 0 && TP_CMP(COOLER, temp_cooler.getraw(), temp_sensor_range_cooler.raw_max))
2937+
if (cutter.unitPower > 0 && TP_CMP(COOLER, rawCoolerTemp(), temp_sensor_range_cooler.raw_max))
29382938
MAXTEMP_ERROR(H_COOLER, temp_cooler.celsius);
2939-
if (TP_CMP(COOLER, temp_sensor_range_cooler.raw_min, temp_cooler.getraw()))
2939+
if (TP_CMP(COOLER, temp_sensor_range_cooler.raw_min, rawCoolerTemp()))
29402940
MINTEMP_ERROR(H_COOLER, temp_cooler.celsius);
29412941
#endif
29422942

29432943
#if ALL(HAS_TEMP_BOARD, THERMAL_PROTECTION_BOARD)
2944-
if (TP_CMP(BOARD, temp_board.getraw(), temp_sensor_range_board.raw_max))
2944+
if (TP_CMP(BOARD, rawBoardTemp(), temp_sensor_range_board.raw_max))
29452945
MAXTEMP_ERROR(H_BOARD, temp_board.celsius);
2946-
if (TP_CMP(BOARD, temp_sensor_range_board.raw_min, temp_board.getraw()))
2946+
if (TP_CMP(BOARD, temp_sensor_range_board.raw_min, rawBoardTemp()))
29472947
MINTEMP_ERROR(H_BOARD, temp_board.celsius);
29482948
#endif
29492949

29502950
#if ALL(HAS_TEMP_SOC, THERMAL_PROTECTION_SOC)
2951-
if (TP_CMP(SOC, temp_soc.getraw(), maxtemp_raw_SOC)) MAXTEMP_ERROR(H_SOC, temp_soc.celsius);
2951+
if (TP_CMP(SOC, rawSocTemp(), maxtemp_raw_SOC)) MAXTEMP_ERROR(H_SOC, temp_soc.celsius);
29522952
#endif
29532953

29542954
} // Temperature::updateTemperaturesFromRawValues
@@ -3354,13 +3354,13 @@ void Temperature::init() {
33543354
#define VARIANCE_WINDOW period_seconds
33553355
#endif
33563356

3357-
if (state == TRMalfunction) { // temperature invariance may continue, regardless of heater state
3358-
variance += ABS(current - last_temp); // no need for detection window now, a single change in variance is enough
3357+
if (state == TRMalfunction) { // Temperature invariance may continue, regardless of heater state
3358+
variance += ABS(current - last_temp); // No need for detection window now, a single change in variance is enough
33593359
last_temp = current;
3360-
if (!NEAR_ZERO(variance)) {
3360+
if (variance > 0.25f) { // Require meaningful temperature change, not just ADC noise
33613361
variance_timer = millis() + SEC_TO_MS(VARIANCE_WINDOW);
33623362
variance = 0.0;
3363-
state = TRStable; // resume from where we detected the problem
3363+
state = TRStable; // Resume from where we detected the problem
33643364
}
33653365
}
33663366
#endif

β€ŽMarlin/src/module/temperature.hβ€Ž

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,16 +1024,14 @@ class Temperature {
10241024
return TERN0(HAS_HOTEND, static_cast<celsius_t>(temp_hotend[HOTEND_INDEX].celsius + 0.5f));
10251025
}
10261026

1027-
#if ENABLED(SHOW_TEMP_ADC_VALUES)
1028-
static raw_adc_t rawHotendTemp(const uint8_t E_NAME) {
1029-
return TERN0(HAS_HOTEND, temp_hotend[HOTEND_INDEX].getraw());
1030-
}
1031-
#endif
1032-
10331027
static celsius_t degTargetHotend(const uint8_t E_NAME) {
10341028
return TERN0(HAS_HOTEND, temp_hotend[HOTEND_INDEX].target);
10351029
}
10361030

1031+
static raw_adc_t rawHotendTemp(const uint8_t E_NAME) {
1032+
return TERN0(HAS_HOTEND, temp_hotend[HOTEND_INDEX].getraw());
1033+
}
1034+
10371035
#if HAS_HOTEND
10381036

10391037
static void _setTargetHotend(const celsius_t celsius, const uint8_t E_NAME) {
@@ -1100,10 +1098,7 @@ class Temperature {
11001098
#endif
11011099

11021100
#if HAS_HEATED_BED
1103-
1104-
#if ENABLED(SHOW_TEMP_ADC_VALUES)
1105-
static raw_adc_t rawBedTemp() { return temp_bed.getraw(); }
1106-
#endif
1101+
static raw_adc_t rawBedTemp() { return temp_bed.getraw(); }
11071102
static celsius_float_t degBed() { return temp_bed.celsius; }
11081103
static celsius_t wholeDegBed() { return static_cast<celsius_t>(degBed() + 0.5f); }
11091104
static celsius_t degTargetBed() { return temp_bed.target; }
@@ -1139,9 +1134,7 @@ class Temperature {
11391134
#endif // HAS_HEATED_BED
11401135

11411136
#if HAS_TEMP_PROBE
1142-
#if ENABLED(SHOW_TEMP_ADC_VALUES)
1143-
static raw_adc_t rawProbeTemp() { return temp_probe.getraw(); }
1144-
#endif
1137+
static raw_adc_t rawProbeTemp() { return temp_probe.getraw(); }
11451138
static celsius_float_t degProbe() { return temp_probe.celsius; }
11461139
static celsius_t wholeDegProbe() { return static_cast<celsius_t>(degProbe() + 0.5f); }
11471140
static bool isProbeBelowTemp(const celsius_t target_temp) { return wholeDegProbe() < target_temp; }
@@ -1150,9 +1143,7 @@ class Temperature {
11501143
#endif
11511144

11521145
#if HAS_TEMP_CHAMBER
1153-
#if ENABLED(SHOW_TEMP_ADC_VALUES)
1154-
static raw_adc_t rawChamberTemp() { return temp_chamber.getraw(); }
1155-
#endif
1146+
static raw_adc_t rawChamberTemp() { return temp_chamber.getraw(); }
11561147
static celsius_float_t degChamber() { return temp_chamber.celsius; }
11571148
static celsius_t wholeDegChamber() { return static_cast<celsius_t>(degChamber() + 0.5f); }
11581149
#if HAS_HEATED_CHAMBER
@@ -1174,9 +1165,7 @@ class Temperature {
11741165
#endif
11751166

11761167
#if HAS_TEMP_COOLER
1177-
#if ENABLED(SHOW_TEMP_ADC_VALUES)
1178-
static raw_adc_t rawCoolerTemp() { return temp_cooler.getraw(); }
1179-
#endif
1168+
static raw_adc_t rawCoolerTemp() { return temp_cooler.getraw(); }
11801169
static celsius_float_t degCooler() { return temp_cooler.celsius; }
11811170
static celsius_t wholeDegCooler() { return static_cast<celsius_t>(temp_cooler.celsius + 0.5f); }
11821171
#if HAS_COOLER
@@ -1189,25 +1178,19 @@ class Temperature {
11891178
#endif
11901179

11911180
#if HAS_TEMP_BOARD
1192-
#if ENABLED(SHOW_TEMP_ADC_VALUES)
1193-
static raw_adc_t rawBoardTemp() { return temp_board.getraw(); }
1194-
#endif
1181+
static raw_adc_t rawBoardTemp() { return temp_board.getraw(); }
11951182
static celsius_float_t degBoard() { return temp_board.celsius; }
11961183
static celsius_t wholeDegBoard() { return static_cast<celsius_t>(temp_board.celsius + 0.5f); }
11971184
#endif
11981185

11991186
#if HAS_TEMP_SOC
1200-
#if ENABLED(SHOW_TEMP_ADC_VALUES)
1201-
static raw_adc_t rawSocTemp() { return temp_soc.getraw(); }
1202-
#endif
1187+
static raw_adc_t rawSocTemp() { return temp_soc.getraw(); }
12031188
static celsius_float_t degSoc() { return temp_soc.celsius; }
12041189
static celsius_t wholeDegSoc() { return static_cast<celsius_t>(temp_soc.celsius + 0.5f); }
12051190
#endif
12061191

12071192
#if HAS_TEMP_REDUNDANT
1208-
#if ENABLED(SHOW_TEMP_ADC_VALUES)
1209-
static raw_adc_t rawRedundantTemp() { return temp_redundant.getraw(); }
1210-
#endif
1193+
static raw_adc_t rawRedundantTemp() { return temp_redundant.getraw(); }
12111194
static celsius_float_t degRedundant() { return temp_redundant.celsius; }
12121195
static celsius_float_t degRedundantTarget() { return (*temp_redundant.target).celsius; }
12131196
static celsius_t wholeDegRedundant() { return static_cast<celsius_t>(temp_redundant.celsius + 0.5f); }

0 commit comments

Comments
Β (0)