Sfoglia il codice sorgente

Temperature singleton class

Scott Lahteine 8 anni fa
parent
commit
084f6b5b44

+ 0
- 4
Marlin/Marlin.h Vedi File

@@ -340,10 +340,6 @@ extern int16_t code_value_short();
340 340
   extern uint8_t host_keepalive_interval;
341 341
 #endif
342 342
 
343
-#if ENABLED(PREVENT_DANGEROUS_EXTRUDE)
344
-  extern float extrude_min_temp;
345
-#endif
346
-
347 343
 #if FAN_COUNT > 0
348 344
   extern int fanSpeeds[FAN_COUNT];
349 345
 #endif

+ 60
- 66
Marlin/Marlin_main.cpp Vedi File

@@ -544,10 +544,6 @@ static void report_current_position();
544 544
   }
545 545
 #endif
546 546
 
547
-#if ENABLED(PREVENT_DANGEROUS_EXTRUDE)
548
-  float extrude_min_temp = EXTRUDE_MINTEMP;
549
-#endif
550
-
551 547
 #if ENABLED(SDSUPPORT)
552 548
   #include "SdFatUtil.h"
553 549
   int freeMemory() { return SdFatUtil::FreeRam(); }
@@ -816,7 +812,7 @@ void setup() {
816 812
 
817 813
   lcd_init();
818 814
 
819
-  tp_init();    // Initialize temperature loop
815
+  thermalManager.init();    // Initialize temperature loop
820 816
 
821 817
   #if ENABLED(DELTA) || ENABLED(SCARA)
822 818
     // Vital to init kinematic equivalent for X0 Y0 Z0
@@ -3839,7 +3835,7 @@ inline void gcode_M31() {
3839 3835
   SERIAL_ECHO_START;
3840 3836
   SERIAL_ECHOLN(time);
3841 3837
   lcd_setstatus(time);
3842
-  autotempShutdown();
3838
+  thermalManager.autotempShutdown();
3843 3839
 }
3844 3840
 
3845 3841
 #if ENABLED(SDSUPPORT)
@@ -4274,10 +4270,10 @@ inline void gcode_M104() {
4274 4270
 
4275 4271
   if (code_seen('S')) {
4276 4272
     float temp = code_value();
4277
-    setTargetHotend(temp, target_extruder);
4273
+    thermalManager.setTargetHotend(temp, target_extruder);
4278 4274
     #if ENABLED(DUAL_X_CARRIAGE)
4279 4275
       if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && target_extruder == 0)
4280
-        setTargetHotend1(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset);
4276
+        thermalManager.setTargetHotend(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset, 1);
4281 4277
     #endif
4282 4278
 
4283 4279
     /**
@@ -4296,7 +4292,7 @@ inline void gcode_M104() {
4296 4292
      */
4297 4293
     else print_job_timer.start();
4298 4294
 
4299
-    if (temp > degHotend(target_extruder)) LCD_MESSAGEPGM(MSG_HEATING);
4295
+    if (temp > thermalManager.degHotend(target_extruder)) LCD_MESSAGEPGM(MSG_HEATING);
4300 4296
   }
4301 4297
 }
4302 4298
 
@@ -4305,41 +4301,41 @@ inline void gcode_M104() {
4305 4301
   void print_heaterstates() {
4306 4302
     #if HAS_TEMP_HOTEND
4307 4303
       SERIAL_PROTOCOLPGM(" T:");
4308
-      SERIAL_PROTOCOL_F(degHotend(target_extruder), 1);
4304
+      SERIAL_PROTOCOL_F(thermalManager.degHotend(target_extruder), 1);
4309 4305
       SERIAL_PROTOCOLPGM(" /");
4310
-      SERIAL_PROTOCOL_F(degTargetHotend(target_extruder), 1);
4306
+      SERIAL_PROTOCOL_F(thermalManager.degTargetHotend(target_extruder), 1);
4311 4307
     #endif
4312 4308
     #if HAS_TEMP_BED
4313 4309
       SERIAL_PROTOCOLPGM(" B:");
4314
-      SERIAL_PROTOCOL_F(degBed(), 1);
4310
+      SERIAL_PROTOCOL_F(thermalManager.degBed(), 1);
4315 4311
       SERIAL_PROTOCOLPGM(" /");
4316
-      SERIAL_PROTOCOL_F(degTargetBed(), 1);
4312
+      SERIAL_PROTOCOL_F(thermalManager.degTargetBed(), 1);
4317 4313
     #endif
4318 4314
     #if EXTRUDERS > 1
4319 4315
       for (int8_t e = 0; e < EXTRUDERS; ++e) {
4320 4316
         SERIAL_PROTOCOLPGM(" T");
4321 4317
         SERIAL_PROTOCOL(e);
4322 4318
         SERIAL_PROTOCOLCHAR(':');
4323
-        SERIAL_PROTOCOL_F(degHotend(e), 1);
4319
+        SERIAL_PROTOCOL_F(thermalManager.degHotend(e), 1);
4324 4320
         SERIAL_PROTOCOLPGM(" /");
4325
-        SERIAL_PROTOCOL_F(degTargetHotend(e), 1);
4321
+        SERIAL_PROTOCOL_F(thermalManager.degTargetHotend(e), 1);
4326 4322
       }
4327 4323
     #endif
4328 4324
     #if HAS_TEMP_BED
4329 4325
       SERIAL_PROTOCOLPGM(" B@:");
4330 4326
       #ifdef BED_WATTS
4331
-        SERIAL_PROTOCOL(((BED_WATTS) * getHeaterPower(-1)) / 127);
4327
+        SERIAL_PROTOCOL(((BED_WATTS) * thermalManager.getHeaterPower(-1)) / 127);
4332 4328
         SERIAL_PROTOCOLCHAR('W');
4333 4329
       #else
4334
-        SERIAL_PROTOCOL(getHeaterPower(-1));
4330
+        SERIAL_PROTOCOL(thermalManager.getHeaterPower(-1));
4335 4331
       #endif
4336 4332
     #endif
4337 4333
     SERIAL_PROTOCOLPGM(" @:");
4338 4334
     #ifdef EXTRUDER_WATTS
4339
-      SERIAL_PROTOCOL(((EXTRUDER_WATTS) * getHeaterPower(target_extruder)) / 127);
4335
+      SERIAL_PROTOCOL(((EXTRUDER_WATTS) * thermalManager.getHeaterPower(target_extruder)) / 127);
4340 4336
       SERIAL_PROTOCOLCHAR('W');
4341 4337
     #else
4342
-      SERIAL_PROTOCOL(getHeaterPower(target_extruder));
4338
+      SERIAL_PROTOCOL(thermalManager.getHeaterPower(target_extruder));
4343 4339
     #endif
4344 4340
     #if EXTRUDERS > 1
4345 4341
       for (int8_t e = 0; e < EXTRUDERS; ++e) {
@@ -4347,27 +4343,27 @@ inline void gcode_M104() {
4347 4343
         SERIAL_PROTOCOL(e);
4348 4344
         SERIAL_PROTOCOLCHAR(':');
4349 4345
         #ifdef EXTRUDER_WATTS
4350
-          SERIAL_PROTOCOL(((EXTRUDER_WATTS) * getHeaterPower(e)) / 127);
4346
+          SERIAL_PROTOCOL(((EXTRUDER_WATTS) * thermalManager.getHeaterPower(e)) / 127);
4351 4347
           SERIAL_PROTOCOLCHAR('W');
4352 4348
         #else
4353
-          SERIAL_PROTOCOL(getHeaterPower(e));
4349
+          SERIAL_PROTOCOL(thermalManager.getHeaterPower(e));
4354 4350
         #endif
4355 4351
       }
4356 4352
     #endif
4357 4353
     #if ENABLED(SHOW_TEMP_ADC_VALUES)
4358 4354
       #if HAS_TEMP_BED
4359 4355
         SERIAL_PROTOCOLPGM("    ADC B:");
4360
-        SERIAL_PROTOCOL_F(degBed(), 1);
4356
+        SERIAL_PROTOCOL_F(thermalManager.degBed(), 1);
4361 4357
         SERIAL_PROTOCOLPGM("C->");
4362
-        SERIAL_PROTOCOL_F(rawBedTemp() / OVERSAMPLENR, 0);
4358
+        SERIAL_PROTOCOL_F(thermalManager.rawBedTemp() / OVERSAMPLENR, 0);
4363 4359
       #endif
4364 4360
       for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder) {
4365 4361
         SERIAL_PROTOCOLPGM("  T");
4366 4362
         SERIAL_PROTOCOL(cur_extruder);
4367 4363
         SERIAL_PROTOCOLCHAR(':');
4368
-        SERIAL_PROTOCOL_F(degHotend(cur_extruder), 1);
4364
+        SERIAL_PROTOCOL_F(thermalManager.degHotend(cur_extruder), 1);
4369 4365
         SERIAL_PROTOCOLPGM("C->");
4370
-        SERIAL_PROTOCOL_F(rawHotendTemp(cur_extruder) / OVERSAMPLENR, 0);
4366
+        SERIAL_PROTOCOL_F(thermalManager.rawHotendTemp(cur_extruder) / OVERSAMPLENR, 0);
4371 4367
       }
4372 4368
     #endif
4373 4369
   }
@@ -4427,10 +4423,10 @@ inline void gcode_M109() {
4427 4423
   bool no_wait_for_cooling = code_seen('S');
4428 4424
   if (no_wait_for_cooling || code_seen('R')) {
4429 4425
     float temp = code_value();
4430
-    setTargetHotend(temp, target_extruder);
4426
+    thermalManager.setTargetHotend(temp, target_extruder);
4431 4427
     #if ENABLED(DUAL_X_CARRIAGE)
4432 4428
       if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && target_extruder == 0)
4433
-        setTargetHotend1(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset);
4429
+        thermalManager.setTargetHotend(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset, 1);
4434 4430
     #endif
4435 4431
 
4436 4432
     /**
@@ -4449,7 +4445,7 @@ inline void gcode_M109() {
4449 4445
      */
4450 4446
     else print_job_timer.start();
4451 4447
 
4452
-    if (temp > degHotend(target_extruder)) LCD_MESSAGEPGM(MSG_HEATING);
4448
+    if (temp > thermalManager.degHotend(target_extruder)) LCD_MESSAGEPGM(MSG_HEATING);
4453 4449
   }
4454 4450
 
4455 4451
   #if ENABLED(AUTOTEMP)
@@ -4462,7 +4458,7 @@ inline void gcode_M109() {
4462 4458
     #define TEMP_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_RESIDENCY_TIME) * 1000UL))
4463 4459
   #else
4464 4460
     // Loop until the temperature is very close target
4465
-    #define TEMP_CONDITIONS (wants_to_cool ? isCoolingHotend(target_extruder) : isHeatingHotend(target_extruder))
4461
+    #define TEMP_CONDITIONS (wants_to_cool ? thermalManager.isCoolingHotend(target_extruder) : thermalManager.isHeatingHotend(target_extruder))
4466 4462
   #endif //TEMP_RESIDENCY_TIME > 0
4467 4463
 
4468 4464
   float theTarget = -1;
@@ -4473,7 +4469,6 @@ inline void gcode_M109() {
4473 4469
   KEEPALIVE_STATE(NOT_BUSY);
4474 4470
 
4475 4471
   do {
4476
-
4477 4472
     now = millis();
4478 4473
     if (ELAPSED(now, next_temp_ms)) { //Print temp & remaining time every 1s while waiting
4479 4474
       next_temp_ms = now + 1000UL;
@@ -4495,9 +4490,9 @@ inline void gcode_M109() {
4495 4490
     }
4496 4491
 
4497 4492
     // Target temperature might be changed during the loop
4498
-    if (theTarget != degTargetHotend(target_extruder)) {
4499
-      theTarget = degTargetHotend(target_extruder);
4500
-      wants_to_cool = isCoolingHotend(target_extruder);
4493
+    if (theTarget != thermalManager.degTargetHotend(target_extruder)) {
4494
+      wants_to_cool = thermalManager.isCoolingHotend(target_extruder);
4495
+      theTarget = thermalManager.degTargetHotend(target_extruder);
4501 4496
 
4502 4497
       // Exit if S<lower>, continue if S<higher>, R<lower>, or R<higher>
4503 4498
       if (no_wait_for_cooling && wants_to_cool) break;
@@ -4512,7 +4507,7 @@ inline void gcode_M109() {
4512 4507
 
4513 4508
     #if TEMP_RESIDENCY_TIME > 0
4514 4509
 
4515
-      float temp_diff = fabs(theTarget - degHotend(target_extruder));
4510
+      float temp_diff = fabs(theTarget - thermalManager.degHotend(target_extruder));
4516 4511
 
4517 4512
       if (!residency_start_ms) {
4518 4513
         // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
@@ -4542,7 +4537,7 @@ inline void gcode_M109() {
4542 4537
 
4543 4538
     LCD_MESSAGEPGM(MSG_BED_HEATING);
4544 4539
     bool no_wait_for_cooling = code_seen('S');
4545
-    if (no_wait_for_cooling || code_seen('R')) setTargetBed(code_value());
4540
+    if (no_wait_for_cooling || code_seen('R')) thermalManager.setTargetBed(code_value());
4546 4541
 
4547 4542
     #if TEMP_BED_RESIDENCY_TIME > 0
4548 4543
       millis_t residency_start_ms = 0;
@@ -4550,7 +4545,7 @@ inline void gcode_M109() {
4550 4545
       #define TEMP_BED_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_BED_RESIDENCY_TIME) * 1000UL))
4551 4546
     #else
4552 4547
       // Loop until the temperature is very close target
4553
-      #define TEMP_BED_CONDITIONS (wants_to_cool ? isCoolingBed() : isHeatingBed())
4548
+      #define TEMP_BED_CONDITIONS (wants_to_cool ? thermalManager.isCoolingBed() : thermalManager.isHeatingBed())
4554 4549
     #endif //TEMP_BED_RESIDENCY_TIME > 0
4555 4550
 
4556 4551
     float theTarget = -1;
@@ -4580,16 +4575,16 @@ inline void gcode_M109() {
4580 4575
       }
4581 4576
 
4582 4577
       // Target temperature might be changed during the loop
4583
-      if (theTarget != degTargetBed()) {
4584
-        theTarget = degTargetBed();
4585
-        wants_to_cool = isCoolingBed();
4578
+      if (theTarget != thermalManager.degTargetBed()) {
4579
+        wants_to_cool = thermalManager.isCoolingBed();
4580
+        theTarget = thermalManager.degTargetBed();
4586 4581
 
4587 4582
         // Exit if S<lower>, continue if S<higher>, R<lower>, or R<higher>
4588 4583
         if (no_wait_for_cooling && wants_to_cool) break;
4589 4584
 
4590 4585
         // Prevent a wait-forever situation if R is misused i.e. M190 R0
4591
-        // Simply don't wait for cooling below 30C
4592
-        if (wants_to_cool && theTarget < (EXTRUDE_MINTEMP)/2) break;
4586
+        // Simply don't wait to cool a bed under 30C
4587
+        if (wants_to_cool && theTarget < 30) break;
4593 4588
       }
4594 4589
 
4595 4590
       idle();
@@ -4597,7 +4592,7 @@ inline void gcode_M109() {
4597 4592
 
4598 4593
       #if TEMP_BED_RESIDENCY_TIME > 0
4599 4594
 
4600
-        float temp_diff = fabs(degBed() - degTargetBed());
4595
+        float temp_diff = fabs(theTarget - thermalManager.degBed());
4601 4596
 
4602 4597
         if (!residency_start_ms) {
4603 4598
           // Start the TEMP_BED_RESIDENCY_TIME timer when we reach target temp for the first time.
@@ -4720,7 +4715,7 @@ inline void gcode_M112() { kill(PSTR(MSG_KILLED)); }
4720 4715
  */
4721 4716
 inline void gcode_M140() {
4722 4717
   if (DEBUGGING(DRYRUN)) return;
4723
-  if (code_seen('S')) setTargetBed(code_value());
4718
+  if (code_seen('S')) thermalManager.setTargetBed(code_value());
4724 4719
 }
4725 4720
 
4726 4721
 #if ENABLED(ULTIPANEL)
@@ -4811,7 +4806,7 @@ inline void gcode_M140() {
4811 4806
  *      This code should ALWAYS be available for EMERGENCY SHUTDOWN!
4812 4807
  */
4813 4808
 inline void gcode_M81() {
4814
-  disable_all_heaters();
4809
+  thermalManager.disable_all_heaters();
4815 4810
   stepper.finish_and_disable();
4816 4811
   #if FAN_COUNT > 0
4817 4812
     #if FAN_COUNT > 1
@@ -5469,7 +5464,7 @@ inline void gcode_M226() {
5469 5464
         NOMORE(lpq_len, LPQ_MAX_LEN);
5470 5465
       #endif
5471 5466
 
5472
-      updatePID();
5467
+      thermalManager.updatePID();
5473 5468
       SERIAL_ECHO_START;
5474 5469
       #if ENABLED(PID_PARAMS_PER_EXTRUDER)
5475 5470
         SERIAL_ECHO(" e:"); // specify extruder in serial output
@@ -5499,18 +5494,19 @@ inline void gcode_M226() {
5499 5494
 #if ENABLED(PIDTEMPBED)
5500 5495
 
5501 5496
   inline void gcode_M304() {
5502
-    if (code_seen('P')) bedKp = code_value();
5503
-    if (code_seen('I')) bedKi = scalePID_i(code_value());
5504
-    if (code_seen('D')) bedKd = scalePID_d(code_value());
5497
+    if (code_seen('P')) thermalManager.bedKp = code_value();
5498
+    if (code_seen('I')) thermalManager.bedKi = scalePID_i(code_value());
5499
+    if (code_seen('D')) thermalManager.bedKd = scalePID_d(code_value());
5500
+
5501
+    thermalManager.updatePID();
5505 5502
 
5506
-    updatePID();
5507 5503
     SERIAL_ECHO_START;
5508 5504
     SERIAL_ECHO(" p:");
5509
-    SERIAL_ECHO(bedKp);
5505
+    SERIAL_ECHO(thermalManager.bedKp);
5510 5506
     SERIAL_ECHO(" i:");
5511
-    SERIAL_ECHO(unscalePID_i(bedKi));
5507
+    SERIAL_ECHO(unscalePID_i(thermalManager.bedKi));
5512 5508
     SERIAL_ECHO(" d:");
5513
-    SERIAL_ECHOLN(unscalePID_d(bedKd));
5509
+    SERIAL_ECHOLN(unscalePID_d(thermalManager.bedKd));
5514 5510
   }
5515 5511
 
5516 5512
 #endif // PIDTEMPBED
@@ -5567,13 +5563,11 @@ inline void gcode_M226() {
5567 5563
 
5568 5564
 #if ENABLED(PREVENT_DANGEROUS_EXTRUDE)
5569 5565
 
5570
-  void set_extrude_min_temp(float temp) { extrude_min_temp = temp; }
5571
-
5572 5566
   /**
5573 5567
    * M302: Allow cold extrudes, or set the minimum extrude S<temperature>.
5574 5568
    */
5575 5569
   inline void gcode_M302() {
5576
-    set_extrude_min_temp(code_seen('S') ? code_value() : 0);
5570
+    thermalManager.extrude_min_temp = code_seen('S') ? code_value() : 0;
5577 5571
   }
5578 5572
 
5579 5573
 #endif // PREVENT_DANGEROUS_EXTRUDE
@@ -5599,7 +5593,7 @@ inline void gcode_M303() {
5599 5593
 
5600 5594
     KEEPALIVE_STATE(NOT_BUSY); // don't send "busy: processing" messages during autotune output
5601 5595
 
5602
-    PID_autotune(temp, e, c, u);
5596
+    thermalManager.PID_autotune(temp, e, c, u);
5603 5597
 
5604 5598
     KEEPALIVE_STATE(IN_HANDLER);
5605 5599
   #else
@@ -5781,7 +5775,7 @@ inline void gcode_M400() { stepper.synchronize(); }
5781 5775
     NOMORE(meas_delay_cm, MAX_MEASUREMENT_DELAY);
5782 5776
 
5783 5777
     if (filwidth_delay_index2 == -1) { // Initialize the ring buffer if not done since startup
5784
-      int temp_ratio = widthFil_to_size_ratio();
5778
+      int temp_ratio = thermalManager.widthFil_to_size_ratio();
5785 5779
 
5786 5780
       for (uint8_t i = 0; i < COUNT(measurement_delay); ++i)
5787 5781
         measurement_delay[i] = temp_ratio - 100;  // Subtract 100 to scale within a signed byte
@@ -5984,7 +5978,7 @@ inline void gcode_M503() {
5984 5978
    */
5985 5979
   inline void gcode_M600() {
5986 5980
 
5987
-    if (degHotend(active_extruder) < extrude_min_temp) {
5981
+    if (thermalManager.tooColdToExtrude(active_extruder)) {
5988 5982
       SERIAL_ERROR_START;
5989 5983
       SERIAL_ERRORLNPGM(MSG_TOO_COLD_FOR_M600);
5990 5984
       return;
@@ -7268,7 +7262,7 @@ void mesh_buffer_line(float x, float y, float z, const float e, float feed_rate,
7268 7262
     if (DEBUGGING(DRYRUN)) return;
7269 7263
     float de = dest_e - curr_e;
7270 7264
     if (de) {
7271
-      if (degHotend(active_extruder) < extrude_min_temp) {
7265
+      if (thermalManager.tooColdToExtrude(active_extruder)) {
7272 7266
         curr_e = dest_e; // Behave as if the move really took place, but ignore E part
7273 7267
         SERIAL_ECHO_START;
7274 7268
         SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
@@ -7565,7 +7559,7 @@ void plan_arc(
7565 7559
     millis_t ms = millis();
7566 7560
     if (ELAPSED(ms, nextMotorCheck)) {
7567 7561
       nextMotorCheck = ms + 2500UL; // Not a time critical function, so only check every 2.5s
7568
-      if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON || soft_pwm_bed > 0
7562
+      if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON || thermalManager.soft_pwm_bed > 0
7569 7563
           || E0_ENABLE_READ == E_ENABLE_ON // If any of the drivers are enabled...
7570 7564
           #if EXTRUDERS > 1
7571 7565
             || E1_ENABLE_READ == E_ENABLE_ON
@@ -7683,9 +7677,9 @@ void plan_arc(
7683 7677
     if (ELAPSED(millis(), next_status_led_update_ms)) {
7684 7678
       next_status_led_update_ms += 500; // Update every 0.5s
7685 7679
       for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder)
7686
-        max_temp = max(max(max_temp, degHotend(cur_extruder)), degTargetHotend(cur_extruder));
7680
+        max_temp = max(max(max_temp, thermalManager.degHotend(cur_extruder)), thermalManager.degTargetHotend(cur_extruder));
7687 7681
       #if HAS_TEMP_BED
7688
-        max_temp = max(max(max_temp, degTargetBed()), degBed());
7682
+        max_temp = max(max(max_temp, thermalManager.degTargetBed()), thermalManager.degBed());
7689 7683
       #endif
7690 7684
       bool new_led = (max_temp > 55.0) ? true : (max_temp < 54.0) ? false : red_led;
7691 7685
       if (new_led != red_led) {
@@ -7726,7 +7720,7 @@ void idle(
7726 7720
     bool no_stepper_sleep/*=false*/
7727 7721
   #endif
7728 7722
 ) {
7729
-  manage_heater();
7723
+  thermalManager.manage_heater();
7730 7724
   manage_inactivity(
7731 7725
     #if ENABLED(FILAMENTCHANGEENABLE)
7732 7726
       no_stepper_sleep
@@ -7831,7 +7825,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
7831 7825
 
7832 7826
   #if ENABLED(EXTRUDER_RUNOUT_PREVENT)
7833 7827
     if (ELAPSED(ms, previous_cmd_ms + (EXTRUDER_RUNOUT_SECONDS) * 1000UL))
7834
-      if (degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP) {
7828
+      if (thermalManager.degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP) {
7835 7829
         bool oldstatus;
7836 7830
         switch (active_extruder) {
7837 7831
           case 0:
@@ -7914,7 +7908,7 @@ void kill(const char* lcd_msg) {
7914 7908
   #endif
7915 7909
 
7916 7910
   cli(); // Stop interrupts
7917
-  disable_all_heaters();
7911
+  thermalManager.disable_all_heaters();
7918 7912
   disable_all_steppers();
7919 7913
 
7920 7914
   #if HAS_POWER_SWITCH
@@ -8010,7 +8004,7 @@ void kill(const char* lcd_msg) {
8010 8004
 #endif // FAST_PWM_FAN
8011 8005
 
8012 8006
 void stop() {
8013
-  disable_all_heaters();
8007
+  thermalManager.disable_all_heaters();
8014 8008
   if (IsRunning()) {
8015 8009
     Running = false;
8016 8010
     Stopped_gcode_LastN = gcode_LastN; // Save last g_code for restart

+ 1
- 1
Marlin/cardreader.cpp Vedi File

@@ -609,7 +609,7 @@ void CardReader::printingHasFinished() {
609 609
     sdprinting = false;
610 610
     if (SD_FINISHED_STEPPERRELEASE)
611 611
       enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
612
-    autotempShutdown();
612
+    thermalManager.autotempShutdown();
613 613
   }
614 614
 }
615 615
 

+ 28
- 30
Marlin/configuration_store.cpp Vedi File

@@ -95,7 +95,7 @@
95 95
  *  363  M301 L        lpq_len (int)
96 96
  *
97 97
  * PIDTEMPBED:
98
- *  365  M304 PID  bedKp, bedKi, bedKd (float x3)
98
+ *  365  M304 PID  thermalManager.bedKp, thermalManager.bedKi, thermalManager.bedKd (float x3)
99 99
  *
100 100
  * DOGLCD:
101 101
  *  377  M250 C    lcd_contrast (int)
@@ -261,9 +261,9 @@ void Config_StoreSettings()  {
261 261
     #endif // !PIDTEMP
262 262
       {
263 263
         dummy = DUMMY_PID_VALUE; // When read, will not change the existing value
264
-        EEPROM_WRITE_VAR(i, dummy);
264
+        EEPROM_WRITE_VAR(i, dummy); // Kp
265 265
         dummy = 0.0f;
266
-        for (uint8_t q = 3; q--;) EEPROM_WRITE_VAR(i, dummy);
266
+        for (uint8_t q = 3; q--;) EEPROM_WRITE_VAR(i, dummy); // Ki, Kd, Kc
267 267
       }
268 268
 
269 269
   } // Extruders Loop
@@ -274,13 +274,14 @@ void Config_StoreSettings()  {
274 274
   EEPROM_WRITE_VAR(i, lpq_len);
275 275
 
276 276
   #if DISABLED(PIDTEMPBED)
277
-    float bedKp = DUMMY_PID_VALUE, bedKi = DUMMY_PID_VALUE, bedKd = DUMMY_PID_VALUE;
277
+    dummy = DUMMY_PID_VALUE;
278
+    for (uint8_t q = 3; q--;) EEPROM_WRITE_VAR(i, dummy);
279
+  #else
280
+    EEPROM_WRITE_VAR(i, thermalManager.bedKp);
281
+    EEPROM_WRITE_VAR(i, thermalManager.bedKi);
282
+    EEPROM_WRITE_VAR(i, thermalManager.bedKd);
278 283
   #endif
279 284
 
280
-  EEPROM_WRITE_VAR(i, bedKp);
281
-  EEPROM_WRITE_VAR(i, bedKi);
282
-  EEPROM_WRITE_VAR(i, bedKd);
283
-
284 285
   #if DISABLED(HAS_LCD_CONTRAST)
285 286
     const int lcd_contrast = 32;
286 287
   #endif
@@ -450,20 +451,17 @@ void Config_RetrieveSettings() {
450 451
     #endif
451 452
     EEPROM_READ_VAR(i, lpq_len);
452 453
 
453
-    #if DISABLED(PIDTEMPBED)
454
-      float bedKp, bedKi, bedKd;
454
+    #if ENABLED(PIDTEMPBED)
455
+      EEPROM_READ_VAR(i, dummy); // bedKp
456
+      if (dummy != DUMMY_PID_VALUE) {
457
+        thermalManager.bedKp = dummy;
458
+        EEPROM_READ_VAR(i, thermalManager.bedKi);
459
+        EEPROM_READ_VAR(i, thermalManager.bedKd);
460
+      }
461
+    #else
462
+      for (uint8_t q=3; q--;) EEPROM_READ_VAR(i, dummy); // bedKp, bedKi, bedKd
455 463
     #endif
456 464
 
457
-    EEPROM_READ_VAR(i, dummy); // bedKp
458
-    if (dummy != DUMMY_PID_VALUE) {
459
-      bedKp = dummy; UNUSED(bedKp);
460
-      EEPROM_READ_VAR(i, bedKi);
461
-      EEPROM_READ_VAR(i, bedKd);
462
-    }
463
-    else {
464
-      for (uint8_t q=2; q--;) EEPROM_READ_VAR(i, dummy); // bedKi, bedKd
465
-    }
466
-
467 465
     #if DISABLED(HAS_LCD_CONTRAST)
468 466
       int lcd_contrast;
469 467
     #endif
@@ -502,8 +500,8 @@ void Config_RetrieveSettings() {
502 500
     }
503 501
 
504 502
     calculate_volumetric_multipliers();
505
-    // Call updatePID (similar to when we have processed M301)
506
-    updatePID();
503
+    // Call thermalManager.updatePID (similar to when we have processed M301)
504
+    thermalManager.updatePID();
507 505
 
508 506
     // Report settings retrieved and length
509 507
     SERIAL_ECHO_START;
@@ -602,14 +600,14 @@ void Config_ResetDefault() {
602 600
     #if ENABLED(PID_ADD_EXTRUSION_RATE)
603 601
       lpq_len = 20; // default last-position-queue size
604 602
     #endif
605
-    // call updatePID (similar to when we have processed M301)
606
-    updatePID();
603
+    // call thermalManager.updatePID (similar to when we have processed M301)
604
+    thermalManager.updatePID();
607 605
   #endif // PIDTEMP
608 606
 
609 607
   #if ENABLED(PIDTEMPBED)
610
-    bedKp = DEFAULT_bedKp;
611
-    bedKi = scalePID_i(DEFAULT_bedKi);
612
-    bedKd = scalePID_d(DEFAULT_bedKd);
608
+    thermalManager.bedKp = DEFAULT_bedKp;
609
+    thermalManager.bedKi = scalePID_i(DEFAULT_bedKi);
610
+    thermalManager.bedKd = scalePID_d(DEFAULT_bedKd);
613 611
   #endif
614 612
 
615 613
   #if ENABLED(FWRETRACT)
@@ -835,9 +833,9 @@ void Config_PrintSettings(bool forReplay) {
835 833
 
836 834
     #if ENABLED(PIDTEMPBED)
837 835
       CONFIG_ECHO_START;
838
-      SERIAL_ECHOPAIR("  M304 P", bedKp);
839
-      SERIAL_ECHOPAIR(" I", unscalePID_i(bedKi));
840
-      SERIAL_ECHOPAIR(" D", unscalePID_d(bedKd));
836
+      SERIAL_ECHOPAIR("  M304 P", thermalManager.bedKp);
837
+      SERIAL_ECHOPAIR(" I", unscalePID_i(thermalManager.bedKi));
838
+      SERIAL_ECHOPAIR(" D", unscalePID_d(thermalManager.bedKd));
841 839
       SERIAL_EOL;
842 840
     #endif
843 841
 

+ 3
- 3
Marlin/dogm_lcd_implementation.h Vedi File

@@ -294,13 +294,13 @@ FORCE_INLINE void _draw_heater_status(int x, int heater) {
294 294
     const bool isBed = false;
295 295
   #endif
296 296
 
297
-  _draw_centered_temp((isBed ? degTargetBed() : degTargetHotend(heater)) + 0.5, x, 7);
297
+  _draw_centered_temp((isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater)) + 0.5, x, 7);
298 298
 
299
-  _draw_centered_temp((isBed ? degBed() : degHotend(heater)) + 0.5, x, 28);
299
+  _draw_centered_temp((isBed ? thermalManager.degBed() : thermalManager.degHotend(heater)) + 0.5, x, 28);
300 300
 
301 301
   int h = isBed ? 7 : 8,
302 302
       y = isBed ? 18 : 17;
303
-  if (isBed ? isHeatingBed() : isHeatingHotend(heater)) {
303
+  if (isBed ? thermalManager.isHeatingBed() : thermalManager.isHeatingHotend(heater)) {
304 304
     u8g.setColorIndex(0); // white on black
305 305
     u8g.drawBox(x + h, y, 2, 2);
306 306
     u8g.setColorIndex(1); // black on white

+ 1
- 1
Marlin/endstops.cpp Vedi File

@@ -153,7 +153,7 @@ void Endstops::report_state() {
153 153
         card.sdprinting = false;
154 154
         card.closefile();
155 155
         stepper.quick_stop();
156
-        disable_all_heaters(); // switch off all heaters.
156
+        thermalManager.disable_all_heaters(); // switch off all heaters.
157 157
       }
158 158
     #endif
159 159
   }

+ 10
- 9
Marlin/planner.cpp Vedi File

@@ -304,7 +304,7 @@ void Planner::recalculate() {
304 304
     static float oldt = 0;
305 305
 
306 306
     if (!autotemp_enabled) return;
307
-    if (degTargetHotend0() + 2 < autotemp_min) return; // probably temperature set to zero.
307
+    if (thermalManager.degTargetHotend(0) + 2 < autotemp_min) return; // probably temperature set to zero.
308 308
 
309 309
     float high = 0.0;
310 310
     for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) {
@@ -322,7 +322,7 @@ void Planner::recalculate() {
322 322
       t += (AUTOTEMP_OLDWEIGHT) * oldt;
323 323
     }
324 324
     oldt = t;
325
-    setTargetHotend0(t);
325
+    thermalManager.setTargetHotend(t, 0);
326 326
   }
327 327
 
328 328
 #endif //AUTOTEMP
@@ -489,11 +489,12 @@ void Planner::check_axes_activity() {
489 489
   // The target position of the tool in absolute steps
490 490
   // Calculate target position in absolute steps
491 491
   //this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow
492
-  long target[NUM_AXIS];
493
-  target[X_AXIS] = lround(x * axis_steps_per_unit[X_AXIS]);
494
-  target[Y_AXIS] = lround(y * axis_steps_per_unit[Y_AXIS]);
495
-  target[Z_AXIS] = lround(z * axis_steps_per_unit[Z_AXIS]);
496
-  target[E_AXIS] = lround(e * axis_steps_per_unit[E_AXIS]);
492
+  long target[NUM_AXIS] = {
493
+    lround(x * axis_steps_per_unit[X_AXIS]),
494
+    lround(y * axis_steps_per_unit[Y_AXIS]),
495
+    lround(z * axis_steps_per_unit[Z_AXIS]),
496
+    lround(e * axis_steps_per_unit[E_AXIS])
497
+  };
497 498
 
498 499
   long dx = target[X_AXIS] - position[X_AXIS],
499 500
        dy = target[Y_AXIS] - position[Y_AXIS],
@@ -507,7 +508,7 @@ void Planner::check_axes_activity() {
507 508
 
508 509
   #if ENABLED(PREVENT_DANGEROUS_EXTRUDE)
509 510
     if (de) {
510
-      if (degHotend(extruder) < extrude_min_temp) {
511
+      if (thermalManager.tooColdToExtrude(extruder)) {
511 512
         position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
512 513
         de = 0; // no difference
513 514
         SERIAL_ECHO_START;
@@ -788,7 +789,7 @@ void Planner::check_axes_activity() {
788 789
         // If the index has changed (must have gone forward)...
789 790
         if (filwidth_delay_index1 != filwidth_delay_index2) {
790 791
           filwidth_e_count = 0; // Reset the E movement counter
791
-          int8_t meas_sample = widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
792
+          int8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
792 793
           do {
793 794
             filwidth_delay_index2 = (filwidth_delay_index2 + 1) % MMD_CM; // The next unused slot
794 795
             measurement_delay[filwidth_delay_index2] = meas_sample;       // Store the measurement

+ 94
- 288
Marlin/temperature.cpp Vedi File

@@ -21,24 +21,8 @@
21 21
  */
22 22
 
23 23
 /**
24
-  temperature.cpp - temperature control
25
-  Part of Marlin
26
-
27
- Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
28
-
29
- This program is free software: you can redistribute it and/or modify
30
- it under the terms of the GNU General Public License as published by
31
- the Free Software Foundation, either version 3 of the License, or
32
- (at your option) any later version.
33
-
34
- This program is distributed in the hope that it will be useful,
35
- but WITHOUT ANY WARRANTY; without even the implied warranty of
36
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
- GNU General Public License for more details.
38
-
39
- You should have received a copy of the GNU General Public License
40
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
41
-*/
24
+ * temperature.cpp - temperature control
25
+ */
42 26
 
43 27
 #include "Marlin.h"
44 28
 #include "ultralcd.h"
@@ -50,144 +34,10 @@
50 34
   #include "watchdog.h"
51 35
 #endif
52 36
 
53
-//===========================================================================
54
-//================================== macros =================================
55
-//===========================================================================
56
-
57 37
 #ifdef K1 // Defined in Configuration.h in the PID settings
58 38
   #define K2 (1.0-K1)
59 39
 #endif
60 40
 
61
-#if ENABLED(PIDTEMPBED) || ENABLED(PIDTEMP)
62
-  #define PID_dT ((OVERSAMPLENR * 12.0)/(F_CPU / 64.0 / 256.0))
63
-#endif
64
-
65
-//===========================================================================
66
-//============================= public variables ============================
67
-//===========================================================================
68
-
69
-int target_temperature[4] = { 0 };
70
-int target_temperature_bed = 0;
71
-int current_temperature_raw[4] = { 0 };
72
-float current_temperature[4] = { 0.0 };
73
-int current_temperature_bed_raw = 0;
74
-float current_temperature_bed = 0.0;
75
-#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
76
-  int redundant_temperature_raw = 0;
77
-  float redundant_temperature = 0.0;
78
-#endif
79
-
80
-#if ENABLED(PIDTEMPBED)
81
-  float bedKp = DEFAULT_bedKp;
82
-  float bedKi = (DEFAULT_bedKi* PID_dT);
83
-  float bedKd = (DEFAULT_bedKd / PID_dT);
84
-#endif //PIDTEMPBED
85
-
86
-#if ENABLED(FAN_SOFT_PWM)
87
-  unsigned char fanSpeedSoftPwm[FAN_COUNT];
88
-#endif
89
-
90
-unsigned char soft_pwm_bed;
91
-
92
-#if ENABLED(BABYSTEPPING)
93
-  volatile int babystepsTodo[3] = { 0 };
94
-#endif
95
-
96
-#if ENABLED(FILAMENT_WIDTH_SENSOR)
97
-  int current_raw_filwidth = 0;  //Holds measured filament diameter - one extruder only
98
-#endif
99
-
100
-#if ENABLED(THERMAL_PROTECTION_HOTENDS) || ENABLED(THERMAL_PROTECTION_BED)
101
-  enum TRState { TRReset, TRInactive, TRFirstHeating, TRStable, TRRunaway };
102
-  void thermal_runaway_protection(TRState* state, millis_t* timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
103
-  #if ENABLED(THERMAL_PROTECTION_HOTENDS)
104
-    static TRState thermal_runaway_state_machine[4] = { TRReset, TRReset, TRReset, TRReset };
105
-    static millis_t thermal_runaway_timer[4]; // = {0,0,0,0};
106
-  #endif
107
-  #if ENABLED(THERMAL_PROTECTION_BED) && TEMP_SENSOR_BED != 0
108
-    static TRState thermal_runaway_bed_state_machine = TRReset;
109
-    static millis_t thermal_runaway_bed_timer;
110
-  #endif
111
-#endif
112
-
113
-//===========================================================================
114
-//============================ private variables ============================
115
-//===========================================================================
116
-
117
-static volatile bool temp_meas_ready = false;
118
-
119
-#if ENABLED(PIDTEMP)
120
-  //static cannot be external:
121
-  static float temp_iState[EXTRUDERS] = { 0 };
122
-  static float temp_dState[EXTRUDERS] = { 0 };
123
-  static float pTerm[EXTRUDERS];
124
-  static float iTerm[EXTRUDERS];
125
-  static float dTerm[EXTRUDERS];
126
-  #if ENABLED(PID_ADD_EXTRUSION_RATE)
127
-    static float cTerm[EXTRUDERS];
128
-    static long last_position[EXTRUDERS];
129
-    static long lpq[LPQ_MAX_LEN];
130
-    static int lpq_ptr = 0;
131
-  #endif
132
-  //int output;
133
-  static float pid_error[EXTRUDERS];
134
-  static float temp_iState_min[EXTRUDERS];
135
-  static float temp_iState_max[EXTRUDERS];
136
-  static bool pid_reset[EXTRUDERS];
137
-#endif //PIDTEMP
138
-#if ENABLED(PIDTEMPBED)
139
-  //static cannot be external:
140
-  static float temp_iState_bed = { 0 };
141
-  static float temp_dState_bed = { 0 };
142
-  static float pTerm_bed;
143
-  static float iTerm_bed;
144
-  static float dTerm_bed;
145
-  //int output;
146
-  static float pid_error_bed;
147
-  static float temp_iState_min_bed;
148
-  static float temp_iState_max_bed;
149
-#else //PIDTEMPBED
150
-  static millis_t  next_bed_check_ms;
151
-#endif //PIDTEMPBED
152
-static unsigned char soft_pwm[EXTRUDERS];
153
-
154
-#if ENABLED(FAN_SOFT_PWM)
155
-  static unsigned char soft_pwm_fan[FAN_COUNT];
156
-#endif
157
-#if HAS_AUTO_FAN
158
-  static millis_t next_auto_fan_check_ms;
159
-#endif
160
-
161
-#if ENABLED(PIDTEMP)
162
-  #if ENABLED(PID_PARAMS_PER_EXTRUDER)
163
-    float Kp[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Kp);
164
-    float Ki[EXTRUDERS] = ARRAY_BY_EXTRUDERS1((DEFAULT_Ki) * (PID_dT));
165
-    float Kd[EXTRUDERS] = ARRAY_BY_EXTRUDERS1((DEFAULT_Kd) / (PID_dT));
166
-    #if ENABLED(PID_ADD_EXTRUSION_RATE)
167
-      float Kc[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Kc);
168
-    #endif // PID_ADD_EXTRUSION_RATE
169
-  #else //PID_PARAMS_PER_EXTRUDER
170
-    float Kp = DEFAULT_Kp;
171
-    float Ki = (DEFAULT_Ki) * (PID_dT);
172
-    float Kd = (DEFAULT_Kd) / (PID_dT);
173
-    #if ENABLED(PID_ADD_EXTRUSION_RATE)
174
-      float Kc = DEFAULT_Kc;
175
-    #endif // PID_ADD_EXTRUSION_RATE
176
-  #endif // PID_PARAMS_PER_EXTRUDER
177
-#endif //PIDTEMP
178
-
179
-// Init min and max temp with extreme values to prevent false errors during startup
180
-static int minttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS(HEATER_0_RAW_LO_TEMP , HEATER_1_RAW_LO_TEMP , HEATER_2_RAW_LO_TEMP, HEATER_3_RAW_LO_TEMP);
181
-static int maxttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS(HEATER_0_RAW_HI_TEMP , HEATER_1_RAW_HI_TEMP , HEATER_2_RAW_HI_TEMP, HEATER_3_RAW_HI_TEMP);
182
-static int minttemp[EXTRUDERS] = { 0 };
183
-static int maxttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(16383);
184
-#ifdef BED_MINTEMP
185
-  static int bed_minttemp_raw = HEATER_BED_RAW_LO_TEMP;
186
-#endif
187
-#ifdef BED_MAXTEMP
188
-  static int bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP;
189
-#endif
190
-
191 41
 #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
192 42
   static void* heater_ttbl_map[2] = {(void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE };
193 43
   static uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN };
@@ -196,39 +46,11 @@ static int maxttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(16383);
196 46
   static uint8_t heater_ttbllen_map[EXTRUDERS] = ARRAY_BY_EXTRUDERS(HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN, HEATER_2_TEMPTABLE_LEN, HEATER_3_TEMPTABLE_LEN);
197 47
 #endif
198 48
 
199
-static float analog2temp(int raw, uint8_t e);
200
-static float analog2tempBed(int raw);
201
-static void updateTemperaturesFromRawValues();
202
-
203
-#if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
204
-  int watch_target_temp[EXTRUDERS] = { 0 };
205
-  millis_t watch_heater_next_ms[EXTRUDERS] = { 0 };
206
-#endif
207
-
208
-#if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
209
-  int watch_target_bed_temp = 0;
210
-  millis_t watch_bed_next_ms = 0;
211
-#endif
212
-
213
-#ifndef SOFT_PWM_SCALE
214
-  #define SOFT_PWM_SCALE 0
215
-#endif
216
-
217
-#if ENABLED(FILAMENT_WIDTH_SENSOR)
218
-  static int meas_shift_index;  //used to point to a delayed sample in buffer for filament width sensor
219
-#endif
220
-
221
-#if ENABLED(HEATER_0_USES_MAX6675)
222
-  static int read_max6675();
223
-#endif
224
-
225
-//===========================================================================
226
-//================================ Functions ================================
227
-//===========================================================================
49
+Temperature thermalManager;
228 50
 
229 51
 #if HAS_PID_HEATING
230 52
 
231
-  void PID_autotune(float temp, int extruder, int ncycles, bool set_result/*=false*/) {
53
+  void Temperature::PID_autotune(float temp, int extruder, int ncycles, bool set_result/*=false*/) {
232 54
     float input = 0.0;
233 55
     int cycles = 0;
234 56
     bool heating = true;
@@ -242,7 +64,7 @@ static void updateTemperaturesFromRawValues();
242 64
     float max = 0, min = 10000;
243 65
 
244 66
     #if HAS_AUTO_FAN
245
-      millis_t next_auto_fan_check_ms = temp_ms + 2500UL;
67
+      next_auto_fan_check_ms = temp_ms + 2500UL;
246 68
     #endif
247 69
 
248 70
     if (false
@@ -459,9 +281,37 @@ static void updateTemperaturesFromRawValues();
459 281
     }
460 282
   }
461 283
 
462
-#endif // PIDTEMP
284
+#endif // HAS_PID_HEATING
285
+
286
+#if ENABLED(PIDTEMP)
287
+
288
+  #if ENABLED(PID_PARAMS_PER_EXTRUDER)
289
+
290
+    float Temperature::Kp[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Kp),
291
+          Temperature::Ki[EXTRUDERS] = ARRAY_BY_EXTRUDERS1((DEFAULT_Ki) * (PID_dT)),
292
+          Temperature::Kd[EXTRUDERS] = ARRAY_BY_EXTRUDERS1((DEFAULT_Kd) / (PID_dT));
463 293
 
464
-void updatePID() {
294
+    #if ENABLED(PID_ADD_EXTRUSION_RATE)
295
+      float Temperature::Kc[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Kc);
296
+    #endif
297
+
298
+  #else
299
+
300
+    float Temperature::Kp = DEFAULT_Kp,
301
+          Temperature::Ki = (DEFAULT_Ki) * (PID_dT),
302
+          Temperature::Kd = (DEFAULT_Kd) / (PID_dT);
303
+
304
+    #if ENABLED(PID_ADD_EXTRUSION_RATE)
305
+      float Temperature::Kc = DEFAULT_Kc;
306
+    #endif
307
+
308
+  #endif
309
+
310
+#endif
311
+
312
+Temperature::Temperature() { }
313
+
314
+void Temperature::updatePID() {
465 315
   #if ENABLED(PIDTEMP)
466 316
     for (int e = 0; e < EXTRUDERS; e++) {
467 317
       temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e);
@@ -475,85 +325,41 @@ void updatePID() {
475 325
   #endif
476 326
 }
477 327
 
478
-int getHeaterPower(int heater) {
328
+int Temperature::getHeaterPower(int heater) {
479 329
   return heater < 0 ? soft_pwm_bed : soft_pwm[heater];
480 330
 }
481 331
 
482 332
 #if HAS_AUTO_FAN
483 333
 
484
-void setExtruderAutoFanState(int pin, bool state) {
485
-  unsigned char newFanSpeed = (state != 0) ? EXTRUDER_AUTO_FAN_SPEED : 0;
486
-  // this idiom allows both digital and PWM fan outputs (see M42 handling).
487
-  digitalWrite(pin, newFanSpeed);
488
-  analogWrite(pin, newFanSpeed);
489
-}
490
-
491
-void checkExtruderAutoFans() {
492
-  uint8_t fanState = 0;
493
-
494
-  // which fan pins need to be turned on?
495
-  #if HAS_AUTO_FAN_0
496
-    if (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE)
497
-      fanState |= 1;
498
-  #endif
499
-  #if HAS_AUTO_FAN_1
500
-    if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) {
501
-      if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN)
502
-        fanState |= 1;
503
-      else
504
-        fanState |= 2;
334
+  void Temperature::checkExtruderAutoFans() {
335
+    const uint8_t fanPin[] = { EXTRUDER_0_AUTO_FAN_PIN, EXTRUDER_1_AUTO_FAN_PIN, EXTRUDER_2_AUTO_FAN_PIN, EXTRUDER_3_AUTO_FAN_PIN };
336
+    const int fanBit[] = { 0,
337
+      EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN ? 0 : 1,
338
+      EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN ? 0 :
339
+      EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN ? 1 : 2,
340
+      EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN ? 0 :
341
+      EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN ? 1 :
342
+      EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN ? 2 : 3
343
+    };
344
+    uint8_t fanState = 0;
345
+    for (int f = 0; f <= 3; f++) {
346
+      if (current_temperature[f] > EXTRUDER_AUTO_FAN_TEMPERATURE)
347
+        SBI(fanState, fanBit[f]);
505 348
     }
506
-  #endif
507
-  #if HAS_AUTO_FAN_2
508
-    if (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE) {
509
-      if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN)
510
-        fanState |= 1;
511
-      else if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN)
512
-        fanState |= 2;
513
-      else
514
-        fanState |= 4;
515
-    }
516
-  #endif
517
-  #if HAS_AUTO_FAN_3
518
-    if (current_temperature[3] > EXTRUDER_AUTO_FAN_TEMPERATURE) {
519
-      if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN)
520
-        fanState |= 1;
521
-      else if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN)
522
-        fanState |= 2;
523
-      else if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN)
524
-        fanState |= 4;
525
-      else
526
-        fanState |= 8;
349
+    for (int f = 0; f <= 3; f++) {
350
+      unsigned char newFanSpeed = TEST(fanState, f) ? EXTRUDER_AUTO_FAN_SPEED : 0;
351
+      // this idiom allows both digital and PWM fan outputs (see M42 handling).
352
+      digitalWrite(fanPin[f], newFanSpeed);
353
+      analogWrite(fanPin[f], newFanSpeed);
527 354
     }
528
-  #endif
529
-
530
-  // update extruder auto fan states
531
-  #if HAS_AUTO_FAN_0
532
-    setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, (fanState & 1) != 0);
533
-  #endif
534
-  #if HAS_AUTO_FAN_1
535
-    if (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN)
536
-      setExtruderAutoFanState(EXTRUDER_1_AUTO_FAN_PIN, (fanState & 2) != 0);
537
-  #endif
538
-  #if HAS_AUTO_FAN_2
539
-    if (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN
540
-        && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN)
541
-      setExtruderAutoFanState(EXTRUDER_2_AUTO_FAN_PIN, (fanState & 4) != 0);
542
-  #endif
543
-  #if HAS_AUTO_FAN_3
544
-    if (EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN
545
-        && EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN
546
-        && EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_2_AUTO_FAN_PIN)
547
-      setExtruderAutoFanState(EXTRUDER_3_AUTO_FAN_PIN, (fanState & 8) != 0);
548
-  #endif
549
-}
355
+  }
550 356
 
551 357
 #endif // HAS_AUTO_FAN
552 358
 
553 359
 //
554 360
 // Temperature Error Handlers
555 361
 //
556
-inline void _temp_error(int e, const char* serial_msg, const char* lcd_msg) {
362
+void Temperature::_temp_error(int e, const char* serial_msg, const char* lcd_msg) {
557 363
   static bool killed = false;
558 364
   if (IsRunning()) {
559 365
     SERIAL_ERROR_START;
@@ -572,14 +378,14 @@ inline void _temp_error(int e, const char* serial_msg, const char* lcd_msg) {
572 378
   #endif
573 379
 }
574 380
 
575
-void max_temp_error(uint8_t e) {
381
+void Temperature::max_temp_error(uint8_t e) {
576 382
   _temp_error(e, PSTR(MSG_T_MAXTEMP), PSTR(MSG_ERR_MAXTEMP));
577 383
 }
578
-void min_temp_error(uint8_t e) {
384
+void Temperature::min_temp_error(uint8_t e) {
579 385
   _temp_error(e, PSTR(MSG_T_MINTEMP), PSTR(MSG_ERR_MINTEMP));
580 386
 }
581 387
 
582
-float get_pid_output(int e) {
388
+float Temperature::get_pid_output(int e) {
583 389
   float pid_output;
584 390
   #if ENABLED(PIDTEMP)
585 391
     #if DISABLED(PID_OPENLOOP)
@@ -658,7 +464,7 @@ float get_pid_output(int e) {
658 464
 }
659 465
 
660 466
 #if ENABLED(PIDTEMPBED)
661
-  float get_pid_output_bed() {
467
+  float Temperature::get_pid_output_bed() {
662 468
     float pid_output;
663 469
     #if DISABLED(PID_OPENLOOP)
664 470
       pid_error_bed = target_temperature_bed - current_temperature_bed;
@@ -710,7 +516,7 @@ float get_pid_output(int e) {
710 516
  *  - Apply filament width to the extrusion rate (may move)
711 517
  *  - Update the heated bed PID output value
712 518
  */
713
-void manage_heater() {
519
+void Temperature::manage_heater() {
714 520
 
715 521
   if (!temp_meas_ready) return;
716 522
 
@@ -811,7 +617,7 @@ void manage_heater() {
811 617
 
812 618
   #if TEMP_SENSOR_BED != 0
813 619
 
814
-    #if ENABLED(THERMAL_PROTECTION_BED)
620
+    #if HAS_THERMALLY_PROTECTED_BED
815 621
       thermal_runaway_protection(&thermal_runaway_bed_state_machine, &thermal_runaway_bed_timer, current_temperature_bed, target_temperature_bed, -1, THERMAL_PROTECTION_BED_PERIOD, THERMAL_PROTECTION_BED_HYSTERESIS);
816 622
     #endif
817 623
 
@@ -846,9 +652,10 @@ void manage_heater() {
846 652
 }
847 653
 
848 654
 #define PGM_RD_W(x)   (short)pgm_read_word(&x)
655
+
849 656
 // Derived from RepRap FiveD extruder::getTemperature()
850 657
 // For hot end temperature measurement.
851
-static float analog2temp(int raw, uint8_t e) {
658
+float Temperature::analog2temp(int raw, uint8_t e) {
852 659
   #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
853 660
     if (e > EXTRUDERS)
854 661
   #else
@@ -891,7 +698,7 @@ static float analog2temp(int raw, uint8_t e) {
891 698
 
892 699
 // Derived from RepRap FiveD extruder::getTemperature()
893 700
 // For bed temperature measurement.
894
-static float analog2tempBed(int raw) {
701
+float Temperature::analog2tempBed(int raw) {
895 702
   #if ENABLED(BED_USES_THERMISTOR)
896 703
     float celsius = 0;
897 704
     byte i;
@@ -923,18 +730,22 @@ static float analog2tempBed(int raw) {
923 730
   #endif
924 731
 }
925 732
 
926
-/* Called to get the raw values into the the actual temperatures. The raw values are created in interrupt context,
927
-    and this function is called from normal context as it is too slow to run in interrupts and will block the stepper routine otherwise */
928
-static void updateTemperaturesFromRawValues() {
733
+/**
734
+ * Get the raw values into the actual temperatures.
735
+ * The raw values are created in interrupt context,
736
+ * and this function is called from normal context
737
+ * as it would block the stepper routine.
738
+ */
739
+void Temperature::updateTemperaturesFromRawValues() {
929 740
   #if ENABLED(HEATER_0_USES_MAX6675)
930 741
     current_temperature_raw[0] = read_max6675();
931 742
   #endif
932 743
   for (uint8_t e = 0; e < EXTRUDERS; e++) {
933
-    current_temperature[e] = analog2temp(current_temperature_raw[e], e);
744
+    current_temperature[e] = Temperature::analog2temp(current_temperature_raw[e], e);
934 745
   }
935
-  current_temperature_bed = analog2tempBed(current_temperature_bed_raw);
746
+  current_temperature_bed = Temperature::analog2tempBed(current_temperature_bed_raw);
936 747
   #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
937
-    redundant_temperature = analog2temp(redundant_temperature_raw, 1);
748
+    redundant_temperature = Temperature::analog2temp(redundant_temperature_raw, 1);
938 749
   #endif
939 750
   #if ENABLED(FILAMENT_WIDTH_SENSOR)
940 751
     filament_width_meas = analog2widthFil();
@@ -954,13 +765,13 @@ static void updateTemperaturesFromRawValues() {
954 765
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
955 766
 
956 767
   // Convert raw Filament Width to millimeters
957
-  float analog2widthFil() {
768
+  float Temperature::analog2widthFil() {
958 769
     return current_raw_filwidth / 16383.0 * 5.0;
959 770
     //return current_raw_filwidth;
960 771
   }
961 772
 
962 773
   // Convert raw Filament Width to a ratio
963
-  int widthFil_to_size_ratio() {
774
+  int Temperature::widthFil_to_size_ratio() {
964 775
     float temp = filament_width_meas;
965 776
     if (temp < MEASURED_LOWER_LIMIT) temp = filament_width_nominal;  //assume sensor cut out
966 777
     else NOMORE(temp, MEASURED_UPPER_LIMIT);
@@ -974,7 +785,8 @@ static void updateTemperaturesFromRawValues() {
974 785
  * Initialize the temperature manager
975 786
  * The manager is implemented by periodic calls to manage_heater()
976 787
  */
977
-void tp_init() {
788
+void Temperature::init() {
789
+
978 790
   #if MB(RUMBA) && ((TEMP_SENSOR_0==-1)||(TEMP_SENSOR_1==-1)||(TEMP_SENSOR_2==-1)||(TEMP_SENSOR_BED==-1))
979 791
     //disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector
980 792
     MCUCR = _BV(JTD);
@@ -1189,7 +1001,7 @@ void tp_init() {
1189 1001
    * their target temperature by a configurable margin.
1190 1002
    * This is called when the temperature is set. (M104, M109)
1191 1003
    */
1192
-  void start_watching_heater(int e) {
1004
+  void Temperature::start_watching_heater(int e) {
1193 1005
     if (degHotend(e) < degTargetHotend(e) - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1)) {
1194 1006
       watch_target_temp[e] = degHotend(e) + WATCH_TEMP_INCREASE;
1195 1007
       watch_heater_next_ms[e] = millis() + (WATCH_TEMP_PERIOD) * 1000UL;
@@ -1205,7 +1017,7 @@ void tp_init() {
1205 1017
    * their target temperature by a configurable margin.
1206 1018
    * This is called when the temperature is set. (M140, M190)
1207 1019
    */
1208
-  void start_watching_bed() {
1020
+  void Temperature::start_watching_bed() {
1209 1021
     if (degBed() < degTargetBed() - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1)) {
1210 1022
       watch_target_bed_temp = degBed() + WATCH_BED_TEMP_INCREASE;
1211 1023
       watch_bed_next_ms = millis() + (WATCH_BED_TEMP_PERIOD) * 1000UL;
@@ -1215,9 +1027,9 @@ void tp_init() {
1215 1027
   }
1216 1028
 #endif
1217 1029
 
1218
-#if ENABLED(THERMAL_PROTECTION_HOTENDS) || ENABLED(THERMAL_PROTECTION_BED)
1030
+#if ENABLED(THERMAL_PROTECTION_HOTENDS) || HAS_THERMALLY_PROTECTED_BED
1219 1031
 
1220
-  void thermal_runaway_protection(TRState* state, millis_t* timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc) {
1032
+  void Temperature::thermal_runaway_protection(TRState* state, millis_t* timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc) {
1221 1033
 
1222 1034
     static float tr_target_temperature[EXTRUDERS + 1] = { 0.0 };
1223 1035
 
@@ -1273,7 +1085,7 @@ void tp_init() {
1273 1085
 
1274 1086
 #endif // THERMAL_PROTECTION_HOTENDS || THERMAL_PROTECTION_BED
1275 1087
 
1276
-void disable_all_heaters() {
1088
+void Temperature::disable_all_heaters() {
1277 1089
   for (int i = 0; i < EXTRUDERS; i++) setTargetHotend(0, i);
1278 1090
   setTargetBed(0);
1279 1091
 
@@ -1327,9 +1139,9 @@ void disable_all_heaters() {
1327 1139
     #define MAX6675_DISCARD_BITS 3
1328 1140
   #endif
1329 1141
 
1330
-  static millis_t next_max6675_ms = 0;
1142
+  int Temperature::read_max6675() {
1331 1143
 
1332
-  static int read_max6675() {
1144
+    static millis_t next_max6675_ms = 0;
1333 1145
 
1334 1146
     millis_t ms = millis();
1335 1147
 
@@ -1392,10 +1204,10 @@ enum TempState {
1392 1204
   StartupDelay // Startup, delay initial temp reading a tiny bit so the hardware can settle
1393 1205
 };
1394 1206
 
1395
-static unsigned long raw_temp_value[4] = { 0 };
1396
-static unsigned long raw_temp_bed_value = 0;
1397
-
1398
-static void set_current_temp_raw() {
1207
+/**
1208
+ * Get raw temperatures
1209
+ */
1210
+void Temperature::set_current_temp_raw() {
1399 1211
   #if HAS_TEMP_0 && DISABLED(HEATER_0_USES_MAX6675)
1400 1212
     current_temperature_raw[0] = raw_temp_value[0];
1401 1213
   #endif
@@ -1423,7 +1235,9 @@ static void set_current_temp_raw() {
1423 1235
  *  - Check new temperature values for MIN/MAX errors
1424 1236
  *  - Step the babysteps value for each axis towards 0
1425 1237
  */
1426
-ISR(TIMER0_COMPB_vect) {
1238
+ISR(TIMER0_COMPB_vect) { thermalManager.isr(); }
1239
+
1240
+void Temperature::isr() {
1427 1241
 
1428 1242
   static unsigned char temp_count = 0;
1429 1243
   static TempState temp_state = StartupDelay;
@@ -1845,11 +1659,3 @@ ISR(TIMER0_COMPB_vect) {
1845 1659
     }
1846 1660
   #endif //BABYSTEPPING
1847 1661
 }
1848
-
1849
-#if ENABLED(PIDTEMP)
1850
-  // Apply the scale factors to the PID values
1851
-  float scalePID_i(float i)   { return i * PID_dT; }
1852
-  float unscalePID_i(float i) { return i / PID_dT; }
1853
-  float scalePID_d(float d)   { return d / PID_dT; }
1854
-  float unscalePID_d(float d) { return d * PID_dT; }
1855
-#endif //PIDTEMP

+ 292
- 143
Marlin/temperature.h Vedi File

@@ -21,182 +21,331 @@
21 21
  */
22 22
 
23 23
 /**
24
-  temperature.h - temperature controller
25
-  Part of Marlin
26
-
27
-  Copyright (c) 2011 Erik van der Zalm
28
-
29
-  Grbl is free software: you can redistribute it and/or modify
30
-  it under the terms of the GNU General Public License as published by
31
-  the Free Software Foundation, either version 3 of the License, or
32
-  (at your option) any later version.
33
-
34
-  Grbl is distributed in the hope that it will be useful,
35
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
36
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
-  GNU General Public License for more details.
38
-
39
-  You should have received a copy of the GNU General Public License
40
-  along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
41
-*/
24
+ * temperature.h - temperature controller
25
+ */
42 26
 
43 27
 #ifndef TEMPERATURE_H
44 28
 #define TEMPERATURE_H
45 29
 
46 30
 #include "Marlin.h"
47 31
 #include "planner.h"
32
+
48 33
 #if ENABLED(PID_ADD_EXTRUSION_RATE)
49 34
   #include "stepper.h"
50 35
 #endif
51 36
 
52
-// public functions
53
-void tp_init();  //initialize the heating
54
-void manage_heater(); //it is critical that this is called periodically.
37
+#ifndef SOFT_PWM_SCALE
38
+  #define SOFT_PWM_SCALE 0
39
+#endif
55 40
 
56
-#if ENABLED(FILAMENT_WIDTH_SENSOR)
57
-  // For converting raw Filament Width to milimeters
58
-  float analog2widthFil();
41
+class Temperature {
59 42
 
60
-  // For converting raw Filament Width to an extrusion ratio
61
-  int widthFil_to_size_ratio();
62
-#endif
43
+  public:
63 44
 
64
-// low level conversion routines
65
-// do not use these routines and variables outside of temperature.cpp
66
-extern int target_temperature[4];
67
-extern float current_temperature[4];
68
-#if ENABLED(SHOW_TEMP_ADC_VALUES)
69
-  extern int current_temperature_raw[4];
70
-  extern int current_temperature_bed_raw;
71
-#endif
72
-extern int target_temperature_bed;
73
-extern float current_temperature_bed;
74
-#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
75
-  extern float redundant_temperature;
76
-#endif
45
+    int current_temperature_raw[EXTRUDERS] = { 0 };
46
+    float current_temperature[EXTRUDERS] = { 0.0 };
47
+    int target_temperature[EXTRUDERS] = { 0 };
77 48
 
78
-#if HAS_CONTROLLERFAN
79
-  extern unsigned char soft_pwm_bed;
80
-#endif
49
+    int current_temperature_bed_raw = 0;
50
+    float current_temperature_bed = 0.0;
51
+    int target_temperature_bed = 0;
81 52
 
82
-#if ENABLED(FAN_SOFT_PWM)
83
-  extern unsigned char fanSpeedSoftPwm[FAN_COUNT];
84
-#endif
53
+    #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
54
+      float redundant_temperature = 0.0;
55
+    #endif
85 56
 
86
-#if ENABLED(PIDTEMP)
57
+    unsigned char soft_pwm_bed;
87 58
 
88
-  #if ENABLED(PID_PARAMS_PER_EXTRUDER)
89
-    extern float Kp[EXTRUDERS], Ki[EXTRUDERS], Kd[EXTRUDERS];  // one param per extruder
90
-    #if ENABLED(PID_ADD_EXTRUSION_RATE)
91
-      extern float Kc[EXTRUDERS];
59
+    #if ENABLED(FAN_SOFT_PWM)
60
+      unsigned char fanSpeedSoftPwm[FAN_COUNT];
92 61
     #endif
93
-    #define PID_PARAM(param, e) param[e] // use macro to point to array value
94
-  #else
95
-    extern float Kp, Ki, Kd;  // one param per extruder - saves 20 or 36 bytes of ram (inc array pointer)
96
-    #if ENABLED(PID_ADD_EXTRUSION_RATE)
97
-      extern float Kc;
62
+
63
+    #if ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED)
64
+      #define PID_dT ((OVERSAMPLENR * 12.0)/(F_CPU / 64.0 / 256.0))
98 65
     #endif
99
-    #define PID_PARAM(param, e) param // use macro to point directly to value
100
-  #endif // PID_PARAMS_PER_EXTRUDER
101
-  float scalePID_i(float i);
102
-  float scalePID_d(float d);
103
-  float unscalePID_i(float i);
104
-  float unscalePID_d(float d);
105 66
 
106
-#endif
67
+    #if ENABLED(PIDTEMP)
107 68
 
108
-#if ENABLED(PIDTEMPBED)
109
-  extern float bedKp, bedKi, bedKd;
110
-#endif
69
+      #if ENABLED(PID_PARAMS_PER_EXTRUDER)
111 70
 
112
-#if ENABLED(BABYSTEPPING)
113
-  extern volatile int babystepsTodo[3];
114
-#endif
71
+        static float Kp[EXTRUDERS], Ki[EXTRUDERS], Kd[EXTRUDERS];
72
+        #if ENABLED(PID_ADD_EXTRUSION_RATE)
73
+          float Kc[EXTRUDERS];
74
+        #endif
75
+        #define PID_PARAM(param, e) Temperature::param[e]
115 76
 
116
-//high level conversion routines, for use outside of temperature.cpp
117
-//inline so that there is no performance decrease.
118
-//deg=degreeCelsius
77
+      #else
119 78
 
120
-FORCE_INLINE float degHotend(uint8_t extruder) { return current_temperature[extruder]; }
121
-FORCE_INLINE float degBed() { return current_temperature_bed; }
79
+        static float Kp, Ki, Kd;
80
+        #if ENABLED(PID_ADD_EXTRUSION_RATE)
81
+          static float Kc;
82
+        #endif
83
+        #define PID_PARAM(param, e) Temperature::param
122 84
 
123
-#if ENABLED(SHOW_TEMP_ADC_VALUES)
124
-FORCE_INLINE float rawHotendTemp(uint8_t extruder) { return current_temperature_raw[extruder]; }
125
-FORCE_INLINE float rawBedTemp() { return current_temperature_bed_raw; }
126
-#endif
85
+      #endif // PID_PARAMS_PER_EXTRUDER
127 86
 
128
-FORCE_INLINE float degTargetHotend(uint8_t extruder) { return target_temperature[extruder]; }
129
-FORCE_INLINE float degTargetBed() { return target_temperature_bed; }
87
+      // Apply the scale factors to the PID values
88
+      #define scalePID_i(i)   ( (i) * PID_dT )
89
+      #define unscalePID_i(i) ( (i) / PID_dT )
90
+      #define scalePID_d(d)   ( (d) / PID_dT )
91
+      #define unscalePID_d(d) ( (d) * PID_dT )
130 92
 
131
-#if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
132
-  void start_watching_heater(int e = 0);
133
-#endif
93
+    #endif
134 94
 
135
-#if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
136
-  void start_watching_bed();
137
-#endif
95
+    #if ENABLED(PIDTEMPBED)
96
+      float bedKp = DEFAULT_bedKp,
97
+            bedKi = ((DEFAULT_bedKi) * PID_dT),
98
+            bedKd = ((DEFAULT_bedKd) / PID_dT);
99
+    #endif
138 100
 
139
-FORCE_INLINE void setTargetHotend(const float& celsius, uint8_t extruder) {
140
-  target_temperature[extruder] = celsius;
141
-  #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
142
-    start_watching_heater(extruder);
143
-  #endif
144
-}
145
-FORCE_INLINE void setTargetBed(const float& celsius) {
146
-  target_temperature_bed = celsius;
147
-  #if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
148
-    start_watching_bed();
149
-  #endif
150
-}
151
-
152
-FORCE_INLINE bool isHeatingHotend(uint8_t extruder) { return target_temperature[extruder] > current_temperature[extruder]; }
153
-FORCE_INLINE bool isHeatingBed() { return target_temperature_bed > current_temperature_bed; }
154
-
155
-FORCE_INLINE bool isCoolingHotend(uint8_t extruder) { return target_temperature[extruder] < current_temperature[extruder]; }
156
-FORCE_INLINE bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
157
-
158
-#define HOTEND_ROUTINES(NR) \
159
-  FORCE_INLINE float degHotend##NR() { return degHotend(NR); } \
160
-  FORCE_INLINE float degTargetHotend##NR() { return degTargetHotend(NR); } \
161
-  FORCE_INLINE void setTargetHotend##NR(const float c) { setTargetHotend(c, NR); } \
162
-  FORCE_INLINE bool isHeatingHotend##NR() { return isHeatingHotend(NR); } \
163
-  FORCE_INLINE bool isCoolingHotend##NR() { return isCoolingHotend(NR); }
164
-HOTEND_ROUTINES(0);
165
-#if EXTRUDERS > 1
166
-  HOTEND_ROUTINES(1);
167
-#else
168
-  #define setTargetHotend1(c) do{}while(0)
169
-#endif
170
-#if EXTRUDERS > 2
171
-  HOTEND_ROUTINES(2);
172
-#else
173
-  #define setTargetHotend2(c) do{}while(0)
174
-#endif
175
-#if EXTRUDERS > 3
176
-  HOTEND_ROUTINES(3);
177
-#else
178
-  #define setTargetHotend3(c) do{}while(0)
179
-#endif
101
+    #if ENABLED(BABYSTEPPING)
102
+      volatile int babystepsTodo[3] = { 0 };
103
+    #endif
180 104
 
181
-int getHeaterPower(int heater);
182
-void disable_all_heaters();
183
-void updatePID();
105
+    #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
106
+      int watch_target_temp[EXTRUDERS] = { 0 };
107
+      millis_t watch_heater_next_ms[EXTRUDERS] = { 0 };
108
+    #endif
184 109
 
185
-#if ENABLED(PIDTEMP)
186
-  void PID_autotune(float temp, int extruder, int ncycles, bool set_result=false);
187
-#endif
110
+    #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_BED_TEMP_PERIOD > 0
111
+      int watch_target_bed_temp = 0;
112
+      millis_t watch_bed_next_ms = 0;
113
+    #endif
114
+
115
+    #if ENABLED(PREVENT_DANGEROUS_EXTRUDE)
116
+      float extrude_min_temp = EXTRUDE_MINTEMP;
117
+      FORCE_INLINE bool tooColdToExtrude(uint8_t e) { return degHotend(e) < extrude_min_temp; }
118
+    #else
119
+      FORCE_INLINE bool tooColdToExtrude(uint8_t e) { UNUSED(e); return false; }
120
+    #endif
121
+
122
+  private:
123
+
124
+    #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
125
+      int redundant_temperature_raw = 0;
126
+      float redundant_temperature = 0.0;
127
+    #endif
128
+
129
+    volatile bool temp_meas_ready = false;
130
+
131
+    #if ENABLED(PIDTEMP)
132
+      float temp_iState[EXTRUDERS] = { 0 };
133
+      float temp_dState[EXTRUDERS] = { 0 };
134
+      float pTerm[EXTRUDERS];
135
+      float iTerm[EXTRUDERS];
136
+      float dTerm[EXTRUDERS];
137
+
138
+      #if ENABLED(PID_ADD_EXTRUSION_RATE)
139
+        float cTerm[EXTRUDERS];
140
+        long last_position[EXTRUDERS];
141
+        long lpq[LPQ_MAX_LEN];
142
+        int lpq_ptr = 0;
143
+      #endif
144
+
145
+      float pid_error[EXTRUDERS];
146
+      float temp_iState_min[EXTRUDERS];
147
+      float temp_iState_max[EXTRUDERS];
148
+      bool pid_reset[EXTRUDERS];
149
+    #endif
150
+
151
+    #if ENABLED(PIDTEMPBED)
152
+      float temp_iState_bed = { 0 };
153
+      float temp_dState_bed = { 0 };
154
+      float pTerm_bed;
155
+      float iTerm_bed;
156
+      float dTerm_bed;
157
+      float pid_error_bed;
158
+      float temp_iState_min_bed;
159
+      float temp_iState_max_bed;
160
+    #else
161
+      millis_t next_bed_check_ms;
162
+    #endif
188 163
 
189
-void setExtruderAutoFanState(int pin, bool state);
190
-void checkExtruderAutoFans();
164
+    unsigned long raw_temp_value[4] = { 0 };
165
+    unsigned long raw_temp_bed_value = 0;
166
+
167
+    // Init min and max temp with extreme values to prevent false errors during startup
168
+    int minttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS(HEATER_0_RAW_LO_TEMP , HEATER_1_RAW_LO_TEMP , HEATER_2_RAW_LO_TEMP, HEATER_3_RAW_LO_TEMP);
169
+    int maxttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS(HEATER_0_RAW_HI_TEMP , HEATER_1_RAW_HI_TEMP , HEATER_2_RAW_HI_TEMP, HEATER_3_RAW_HI_TEMP);
170
+    int minttemp[EXTRUDERS] = { 0 };
171
+    int maxttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(16383);
172
+
173
+    #ifdef BED_MINTEMP
174
+      int bed_minttemp_raw = HEATER_BED_RAW_LO_TEMP;
175
+    #endif
176
+
177
+    #ifdef BED_MAXTEMP
178
+      int bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP;
179
+    #endif
180
+
181
+    #if ENABLED(FILAMENT_WIDTH_SENSOR)
182
+      int meas_shift_index;  // Index of a delayed sample in buffer
183
+    #endif
184
+
185
+    #if HAS_AUTO_FAN
186
+      millis_t next_auto_fan_check_ms;
187
+    #endif
188
+
189
+    unsigned char soft_pwm[EXTRUDERS];
190
+
191
+    #if ENABLED(FAN_SOFT_PWM)
192
+      unsigned char soft_pwm_fan[FAN_COUNT];
193
+    #endif
191 194
 
192
-FORCE_INLINE void autotempShutdown() {
193
-  #if ENABLED(AUTOTEMP)
194
-    if (planner.autotemp_enabled) {
195
-      planner.autotemp_enabled = false;
196
-      if (degTargetHotend(active_extruder) > planner.autotemp_min)
197
-        setTargetHotend(0, active_extruder);
195
+    #if ENABLED(FILAMENT_WIDTH_SENSOR)
196
+      int current_raw_filwidth = 0;  //Holds measured filament diameter - one extruder only
197
+    #endif
198
+
199
+  public:
200
+
201
+    /**
202
+     * Static (class) methods
203
+     */
204
+    static float analog2temp(int raw, uint8_t e);
205
+    static float analog2tempBed(int raw);
206
+
207
+    /**
208
+     * Instance Methods
209
+     */
210
+
211
+    Temperature();
212
+
213
+    void init();
214
+
215
+    /**
216
+     * Called from the Temperature ISR
217
+     */
218
+    void isr();
219
+
220
+    /**
221
+     * Call periodically to manage heaters
222
+     */
223
+    void manage_heater();
224
+
225
+    #if ENABLED(FILAMENT_WIDTH_SENSOR)
226
+      float analog2widthFil(); // Convert raw Filament Width to millimeters
227
+      int widthFil_to_size_ratio(); // Convert raw Filament Width to an extrusion ratio
228
+    #endif
229
+
230
+
231
+    //high level conversion routines, for use outside of temperature.cpp
232
+    //inline so that there is no performance decrease.
233
+    //deg=degreeCelsius
234
+
235
+    FORCE_INLINE float degHotend(uint8_t extruder) { return current_temperature[extruder]; }
236
+    FORCE_INLINE float degBed() { return current_temperature_bed; }
237
+
238
+    #if ENABLED(SHOW_TEMP_ADC_VALUES)
239
+    FORCE_INLINE float rawHotendTemp(uint8_t extruder) { return current_temperature_raw[extruder]; }
240
+    FORCE_INLINE float rawBedTemp() { return current_temperature_bed_raw; }
241
+    #endif
242
+
243
+    FORCE_INLINE float degTargetHotend(uint8_t extruder) { return target_temperature[extruder]; }
244
+    FORCE_INLINE float degTargetBed() { return target_temperature_bed; }
245
+
246
+    #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
247
+      void start_watching_heater(int e = 0);
248
+    #endif
249
+
250
+    #if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
251
+      void start_watching_bed();
252
+    #endif
253
+
254
+    FORCE_INLINE void setTargetHotend(const float& celsius, uint8_t extruder) {
255
+      target_temperature[extruder] = celsius;
256
+      #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
257
+        start_watching_heater(extruder);
258
+      #endif
259
+    }
260
+
261
+    FORCE_INLINE void setTargetBed(const float& celsius) {
262
+      target_temperature_bed = celsius;
263
+      #if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
264
+        start_watching_bed();
265
+      #endif
198 266
     }
199
-  #endif
200
-}
267
+
268
+    FORCE_INLINE bool isHeatingHotend(uint8_t extruder) { return target_temperature[extruder] > current_temperature[extruder]; }
269
+    FORCE_INLINE bool isHeatingBed() { return target_temperature_bed > current_temperature_bed; }
270
+
271
+    FORCE_INLINE bool isCoolingHotend(uint8_t extruder) { return target_temperature[extruder] < current_temperature[extruder]; }
272
+    FORCE_INLINE bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
273
+
274
+    /**
275
+     * The software PWM power for a heater
276
+     */
277
+    int getHeaterPower(int heater);
278
+
279
+    /**
280
+     * Switch off all heaters, set all target temperatures to 0
281
+     */
282
+    void disable_all_heaters();
283
+
284
+    /**
285
+     * Perform auto-tuning for hotend or bed in response to M303
286
+     */
287
+    #if HAS_PID_HEATING
288
+      void PID_autotune(float temp, int extruder, int ncycles, bool set_result=false);
289
+    #endif
290
+
291
+    /**
292
+     * Update the temp manager when PID values change
293
+     */
294
+    void updatePID();
295
+
296
+    FORCE_INLINE void autotempShutdown() {
297
+      #if ENABLED(AUTOTEMP)
298
+        if (planner.autotemp_enabled) {
299
+          planner.autotemp_enabled = false;
300
+          if (degTargetHotend(active_extruder) > planner.autotemp_min)
301
+            setTargetHotend(0, active_extruder);
302
+        }
303
+      #endif
304
+    }
305
+
306
+  private:
307
+
308
+    void set_current_temp_raw();
309
+
310
+    void updateTemperaturesFromRawValues();
311
+
312
+    #if ENABLED(HEATER_0_USES_MAX6675)
313
+      int read_max6675();
314
+    #endif
315
+
316
+    void setExtruderAutoFanState(int pin, bool state);
317
+    void checkExtruderAutoFans();
318
+
319
+    float get_pid_output(int e);
320
+
321
+    #if ENABLED(PIDTEMPBED)
322
+      float get_pid_output_bed();
323
+    #endif
324
+
325
+    void _temp_error(int e, const char* serial_msg, const char* lcd_msg);
326
+    void min_temp_error(uint8_t e);
327
+    void max_temp_error(uint8_t e);
328
+
329
+    #if ENABLED(THERMAL_PROTECTION_HOTENDS) || HAS_THERMALLY_PROTECTED_BED
330
+
331
+      typedef enum TRState { TRReset, TRInactive, TRFirstHeating, TRStable, TRRunaway } TRstate;
332
+
333
+      void thermal_runaway_protection(TRState* state, millis_t* timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
334
+
335
+      #if ENABLED(THERMAL_PROTECTION_HOTENDS)
336
+        TRState thermal_runaway_state_machine[EXTRUDERS] = { TRReset };
337
+        millis_t thermal_runaway_timer[EXTRUDERS] = { 0 };
338
+      #endif
339
+
340
+      #if HAS_THERMALLY_PROTECTED_BED
341
+        TRState thermal_runaway_bed_state_machine = TRReset;
342
+        millis_t thermal_runaway_bed_timer;
343
+      #endif
344
+
345
+    #endif // THERMAL_PROTECTION
346
+
347
+};
348
+
349
+extern Temperature thermalManager;
201 350
 
202 351
 #endif // TEMPERATURE_H

+ 39
- 31
Marlin/ultralcd.cpp Vedi File

@@ -479,7 +479,7 @@ inline void line_to_current(AxisEnum axis) {
479 479
     stepper.quick_stop();
480 480
     card.sdprinting = false;
481 481
     card.closefile();
482
-    autotempShutdown();
482
+    thermalManager.autotempShutdown();
483 483
     cancel_heatup = true;
484 484
     lcd_setstatus(MSG_PRINT_ABORTED, true);
485 485
   }
@@ -605,16 +605,16 @@ void lcd_set_home_offsets() {
605 605
  */
606 606
 #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
607 607
   #if TEMP_SENSOR_0 != 0
608
-    void watch_temp_callback_E0() { start_watching_heater(0); }
608
+    void watch_temp_callback_E0() { thermalManager.start_watching_heater(0); }
609 609
   #endif
610 610
   #if EXTRUDERS > 1 && TEMP_SENSOR_1 != 0
611
-    void watch_temp_callback_E1() { start_watching_heater(1); }
611
+    void watch_temp_callback_E1() { thermalManager.start_watching_heater(1); }
612 612
   #endif // EXTRUDERS > 1
613 613
   #if EXTRUDERS > 2 && TEMP_SENSOR_2 != 0
614
-    void watch_temp_callback_E2() { start_watching_heater(2); }
614
+    void watch_temp_callback_E2() { thermalManager.start_watching_heater(2); }
615 615
   #endif // EXTRUDERS > 2
616 616
   #if EXTRUDERS > 3 && TEMP_SENSOR_3 != 0
617
-    void watch_temp_callback_E3() { start_watching_heater(3); }
617
+    void watch_temp_callback_E3() { thermalManager.start_watching_heater(3); }
618 618
   #endif // EXTRUDERS > 3
619 619
 #else
620 620
   #if TEMP_SENSOR_0 != 0
@@ -633,7 +633,7 @@ void lcd_set_home_offsets() {
633 633
 
634 634
 #if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
635 635
   #if TEMP_SENSOR_BED != 0
636
-    void watch_temp_callback_bed() { start_watching_bed(); }
636
+    void watch_temp_callback_bed() { thermalManager.start_watching_bed(); }
637 637
   #endif
638 638
 #else
639 639
   #if TEMP_SENSOR_BED != 0
@@ -670,22 +670,22 @@ static void lcd_tune_menu() {
670 670
   //
671 671
   #if EXTRUDERS == 1
672 672
     #if TEMP_SENSOR_0 != 0
673
-      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
673
+      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
674 674
     #endif
675 675
   #else //EXTRUDERS > 1
676 676
     #if TEMP_SENSOR_0 != 0
677
-      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
677
+      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
678 678
     #endif
679 679
     #if TEMP_SENSOR_1 != 0
680
-      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
680
+      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
681 681
     #endif
682 682
     #if EXTRUDERS > 2
683 683
       #if TEMP_SENSOR_2 != 0
684
-        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
684
+        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
685 685
       #endif
686 686
       #if EXTRUDERS > 3
687 687
         #if TEMP_SENSOR_3 != 0
688
-          MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
688
+          MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
689 689
         #endif
690 690
       #endif // EXTRUDERS > 3
691 691
     #endif // EXTRUDERS > 2
@@ -695,7 +695,7 @@ static void lcd_tune_menu() {
695 695
   // Bed:
696 696
   //
697 697
   #if TEMP_SENSOR_BED != 0
698
-    MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
698
+    MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
699 699
   #endif
700 700
 
701 701
   //
@@ -768,9 +768,9 @@ static void lcd_tune_menu() {
768 768
  *
769 769
  */
770 770
 void _lcd_preheat(int endnum, const float temph, const float tempb, const int fan) {
771
-  if (temph > 0) setTargetHotend(temph, endnum);
771
+  if (temph > 0) thermalManager.setTargetHotend(temph, endnum);
772 772
   #if TEMP_SENSOR_BED != 0
773
-    setTargetBed(tempb);
773
+    thermalManager.setTargetBed(tempb);
774 774
   #else
775 775
     UNUSED(tempb);
776 776
   #endif
@@ -805,19 +805,27 @@ void _lcd_preheat(int endnum, const float temph, const float tempb, const int fa
805 805
 
806 806
   void lcd_preheat_pla0123() {
807 807
     #if EXTRUDERS > 1
808
-      setTargetHotend0(plaPreheatHotendTemp);
809
-      setTargetHotend1(plaPreheatHotendTemp);
810
-      setTargetHotend2(plaPreheatHotendTemp);
808
+      thermalManager.setTargetHotend(plaPreheatHotendTemp, 1);
809
+      #if EXTRUDERS > 2
810
+        thermalManager.setTargetHotend(plaPreheatHotendTemp, 2);
811
+        #if EXTRUDERS > 3
812
+          thermalManager.setTargetHotend(plaPreheatHotendTemp, 3);
813
+        #endif
814
+      #endif
811 815
     #endif
812
-    _lcd_preheat(EXTRUDERS - 1, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed);
816
+    lcd_preheat_pla0();
813 817
   }
814 818
   void lcd_preheat_abs0123() {
815 819
     #if EXTRUDERS > 1
816
-      setTargetHotend0(absPreheatHotendTemp);
817
-      setTargetHotend1(absPreheatHotendTemp);
818
-      setTargetHotend2(absPreheatHotendTemp);
820
+      thermalManager.setTargetHotend(absPreheatHotendTemp, 1);
821
+      #if EXTRUDERS > 2
822
+        thermalManager.setTargetHotend(absPreheatHotendTemp, 2);
823
+        #if EXTRUDERS > 3
824
+          thermalManager.setTargetHotend(absPreheatHotendTemp, 3);
825
+        #endif
826
+      #endif
819 827
     #endif
820
-    _lcd_preheat(EXTRUDERS - 1, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed);
828
+    lcd_preheat_abs0();
821 829
   }
822 830
 
823 831
 #endif // EXTRUDERS > 1
@@ -879,7 +887,7 @@ void lcd_cooldown() {
879 887
   #if FAN_COUNT > 0
880 888
     for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
881 889
   #endif
882
-  disable_all_heaters();
890
+  thermalManager.disable_all_heaters();
883 891
   lcd_return_to_status();
884 892
 }
885 893
 
@@ -1414,14 +1422,14 @@ static void lcd_control_menu() {
1414 1422
       UNUSED(e);
1415 1423
     #endif
1416 1424
     PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
1417
-    updatePID();
1425
+    thermalManager.updatePID();
1418 1426
   }
1419 1427
   void copy_and_scalePID_d(int e) {
1420 1428
     #if DISABLED(PID_PARAMS_PER_EXTRUDER)
1421 1429
       UNUSED(e);
1422 1430
     #endif
1423 1431
     PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
1424
-    updatePID();
1432
+    thermalManager.updatePID();
1425 1433
   }
1426 1434
   #define _PIDTEMP_BASE_FUNCTIONS(eindex) \
1427 1435
     void copy_and_scalePID_i_E ## eindex() { copy_and_scalePID_i(eindex); } \
@@ -1469,22 +1477,22 @@ static void lcd_control_temperature_menu() {
1469 1477
   //
1470 1478
   #if EXTRUDERS == 1
1471 1479
     #if TEMP_SENSOR_0 != 0
1472
-      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
1480
+      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
1473 1481
     #endif
1474 1482
   #else //EXTRUDERS > 1
1475 1483
     #if TEMP_SENSOR_0 != 0
1476
-      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
1484
+      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
1477 1485
     #endif
1478 1486
     #if TEMP_SENSOR_1 != 0
1479
-      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
1487
+      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
1480 1488
     #endif
1481 1489
     #if EXTRUDERS > 2
1482 1490
       #if TEMP_SENSOR_2 != 0
1483
-        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
1491
+        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
1484 1492
       #endif
1485 1493
       #if EXTRUDERS > 3
1486 1494
         #if TEMP_SENSOR_3 != 0
1487
-          MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
1495
+          MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
1488 1496
         #endif
1489 1497
       #endif // EXTRUDERS > 3
1490 1498
     #endif // EXTRUDERS > 2
@@ -1494,7 +1502,7 @@ static void lcd_control_temperature_menu() {
1494 1502
   // Bed:
1495 1503
   //
1496 1504
   #if TEMP_SENSOR_BED != 0
1497
-    MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
1505
+    MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15);
1498 1506
   #endif
1499 1507
 
1500 1508
   //

+ 10
- 10
Marlin/ultralcd_implementation_hitachi_HD44780.h Vedi File

@@ -633,7 +633,7 @@ static void lcd_implementation_status_screen() {
633 633
     //
634 634
     // Hotend 0 Temperature
635 635
     //
636
-    LCD_TEMP_ONLY(degHotend(0), degTargetHotend(0));
636
+    LCD_TEMP_ONLY(thermalManager.degHotend(0), thermalManager.degTargetHotend(0));
637 637
 
638 638
     //
639 639
     // Hotend 1 or Bed Temperature
@@ -643,10 +643,10 @@ static void lcd_implementation_status_screen() {
643 643
       lcd.setCursor(8, 0);
644 644
       #if EXTRUDERS > 1
645 645
         lcd.print(LCD_STR_THERMOMETER[0]);
646
-        LCD_TEMP_ONLY(degHotend(1), degTargetHotend(1));
646
+        LCD_TEMP_ONLY(thermalManager.degHotend(1), thermalManager.degTargetHotend(1));
647 647
       #else
648 648
         lcd.print(LCD_STR_BEDTEMP[0]);
649
-        LCD_TEMP_ONLY(degBed(), degTargetBed());
649
+        LCD_TEMP_ONLY(thermalManager.degBed(), thermalManager.degTargetBed());
650 650
       #endif
651 651
 
652 652
     #endif // EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
@@ -656,7 +656,7 @@ static void lcd_implementation_status_screen() {
656 656
     //
657 657
     // Hotend 0 Temperature
658 658
     //
659
-    LCD_TEMP(degHotend(0), degTargetHotend(0), LCD_STR_THERMOMETER[0]);
659
+    LCD_TEMP(thermalManager.degHotend(0), thermalManager.degTargetHotend(0), LCD_STR_THERMOMETER[0]);
660 660
 
661 661
     //
662 662
     // Hotend 1 or Bed Temperature
@@ -664,9 +664,9 @@ static void lcd_implementation_status_screen() {
664 664
     #if EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
665 665
       lcd.setCursor(10, 0);
666 666
       #if EXTRUDERS > 1
667
-        LCD_TEMP(degHotend(1), degTargetHotend(1), LCD_STR_THERMOMETER[0]);
667
+        LCD_TEMP(thermalManager.degHotend(1), thermalManager.degTargetHotend(1), LCD_STR_THERMOMETER[0]);
668 668
       #else
669
-        LCD_TEMP(degBed(), degTargetBed(), LCD_STR_BEDTEMP[0]);
669
+        LCD_TEMP(thermalManager.degBed(), thermalManager.degTargetBed(), LCD_STR_BEDTEMP[0]);
670 670
       #endif
671 671
 
672 672
     #endif  // EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
@@ -702,7 +702,7 @@ static void lcd_implementation_status_screen() {
702 702
         // If we both have a 2nd extruder and a heated bed,
703 703
         // show the heated bed temp on the left,
704 704
         // since the first line is filled with extruder temps
705
-        LCD_TEMP(degBed(), degTargetBed(), LCD_STR_BEDTEMP[0]);
705
+        LCD_TEMP(thermalManager.degBed(), thermalManager.degTargetBed(), LCD_STR_BEDTEMP[0]);
706 706
 
707 707
       #else
708 708
         // Before homing the axis letters are blinking 'X' <-> '?'.
@@ -925,9 +925,9 @@ void lcd_implementation_drawedit(const char* pstr, const char* value=NULL) {
925 925
     static uint8_t ledsprev = 0;
926 926
     uint8_t leds = 0;
927 927
 
928
-    if (target_temperature_bed > 0) leds |= LED_A;
928
+    if (thermalManager.degTargetBed() > 0) leds |= LED_A;
929 929
 
930
-    if (target_temperature[0] > 0) leds |= LED_B;
930
+    if (thermalManager.degTargetHotend(0) > 0) leds |= LED_B;
931 931
 
932 932
     #if FAN_COUNT > 0
933 933
       if (0
@@ -944,7 +944,7 @@ void lcd_implementation_drawedit(const char* pstr, const char* value=NULL) {
944 944
     #endif // FAN_COUNT > 0
945 945
 
946 946
     #if EXTRUDERS > 1
947
-      if (target_temperature[1] > 0) leds |= LED_C;
947
+      if (thermalManager.degTargetHotend(1) > 0) leds |= LED_C;
948 948
     #endif
949 949
 
950 950
     if (leds != ledsprev) {

Loading…
Annulla
Salva