@@ -490,8 +490,7 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED);
490
490
#if HAS_HEATED_BED
491
491
bed_info_t Temperature::temp_bed; // = { 0 }
492
492
// Init min and max temp with extreme values to prevent false errors during startup
493
- raw_adc_t Temperature::mintemp_raw_BED = TEMP_SENSOR_BED_RAW_LO_TEMP,
494
- Temperature::maxtemp_raw_BED = TEMP_SENSOR_BED_RAW_HI_TEMP;
493
+ temp_raw_range_t Temperature::temp_sensor_range_bed = { TEMP_SENSOR_BED_RAW_LO_TEMP, TEMP_SENSOR_BED_RAW_HI_TEMP };
495
494
#if WATCH_BED
496
495
bed_watch_t Temperature::watch_bed; // = { 0 }
497
496
#endif
@@ -505,8 +504,7 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED);
505
504
#if HAS_HEATED_CHAMBER
506
505
millis_t next_cool_check_ms = 0 ;
507
506
celsius_float_t old_temp = 9999 ;
508
- raw_adc_t Temperature::mintemp_raw_CHAMBER = TEMP_SENSOR_CHAMBER_RAW_LO_TEMP,
509
- Temperature::maxtemp_raw_CHAMBER = TEMP_SENSOR_CHAMBER_RAW_HI_TEMP;
507
+ temp_raw_range_t Temperature::temp_sensor_range_chamber = { TEMP_SENSOR_CHAMBER_RAW_LO_TEMP, TEMP_SENSOR_CHAMBER_RAW_HI_TEMP };
510
508
#if WATCH_CHAMBER
511
509
chamber_watch_t Temperature::watch_chamber; // = { 0 }
512
510
#endif
@@ -522,8 +520,7 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED);
522
520
bool flag_cooler_state;
523
521
// bool flag_cooler_excess = false;
524
522
celsius_float_t previous_temp = 9999 ;
525
- raw_adc_t Temperature::mintemp_raw_COOLER = TEMP_SENSOR_COOLER_RAW_LO_TEMP,
526
- Temperature::maxtemp_raw_COOLER = TEMP_SENSOR_COOLER_RAW_HI_TEMP;
523
+ temp_raw_range_t Temperature::temp_sensor_range_cooler = { TEMP_SENSOR_COOLER_RAW_LO_TEMP, TEMP_SENSOR_COOLER_RAW_HI_TEMP };
527
524
#if WATCH_COOLER
528
525
cooler_watch_t Temperature::watch_cooler; // = { 0 }
529
526
#endif
@@ -538,8 +535,7 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED);
538
535
#if HAS_TEMP_BOARD
539
536
board_info_t Temperature::temp_board; // = { 0 }
540
537
#if ENABLED(THERMAL_PROTECTION_BOARD)
541
- raw_adc_t Temperature::mintemp_raw_BOARD = TEMP_SENSOR_BOARD_RAW_LO_TEMP,
542
- Temperature::maxtemp_raw_BOARD = TEMP_SENSOR_BOARD_RAW_HI_TEMP;
538
+ temp_raw_range_t Temperature::temp_sensor_range_board = { TEMP_SENSOR_BOARD_RAW_LO_TEMP, TEMP_SENSOR_BOARD_RAW_HI_TEMP };
543
539
#endif
544
540
#endif
545
541
@@ -700,7 +696,7 @@ volatile bool Temperature::raw_temps_ready = false;
700
696
TERN_ (EXTENSIBLE_UI, ExtUI::onPidTuning (ExtUI::result_t ::PID_STARTED));
701
697
TERN_ (PROUI_PID_TUNE, dwinPidTuning (isbed ? PIDTEMPBED_START : PIDTEMP_START));
702
698
703
- if (target > GHV (CHAMBER_MAX_TARGET, BED_MAX_TARGET, temp_range[heater_id]. maxtemp - (HOTEND_OVERSHOOT ))) {
699
+ if (target > GHV (CHAMBER_MAX_TARGET, BED_MAX_TARGET, hotend_max_target (heater_id ))) {
704
700
SERIAL_ECHOPGM (STR_PID_AUTOTUNE); SERIAL_ECHOLNPGM (STR_PID_TEMP_TOO_HIGH);
705
701
TERN_ (EXTENSIBLE_UI, ExtUI::onPidTuning (ExtUI::result_t ::PID_TEMP_TOO_HIGH));
706
702
TERN_ (PROUI_PID_TUNE, dwinPidTuning (PID_TEMP_TOO_HIGH));
@@ -718,7 +714,7 @@ volatile bool Temperature::raw_temps_ready = false;
718
714
719
715
#if ENABLED(PRINTER_EVENT_LEDS)
720
716
const celsius_float_t start_temp = GHV (degChamber (), degBed (), degHotend (heater_id));
721
- LEDColor color = ONHEATINGSTART ();
717
+ const LEDColor oldcolor = ONHEATINGSTART ();
722
718
#endif
723
719
724
720
TERN_ (TEMP_TUNING_MAINTAIN_FAN, adaptive_fan_slowing = false );
@@ -882,7 +878,7 @@ volatile bool Temperature::raw_temps_ready = false;
882
878
if (set_result)
883
879
GHV (_set_chamber_pid (tune_pid), _set_bed_pid (tune_pid), _set_hotend_pid (heater_id, tune_pid));
884
880
885
- TERN_ (PRINTER_EVENT_LEDS, printerEventLEDs.onPidTuningDone (color ));
881
+ TERN_ (PRINTER_EVENT_LEDS, printerEventLEDs.onPidTuningDone (oldcolor ));
886
882
887
883
TERN_ (EXTENSIBLE_UI, ExtUI::onPidTuning (ExtUI::result_t ::PID_DONE));
888
884
TERN_ (PROUI_PID_TUNE, dwinPidTuning (AUTOTUNE_DONE));
@@ -894,13 +890,13 @@ volatile bool Temperature::raw_temps_ready = false;
894
890
hal.idletask ();
895
891
896
892
// Run UI update
897
- TERN (DWIN_CREALITY_LCD, dwinUpdate (), ui.update () );
893
+ ui.update ();
898
894
}
899
895
wait_for_heatup = false ;
900
896
901
897
disable_all_heaters ();
902
898
903
- TERN_ (PRINTER_EVENT_LEDS, printerEventLEDs.onPidTuningDone (color ));
899
+ TERN_ (PRINTER_EVENT_LEDS, printerEventLEDs.onPidTuningDone (oldcolor ));
904
900
905
901
TERN_ (EXTENSIBLE_UI, ExtUI::onPidTuning (ExtUI::result_t ::PID_DONE));
906
902
TERN_ (PROUI_PID_TUNE, dwinPidTuning (AUTOTUNE_DONE));
@@ -1143,7 +1139,7 @@ volatile bool Temperature::raw_temps_ready = false;
1143
1139
}
1144
1140
1145
1141
Temperature::MPC_autotuner::MeasurementState Temperature::MPC_autotuner::housekeeping () {
1146
- const millis_t report_interval_ms = 1000UL ;
1142
+ constexpr millis_t report_interval_ms = 1000UL ;
1147
1143
curr_time_ms = millis ();
1148
1144
1149
1145
if (updateTemperaturesIfReady ()) { // temp sample ready
@@ -1158,7 +1154,7 @@ volatile bool Temperature::raw_temps_ready = false;
1158
1154
}
1159
1155
1160
1156
hal.idletask ();
1161
- TERN (DWIN_CREALITY_LCD, dwinUpdate (), ui.update () );
1157
+ ui.update ();
1162
1158
1163
1159
if (!wait_for_heatup) {
1164
1160
SERIAL_ECHOLNPGM (STR_MPC_AUTOTUNE_INTERRUPTED);
@@ -1834,12 +1830,18 @@ void Temperature::mintemp_error(const heater_id_t heater_id OPTARG(ERR_INCLUDE_T
1834
1830
// Check if temperature is within the correct band
1835
1831
if (WITHIN (temp_bed.celsius , BED_MINTEMP, BED_MAXTEMP)) {
1836
1832
#if ENABLED(BED_LIMIT_SWITCHING)
1833
+
1834
+ // Range-limited "bang-bang" bed heating
1837
1835
if (temp_bed.is_above_target (BED_HYSTERESIS))
1838
1836
temp_bed.soft_pwm_amount = 0 ;
1839
1837
else if (temp_bed.is_below_target (BED_HYSTERESIS))
1840
1838
temp_bed.soft_pwm_amount = MAX_BED_POWER >> 1 ;
1839
+
1841
1840
#else // !PIDTEMPBED && !BED_LIMIT_SWITCHING
1841
+
1842
+ // Simple (noisy) "bang-bang" bed heating
1842
1843
temp_bed.soft_pwm_amount = temp_bed.is_below_target () ? MAX_BED_POWER >> 1 : 0 ;
1844
+
1843
1845
#endif
1844
1846
}
1845
1847
else {
@@ -2632,31 +2634,8 @@ void Temperature::updateTemperaturesFromRawValues() {
2632
2634
TERN_ (HAS_POWER_MONITOR, power_monitor.capture_values ());
2633
2635
2634
2636
#if HAS_HOTEND
2635
- static constexpr int8_t temp_dir[HOTENDS] = {
2636
- #if TEMP_SENSOR_IS_ANY_MAX_TC(0)
2637
- 0
2638
- #else
2639
- TEMPDIR (0 )
2640
- #endif
2641
- #if HAS_MULTI_HOTEND
2642
- #if TEMP_SENSOR_IS_ANY_MAX_TC(1)
2643
- , 0
2644
- #else
2645
- , TEMPDIR (1 )
2646
- #endif
2647
- #endif
2648
- #if HOTENDS > 2
2649
- #if TEMP_SENSOR_IS_ANY_MAX_TC(2)
2650
- , 0
2651
- #else
2652
- , TEMPDIR (2 )
2653
- #endif
2654
- #endif
2655
- #if HOTENDS > 3
2656
- #define _TEMPDIR (N ) , TEMPDIR(N)
2657
- REPEAT_S (3 , HOTENDS, _TEMPDIR)
2658
- #endif
2659
- };
2637
+ #define _TEMPDIR (N ) TEMP_SENSOR_IS_ANY_MAX_TC(N) ? 0 : TEMPDIR(N),
2638
+ static constexpr int8_t temp_dir[HOTENDS] = { REPEAT (HOTENDS, _TEMPDIR) };
2660
2639
2661
2640
HOTEND_LOOP () {
2662
2641
const raw_adc_t r = temp_hotend[e].getraw ();
@@ -2683,31 +2662,37 @@ void Temperature::updateTemperaturesFromRawValues() {
2683
2662
2684
2663
#endif // HAS_HOTEND
2685
2664
2686
- #define TP_CMP (S,A,B ) (TEMPDIR(S) < 0 ? ((A)<(B)) : ((A)>(B)))
2687
2665
#if ENABLED(THERMAL_PROTECTION_BED)
2688
- if (TP_CMP (BED, temp_bed.getraw (), maxtemp_raw_BED)) MAXTEMP_ERROR (H_BED, temp_bed.celsius );
2689
- if (temp_bed.target > 0 && !is_bed_preheating () && TP_CMP (BED, mintemp_raw_BED, temp_bed.getraw ())) MINTEMP_ERROR (H_BED, temp_bed.celsius );
2666
+ if (TP_CMP (BED, temp_bed.getraw (), temp_sensor_range_bed.raw_max ))
2667
+ MAXTEMP_ERROR (H_BED, temp_bed.celsius );
2668
+ if (temp_bed.target > 0 && !is_bed_preheating () && TP_CMP (BED, temp_sensor_range_bed.raw_min , temp_bed.getraw ()))
2669
+ MINTEMP_ERROR (H_BED, temp_bed.celsius );
2690
2670
#endif
2691
2671
2692
2672
#if ALL(HAS_HEATED_CHAMBER, THERMAL_PROTECTION_CHAMBER)
2693
- if (TP_CMP (CHAMBER, temp_chamber.getraw (), maxtemp_raw_CHAMBER)) MAXTEMP_ERROR (H_CHAMBER, temp_chamber.celsius );
2694
- if (temp_chamber.target > 0 && TP_CMP (CHAMBER, mintemp_raw_CHAMBER, temp_chamber.getraw ())) MINTEMP_ERROR (H_CHAMBER, temp_chamber.celsius );
2673
+ if (TP_CMP (CHAMBER, temp_chamber.getraw (), temp_sensor_range_chamber.raw_max ))
2674
+ MAXTEMP_ERROR (H_CHAMBER, temp_chamber.celsius );
2675
+ if (temp_chamber.target > 0 && TP_CMP (CHAMBER, temp_sensor_range_chamber.raw_min , temp_chamber.getraw ()))
2676
+ MINTEMP_ERROR (H_CHAMBER, temp_chamber.celsius );
2695
2677
#endif
2696
2678
2697
2679
#if ALL(HAS_COOLER, THERMAL_PROTECTION_COOLER)
2698
- if (cutter.unitPower > 0 && TP_CMP (COOLER, temp_cooler.getraw (), maxtemp_raw_COOLER)) MAXTEMP_ERROR (H_COOLER, temp_cooler.celsius );
2699
- if (TP_CMP (COOLER, mintemp_raw_COOLER, temp_cooler.getraw ())) MINTEMP_ERROR (H_COOLER, temp_cooler.celsius );
2680
+ if (cutter.unitPower > 0 && TP_CMP (COOLER, temp_cooler.getraw (), temp_sensor_range_cooler.raw_max ))
2681
+ MAXTEMP_ERROR (H_COOLER, temp_cooler.celsius );
2682
+ if (TP_CMP (COOLER, temp_sensor_range_cooler.raw_min , temp_cooler.getraw ()))
2683
+ MINTEMP_ERROR (H_COOLER, temp_cooler.celsius );
2700
2684
#endif
2701
2685
2702
2686
#if ALL(HAS_TEMP_BOARD, THERMAL_PROTECTION_BOARD)
2703
- if (TP_CMP (BOARD, temp_board.getraw (), maxtemp_raw_BOARD)) MAXTEMP_ERROR (H_BOARD, temp_board.celsius );
2704
- if (TP_CMP (BOARD, mintemp_raw_BOARD, temp_board.getraw ())) MINTEMP_ERROR (H_BOARD, temp_board.celsius );
2687
+ if (TP_CMP (BOARD, temp_board.getraw (), temp_sensor_range_board.raw_max ))
2688
+ MAXTEMP_ERROR (H_BOARD, temp_board.celsius );
2689
+ if (TP_CMP (BOARD, temp_sensor_range_board.raw_min , temp_board.getraw ()))
2690
+ MINTEMP_ERROR (H_BOARD, temp_board.celsius );
2705
2691
#endif
2706
2692
2707
2693
#if ALL(HAS_TEMP_SOC, THERMAL_PROTECTION_SOC)
2708
2694
if (TP_CMP (SOC, temp_soc.getraw (), maxtemp_raw_SOC)) MAXTEMP_ERROR (H_SOC, temp_soc.celsius );
2709
2695
#endif
2710
- #undef TP_CMP
2711
2696
2712
2697
} // Temperature::updateTemperaturesFromRawValues
2713
2698
@@ -2733,7 +2718,6 @@ void Temperature::init() {
2733
2718
2734
2719
TERN_ (PROBING_HEATERS_OFF, paused_for_probing = false );
2735
2720
2736
-
2737
2721
// Init (and disable) SPI thermocouples
2738
2722
#if TEMP_SENSOR_IS_ANY_MAX_TC(0) && PIN_EXISTS(TEMP_0_CS)
2739
2723
OUT_WRITE (TEMP_0_CS_PIN, HIGH);
@@ -3051,23 +3035,31 @@ void Temperature::init() {
3051
3035
3052
3036
// TODO: combine these into the macros above
3053
3037
#if HAS_HEATED_BED
3054
- while (analog_to_celsius_bed (mintemp_raw_BED) < BED_MINTEMP) mintemp_raw_BED += TEMPDIR (BED) * (OVERSAMPLENR);
3055
- while (analog_to_celsius_bed (maxtemp_raw_BED) > BED_MAXTEMP) maxtemp_raw_BED -= TEMPDIR (BED) * (OVERSAMPLENR);
3038
+ while (analog_to_celsius_bed (temp_sensor_range_bed.raw_min ) < BED_MINTEMP)
3039
+ temp_sensor_range_bed.raw_min += TEMPDIR (BED) * (OVERSAMPLENR);
3040
+ while (analog_to_celsius_bed (temp_sensor_range_bed.raw_max ) > BED_MAXTEMP)
3041
+ temp_sensor_range_bed.raw_max -= TEMPDIR (BED) * (OVERSAMPLENR);
3056
3042
#endif
3057
3043
3058
3044
#if HAS_HEATED_CHAMBER
3059
- while (analog_to_celsius_chamber (mintemp_raw_CHAMBER) < CHAMBER_MINTEMP) mintemp_raw_CHAMBER += TEMPDIR (CHAMBER) * (OVERSAMPLENR);
3060
- while (analog_to_celsius_chamber (maxtemp_raw_CHAMBER) > CHAMBER_MAXTEMP) maxtemp_raw_CHAMBER -= TEMPDIR (CHAMBER) * (OVERSAMPLENR);
3045
+ while (analog_to_celsius_chamber (temp_sensor_range_chamber.raw_min ) < CHAMBER_MINTEMP)
3046
+ temp_sensor_range_chamber.raw_min += TEMPDIR (CHAMBER) * (OVERSAMPLENR);
3047
+ while (analog_to_celsius_chamber (temp_sensor_range_chamber.raw_max ) > CHAMBER_MAXTEMP)
3048
+ temp_sensor_range_chamber.raw_max -= TEMPDIR (CHAMBER) * (OVERSAMPLENR);
3061
3049
#endif
3062
3050
3063
3051
#if HAS_COOLER
3064
- while (analog_to_celsius_cooler (mintemp_raw_COOLER) > COOLER_MINTEMP) mintemp_raw_COOLER += TEMPDIR (COOLER) * (OVERSAMPLENR);
3065
- while (analog_to_celsius_cooler (maxtemp_raw_COOLER) < COOLER_MAXTEMP) maxtemp_raw_COOLER -= TEMPDIR (COOLER) * (OVERSAMPLENR);
3052
+ while (analog_to_celsius_cooler (temp_sensor_range_cooler.raw_min ) > COOLER_MINTEMP)
3053
+ temp_sensor_range_cooler.raw_min += TEMPDIR (COOLER) * (OVERSAMPLENR);
3054
+ while (analog_to_celsius_cooler (temp_sensor_range_cooler.raw_max ) < COOLER_MAXTEMP)
3055
+ temp_sensor_range_cooler.raw_max -= TEMPDIR (COOLER) * (OVERSAMPLENR);
3066
3056
#endif
3067
3057
3068
3058
#if ALL(HAS_TEMP_BOARD, THERMAL_PROTECTION_BOARD)
3069
- while (analog_to_celsius_board (mintemp_raw_BOARD) < BOARD_MINTEMP) mintemp_raw_BOARD += TEMPDIR (BOARD) * (OVERSAMPLENR);
3070
- while (analog_to_celsius_board (maxtemp_raw_BOARD) > BOARD_MAXTEMP) maxtemp_raw_BOARD -= TEMPDIR (BOARD) * (OVERSAMPLENR);
3059
+ while (analog_to_celsius_board (temp_sensor_range_board.raw_min ) < BOARD_MINTEMP)
3060
+ temp_sensor_range_board.raw_min += TEMPDIR (BOARD) * (OVERSAMPLENR);
3061
+ while (analog_to_celsius_board (temp_sensor_range_board.raw_max ) > BOARD_MAXTEMP)
3062
+ temp_sensor_range_board.raw_max -= TEMPDIR (BOARD) * (OVERSAMPLENR);
3071
3063
#endif
3072
3064
3073
3065
#if ALL(HAS_TEMP_SOC, THERMAL_PROTECTION_SOC)
0 commit comments