|
@@ -236,7 +236,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
236
|
236
|
* Alternately heat and cool the nozzle, observing its behavior to
|
237
|
237
|
* determine the best PID values to achieve a stable temperature.
|
238
|
238
|
*/
|
239
|
|
- void Temperature::PID_autotune(const float &target, const int8_t hotend, const int8_t ncycles, const bool set_result/*=false*/) {
|
|
239
|
+ void Temperature::PID_autotune(const float &target, const int8_t heater, const int8_t ncycles, const bool set_result/*=false*/) {
|
240
|
240
|
float current = 0.0;
|
241
|
241
|
int cycles = 0;
|
242
|
242
|
bool heating = true;
|
|
@@ -249,10 +249,10 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
249
|
249
|
float max = 0, min = 10000;
|
250
|
250
|
|
251
|
251
|
#if HAS_PID_FOR_BOTH
|
252
|
|
- #define GHV(B,H) (hotend < 0 ? (B) : (H))
|
253
|
|
- #define SHV(S,B,H) do{ if (hotend < 0) S##_bed = B; else S [hotend] = H; }while(0)
|
254
|
|
- #define ONHEATINGSTART() (hotend < 0 ? printerEventLEDs.onBedHeatingStart() : printerEventLEDs.onHotendHeatingStart())
|
255
|
|
- #define ONHEATING(S,C,T) do{ if (hotend < 0) printerEventLEDs.onBedHeating(S,C,T); else printerEventLEDs.onHotendHeating(S,C,T); }while(0)
|
|
252
|
+ #define GHV(B,H) (heater < 0 ? (B) : (H))
|
|
253
|
+ #define SHV(S,B,H) do{ if (heater < 0) S##_bed = B; else S [heater] = H; }while(0)
|
|
254
|
+ #define ONHEATINGSTART() (heater < 0 ? printerEventLEDs.onBedHeatingStart() : printerEventLEDs.onHotendHeatingStart())
|
|
255
|
+ #define ONHEATING(S,C,T) do{ if (heater < 0) printerEventLEDs.onBedHeating(S,C,T); else printerEventLEDs.onHotendHeating(S,C,T); }while(0)
|
256
|
256
|
#elif ENABLED(PIDTEMPBED)
|
257
|
257
|
#define GHV(B,H) B
|
258
|
258
|
#define SHV(S,B,H) (S##_bed = B)
|
|
@@ -260,7 +260,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
260
|
260
|
#define ONHEATING(S,C,T) printerEventLEDs.onBedHeating(S,C,T)
|
261
|
261
|
#else
|
262
|
262
|
#define GHV(B,H) H
|
263
|
|
- #define SHV(S,B,H) (S [hotend] = H)
|
|
263
|
+ #define SHV(S,B,H) (S [heater] = H)
|
264
|
264
|
#define ONHEATINGSTART() printerEventLEDs.onHotendHeatingStart()
|
265
|
265
|
#define ONHEATING(S,C,T) printerEventLEDs.onHotendHeating(S,C,T)
|
266
|
266
|
#endif
|
|
@@ -268,7 +268,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
268
|
268
|
#if WATCH_THE_BED || WATCH_HOTENDS
|
269
|
269
|
#define HAS_TP_BED (ENABLED(THERMAL_PROTECTION_BED) && ENABLED(PIDTEMPBED))
|
270
|
270
|
#if HAS_TP_BED && ENABLED(THERMAL_PROTECTION_HOTENDS) && ENABLED(PIDTEMP)
|
271
|
|
- #define GTV(B,H) (hotend < 0 ? (B) : (H))
|
|
271
|
+ #define GTV(B,H) (heater < 0 ? (B) : (H))
|
272
|
272
|
#elif HAS_TP_BED
|
273
|
273
|
#define GTV(B,H) (B)
|
274
|
274
|
#else
|
|
@@ -286,22 +286,6 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
286
|
286
|
next_auto_fan_check_ms = next_temp_ms + 2500UL;
|
287
|
287
|
#endif
|
288
|
288
|
|
289
|
|
- #if ENABLED(PIDTEMP)
|
290
|
|
- #define _TOP_HOTEND HOTENDS - 1
|
291
|
|
- #else
|
292
|
|
- #define _TOP_HOTEND -1
|
293
|
|
- #endif
|
294
|
|
- #if ENABLED(PIDTEMPBED)
|
295
|
|
- #define _BOT_HOTEND -1
|
296
|
|
- #else
|
297
|
|
- #define _BOT_HOTEND 0
|
298
|
|
- #endif
|
299
|
|
-
|
300
|
|
- if (!WITHIN(hotend, _BOT_HOTEND, _TOP_HOTEND)) {
|
301
|
|
- SERIAL_ECHOLNPGM(MSG_PID_BAD_EXTRUDER_NUM);
|
302
|
|
- return;
|
303
|
|
- }
|
304
|
|
-
|
305
|
289
|
SERIAL_ECHOLNPGM(MSG_PID_AUTOTUNE_START);
|
306
|
290
|
|
307
|
291
|
disable_all_heaters();
|
|
@@ -310,7 +294,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
310
|
294
|
|
311
|
295
|
wait_for_heatup = true; // Can be interrupted with M108
|
312
|
296
|
#if ENABLED(PRINTER_EVENT_LEDS)
|
313
|
|
- const float start_temp = GHV(current_temperature_bed, current_temperature[hotend]);
|
|
297
|
+ const float start_temp = GHV(current_temperature_bed, current_temperature[heater]);
|
314
|
298
|
LEDColor color = ONHEATINGSTART();
|
315
|
299
|
#endif
|
316
|
300
|
|
|
@@ -323,7 +307,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
323
|
307
|
updateTemperaturesFromRawValues();
|
324
|
308
|
|
325
|
309
|
// Get the current temperature and constrain it
|
326
|
|
- current = GHV(current_temperature_bed, current_temperature[hotend]);
|
|
310
|
+ current = GHV(current_temperature_bed, current_temperature[heater]);
|
327
|
311
|
NOLESS(max, current);
|
328
|
312
|
NOMORE(min, current);
|
329
|
313
|
|
|
@@ -412,7 +396,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
412
|
396
|
// Report heater states every 2 seconds
|
413
|
397
|
if (ELAPSED(ms, next_temp_ms)) {
|
414
|
398
|
#if HAS_TEMP_SENSOR
|
415
|
|
- print_heaterstates();
|
|
399
|
+ print_heater_states(heater >= 0 ? heater : active_extruder);
|
416
|
400
|
SERIAL_EOL();
|
417
|
401
|
#endif
|
418
|
402
|
next_temp_ms = ms + 2000UL;
|
|
@@ -423,9 +407,9 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
423
|
407
|
#if WATCH_THE_BED && WATCH_HOTENDS
|
424
|
408
|
true
|
425
|
409
|
#elif WATCH_HOTENDS
|
426
|
|
- hotend >= 0
|
|
410
|
+ heater >= 0
|
427
|
411
|
#else
|
428
|
|
- hotend < 0
|
|
412
|
+ heater < 0
|
429
|
413
|
#endif
|
430
|
414
|
) {
|
431
|
415
|
if (!heated) { // If not yet reached target...
|
|
@@ -435,10 +419,10 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
435
|
419
|
if (current > watch_temp_target) heated = true; // - Flag if target temperature reached
|
436
|
420
|
}
|
437
|
421
|
else if (ELAPSED(ms, temp_change_ms)) // Watch timer expired
|
438
|
|
- _temp_error(hotend, PSTR(MSG_T_HEATING_FAILED), TEMP_ERR_PSTR(MSG_HEATING_FAILED_LCD, hotend));
|
|
422
|
+ _temp_error(heater, PSTR(MSG_T_HEATING_FAILED), TEMP_ERR_PSTR(MSG_HEATING_FAILED_LCD, heater));
|
439
|
423
|
}
|
440
|
424
|
else if (current < target - (MAX_OVERSHOOT_PID_AUTOTUNE)) // Heated, then temperature fell too far?
|
441
|
|
- _temp_error(hotend, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, hotend));
|
|
425
|
+ _temp_error(heater, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, heater));
|
442
|
426
|
}
|
443
|
427
|
#endif
|
444
|
428
|
} // every 2 seconds
|
|
@@ -477,15 +461,15 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
477
|
461
|
}while(0)
|
478
|
462
|
|
479
|
463
|
#define _SET_EXTRUDER_PID() do { \
|
480
|
|
- PID_PARAM(Kp, hotend) = tune_pid.Kp; \
|
481
|
|
- PID_PARAM(Ki, hotend) = scalePID_i(tune_pid.Ki); \
|
482
|
|
- PID_PARAM(Kd, hotend) = scalePID_d(tune_pid.Kd); \
|
|
464
|
+ PID_PARAM(Kp, heater) = tune_pid.Kp; \
|
|
465
|
+ PID_PARAM(Ki, heater) = scalePID_i(tune_pid.Ki); \
|
|
466
|
+ PID_PARAM(Kd, heater) = scalePID_d(tune_pid.Kd); \
|
483
|
467
|
updatePID(); }while(0)
|
484
|
468
|
|
485
|
469
|
// Use the result? (As with "M303 U1")
|
486
|
470
|
if (set_result) {
|
487
|
471
|
#if HAS_PID_FOR_BOTH
|
488
|
|
- if (hotend < 0) _SET_BED_PID(); else _SET_EXTRUDER_PID();
|
|
472
|
+ if (heater < 0) _SET_BED_PID(); else _SET_EXTRUDER_PID();
|
489
|
473
|
#elif ENABLED(PIDTEMP)
|
490
|
474
|
_SET_EXTRUDER_PID();
|
491
|
475
|
#else
|
|
@@ -575,13 +559,13 @@ int Temperature::getHeaterPower(const int heater) {
|
575
|
559
|
//
|
576
|
560
|
// Temperature Error Handlers
|
577
|
561
|
//
|
578
|
|
-void Temperature::_temp_error(const int8_t e, PGM_P const serial_msg, PGM_P const lcd_msg) {
|
|
562
|
+void Temperature::_temp_error(const int8_t heater, PGM_P const serial_msg, PGM_P const lcd_msg) {
|
579
|
563
|
static bool killed = false;
|
580
|
564
|
if (IsRunning()) {
|
581
|
565
|
SERIAL_ERROR_START();
|
582
|
566
|
serialprintPGM(serial_msg);
|
583
|
567
|
SERIAL_ERRORPGM(MSG_STOPPED_HEATER);
|
584
|
|
- if (e >= 0) SERIAL_ERRORLN((int)e); else SERIAL_ERRORLNPGM(MSG_HEATER_BED);
|
|
568
|
+ if (heater >= 0) SERIAL_ERRORLN((int)heater); else SERIAL_ERRORLNPGM(MSG_HEATER_BED);
|
585
|
569
|
}
|
586
|
570
|
#if DISABLED(BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE)
|
587
|
571
|
if (!killed) {
|
|
@@ -594,12 +578,12 @@ void Temperature::_temp_error(const int8_t e, PGM_P const serial_msg, PGM_P cons
|
594
|
578
|
#endif
|
595
|
579
|
}
|
596
|
580
|
|
597
|
|
-void Temperature::max_temp_error(const int8_t e) {
|
598
|
|
- _temp_error(e, PSTR(MSG_T_MAXTEMP), TEMP_ERR_PSTR(MSG_ERR_MAXTEMP, e));
|
|
581
|
+void Temperature::max_temp_error(const int8_t heater) {
|
|
582
|
+ _temp_error(heater, PSTR(MSG_T_MAXTEMP), TEMP_ERR_PSTR(MSG_ERR_MAXTEMP, heater));
|
599
|
583
|
}
|
600
|
584
|
|
601
|
|
-void Temperature::min_temp_error(const int8_t e) {
|
602
|
|
- _temp_error(e, PSTR(MSG_T_MINTEMP), TEMP_ERR_PSTR(MSG_ERR_MINTEMP, e));
|
|
585
|
+void Temperature::min_temp_error(const int8_t heater) {
|
|
586
|
+ _temp_error(heater, PSTR(MSG_T_MINTEMP), TEMP_ERR_PSTR(MSG_ERR_MINTEMP, heater));
|
603
|
587
|
}
|
604
|
588
|
|
605
|
589
|
float Temperature::get_pid_output(const int8_t e) {
|
|
@@ -2346,15 +2330,15 @@ void Temperature::isr() {
|
2346
|
2330
|
delay(2);
|
2347
|
2331
|
}
|
2348
|
2332
|
|
2349
|
|
- void Temperature::print_heaterstates(
|
|
2333
|
+ void Temperature::print_heater_states(const uint8_t target_extruder
|
2350
|
2334
|
#if NUM_SERIAL > 1
|
2351
|
|
- const int8_t port
|
|
2335
|
+ , const int8_t port
|
2352
|
2336
|
#endif
|
2353
|
2337
|
) {
|
2354
|
2338
|
#if HAS_TEMP_HOTEND
|
2355
|
|
- print_heater_state(degHotend(gcode.target_extruder), degTargetHotend(gcode.target_extruder)
|
|
2339
|
+ print_heater_state(degHotend(target_extruder), degTargetHotend(target_extruder)
|
2356
|
2340
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
2357
|
|
- , rawHotendTemp(gcode.target_extruder)
|
|
2341
|
+ , rawHotendTemp(target_extruder)
|
2358
|
2342
|
#endif
|
2359
|
2343
|
#if NUM_SERIAL > 1
|
2360
|
2344
|
, port
|
|
@@ -2392,7 +2376,7 @@ void Temperature::isr() {
|
2392
|
2376
|
);
|
2393
|
2377
|
#endif
|
2394
|
2378
|
SERIAL_PROTOCOLPGM_P(port, " @:");
|
2395
|
|
- SERIAL_PROTOCOL_P(port, getHeaterPower(gcode.target_extruder));
|
|
2379
|
+ SERIAL_PROTOCOL_P(port, getHeaterPower(target_extruder));
|
2396
|
2380
|
#if HAS_HEATED_BED
|
2397
|
2381
|
SERIAL_PROTOCOLPGM_P(port, " B@:");
|
2398
|
2382
|
SERIAL_PROTOCOL_P(port, getHeaterPower(-1));
|
|
@@ -2414,7 +2398,7 @@ void Temperature::isr() {
|
2414
|
2398
|
void Temperature::auto_report_temperatures() {
|
2415
|
2399
|
if (auto_report_temp_interval && ELAPSED(millis(), next_temp_report_ms)) {
|
2416
|
2400
|
next_temp_report_ms = millis() + 1000UL * auto_report_temp_interval;
|
2417
|
|
- print_heaterstates();
|
|
2401
|
+ print_heater_states(active_extruder);
|
2418
|
2402
|
SERIAL_EOL();
|
2419
|
2403
|
}
|
2420
|
2404
|
}
|
|
@@ -2480,9 +2464,9 @@ void Temperature::isr() {
|
2480
|
2464
|
}
|
2481
|
2465
|
|
2482
|
2466
|
now = millis();
|
2483
|
|
- if (ELAPSED(now, next_temp_ms)) { //Print temp & remaining time every 1s while waiting
|
|
2467
|
+ if (ELAPSED(now, next_temp_ms)) { // Print temp & remaining time every 1s while waiting
|
2484
|
2468
|
next_temp_ms = now + 1000UL;
|
2485
|
|
- print_heaterstates();
|
|
2469
|
+ print_heater_states(target_extruder);
|
2486
|
2470
|
#if TEMP_RESIDENCY_TIME > 0
|
2487
|
2471
|
SERIAL_PROTOCOLPGM(" W:");
|
2488
|
2472
|
if (residency_start_ms)
|
|
@@ -2587,8 +2571,6 @@ void Temperature::isr() {
|
2587
|
2571
|
KEEPALIVE_STATE(NOT_BUSY);
|
2588
|
2572
|
#endif
|
2589
|
2573
|
|
2590
|
|
- gcode.target_extruder = active_extruder; // for print_heaterstates
|
2591
|
|
-
|
2592
|
2574
|
#if ENABLED(PRINTER_EVENT_LEDS)
|
2593
|
2575
|
const float start_temp = degBed();
|
2594
|
2576
|
printerEventLEDs.onBedHeatingStart();
|
|
@@ -2607,7 +2589,7 @@ void Temperature::isr() {
|
2607
|
2589
|
now = millis();
|
2608
|
2590
|
if (ELAPSED(now, next_temp_ms)) { //Print Temp Reading every 1 second while heating up.
|
2609
|
2591
|
next_temp_ms = now + 1000UL;
|
2610
|
|
- print_heaterstates();
|
|
2592
|
+ print_heater_states(active_extruder);
|
2611
|
2593
|
#if TEMP_BED_RESIDENCY_TIME > 0
|
2612
|
2594
|
SERIAL_PROTOCOLPGM(" W:");
|
2613
|
2595
|
if (residency_start_ms)
|