Parcourir la source

Temperature singleton class

Scott Lahteine il y a 8 ans
Parent
révision
084f6b5b44

+ 0
- 4
Marlin/Marlin.h Voir le fichier

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

+ 60
- 66
Marlin/Marlin_main.cpp Voir le fichier

544
   }
544
   }
545
 #endif
545
 #endif
546
 
546
 
547
-#if ENABLED(PREVENT_DANGEROUS_EXTRUDE)
548
-  float extrude_min_temp = EXTRUDE_MINTEMP;
549
-#endif
550
-
551
 #if ENABLED(SDSUPPORT)
547
 #if ENABLED(SDSUPPORT)
552
   #include "SdFatUtil.h"
548
   #include "SdFatUtil.h"
553
   int freeMemory() { return SdFatUtil::FreeRam(); }
549
   int freeMemory() { return SdFatUtil::FreeRam(); }
816
 
812
 
817
   lcd_init();
813
   lcd_init();
818
 
814
 
819
-  tp_init();    // Initialize temperature loop
815
+  thermalManager.init();    // Initialize temperature loop
820
 
816
 
821
   #if ENABLED(DELTA) || ENABLED(SCARA)
817
   #if ENABLED(DELTA) || ENABLED(SCARA)
822
     // Vital to init kinematic equivalent for X0 Y0 Z0
818
     // Vital to init kinematic equivalent for X0 Y0 Z0
3839
   SERIAL_ECHO_START;
3835
   SERIAL_ECHO_START;
3840
   SERIAL_ECHOLN(time);
3836
   SERIAL_ECHOLN(time);
3841
   lcd_setstatus(time);
3837
   lcd_setstatus(time);
3842
-  autotempShutdown();
3838
+  thermalManager.autotempShutdown();
3843
 }
3839
 }
3844
 
3840
 
3845
 #if ENABLED(SDSUPPORT)
3841
 #if ENABLED(SDSUPPORT)
4274
 
4270
 
4275
   if (code_seen('S')) {
4271
   if (code_seen('S')) {
4276
     float temp = code_value();
4272
     float temp = code_value();
4277
-    setTargetHotend(temp, target_extruder);
4273
+    thermalManager.setTargetHotend(temp, target_extruder);
4278
     #if ENABLED(DUAL_X_CARRIAGE)
4274
     #if ENABLED(DUAL_X_CARRIAGE)
4279
       if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && target_extruder == 0)
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
     #endif
4277
     #endif
4282
 
4278
 
4283
     /**
4279
     /**
4296
      */
4292
      */
4297
     else print_job_timer.start();
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
   void print_heaterstates() {
4301
   void print_heaterstates() {
4306
     #if HAS_TEMP_HOTEND
4302
     #if HAS_TEMP_HOTEND
4307
       SERIAL_PROTOCOLPGM(" T:");
4303
       SERIAL_PROTOCOLPGM(" T:");
4308
-      SERIAL_PROTOCOL_F(degHotend(target_extruder), 1);
4304
+      SERIAL_PROTOCOL_F(thermalManager.degHotend(target_extruder), 1);
4309
       SERIAL_PROTOCOLPGM(" /");
4305
       SERIAL_PROTOCOLPGM(" /");
4310
-      SERIAL_PROTOCOL_F(degTargetHotend(target_extruder), 1);
4306
+      SERIAL_PROTOCOL_F(thermalManager.degTargetHotend(target_extruder), 1);
4311
     #endif
4307
     #endif
4312
     #if HAS_TEMP_BED
4308
     #if HAS_TEMP_BED
4313
       SERIAL_PROTOCOLPGM(" B:");
4309
       SERIAL_PROTOCOLPGM(" B:");
4314
-      SERIAL_PROTOCOL_F(degBed(), 1);
4310
+      SERIAL_PROTOCOL_F(thermalManager.degBed(), 1);
4315
       SERIAL_PROTOCOLPGM(" /");
4311
       SERIAL_PROTOCOLPGM(" /");
4316
-      SERIAL_PROTOCOL_F(degTargetBed(), 1);
4312
+      SERIAL_PROTOCOL_F(thermalManager.degTargetBed(), 1);
4317
     #endif
4313
     #endif
4318
     #if EXTRUDERS > 1
4314
     #if EXTRUDERS > 1
4319
       for (int8_t e = 0; e < EXTRUDERS; ++e) {
4315
       for (int8_t e = 0; e < EXTRUDERS; ++e) {
4320
         SERIAL_PROTOCOLPGM(" T");
4316
         SERIAL_PROTOCOLPGM(" T");
4321
         SERIAL_PROTOCOL(e);
4317
         SERIAL_PROTOCOL(e);
4322
         SERIAL_PROTOCOLCHAR(':');
4318
         SERIAL_PROTOCOLCHAR(':');
4323
-        SERIAL_PROTOCOL_F(degHotend(e), 1);
4319
+        SERIAL_PROTOCOL_F(thermalManager.degHotend(e), 1);
4324
         SERIAL_PROTOCOLPGM(" /");
4320
         SERIAL_PROTOCOLPGM(" /");
4325
-        SERIAL_PROTOCOL_F(degTargetHotend(e), 1);
4321
+        SERIAL_PROTOCOL_F(thermalManager.degTargetHotend(e), 1);
4326
       }
4322
       }
4327
     #endif
4323
     #endif
4328
     #if HAS_TEMP_BED
4324
     #if HAS_TEMP_BED
4329
       SERIAL_PROTOCOLPGM(" B@:");
4325
       SERIAL_PROTOCOLPGM(" B@:");
4330
       #ifdef BED_WATTS
4326
       #ifdef BED_WATTS
4331
-        SERIAL_PROTOCOL(((BED_WATTS) * getHeaterPower(-1)) / 127);
4327
+        SERIAL_PROTOCOL(((BED_WATTS) * thermalManager.getHeaterPower(-1)) / 127);
4332
         SERIAL_PROTOCOLCHAR('W');
4328
         SERIAL_PROTOCOLCHAR('W');
4333
       #else
4329
       #else
4334
-        SERIAL_PROTOCOL(getHeaterPower(-1));
4330
+        SERIAL_PROTOCOL(thermalManager.getHeaterPower(-1));
4335
       #endif
4331
       #endif
4336
     #endif
4332
     #endif
4337
     SERIAL_PROTOCOLPGM(" @:");
4333
     SERIAL_PROTOCOLPGM(" @:");
4338
     #ifdef EXTRUDER_WATTS
4334
     #ifdef EXTRUDER_WATTS
4339
-      SERIAL_PROTOCOL(((EXTRUDER_WATTS) * getHeaterPower(target_extruder)) / 127);
4335
+      SERIAL_PROTOCOL(((EXTRUDER_WATTS) * thermalManager.getHeaterPower(target_extruder)) / 127);
4340
       SERIAL_PROTOCOLCHAR('W');
4336
       SERIAL_PROTOCOLCHAR('W');
4341
     #else
4337
     #else
4342
-      SERIAL_PROTOCOL(getHeaterPower(target_extruder));
4338
+      SERIAL_PROTOCOL(thermalManager.getHeaterPower(target_extruder));
4343
     #endif
4339
     #endif
4344
     #if EXTRUDERS > 1
4340
     #if EXTRUDERS > 1
4345
       for (int8_t e = 0; e < EXTRUDERS; ++e) {
4341
       for (int8_t e = 0; e < EXTRUDERS; ++e) {
4347
         SERIAL_PROTOCOL(e);
4343
         SERIAL_PROTOCOL(e);
4348
         SERIAL_PROTOCOLCHAR(':');
4344
         SERIAL_PROTOCOLCHAR(':');
4349
         #ifdef EXTRUDER_WATTS
4345
         #ifdef EXTRUDER_WATTS
4350
-          SERIAL_PROTOCOL(((EXTRUDER_WATTS) * getHeaterPower(e)) / 127);
4346
+          SERIAL_PROTOCOL(((EXTRUDER_WATTS) * thermalManager.getHeaterPower(e)) / 127);
4351
           SERIAL_PROTOCOLCHAR('W');
4347
           SERIAL_PROTOCOLCHAR('W');
4352
         #else
4348
         #else
4353
-          SERIAL_PROTOCOL(getHeaterPower(e));
4349
+          SERIAL_PROTOCOL(thermalManager.getHeaterPower(e));
4354
         #endif
4350
         #endif
4355
       }
4351
       }
4356
     #endif
4352
     #endif
4357
     #if ENABLED(SHOW_TEMP_ADC_VALUES)
4353
     #if ENABLED(SHOW_TEMP_ADC_VALUES)
4358
       #if HAS_TEMP_BED
4354
       #if HAS_TEMP_BED
4359
         SERIAL_PROTOCOLPGM("    ADC B:");
4355
         SERIAL_PROTOCOLPGM("    ADC B:");
4360
-        SERIAL_PROTOCOL_F(degBed(), 1);
4356
+        SERIAL_PROTOCOL_F(thermalManager.degBed(), 1);
4361
         SERIAL_PROTOCOLPGM("C->");
4357
         SERIAL_PROTOCOLPGM("C->");
4362
-        SERIAL_PROTOCOL_F(rawBedTemp() / OVERSAMPLENR, 0);
4358
+        SERIAL_PROTOCOL_F(thermalManager.rawBedTemp() / OVERSAMPLENR, 0);
4363
       #endif
4359
       #endif
4364
       for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder) {
4360
       for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder) {
4365
         SERIAL_PROTOCOLPGM("  T");
4361
         SERIAL_PROTOCOLPGM("  T");
4366
         SERIAL_PROTOCOL(cur_extruder);
4362
         SERIAL_PROTOCOL(cur_extruder);
4367
         SERIAL_PROTOCOLCHAR(':');
4363
         SERIAL_PROTOCOLCHAR(':');
4368
-        SERIAL_PROTOCOL_F(degHotend(cur_extruder), 1);
4364
+        SERIAL_PROTOCOL_F(thermalManager.degHotend(cur_extruder), 1);
4369
         SERIAL_PROTOCOLPGM("C->");
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
     #endif
4368
     #endif
4373
   }
4369
   }
4427
   bool no_wait_for_cooling = code_seen('S');
4423
   bool no_wait_for_cooling = code_seen('S');
4428
   if (no_wait_for_cooling || code_seen('R')) {
4424
   if (no_wait_for_cooling || code_seen('R')) {
4429
     float temp = code_value();
4425
     float temp = code_value();
4430
-    setTargetHotend(temp, target_extruder);
4426
+    thermalManager.setTargetHotend(temp, target_extruder);
4431
     #if ENABLED(DUAL_X_CARRIAGE)
4427
     #if ENABLED(DUAL_X_CARRIAGE)
4432
       if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && target_extruder == 0)
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
     #endif
4430
     #endif
4435
 
4431
 
4436
     /**
4432
     /**
4449
      */
4445
      */
4450
     else print_job_timer.start();
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
   #if ENABLED(AUTOTEMP)
4451
   #if ENABLED(AUTOTEMP)
4462
     #define TEMP_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_RESIDENCY_TIME) * 1000UL))
4458
     #define TEMP_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_RESIDENCY_TIME) * 1000UL))
4463
   #else
4459
   #else
4464
     // Loop until the temperature is very close target
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
   #endif //TEMP_RESIDENCY_TIME > 0
4462
   #endif //TEMP_RESIDENCY_TIME > 0
4467
 
4463
 
4468
   float theTarget = -1;
4464
   float theTarget = -1;
4473
   KEEPALIVE_STATE(NOT_BUSY);
4469
   KEEPALIVE_STATE(NOT_BUSY);
4474
 
4470
 
4475
   do {
4471
   do {
4476
-
4477
     now = millis();
4472
     now = millis();
4478
     if (ELAPSED(now, next_temp_ms)) { //Print temp & remaining time every 1s while waiting
4473
     if (ELAPSED(now, next_temp_ms)) { //Print temp & remaining time every 1s while waiting
4479
       next_temp_ms = now + 1000UL;
4474
       next_temp_ms = now + 1000UL;
4495
     }
4490
     }
4496
 
4491
 
4497
     // Target temperature might be changed during the loop
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
       // Exit if S<lower>, continue if S<higher>, R<lower>, or R<higher>
4497
       // Exit if S<lower>, continue if S<higher>, R<lower>, or R<higher>
4503
       if (no_wait_for_cooling && wants_to_cool) break;
4498
       if (no_wait_for_cooling && wants_to_cool) break;
4512
 
4507
 
4513
     #if TEMP_RESIDENCY_TIME > 0
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
       if (!residency_start_ms) {
4512
       if (!residency_start_ms) {
4518
         // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
4513
         // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
4542
 
4537
 
4543
     LCD_MESSAGEPGM(MSG_BED_HEATING);
4538
     LCD_MESSAGEPGM(MSG_BED_HEATING);
4544
     bool no_wait_for_cooling = code_seen('S');
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
     #if TEMP_BED_RESIDENCY_TIME > 0
4542
     #if TEMP_BED_RESIDENCY_TIME > 0
4548
       millis_t residency_start_ms = 0;
4543
       millis_t residency_start_ms = 0;
4550
       #define TEMP_BED_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_BED_RESIDENCY_TIME) * 1000UL))
4545
       #define TEMP_BED_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_BED_RESIDENCY_TIME) * 1000UL))
4551
     #else
4546
     #else
4552
       // Loop until the temperature is very close target
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
     #endif //TEMP_BED_RESIDENCY_TIME > 0
4549
     #endif //TEMP_BED_RESIDENCY_TIME > 0
4555
 
4550
 
4556
     float theTarget = -1;
4551
     float theTarget = -1;
4580
       }
4575
       }
4581
 
4576
 
4582
       // Target temperature might be changed during the loop
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
         // Exit if S<lower>, continue if S<higher>, R<lower>, or R<higher>
4582
         // Exit if S<lower>, continue if S<higher>, R<lower>, or R<higher>
4588
         if (no_wait_for_cooling && wants_to_cool) break;
4583
         if (no_wait_for_cooling && wants_to_cool) break;
4589
 
4584
 
4590
         // Prevent a wait-forever situation if R is misused i.e. M190 R0
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
       idle();
4590
       idle();
4597
 
4592
 
4598
       #if TEMP_BED_RESIDENCY_TIME > 0
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
         if (!residency_start_ms) {
4597
         if (!residency_start_ms) {
4603
           // Start the TEMP_BED_RESIDENCY_TIME timer when we reach target temp for the first time.
4598
           // Start the TEMP_BED_RESIDENCY_TIME timer when we reach target temp for the first time.
4720
  */
4715
  */
4721
 inline void gcode_M140() {
4716
 inline void gcode_M140() {
4722
   if (DEBUGGING(DRYRUN)) return;
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
 #if ENABLED(ULTIPANEL)
4721
 #if ENABLED(ULTIPANEL)
4811
  *      This code should ALWAYS be available for EMERGENCY SHUTDOWN!
4806
  *      This code should ALWAYS be available for EMERGENCY SHUTDOWN!
4812
  */
4807
  */
4813
 inline void gcode_M81() {
4808
 inline void gcode_M81() {
4814
-  disable_all_heaters();
4809
+  thermalManager.disable_all_heaters();
4815
   stepper.finish_and_disable();
4810
   stepper.finish_and_disable();
4816
   #if FAN_COUNT > 0
4811
   #if FAN_COUNT > 0
4817
     #if FAN_COUNT > 1
4812
     #if FAN_COUNT > 1
5469
         NOMORE(lpq_len, LPQ_MAX_LEN);
5464
         NOMORE(lpq_len, LPQ_MAX_LEN);
5470
       #endif
5465
       #endif
5471
 
5466
 
5472
-      updatePID();
5467
+      thermalManager.updatePID();
5473
       SERIAL_ECHO_START;
5468
       SERIAL_ECHO_START;
5474
       #if ENABLED(PID_PARAMS_PER_EXTRUDER)
5469
       #if ENABLED(PID_PARAMS_PER_EXTRUDER)
5475
         SERIAL_ECHO(" e:"); // specify extruder in serial output
5470
         SERIAL_ECHO(" e:"); // specify extruder in serial output
5499
 #if ENABLED(PIDTEMPBED)
5494
 #if ENABLED(PIDTEMPBED)
5500
 
5495
 
5501
   inline void gcode_M304() {
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
     SERIAL_ECHO_START;
5503
     SERIAL_ECHO_START;
5508
     SERIAL_ECHO(" p:");
5504
     SERIAL_ECHO(" p:");
5509
-    SERIAL_ECHO(bedKp);
5505
+    SERIAL_ECHO(thermalManager.bedKp);
5510
     SERIAL_ECHO(" i:");
5506
     SERIAL_ECHO(" i:");
5511
-    SERIAL_ECHO(unscalePID_i(bedKi));
5507
+    SERIAL_ECHO(unscalePID_i(thermalManager.bedKi));
5512
     SERIAL_ECHO(" d:");
5508
     SERIAL_ECHO(" d:");
5513
-    SERIAL_ECHOLN(unscalePID_d(bedKd));
5509
+    SERIAL_ECHOLN(unscalePID_d(thermalManager.bedKd));
5514
   }
5510
   }
5515
 
5511
 
5516
 #endif // PIDTEMPBED
5512
 #endif // PIDTEMPBED
5567
 
5563
 
5568
 #if ENABLED(PREVENT_DANGEROUS_EXTRUDE)
5564
 #if ENABLED(PREVENT_DANGEROUS_EXTRUDE)
5569
 
5565
 
5570
-  void set_extrude_min_temp(float temp) { extrude_min_temp = temp; }
5571
-
5572
   /**
5566
   /**
5573
    * M302: Allow cold extrudes, or set the minimum extrude S<temperature>.
5567
    * M302: Allow cold extrudes, or set the minimum extrude S<temperature>.
5574
    */
5568
    */
5575
   inline void gcode_M302() {
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
 #endif // PREVENT_DANGEROUS_EXTRUDE
5573
 #endif // PREVENT_DANGEROUS_EXTRUDE
5599
 
5593
 
5600
     KEEPALIVE_STATE(NOT_BUSY); // don't send "busy: processing" messages during autotune output
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
     KEEPALIVE_STATE(IN_HANDLER);
5598
     KEEPALIVE_STATE(IN_HANDLER);
5605
   #else
5599
   #else
5781
     NOMORE(meas_delay_cm, MAX_MEASUREMENT_DELAY);
5775
     NOMORE(meas_delay_cm, MAX_MEASUREMENT_DELAY);
5782
 
5776
 
5783
     if (filwidth_delay_index2 == -1) { // Initialize the ring buffer if not done since startup
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
       for (uint8_t i = 0; i < COUNT(measurement_delay); ++i)
5780
       for (uint8_t i = 0; i < COUNT(measurement_delay); ++i)
5787
         measurement_delay[i] = temp_ratio - 100;  // Subtract 100 to scale within a signed byte
5781
         measurement_delay[i] = temp_ratio - 100;  // Subtract 100 to scale within a signed byte
5984
    */
5978
    */
5985
   inline void gcode_M600() {
5979
   inline void gcode_M600() {
5986
 
5980
 
5987
-    if (degHotend(active_extruder) < extrude_min_temp) {
5981
+    if (thermalManager.tooColdToExtrude(active_extruder)) {
5988
       SERIAL_ERROR_START;
5982
       SERIAL_ERROR_START;
5989
       SERIAL_ERRORLNPGM(MSG_TOO_COLD_FOR_M600);
5983
       SERIAL_ERRORLNPGM(MSG_TOO_COLD_FOR_M600);
5990
       return;
5984
       return;
7268
     if (DEBUGGING(DRYRUN)) return;
7262
     if (DEBUGGING(DRYRUN)) return;
7269
     float de = dest_e - curr_e;
7263
     float de = dest_e - curr_e;
7270
     if (de) {
7264
     if (de) {
7271
-      if (degHotend(active_extruder) < extrude_min_temp) {
7265
+      if (thermalManager.tooColdToExtrude(active_extruder)) {
7272
         curr_e = dest_e; // Behave as if the move really took place, but ignore E part
7266
         curr_e = dest_e; // Behave as if the move really took place, but ignore E part
7273
         SERIAL_ECHO_START;
7267
         SERIAL_ECHO_START;
7274
         SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
7268
         SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
7565
     millis_t ms = millis();
7559
     millis_t ms = millis();
7566
     if (ELAPSED(ms, nextMotorCheck)) {
7560
     if (ELAPSED(ms, nextMotorCheck)) {
7567
       nextMotorCheck = ms + 2500UL; // Not a time critical function, so only check every 2.5s
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
           || E0_ENABLE_READ == E_ENABLE_ON // If any of the drivers are enabled...
7563
           || E0_ENABLE_READ == E_ENABLE_ON // If any of the drivers are enabled...
7570
           #if EXTRUDERS > 1
7564
           #if EXTRUDERS > 1
7571
             || E1_ENABLE_READ == E_ENABLE_ON
7565
             || E1_ENABLE_READ == E_ENABLE_ON
7683
     if (ELAPSED(millis(), next_status_led_update_ms)) {
7677
     if (ELAPSED(millis(), next_status_led_update_ms)) {
7684
       next_status_led_update_ms += 500; // Update every 0.5s
7678
       next_status_led_update_ms += 500; // Update every 0.5s
7685
       for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder)
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
       #if HAS_TEMP_BED
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
       #endif
7683
       #endif
7690
       bool new_led = (max_temp > 55.0) ? true : (max_temp < 54.0) ? false : red_led;
7684
       bool new_led = (max_temp > 55.0) ? true : (max_temp < 54.0) ? false : red_led;
7691
       if (new_led != red_led) {
7685
       if (new_led != red_led) {
7726
     bool no_stepper_sleep/*=false*/
7720
     bool no_stepper_sleep/*=false*/
7727
   #endif
7721
   #endif
7728
 ) {
7722
 ) {
7729
-  manage_heater();
7723
+  thermalManager.manage_heater();
7730
   manage_inactivity(
7724
   manage_inactivity(
7731
     #if ENABLED(FILAMENTCHANGEENABLE)
7725
     #if ENABLED(FILAMENTCHANGEENABLE)
7732
       no_stepper_sleep
7726
       no_stepper_sleep
7831
 
7825
 
7832
   #if ENABLED(EXTRUDER_RUNOUT_PREVENT)
7826
   #if ENABLED(EXTRUDER_RUNOUT_PREVENT)
7833
     if (ELAPSED(ms, previous_cmd_ms + (EXTRUDER_RUNOUT_SECONDS) * 1000UL))
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
         bool oldstatus;
7829
         bool oldstatus;
7836
         switch (active_extruder) {
7830
         switch (active_extruder) {
7837
           case 0:
7831
           case 0:
7914
   #endif
7908
   #endif
7915
 
7909
 
7916
   cli(); // Stop interrupts
7910
   cli(); // Stop interrupts
7917
-  disable_all_heaters();
7911
+  thermalManager.disable_all_heaters();
7918
   disable_all_steppers();
7912
   disable_all_steppers();
7919
 
7913
 
7920
   #if HAS_POWER_SWITCH
7914
   #if HAS_POWER_SWITCH
8010
 #endif // FAST_PWM_FAN
8004
 #endif // FAST_PWM_FAN
8011
 
8005
 
8012
 void stop() {
8006
 void stop() {
8013
-  disable_all_heaters();
8007
+  thermalManager.disable_all_heaters();
8014
   if (IsRunning()) {
8008
   if (IsRunning()) {
8015
     Running = false;
8009
     Running = false;
8016
     Stopped_gcode_LastN = gcode_LastN; // Save last g_code for restart
8010
     Stopped_gcode_LastN = gcode_LastN; // Save last g_code for restart

+ 1
- 1
Marlin/cardreader.cpp Voir le fichier

609
     sdprinting = false;
609
     sdprinting = false;
610
     if (SD_FINISHED_STEPPERRELEASE)
610
     if (SD_FINISHED_STEPPERRELEASE)
611
       enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
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 Voir le fichier

95
  *  363  M301 L        lpq_len (int)
95
  *  363  M301 L        lpq_len (int)
96
  *
96
  *
97
  * PIDTEMPBED:
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
  * DOGLCD:
100
  * DOGLCD:
101
  *  377  M250 C    lcd_contrast (int)
101
  *  377  M250 C    lcd_contrast (int)
261
     #endif // !PIDTEMP
261
     #endif // !PIDTEMP
262
       {
262
       {
263
         dummy = DUMMY_PID_VALUE; // When read, will not change the existing value
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
         dummy = 0.0f;
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
   } // Extruders Loop
269
   } // Extruders Loop
274
   EEPROM_WRITE_VAR(i, lpq_len);
274
   EEPROM_WRITE_VAR(i, lpq_len);
275
 
275
 
276
   #if DISABLED(PIDTEMPBED)
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
   #endif
283
   #endif
279
 
284
 
280
-  EEPROM_WRITE_VAR(i, bedKp);
281
-  EEPROM_WRITE_VAR(i, bedKi);
282
-  EEPROM_WRITE_VAR(i, bedKd);
283
-
284
   #if DISABLED(HAS_LCD_CONTRAST)
285
   #if DISABLED(HAS_LCD_CONTRAST)
285
     const int lcd_contrast = 32;
286
     const int lcd_contrast = 32;
286
   #endif
287
   #endif
450
     #endif
451
     #endif
451
     EEPROM_READ_VAR(i, lpq_len);
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
     #endif
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
     #if DISABLED(HAS_LCD_CONTRAST)
465
     #if DISABLED(HAS_LCD_CONTRAST)
468
       int lcd_contrast;
466
       int lcd_contrast;
469
     #endif
467
     #endif
502
     }
500
     }
503
 
501
 
504
     calculate_volumetric_multipliers();
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
     // Report settings retrieved and length
506
     // Report settings retrieved and length
509
     SERIAL_ECHO_START;
507
     SERIAL_ECHO_START;
602
     #if ENABLED(PID_ADD_EXTRUSION_RATE)
600
     #if ENABLED(PID_ADD_EXTRUSION_RATE)
603
       lpq_len = 20; // default last-position-queue size
601
       lpq_len = 20; // default last-position-queue size
604
     #endif
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
   #endif // PIDTEMP
605
   #endif // PIDTEMP
608
 
606
 
609
   #if ENABLED(PIDTEMPBED)
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
   #endif
611
   #endif
614
 
612
 
615
   #if ENABLED(FWRETRACT)
613
   #if ENABLED(FWRETRACT)
835
 
833
 
836
     #if ENABLED(PIDTEMPBED)
834
     #if ENABLED(PIDTEMPBED)
837
       CONFIG_ECHO_START;
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
       SERIAL_EOL;
839
       SERIAL_EOL;
842
     #endif
840
     #endif
843
 
841
 

+ 3
- 3
Marlin/dogm_lcd_implementation.h Voir le fichier

294
     const bool isBed = false;
294
     const bool isBed = false;
295
   #endif
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
   int h = isBed ? 7 : 8,
301
   int h = isBed ? 7 : 8,
302
       y = isBed ? 18 : 17;
302
       y = isBed ? 18 : 17;
303
-  if (isBed ? isHeatingBed() : isHeatingHotend(heater)) {
303
+  if (isBed ? thermalManager.isHeatingBed() : thermalManager.isHeatingHotend(heater)) {
304
     u8g.setColorIndex(0); // white on black
304
     u8g.setColorIndex(0); // white on black
305
     u8g.drawBox(x + h, y, 2, 2);
305
     u8g.drawBox(x + h, y, 2, 2);
306
     u8g.setColorIndex(1); // black on white
306
     u8g.setColorIndex(1); // black on white

+ 1
- 1
Marlin/endstops.cpp Voir le fichier

153
         card.sdprinting = false;
153
         card.sdprinting = false;
154
         card.closefile();
154
         card.closefile();
155
         stepper.quick_stop();
155
         stepper.quick_stop();
156
-        disable_all_heaters(); // switch off all heaters.
156
+        thermalManager.disable_all_heaters(); // switch off all heaters.
157
       }
157
       }
158
     #endif
158
     #endif
159
   }
159
   }

+ 10
- 9
Marlin/planner.cpp Voir le fichier

304
     static float oldt = 0;
304
     static float oldt = 0;
305
 
305
 
306
     if (!autotemp_enabled) return;
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
     float high = 0.0;
309
     float high = 0.0;
310
     for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) {
310
     for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) {
322
       t += (AUTOTEMP_OLDWEIGHT) * oldt;
322
       t += (AUTOTEMP_OLDWEIGHT) * oldt;
323
     }
323
     }
324
     oldt = t;
324
     oldt = t;
325
-    setTargetHotend0(t);
325
+    thermalManager.setTargetHotend(t, 0);
326
   }
326
   }
327
 
327
 
328
 #endif //AUTOTEMP
328
 #endif //AUTOTEMP
489
   // The target position of the tool in absolute steps
489
   // The target position of the tool in absolute steps
490
   // Calculate target position in absolute steps
490
   // Calculate target position in absolute steps
491
   //this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow
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
   long dx = target[X_AXIS] - position[X_AXIS],
499
   long dx = target[X_AXIS] - position[X_AXIS],
499
        dy = target[Y_AXIS] - position[Y_AXIS],
500
        dy = target[Y_AXIS] - position[Y_AXIS],
507
 
508
 
508
   #if ENABLED(PREVENT_DANGEROUS_EXTRUDE)
509
   #if ENABLED(PREVENT_DANGEROUS_EXTRUDE)
509
     if (de) {
510
     if (de) {
510
-      if (degHotend(extruder) < extrude_min_temp) {
511
+      if (thermalManager.tooColdToExtrude(extruder)) {
511
         position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
512
         position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
512
         de = 0; // no difference
513
         de = 0; // no difference
513
         SERIAL_ECHO_START;
514
         SERIAL_ECHO_START;
788
         // If the index has changed (must have gone forward)...
789
         // If the index has changed (must have gone forward)...
789
         if (filwidth_delay_index1 != filwidth_delay_index2) {
790
         if (filwidth_delay_index1 != filwidth_delay_index2) {
790
           filwidth_e_count = 0; // Reset the E movement counter
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
           do {
793
           do {
793
             filwidth_delay_index2 = (filwidth_delay_index2 + 1) % MMD_CM; // The next unused slot
794
             filwidth_delay_index2 = (filwidth_delay_index2 + 1) % MMD_CM; // The next unused slot
794
             measurement_delay[filwidth_delay_index2] = meas_sample;       // Store the measurement
795
             measurement_delay[filwidth_delay_index2] = meas_sample;       // Store the measurement

+ 94
- 288
Marlin/temperature.cpp Voir le fichier

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
 #include "Marlin.h"
27
 #include "Marlin.h"
44
 #include "ultralcd.h"
28
 #include "ultralcd.h"
50
   #include "watchdog.h"
34
   #include "watchdog.h"
51
 #endif
35
 #endif
52
 
36
 
53
-//===========================================================================
54
-//================================== macros =================================
55
-//===========================================================================
56
-
57
 #ifdef K1 // Defined in Configuration.h in the PID settings
37
 #ifdef K1 // Defined in Configuration.h in the PID settings
58
   #define K2 (1.0-K1)
38
   #define K2 (1.0-K1)
59
 #endif
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
 #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
41
 #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
192
   static void* heater_ttbl_map[2] = {(void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE };
42
   static void* heater_ttbl_map[2] = {(void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE };
193
   static uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN };
43
   static uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN };
196
   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);
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
 #endif
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
 #if HAS_PID_HEATING
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
     float input = 0.0;
54
     float input = 0.0;
233
     int cycles = 0;
55
     int cycles = 0;
234
     bool heating = true;
56
     bool heating = true;
242
     float max = 0, min = 10000;
64
     float max = 0, min = 10000;
243
 
65
 
244
     #if HAS_AUTO_FAN
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
     #endif
68
     #endif
247
 
69
 
248
     if (false
70
     if (false
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
   #if ENABLED(PIDTEMP)
315
   #if ENABLED(PIDTEMP)
466
     for (int e = 0; e < EXTRUDERS; e++) {
316
     for (int e = 0; e < EXTRUDERS; e++) {
467
       temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e);
317
       temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e);
475
   #endif
325
   #endif
476
 }
326
 }
477
 
327
 
478
-int getHeaterPower(int heater) {
328
+int Temperature::getHeaterPower(int heater) {
479
   return heater < 0 ? soft_pwm_bed : soft_pwm[heater];
329
   return heater < 0 ? soft_pwm_bed : soft_pwm[heater];
480
 }
330
 }
481
 
331
 
482
 #if HAS_AUTO_FAN
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
 #endif // HAS_AUTO_FAN
357
 #endif // HAS_AUTO_FAN
552
 
358
 
553
 //
359
 //
554
 // Temperature Error Handlers
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
   static bool killed = false;
363
   static bool killed = false;
558
   if (IsRunning()) {
364
   if (IsRunning()) {
559
     SERIAL_ERROR_START;
365
     SERIAL_ERROR_START;
572
   #endif
378
   #endif
573
 }
379
 }
574
 
380
 
575
-void max_temp_error(uint8_t e) {
381
+void Temperature::max_temp_error(uint8_t e) {
576
   _temp_error(e, PSTR(MSG_T_MAXTEMP), PSTR(MSG_ERR_MAXTEMP));
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
   _temp_error(e, PSTR(MSG_T_MINTEMP), PSTR(MSG_ERR_MINTEMP));
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
   float pid_output;
389
   float pid_output;
584
   #if ENABLED(PIDTEMP)
390
   #if ENABLED(PIDTEMP)
585
     #if DISABLED(PID_OPENLOOP)
391
     #if DISABLED(PID_OPENLOOP)
658
 }
464
 }
659
 
465
 
660
 #if ENABLED(PIDTEMPBED)
466
 #if ENABLED(PIDTEMPBED)
661
-  float get_pid_output_bed() {
467
+  float Temperature::get_pid_output_bed() {
662
     float pid_output;
468
     float pid_output;
663
     #if DISABLED(PID_OPENLOOP)
469
     #if DISABLED(PID_OPENLOOP)
664
       pid_error_bed = target_temperature_bed - current_temperature_bed;
470
       pid_error_bed = target_temperature_bed - current_temperature_bed;
710
  *  - Apply filament width to the extrusion rate (may move)
516
  *  - Apply filament width to the extrusion rate (may move)
711
  *  - Update the heated bed PID output value
517
  *  - Update the heated bed PID output value
712
  */
518
  */
713
-void manage_heater() {
519
+void Temperature::manage_heater() {
714
 
520
 
715
   if (!temp_meas_ready) return;
521
   if (!temp_meas_ready) return;
716
 
522
 
811
 
617
 
812
   #if TEMP_SENSOR_BED != 0
618
   #if TEMP_SENSOR_BED != 0
813
 
619
 
814
-    #if ENABLED(THERMAL_PROTECTION_BED)
620
+    #if HAS_THERMALLY_PROTECTED_BED
815
       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);
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
     #endif
622
     #endif
817
 
623
 
846
 }
652
 }
847
 
653
 
848
 #define PGM_RD_W(x)   (short)pgm_read_word(&x)
654
 #define PGM_RD_W(x)   (short)pgm_read_word(&x)
655
+
849
 // Derived from RepRap FiveD extruder::getTemperature()
656
 // Derived from RepRap FiveD extruder::getTemperature()
850
 // For hot end temperature measurement.
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
   #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
659
   #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
853
     if (e > EXTRUDERS)
660
     if (e > EXTRUDERS)
854
   #else
661
   #else
891
 
698
 
892
 // Derived from RepRap FiveD extruder::getTemperature()
699
 // Derived from RepRap FiveD extruder::getTemperature()
893
 // For bed temperature measurement.
700
 // For bed temperature measurement.
894
-static float analog2tempBed(int raw) {
701
+float Temperature::analog2tempBed(int raw) {
895
   #if ENABLED(BED_USES_THERMISTOR)
702
   #if ENABLED(BED_USES_THERMISTOR)
896
     float celsius = 0;
703
     float celsius = 0;
897
     byte i;
704
     byte i;
923
   #endif
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
   #if ENABLED(HEATER_0_USES_MAX6675)
740
   #if ENABLED(HEATER_0_USES_MAX6675)
930
     current_temperature_raw[0] = read_max6675();
741
     current_temperature_raw[0] = read_max6675();
931
   #endif
742
   #endif
932
   for (uint8_t e = 0; e < EXTRUDERS; e++) {
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
   #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
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
   #endif
749
   #endif
939
   #if ENABLED(FILAMENT_WIDTH_SENSOR)
750
   #if ENABLED(FILAMENT_WIDTH_SENSOR)
940
     filament_width_meas = analog2widthFil();
751
     filament_width_meas = analog2widthFil();
954
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
765
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
955
 
766
 
956
   // Convert raw Filament Width to millimeters
767
   // Convert raw Filament Width to millimeters
957
-  float analog2widthFil() {
768
+  float Temperature::analog2widthFil() {
958
     return current_raw_filwidth / 16383.0 * 5.0;
769
     return current_raw_filwidth / 16383.0 * 5.0;
959
     //return current_raw_filwidth;
770
     //return current_raw_filwidth;
960
   }
771
   }
961
 
772
 
962
   // Convert raw Filament Width to a ratio
773
   // Convert raw Filament Width to a ratio
963
-  int widthFil_to_size_ratio() {
774
+  int Temperature::widthFil_to_size_ratio() {
964
     float temp = filament_width_meas;
775
     float temp = filament_width_meas;
965
     if (temp < MEASURED_LOWER_LIMIT) temp = filament_width_nominal;  //assume sensor cut out
776
     if (temp < MEASURED_LOWER_LIMIT) temp = filament_width_nominal;  //assume sensor cut out
966
     else NOMORE(temp, MEASURED_UPPER_LIMIT);
777
     else NOMORE(temp, MEASURED_UPPER_LIMIT);
974
  * Initialize the temperature manager
785
  * Initialize the temperature manager
975
  * The manager is implemented by periodic calls to manage_heater()
786
  * The manager is implemented by periodic calls to manage_heater()
976
  */
787
  */
977
-void tp_init() {
788
+void Temperature::init() {
789
+
978
   #if MB(RUMBA) && ((TEMP_SENSOR_0==-1)||(TEMP_SENSOR_1==-1)||(TEMP_SENSOR_2==-1)||(TEMP_SENSOR_BED==-1))
790
   #if MB(RUMBA) && ((TEMP_SENSOR_0==-1)||(TEMP_SENSOR_1==-1)||(TEMP_SENSOR_2==-1)||(TEMP_SENSOR_BED==-1))
979
     //disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector
791
     //disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector
980
     MCUCR = _BV(JTD);
792
     MCUCR = _BV(JTD);
1189
    * their target temperature by a configurable margin.
1001
    * their target temperature by a configurable margin.
1190
    * This is called when the temperature is set. (M104, M109)
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
     if (degHotend(e) < degTargetHotend(e) - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1)) {
1005
     if (degHotend(e) < degTargetHotend(e) - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1)) {
1194
       watch_target_temp[e] = degHotend(e) + WATCH_TEMP_INCREASE;
1006
       watch_target_temp[e] = degHotend(e) + WATCH_TEMP_INCREASE;
1195
       watch_heater_next_ms[e] = millis() + (WATCH_TEMP_PERIOD) * 1000UL;
1007
       watch_heater_next_ms[e] = millis() + (WATCH_TEMP_PERIOD) * 1000UL;
1205
    * their target temperature by a configurable margin.
1017
    * their target temperature by a configurable margin.
1206
    * This is called when the temperature is set. (M140, M190)
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
     if (degBed() < degTargetBed() - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1)) {
1021
     if (degBed() < degTargetBed() - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1)) {
1210
       watch_target_bed_temp = degBed() + WATCH_BED_TEMP_INCREASE;
1022
       watch_target_bed_temp = degBed() + WATCH_BED_TEMP_INCREASE;
1211
       watch_bed_next_ms = millis() + (WATCH_BED_TEMP_PERIOD) * 1000UL;
1023
       watch_bed_next_ms = millis() + (WATCH_BED_TEMP_PERIOD) * 1000UL;
1215
   }
1027
   }
1216
 #endif
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
     static float tr_target_temperature[EXTRUDERS + 1] = { 0.0 };
1034
     static float tr_target_temperature[EXTRUDERS + 1] = { 0.0 };
1223
 
1035
 
1273
 
1085
 
1274
 #endif // THERMAL_PROTECTION_HOTENDS || THERMAL_PROTECTION_BED
1086
 #endif // THERMAL_PROTECTION_HOTENDS || THERMAL_PROTECTION_BED
1275
 
1087
 
1276
-void disable_all_heaters() {
1088
+void Temperature::disable_all_heaters() {
1277
   for (int i = 0; i < EXTRUDERS; i++) setTargetHotend(0, i);
1089
   for (int i = 0; i < EXTRUDERS; i++) setTargetHotend(0, i);
1278
   setTargetBed(0);
1090
   setTargetBed(0);
1279
 
1091
 
1327
     #define MAX6675_DISCARD_BITS 3
1139
     #define MAX6675_DISCARD_BITS 3
1328
   #endif
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
     millis_t ms = millis();
1146
     millis_t ms = millis();
1335
 
1147
 
1392
   StartupDelay // Startup, delay initial temp reading a tiny bit so the hardware can settle
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
   #if HAS_TEMP_0 && DISABLED(HEATER_0_USES_MAX6675)
1211
   #if HAS_TEMP_0 && DISABLED(HEATER_0_USES_MAX6675)
1400
     current_temperature_raw[0] = raw_temp_value[0];
1212
     current_temperature_raw[0] = raw_temp_value[0];
1401
   #endif
1213
   #endif
1423
  *  - Check new temperature values for MIN/MAX errors
1235
  *  - Check new temperature values for MIN/MAX errors
1424
  *  - Step the babysteps value for each axis towards 0
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
   static unsigned char temp_count = 0;
1242
   static unsigned char temp_count = 0;
1429
   static TempState temp_state = StartupDelay;
1243
   static TempState temp_state = StartupDelay;
1845
     }
1659
     }
1846
   #endif //BABYSTEPPING
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 Voir le fichier

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
 #ifndef TEMPERATURE_H
27
 #ifndef TEMPERATURE_H
44
 #define TEMPERATURE_H
28
 #define TEMPERATURE_H
45
 
29
 
46
 #include "Marlin.h"
30
 #include "Marlin.h"
47
 #include "planner.h"
31
 #include "planner.h"
32
+
48
 #if ENABLED(PID_ADD_EXTRUSION_RATE)
33
 #if ENABLED(PID_ADD_EXTRUSION_RATE)
49
   #include "stepper.h"
34
   #include "stepper.h"
50
 #endif
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
     #endif
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
     #endif
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
 #endif // TEMPERATURE_H
351
 #endif // TEMPERATURE_H

+ 39
- 31
Marlin/ultralcd.cpp Voir le fichier

479
     stepper.quick_stop();
479
     stepper.quick_stop();
480
     card.sdprinting = false;
480
     card.sdprinting = false;
481
     card.closefile();
481
     card.closefile();
482
-    autotempShutdown();
482
+    thermalManager.autotempShutdown();
483
     cancel_heatup = true;
483
     cancel_heatup = true;
484
     lcd_setstatus(MSG_PRINT_ABORTED, true);
484
     lcd_setstatus(MSG_PRINT_ABORTED, true);
485
   }
485
   }
605
  */
605
  */
606
 #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
606
 #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
607
   #if TEMP_SENSOR_0 != 0
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
   #endif
609
   #endif
610
   #if EXTRUDERS > 1 && TEMP_SENSOR_1 != 0
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
   #endif // EXTRUDERS > 1
612
   #endif // EXTRUDERS > 1
613
   #if EXTRUDERS > 2 && TEMP_SENSOR_2 != 0
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
   #endif // EXTRUDERS > 2
615
   #endif // EXTRUDERS > 2
616
   #if EXTRUDERS > 3 && TEMP_SENSOR_3 != 0
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
   #endif // EXTRUDERS > 3
618
   #endif // EXTRUDERS > 3
619
 #else
619
 #else
620
   #if TEMP_SENSOR_0 != 0
620
   #if TEMP_SENSOR_0 != 0
633
 
633
 
634
 #if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
634
 #if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
635
   #if TEMP_SENSOR_BED != 0
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
   #endif
637
   #endif
638
 #else
638
 #else
639
   #if TEMP_SENSOR_BED != 0
639
   #if TEMP_SENSOR_BED != 0
670
   //
670
   //
671
   #if EXTRUDERS == 1
671
   #if EXTRUDERS == 1
672
     #if TEMP_SENSOR_0 != 0
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
     #endif
674
     #endif
675
   #else //EXTRUDERS > 1
675
   #else //EXTRUDERS > 1
676
     #if TEMP_SENSOR_0 != 0
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
     #endif
678
     #endif
679
     #if TEMP_SENSOR_1 != 0
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
     #endif
681
     #endif
682
     #if EXTRUDERS > 2
682
     #if EXTRUDERS > 2
683
       #if TEMP_SENSOR_2 != 0
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
       #endif
685
       #endif
686
       #if EXTRUDERS > 3
686
       #if EXTRUDERS > 3
687
         #if TEMP_SENSOR_3 != 0
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
         #endif
689
         #endif
690
       #endif // EXTRUDERS > 3
690
       #endif // EXTRUDERS > 3
691
     #endif // EXTRUDERS > 2
691
     #endif // EXTRUDERS > 2
695
   // Bed:
695
   // Bed:
696
   //
696
   //
697
   #if TEMP_SENSOR_BED != 0
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
   #endif
699
   #endif
700
 
700
 
701
   //
701
   //
768
  *
768
  *
769
  */
769
  */
770
 void _lcd_preheat(int endnum, const float temph, const float tempb, const int fan) {
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
   #if TEMP_SENSOR_BED != 0
772
   #if TEMP_SENSOR_BED != 0
773
-    setTargetBed(tempb);
773
+    thermalManager.setTargetBed(tempb);
774
   #else
774
   #else
775
     UNUSED(tempb);
775
     UNUSED(tempb);
776
   #endif
776
   #endif
805
 
805
 
806
   void lcd_preheat_pla0123() {
806
   void lcd_preheat_pla0123() {
807
     #if EXTRUDERS > 1
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
     #endif
815
     #endif
812
-    _lcd_preheat(EXTRUDERS - 1, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed);
816
+    lcd_preheat_pla0();
813
   }
817
   }
814
   void lcd_preheat_abs0123() {
818
   void lcd_preheat_abs0123() {
815
     #if EXTRUDERS > 1
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
     #endif
827
     #endif
820
-    _lcd_preheat(EXTRUDERS - 1, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed);
828
+    lcd_preheat_abs0();
821
   }
829
   }
822
 
830
 
823
 #endif // EXTRUDERS > 1
831
 #endif // EXTRUDERS > 1
879
   #if FAN_COUNT > 0
887
   #if FAN_COUNT > 0
880
     for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
888
     for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
881
   #endif
889
   #endif
882
-  disable_all_heaters();
890
+  thermalManager.disable_all_heaters();
883
   lcd_return_to_status();
891
   lcd_return_to_status();
884
 }
892
 }
885
 
893
 
1414
       UNUSED(e);
1422
       UNUSED(e);
1415
     #endif
1423
     #endif
1416
     PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
1424
     PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
1417
-    updatePID();
1425
+    thermalManager.updatePID();
1418
   }
1426
   }
1419
   void copy_and_scalePID_d(int e) {
1427
   void copy_and_scalePID_d(int e) {
1420
     #if DISABLED(PID_PARAMS_PER_EXTRUDER)
1428
     #if DISABLED(PID_PARAMS_PER_EXTRUDER)
1421
       UNUSED(e);
1429
       UNUSED(e);
1422
     #endif
1430
     #endif
1423
     PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
1431
     PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
1424
-    updatePID();
1432
+    thermalManager.updatePID();
1425
   }
1433
   }
1426
   #define _PIDTEMP_BASE_FUNCTIONS(eindex) \
1434
   #define _PIDTEMP_BASE_FUNCTIONS(eindex) \
1427
     void copy_and_scalePID_i_E ## eindex() { copy_and_scalePID_i(eindex); } \
1435
     void copy_and_scalePID_i_E ## eindex() { copy_and_scalePID_i(eindex); } \
1469
   //
1477
   //
1470
   #if EXTRUDERS == 1
1478
   #if EXTRUDERS == 1
1471
     #if TEMP_SENSOR_0 != 0
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
     #endif
1481
     #endif
1474
   #else //EXTRUDERS > 1
1482
   #else //EXTRUDERS > 1
1475
     #if TEMP_SENSOR_0 != 0
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
     #endif
1485
     #endif
1478
     #if TEMP_SENSOR_1 != 0
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
     #endif
1488
     #endif
1481
     #if EXTRUDERS > 2
1489
     #if EXTRUDERS > 2
1482
       #if TEMP_SENSOR_2 != 0
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
       #endif
1492
       #endif
1485
       #if EXTRUDERS > 3
1493
       #if EXTRUDERS > 3
1486
         #if TEMP_SENSOR_3 != 0
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
         #endif
1496
         #endif
1489
       #endif // EXTRUDERS > 3
1497
       #endif // EXTRUDERS > 3
1490
     #endif // EXTRUDERS > 2
1498
     #endif // EXTRUDERS > 2
1494
   // Bed:
1502
   // Bed:
1495
   //
1503
   //
1496
   #if TEMP_SENSOR_BED != 0
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
   #endif
1506
   #endif
1499
 
1507
 
1500
   //
1508
   //

+ 10
- 10
Marlin/ultralcd_implementation_hitachi_HD44780.h Voir le fichier

633
     //
633
     //
634
     // Hotend 0 Temperature
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
     // Hotend 1 or Bed Temperature
639
     // Hotend 1 or Bed Temperature
643
       lcd.setCursor(8, 0);
643
       lcd.setCursor(8, 0);
644
       #if EXTRUDERS > 1
644
       #if EXTRUDERS > 1
645
         lcd.print(LCD_STR_THERMOMETER[0]);
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
       #else
647
       #else
648
         lcd.print(LCD_STR_BEDTEMP[0]);
648
         lcd.print(LCD_STR_BEDTEMP[0]);
649
-        LCD_TEMP_ONLY(degBed(), degTargetBed());
649
+        LCD_TEMP_ONLY(thermalManager.degBed(), thermalManager.degTargetBed());
650
       #endif
650
       #endif
651
 
651
 
652
     #endif // EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
652
     #endif // EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
656
     //
656
     //
657
     // Hotend 0 Temperature
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
     // Hotend 1 or Bed Temperature
662
     // Hotend 1 or Bed Temperature
664
     #if EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
664
     #if EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
665
       lcd.setCursor(10, 0);
665
       lcd.setCursor(10, 0);
666
       #if EXTRUDERS > 1
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
       #else
668
       #else
669
-        LCD_TEMP(degBed(), degTargetBed(), LCD_STR_BEDTEMP[0]);
669
+        LCD_TEMP(thermalManager.degBed(), thermalManager.degTargetBed(), LCD_STR_BEDTEMP[0]);
670
       #endif
670
       #endif
671
 
671
 
672
     #endif  // EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
672
     #endif  // EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
702
         // If we both have a 2nd extruder and a heated bed,
702
         // If we both have a 2nd extruder and a heated bed,
703
         // show the heated bed temp on the left,
703
         // show the heated bed temp on the left,
704
         // since the first line is filled with extruder temps
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
       #else
707
       #else
708
         // Before homing the axis letters are blinking 'X' <-> '?'.
708
         // Before homing the axis letters are blinking 'X' <-> '?'.
925
     static uint8_t ledsprev = 0;
925
     static uint8_t ledsprev = 0;
926
     uint8_t leds = 0;
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
     #if FAN_COUNT > 0
932
     #if FAN_COUNT > 0
933
       if (0
933
       if (0
944
     #endif // FAN_COUNT > 0
944
     #endif // FAN_COUNT > 0
945
 
945
 
946
     #if EXTRUDERS > 1
946
     #if EXTRUDERS > 1
947
-      if (target_temperature[1] > 0) leds |= LED_C;
947
+      if (thermalManager.degTargetHotend(1) > 0) leds |= LED_C;
948
     #endif
948
     #endif
949
 
949
 
950
     if (leds != ledsprev) {
950
     if (leds != ledsprev) {

Chargement…
Annuler
Enregistrer