Skip to content

Commit d678504

Browse files
thinkyheadLCh-77
authored andcommittedJul 19, 2022
♻️ Encapsulate PID in class (MarlinFirmware#24389)
1 parent af0ab24 commit d678504

File tree

12 files changed

+210
-292
lines changed

12 files changed

+210
-292
lines changed
 

‎Marlin/src/MarlinCore.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ void idle(bool no_stepper_sleep/*=false*/) {
789789
manage_inactivity(no_stepper_sleep);
790790

791791
// Manage Heaters (and Watchdog)
792-
thermalManager.manage_heater();
792+
thermalManager.task();
793793

794794
// Max7219 heartbeat, animation, etc
795795
TERN_(MAX7219_DEBUG, max7219.idle_tasks());

‎Marlin/src/core/language.h

-4
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,6 @@
227227
#define STR_PID_DEBUG " PID_DEBUG "
228228
#define STR_PID_DEBUG_INPUT ": Input "
229229
#define STR_PID_DEBUG_OUTPUT " Output "
230-
#define STR_PID_DEBUG_PTERM " pTerm "
231-
#define STR_PID_DEBUG_ITERM " iTerm "
232-
#define STR_PID_DEBUG_DTERM " dTerm "
233-
#define STR_PID_DEBUG_CTERM " cTerm "
234230
#define STR_INVALID_EXTRUDER_NUM " - Invalid extruder number !"
235231
#define STR_MPC_AUTOTUNE "MPC Autotune"
236232
#define STR_MPC_AUTOTUNE_START " start for " STR_E

‎Marlin/src/core/utility.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ void safe_delay(millis_t ms) {
2929
while (ms > 50) {
3030
ms -= 50;
3131
delay(50);
32-
thermalManager.manage_heater();
32+
thermalManager.task();
3333
}
3434
delay(ms);
35-
thermalManager.manage_heater(); // This keeps us safe if too many small safe_delay() calls are made
35+
thermalManager.task(); // This keeps us safe if too many small safe_delay() calls are made
3636
}
3737

3838
// A delay to provide brittle hosts time to receive bytes

‎Marlin/src/gcode/motion/G2_G3.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ void plan_arc(
290290

291291
for (uint16_t i = 1; i < segments; i++) { // Iterate (segments-1) times
292292

293-
thermalManager.manage_heater();
293+
thermalManager.task();
294294
const millis_t ms = millis();
295295
if (ELAPSED(ms, next_idle_ms)) {
296296
next_idle_ms = ms + 200UL;

‎Marlin/src/gcode/queue.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ inline bool process_line_done(uint8_t &sis, char (&buff)[MAX_CMD_SIZE], int &ind
384384
buff[ind] = '\0'; // Of course, I'm a Terminator.
385385
const bool is_empty = (ind == 0); // An empty line?
386386
if (is_empty)
387-
thermalManager.manage_heater(); // Keep sensors satisfied
387+
thermalManager.task(); // Keep sensors satisfied
388388
else
389389
ind = 0; // Start a new line
390390
return is_empty; // Inform the caller

‎Marlin/src/lcd/extui/ui_api.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ namespace ExtUI {
169169
}
170170

171171
void yield() {
172-
if (!flags.printer_killed) thermalManager.manage_heater();
172+
if (!flags.printer_killed) thermalManager.task();
173173
}
174174

175175
void enableHeater(const extruder_t extruder) {

‎Marlin/src/libs/buzzer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void Buzzer::tone(const uint16_t duration, const uint16_t frequency/*=0*/) {
4848
if (!ui.sound_on) return;
4949
while (buffer.isFull()) {
5050
tick();
51-
thermalManager.manage_heater();
51+
thermalManager.task();
5252
}
5353
tone_t tone = { duration, frequency };
5454
buffer.enqueue(tone);

‎Marlin/src/module/motion.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) {
970970
next_idle_ms = ms + 200UL;
971971
return idle();
972972
}
973-
thermalManager.manage_heater(); // Returns immediately on most calls
973+
thermalManager.task(); // Returns immediately on most calls
974974
}
975975

976976
#if IS_KINEMATIC

‎Marlin/src/module/planner_bezier.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void cubic_b_spline(
123123

124124
for (float t = 0; t < 1;) {
125125

126-
thermalManager.manage_heater();
126+
thermalManager.task();
127127
millis_t now = millis();
128128
if (ELAPSED(now, next_idle_ms)) {
129129
next_idle_ms = now + 200UL;

‎Marlin/src/module/temperature.cpp

+189-273
Large diffs are not rendered by default.

‎Marlin/src/module/temperature.h

+11-5
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ typedef struct TempInfo {
232232
typedef struct HeaterInfo : public TempInfo {
233233
celsius_t target;
234234
uint8_t soft_pwm_amount;
235+
bool is_below_target(const celsius_t offs=0) const { return (celsius < (target + offs)); }
235236
} heater_info_t;
236237

237238
// A heater with PID stabilization
@@ -715,9 +716,9 @@ class Temperature {
715716
static void readings_ready();
716717

717718
/**
718-
* Call periodically to manage heaters
719+
* Call periodically to manage heaters and keep the watchdog fed
719720
*/
720-
static void manage_heater() __O2; // __O2 added to work around a compiler error
721+
static void task();
721722

722723
/**
723724
* Preheating hotends
@@ -807,6 +808,8 @@ class Temperature {
807808
#endif
808809
}
809810

811+
static void manage_hotends(const millis_t &ms);
812+
810813
#endif // HAS_HOTEND
811814

812815
#if HAS_HEATED_BED
@@ -819,6 +822,9 @@ class Temperature {
819822
static celsius_t degTargetBed() { return temp_bed.target; }
820823
static bool isHeatingBed() { return temp_bed.target > temp_bed.celsius; }
821824
static bool isCoolingBed() { return temp_bed.target < temp_bed.celsius; }
825+
static bool degBedNear(const celsius_t temp) {
826+
return ABS(wholeDegBed() - temp) < (TEMP_BED_HYSTERESIS);
827+
}
822828

823829
// Start watching the Bed to make sure it's really heating up
824830
static void start_watching_bed() { TERN_(WATCH_BED, watch_bed.restart(degBed(), degTargetBed())); }
@@ -835,9 +841,7 @@ class Temperature {
835841

836842
static void wait_for_bed_heating();
837843

838-
static bool degBedNear(const celsius_t temp) {
839-
return ABS(wholeDegBed() - temp) < (TEMP_BED_HYSTERESIS);
840-
}
844+
static void manage_heated_bed(const millis_t &ms);
841845

842846
#endif // HAS_HEATED_BED
843847

@@ -863,6 +867,7 @@ class Temperature {
863867
static bool isHeatingChamber() { return temp_chamber.target > temp_chamber.celsius; }
864868
static bool isCoolingChamber() { return temp_chamber.target < temp_chamber.celsius; }
865869
static bool wait_for_chamber(const bool no_wait_for_cooling=true);
870+
static void manage_heated_chamber(const millis_t &ms);
866871
#endif
867872
#endif
868873

@@ -886,6 +891,7 @@ class Temperature {
886891
static bool isLaserHeating() { return temp_cooler.target > temp_cooler.celsius; }
887892
static bool isLaserCooling() { return temp_cooler.target < temp_cooler.celsius; }
888893
static bool wait_for_cooler(const bool no_wait_for_cooling=true);
894+
static void manage_cooler(const millis_t &ms);
889895
#endif
890896
#endif
891897

‎Marlin/src/sd/usb_flashdrive/Sd2Card_FlashDrive.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
#define USB_HOST_MANUAL_POLL // Optimization to shut off IRQ automatically
6363

6464
// Workarounds to keep Marlin's watchdog timer from barking...
65-
void marlin_yield() { thermalManager.manage_heater(); }
65+
void marlin_yield() { thermalManager.task(); }
6666
#define SYSTEM_OR_SPECIAL_YIELD(...) marlin_yield();
6767
#define delay(x) safe_delay(x)
6868

0 commit comments

Comments
 (0)
Please sign in to comment.