Skip to content

Commit 33be9d5

Browse files
committed
Use a struct
1 parent 6c159b2 commit 33be9d5

File tree

4 files changed

+36
-30
lines changed

4 files changed

+36
-30
lines changed

Marlin/src/feature/hotend_idle.cpp

+8-11
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,26 @@
4040
extern HotendIdleProtection hotend_idle;
4141

4242
millis_t HotendIdleProtection::next_protect_ms = 0;
43-
uint16_t HotendIdleProtection::timeout = HOTEND_IDLE_TIMEOUT_SEC,
44-
HotendIdleProtection::trigger = HOTEND_IDLE_MIN_TRIGGER,
45-
HotendIdleProtection::nozzle_target = HOTEND_IDLE_NOZZLE_TARGET,
46-
HotendIdleProtection::bed_target = HOTEND_IDLE_BED_TARGET;
43+
hotend_idle_settings_t HotendIdleProtection::cfg; // Initialized by settings.load()
4744

4845
void HotendIdleProtection::check_hotends(const millis_t &ms) {
4946
bool do_prot = false;
5047
HOTEND_LOOP() {
5148
const bool busy = (TERN0(HAS_RESUME_CONTINUE, wait_for_user) || planner.has_blocks_queued());
52-
if (thermalManager.degHotend(e) >= (trigger) && !busy) {
49+
if (thermalManager.degHotend(e) >= cfg.trigger && !busy) {
5350
do_prot = true; break;
5451
}
5552
}
5653
if (bool(next_protect_ms) != do_prot)
57-
next_protect_ms = do_prot ? ms + (timeout * 1000) : 0;
54+
next_protect_ms = do_prot ? ms + cfg.timeout * 1000 : 0;
5855
}
5956

6057
void HotendIdleProtection::check_e_motion(const millis_t &ms) {
6158
static float old_e_position = 0;
6259
if (old_e_position != current_position.e) {
6360
old_e_position = current_position.e; // Track filament motion
6461
if (next_protect_ms) // If some heater is on then...
65-
next_protect_ms = ms + (timeout * 1000); // ...delay the timeout till later
62+
next_protect_ms = ms + cfg.timeout * 1000; // ...delay the timeout till later
6663
}
6764
}
6865

@@ -83,12 +80,12 @@ void HotendIdleProtection::timed_out() {
8380
SERIAL_ECHOLNPGM("Hotend Idle Timeout");
8481
LCD_MESSAGE(MSG_HOTEND_IDLE_TIMEOUT);
8582
HOTEND_LOOP() {
86-
if (nozzle_target < thermalManager.degTargetHotend(e))
87-
thermalManager.setTargetHotend(nozzle_target, e);
83+
if (cfg.nozzle_target < thermalManager.degTargetHotend(e))
84+
thermalManager.setTargetHotend(cfg.nozzle_target, e);
8885
}
8986
#if HAS_HEATED_BED
90-
if (bed_target < thermalManager.degTargetBed())
91-
thermalManager.setTargetBed(bed_target);
87+
if (cfg.bed_target < thermalManager.degTargetBed())
88+
thermalManager.setTargetBed(cfg.bed_target);
9289
#endif
9390
}
9491

Marlin/src/feature/hotend_idle.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,25 @@
2121
*/
2222
#pragma once
2323

24-
#include "../core/millis_t.h"
24+
#include "../inc/MarlinConfig.h"
25+
26+
typedef struct {
27+
uint16_t timeout = HOTEND_IDLE_TIMEOUT_SEC,
28+
trigger = HOTEND_IDLE_MIN_TRIGGER,
29+
nozzle_target = HOTEND_IDLE_NOZZLE_TARGET,
30+
bed_target = HOTEND_IDLE_BED_TARGET;
31+
void reset() {
32+
timeout = HOTEND_IDLE_TIMEOUT_SEC;
33+
trigger = HOTEND_IDLE_MIN_TRIGGER;
34+
nozzle_target = HOTEND_IDLE_NOZZLE_TARGET;
35+
bed_target = HOTEND_IDLE_BED_TARGET;
36+
}
37+
} hotend_idle_settings_t;
2538

2639
class HotendIdleProtection {
2740
public:
2841
static void check();
29-
static uint16_t timeout, trigger, nozzle_target, bed_target;
42+
static hotend_idle_settings_t cfg;
3043
private:
3144
static millis_t next_protect_ms;
3245
static void check_hotends(const millis_t &ms);

Marlin/src/lcd/menu/menu_configuration.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,10 @@ void menu_advanced_settings();
287287
START_MENU();
288288
BACK_ITEM(MSG_BACK);
289289

290-
EDIT_ITEM(uint16_3, MSG_TIMEOUT, &hotend_idle.timeout, 0, 999);
291-
EDIT_ITEM(uint16_3, MSG_TEMPERATURE, &hotend_idle.trigger, 0, 999);
292-
EDIT_ITEM(uint16_3, MSG_HOTEND_IDLE_NOZZLE_TARGET, &hotend_idle.nozzle_target, 0, 999);
293-
EDIT_ITEM(uint16_3, MSG_HOTEND_IDLE_BED_TARGET, &hotend_idle.bed_target, 0, 999);
290+
EDIT_ITEM(uint16_3, MSG_TIMEOUT, &hotend_idle.cfg.timeout, 0, 999);
291+
EDIT_ITEM(uint16_3, MSG_TEMPERATURE, &hotend_idle.cfg.trigger, 0, 999);
292+
EDIT_ITEM(uint16_3, MSG_HOTEND_IDLE_NOZZLE_TARGET, &hotend_idle.cfg.nozzle_target, 0, 999);
293+
EDIT_ITEM(uint16_3, MSG_HOTEND_IDLE_BED_TARGET, &hotend_idle.cfg.bed_target, 0, 999);
294294

295295
END_MENU();
296296
}

Marlin/src/module/settings.cpp

+9-13
Original file line numberDiff line numberDiff line change
@@ -628,13 +628,10 @@ typedef struct SettingsDataStruct {
628628
#endif
629629

630630
//
631-
// HOTEND_IDLE_TIMEOUT Settings
631+
// HOTEND_IDLE_TIMEOUT
632632
//
633633
#if ENABLED(HOTEND_IDLE_TIMEOUT)
634-
uint16_t hotend_idle_timeout,
635-
hotend_idle_trigger,
636-
hotend_idle_nozzle_target,
637-
hotend_idle_bed_target;
634+
hotend_idle_settings_t hotend_idle_config;
638635
#endif
639636

640637
} SettingsData;
@@ -1732,10 +1729,7 @@ void MarlinSettings::postprocess() {
17321729
// HOTEND_IDLE_TIMEOUT
17331730
//
17341731
#if ENABLED(HOTEND_IDLE_TIMEOUT)
1735-
EEPROM_WRITE(hotend_idle.timeout);
1736-
EEPROM_WRITE(hotend_idle.trigger);
1737-
EEPROM_WRITE(hotend_idle.nozzle_target);
1738-
EEPROM_WRITE(hotend_idle.bed_target);
1732+
EEPROM_WRITE(hotend_idle.cfg);
17391733
#endif
17401734

17411735
//
@@ -2809,10 +2803,7 @@ void MarlinSettings::postprocess() {
28092803
// HOTEND_IDLE_TIMEOUT
28102804
//
28112805
#if ENABLED(HOTEND_IDLE_TIMEOUT)
2812-
EEPROM_READ(hotend_idle.timeout);
2813-
EEPROM_READ(hotend_idle.trigger);
2814-
EEPROM_READ(hotend_idle.nozzle_target);
2815-
EEPROM_READ(hotend_idle.bed_target);
2806+
EEPROM_READ(hotend_idle.cfg);
28162807
#endif
28172808

28182809
//
@@ -3624,6 +3615,11 @@ void MarlinSettings::reset() {
36243615
#endif
36253616
#endif
36263617

3618+
//
3619+
// Hotend Idle Timeout
3620+
//
3621+
TERN_(HOTEND_IDLE_TIMEOUT, hotend_idle.cfg.reset());
3622+
36273623
postprocess();
36283624

36293625
#if ANY(EEPROM_CHITCHAT, DEBUG_LEVELING_FEATURE)

0 commit comments

Comments
 (0)