Skip to content

Commit 4ad6fa5

Browse files
committed
πŸ§‘β€πŸ’» More extensible Temperature::lcd_preheat
1 parent 367cea0 commit 4ad6fa5

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

β€ŽMarlin/src/lcd/menu/menu_temperature.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,47 +45,55 @@
4545

4646
#if HAS_PREHEAT
4747

48-
void Temperature::lcd_preheat(const uint8_t e, const int8_t indh/*=-1*/, const int8_t indb/*=-1*/, const int8_t indc/*=-1*/) {
49-
UNUSED(e); UNUSED(indh); UNUSED(indb); UNUSED(indc);
48+
/**
49+
* @fn Temperature::lcd_preheat
50+
* @brief Apply the "preheat" parameters for a material preset to the
51+
* hotend (or laser), bed, chamber, or all of the above.
52+
* @param m Material index
53+
* @param targets Bit mask of targets to "preheat" (or turn off)
54+
* @param e Extruder index (if needed)
55+
*/
56+
void Temperature::lcd_preheat(const uint8_t m, const uint8_t targets, const uint8_t e/*=0*/) {
57+
UNUSED(e);
5058
#if HAS_HOTEND
51-
if (indh >= 0 && ui.material_preset[indh].hotend_temp > 0) setTargetHotend(ui.material_preset[indh].hotend_temp, e);
59+
if (targets & PreheatTarget::HOTEND) setTargetHotend(ui.material_preset[m].hotend_temp, e);
5260
#endif
5361
#if HAS_HEATED_BED
54-
if (indb >= 0 && ui.material_preset[indb].bed_temp > 0) setTargetBed(ui.material_preset[indb].bed_temp);
62+
if (targets & PreheatTarget::BED) setTargetBed(ui.material_preset[m].bed_temp);
5563
#endif
5664
#if HAS_HEATED_CHAMBER
57-
if (indc >= 0 && ui.material_preset[indc].chamber_temp > 0) setTargetChamber(ui.material_preset[indc].chamber_temp);
65+
if (targets & PreheatTarget::CHAMBER) setTargetChamber(ui.material_preset[m].chamber_temp);
5866
#endif
5967
#if HAS_FAN
60-
if (indh >= 0) {
68+
if (targets & PreheatTarget::HOTEND) {
6169
const uint8_t fan_index = active_extruder < (FAN_COUNT) ? active_extruder : 0;
6270
if (true
6371
#if REDUNDANT_PART_COOLING_FAN
6472
&& fan_index != REDUNDANT_PART_COOLING_FAN
6573
#endif
66-
) set_fan_speed(fan_index, ui.material_preset[indh].fan_speed);
74+
) set_fan_speed(fan_index, ui.material_preset[m].fan_speed);
6775
}
6876
#endif
6977
ui.return_to_status();
7078
}
7179

7280
#if HAS_TEMP_HOTEND
73-
inline void _preheat_end(const uint8_t e, const uint8_t m) { thermalManager.lcd_preheat(e, m); }
81+
inline void _preheat_end(const uint8_t e, const uint8_t m) { thermalManager.lcd_preheat(m, PreheatTarget::HOTEND, e); }
7482
void do_preheat_end_m() { _preheat_end(0, editable.int8); }
7583
#endif
7684
#if HAS_HEATED_BED
77-
inline void _preheat_bed(const uint8_t m) { thermalManager.lcd_preheat(0, -1, m); }
85+
inline void _preheat_bed(const uint8_t m) { thermalManager.lcd_preheat(m, PreheatTarget::BED); }
7886
#endif
7987
#if HAS_HEATED_CHAMBER
80-
inline void _preheat_chamber(const uint8_t m) { thermalManager.lcd_preheat(0, -1, -1, m); }
88+
inline void _preheat_chamber(const uint8_t m) { thermalManager.lcd_preheat(m, PreheatTarget::CHAMBER); }
8189
#endif
8290
#if HAS_COOLER
83-
inline void _precool_laser(const uint8_t e, const uint8_t m) { thermalManager.lcd_preheat(e, m); }
91+
inline void _precool_laser(const uint8_t e, const uint8_t m) { thermalManager.lcd_preheat(m, PreheatTarget::HOTEND, e); }
8492
void do_precool_laser_m() { _precool_laser(thermalManager.temp_cooler.target, editable.int8); }
8593
#endif
8694

8795
#if HAS_TEMP_HOTEND && (HAS_HEATED_BED || HAS_HEATED_CHAMBER)
88-
inline void _preheat_all(const uint8_t e, const uint8_t m) { thermalManager.lcd_preheat(e, m, m, m); }
96+
inline void _preheat_all(const uint8_t e, const uint8_t m) { thermalManager.lcd_preheat(m, PreheatTarget::ALL, e); }
8997

9098
// Indexed "Preheat ABC" and "Heat Bed" items
9199
#define PREHEAT_ITEMS(M,E) do{ \

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,15 @@ typedef struct { raw_adc_t raw_min, raw_max; celsius_t mintemp, maxtemp; } temp_
599599
#define HAS_FAN_LOGIC 1
600600
#endif
601601

602+
#if HAS_MARLINUI_MENU && HAS_TEMPERATURE && HAS_PREHEAT
603+
enum PreheatTarget : uint8_t {
604+
HOTEND = (1 << 0),
605+
BED = (1 << 1),
606+
CHAMBER = (1 << 2),
607+
ALL = 0xFF
608+
};
609+
#endif
610+
602611
class Temperature {
603612

604613
public:
@@ -1335,7 +1344,8 @@ class Temperature {
13351344
#endif
13361345

13371346
#if HAS_MARLINUI_MENU && HAS_TEMPERATURE && HAS_PREHEAT
1338-
static void lcd_preheat(const uint8_t e, const int8_t indh=-1, const int8_t indb=-1, const int8_t indc=-1);
1347+
// Apply the "preheat" parameters for a material preset to the hotend (or laser), bed, chamber, or all of the above
1348+
static void lcd_preheat(const uint8_t m, const uint8_t targets, const uint8_t e=0);
13391349
#endif
13401350

13411351
private:

0 commit comments

Comments
Β (0)