Browse Source

Macros to the top, a few HAS_* macros

Scott Lahteine 10 years ago
parent
commit
864dddc878
1 changed files with 97 additions and 92 deletions
  1. 97
    92
      Marlin/temperature.cpp

+ 97
- 92
Marlin/temperature.cpp View File

37
 
37
 
38
 #include "Sd2PinMap.h"
38
 #include "Sd2PinMap.h"
39
 
39
 
40
+//===========================================================================
41
+//================================== macros =================================
42
+//===========================================================================
43
+
44
+#if EXTRUDERS > 4
45
+  #error Unsupported number of extruders
46
+#elif EXTRUDERS > 3
47
+  #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2, v3, v4 }
48
+#elif EXTRUDERS > 2
49
+  #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2, v3 }
50
+#elif EXTRUDERS > 1
51
+  #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2 }
52
+#else
53
+  #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1 }
54
+#endif
55
+
56
+#define PIN_EXISTS(PIN) (defined(PIN) && PIN >= 0)
57
+#define HAS_TEMP_0 PIN_EXISTS(TEMP_0_PIN)
58
+#define HAS_TEMP_1 PIN_EXISTS(TEMP_1_PIN)
59
+#define HAS_TEMP_2 PIN_EXISTS(TEMP_2_PIN)
60
+#define HAS_TEMP_3 PIN_EXISTS(TEMP_3_PIN)
61
+#define HAS_TEMP_BED PIN_EXISTS(TEMP_BED_PIN)
62
+#define HAS_FILAMENT_SENSOR (defined(FILAMENT_SENSOR) && PIN_EXISTS(FILWIDTH_PIN))
63
+#define HAS_HEATER_0 PIN_EXISTS(HEATER_0_PIN)
64
+#define HAS_HEATER_1 PIN_EXISTS(HEATER_1_PIN)
65
+#define HAS_HEATER_2 PIN_EXISTS(HEATER_2_PIN)
66
+#define HAS_HEATER_3 PIN_EXISTS(HEATER_3_PIN)
67
+#define HAS_HEATER_BED PIN_EXISTS(HEATER_BED_PIN)
68
+#define HAS_AUTO_FAN  PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \
69
+                      PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
40
 
70
 
41
 //===========================================================================
71
 //===========================================================================
42
 //============================= public variables ============================
72
 //============================= public variables ============================
117
 #ifdef FAN_SOFT_PWM
147
 #ifdef FAN_SOFT_PWM
118
   static unsigned char soft_pwm_fan;
148
   static unsigned char soft_pwm_fan;
119
 #endif
149
 #endif
120
-#if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \
121
-    (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
122
-    (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1)
150
+#if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \
151
+    PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
123
   static unsigned long extruder_autofan_last_check;
152
   static unsigned long extruder_autofan_last_check;
124
 #endif  
153
 #endif  
125
 
154
 
126
-#if EXTRUDERS > 4
127
-  #error Unsupported number of extruders
128
-#elif EXTRUDERS > 3
129
-  #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2, v3, v4 }
130
-#elif EXTRUDERS > 2
131
-  #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2, v3 }
132
-#elif EXTRUDERS > 1
133
-  #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2 }
134
-#else
135
-  #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1 }
136
-#endif
137
-
138
 #ifdef PIDTEMP
155
 #ifdef PIDTEMP
139
   #ifdef PID_PARAMS_PER_EXTRUDER
156
   #ifdef PID_PARAMS_PER_EXTRUDER
140
     float Kp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kp, DEFAULT_Kp, DEFAULT_Kp, DEFAULT_Kp);
157
     float Kp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kp, DEFAULT_Kp, DEFAULT_Kp, DEFAULT_Kp);
192
   static int read_max6675();
209
   static int read_max6675();
193
 #endif
210
 #endif
194
 
211
 
195
-#define HAS_TEMP_0 (defined(TEMP_0_PIN) && TEMP_0_PIN > -1)
196
-#define HAS_TEMP_1 (defined(TEMP_1_PIN) && TEMP_1_PIN > -1)
197
-#define HAS_TEMP_2 (defined(TEMP_2_PIN) && TEMP_2_PIN > -1)
198
-#define HAS_TEMP_3 (defined(TEMP_3_PIN) && TEMP_3_PIN > -1)
199
-#define HAS_TEMP_BED (defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1)
200
-#define HAS_FILAMENT_SENSOR (defined(FILAMENT_SENSOR) && defined(FILWIDTH_PIN) && FILWIDTH_PIN > -1)
201
-
202
 //===========================================================================
212
 //===========================================================================
203
 //=============================   functions      ============================
213
 //=============================   functions      ============================
204
 //===========================================================================
214
 //===========================================================================
217
   float Kp, Ki, Kd;
227
   float Kp, Ki, Kd;
218
   float max = 0, min = 10000;
228
   float max = 0, min = 10000;
219
 
229
 
220
-  #if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \
221
-      (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
222
-      (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) || \
223
-      (defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1)
230
+  #if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \
231
+      PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
224
         unsigned long extruder_autofan_last_check = temp_millis;
232
         unsigned long extruder_autofan_last_check = temp_millis;
225
   #endif
233
   #endif
226
 
234
 
255
       max = max(max, input);
263
       max = max(max, input);
256
       min = min(min, input);
264
       min = min(min, input);
257
 
265
 
258
-      #if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \
259
-          (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
260
-          (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) || \
261
-          (defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1)
266
+      #if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \
267
+          PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
262
         if (ms > extruder_autofan_last_check + 2500) {
268
         if (ms > extruder_autofan_last_check + 2500) {
263
           checkExtruderAutoFans();
269
           checkExtruderAutoFans();
264
           extruder_autofan_last_check = ms;
270
           extruder_autofan_last_check = ms;
336
       return;
342
       return;
337
     }
343
     }
338
     // Every 2 seconds...
344
     // Every 2 seconds...
339
-    if (ms - temp_millis > 2000) {
345
+    if (ms > temp_millis + 2000) {
340
       int p;
346
       int p;
341
       if (extruder < 0) {
347
       if (extruder < 0) {
342
         p = soft_pwm_bed;
348
         p = soft_pwm_bed;
381
   return heater < 0 ? soft_pwm_bed : soft_pwm[heater];
387
   return heater < 0 ? soft_pwm_bed : soft_pwm[heater];
382
 }
388
 }
383
 
389
 
384
-#if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \
385
-    (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
386
-    (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1)
390
+#if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \
391
+    PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN)
387
 
392
 
388
-  #if defined(FAN_PIN) && FAN_PIN > -1
393
+  #if PIN_EXISTS(FAN_PIN)
389
     #if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN 
394
     #if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN 
390
        #error "You cannot set EXTRUDER_0_AUTO_FAN_PIN equal to FAN_PIN"
395
        #error "You cannot set EXTRUDER_0_AUTO_FAN_PIN equal to FAN_PIN"
391
     #endif
396
     #endif
411
   uint8_t fanState = 0;
416
   uint8_t fanState = 0;
412
 
417
 
413
   // which fan pins need to be turned on?      
418
   // which fan pins need to be turned on?      
414
-  #if defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1
419
+  #if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN)
415
     if (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE) 
420
     if (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE) 
416
       fanState |= 1;
421
       fanState |= 1;
417
   #endif
422
   #endif
418
-  #if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1
423
+  #if PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN)
419
     if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) 
424
     if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) 
420
     {
425
     {
421
       if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) 
426
       if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) 
424
         fanState |= 2;
429
         fanState |= 2;
425
     }
430
     }
426
   #endif
431
   #endif
427
-  #if defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1
432
+  #if PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN)
428
     if (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE) 
433
     if (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE) 
429
     {
434
     {
430
       if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) 
435
       if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) 
435
         fanState |= 4;
440
         fanState |= 4;
436
     }
441
     }
437
   #endif
442
   #endif
438
-  #if defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1
443
+  #if PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
439
     if (current_temperature[3] > EXTRUDER_AUTO_FAN_TEMPERATURE) 
444
     if (current_temperature[3] > EXTRUDER_AUTO_FAN_TEMPERATURE) 
440
     {
445
     {
441
       if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) 
446
       if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) 
450
   #endif
455
   #endif
451
   
456
   
452
   // update extruder auto fan states
457
   // update extruder auto fan states
453
-  #if defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1
458
+  #if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN)
454
     setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, (fanState & 1) != 0);
459
     setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, (fanState & 1) != 0);
455
   #endif 
460
   #endif 
456
-  #if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1
461
+  #if PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN)
457
     if (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN)
462
     if (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN)
458
       setExtruderAutoFanState(EXTRUDER_1_AUTO_FAN_PIN, (fanState & 2) != 0);
463
       setExtruderAutoFanState(EXTRUDER_1_AUTO_FAN_PIN, (fanState & 2) != 0);
459
   #endif 
464
   #endif 
460
-  #if defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1
465
+  #if PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN)
461
     if (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN
466
     if (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN
462
         && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN)
467
         && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN)
463
       setExtruderAutoFanState(EXTRUDER_2_AUTO_FAN_PIN, (fanState & 4) != 0);
468
       setExtruderAutoFanState(EXTRUDER_2_AUTO_FAN_PIN, (fanState & 4) != 0);
464
   #endif
469
   #endif
465
-  #if defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1
470
+  #if PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
466
     if (EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN
471
     if (EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN
467
         && EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN
472
         && EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN
468
         && EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_2_AUTO_FAN_PIN)
473
         && EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_2_AUTO_FAN_PIN)
475
 //
480
 //
476
 // Error checking and Write Routines
481
 // Error checking and Write Routines
477
 //
482
 //
478
-#if !defined(HEATER_0_PIN) || HEATER_0_PIN < 0
483
+#if !HAS_HEATER_0
479
   #error HEATER_0_PIN not defined for this board
484
   #error HEATER_0_PIN not defined for this board
480
 #endif
485
 #endif
481
 #define WRITE_HEATER_0P(v) WRITE(HEATER_0_PIN, v)
486
 #define WRITE_HEATER_0P(v) WRITE(HEATER_0_PIN, v)
482
 #if EXTRUDERS > 1 || defined(HEATERS_PARALLEL)
487
 #if EXTRUDERS > 1 || defined(HEATERS_PARALLEL)
483
-  #if !defined(HEATER_1_PIN) || HEATER_1_PIN < 0
488
+  #if !HAS_HEATER_1
484
     #error HEATER_1_PIN not defined for this board
489
     #error HEATER_1_PIN not defined for this board
485
   #endif
490
   #endif
486
   #define WRITE_HEATER_1(v) WRITE(HEATER_1_PIN, v)
491
   #define WRITE_HEATER_1(v) WRITE(HEATER_1_PIN, v)
487
   #if EXTRUDERS > 2
492
   #if EXTRUDERS > 2
488
-    #if !defined(HEATER_2_PIN) || HEATER_2_PIN < 0
493
+    #if !HAS_HEATER_2
489
       #error HEATER_2_PIN not defined for this board
494
       #error HEATER_2_PIN not defined for this board
490
     #endif
495
     #endif
491
     #define WRITE_HEATER_2(v) WRITE(HEATER_2_PIN, v)
496
     #define WRITE_HEATER_2(v) WRITE(HEATER_2_PIN, v)
492
     #if EXTRUDERS > 3
497
     #if EXTRUDERS > 3
493
-      #if !defined(HEATER_3_PIN) || HEATER_3_PIN < 0
498
+      #if !HAS_HEATER_3
494
         #error HEATER_3_PIN not defined for this board
499
         #error HEATER_3_PIN not defined for this board
495
       #endif
500
       #endif
496
       #define WRITE_HEATER_3(v) WRITE(HEATER_3_PIN, v)
501
       #define WRITE_HEATER_3(v) WRITE(HEATER_3_PIN, v)
502
 #else
507
 #else
503
   #define WRITE_HEATER_0(v) WRITE_HEATER_0P(v)
508
   #define WRITE_HEATER_0(v) WRITE_HEATER_0P(v)
504
 #endif
509
 #endif
505
-#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
510
+#if HAS_HEATER_BED
506
   #define WRITE_HEATER_BED(v) WRITE(HEATER_BED_PIN, v)
511
   #define WRITE_HEATER_BED(v) WRITE(HEATER_BED_PIN, v)
507
 #endif
512
 #endif
508
 
513
 
626
 
631
 
627
   } // Extruders Loop
632
   } // Extruders Loop
628
 
633
 
629
-  #if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \
630
-      (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
631
-      (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1)
634
+  #if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \
635
+      PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
632
     if (ms > extruder_autofan_last_check + 2500) { // only need to check fan state very infrequently
636
     if (ms > extruder_autofan_last_check + 2500) { // only need to check fan state very infrequently
633
       checkExtruderAutoFans();
637
       checkExtruderAutoFans();
634
       extruder_autofan_last_check = ms;
638
       extruder_autofan_last_check = ms;
680
     #elif !defined(BED_LIMIT_SWITCHING)
684
     #elif !defined(BED_LIMIT_SWITCHING)
681
       // Check if temperature is within the correct range
685
       // Check if temperature is within the correct range
682
       if (current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP) {
686
       if (current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP) {
683
-        soft_pwm_bed = current_temperature_bed >= target_temperature_bed ? 0 : MAX_BED_POWER >> 1;
687
+        soft_pwm_bed = current_temperature_bed < target_temperature_bed ? MAX_BED_POWER >> 1 : 0;
684
       }
688
       }
685
       else {
689
       else {
686
         soft_pwm_bed = 0;
690
         soft_pwm_bed = 0;
707
       meas_shift_index = delay_index1 - meas_delay_cm;
711
       meas_shift_index = delay_index1 - meas_delay_cm;
708
 		  if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
712
 		  if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
709
 		  
713
 		  
710
-		  // Get the delayed info and add 100 to reconstitute to a percent of
714
+      // Get the delayed info and add 100 to reconstitute to a percent of
711
       // the nominal filament diameter then square it to get an area
715
       // the nominal filament diameter then square it to get an area
712
-		  meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY);
716
+      meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY);
713
       float vm = pow((measurement_delay[meas_shift_index] + 100.0) / 100.0, 2);
717
       float vm = pow((measurement_delay[meas_shift_index] + 100.0) / 100.0, 2);
714
       if (vm < 0.01) vm = 0.01;
718
       if (vm < 0.01) vm = 0.01;
715
       volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vm;
719
       volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vm;
722
 // For hot end temperature measurement.
726
 // For hot end temperature measurement.
723
 static float analog2temp(int raw, uint8_t e) {
727
 static float analog2temp(int raw, uint8_t e) {
724
 #ifdef TEMP_SENSOR_1_AS_REDUNDANT
728
 #ifdef TEMP_SENSOR_1_AS_REDUNDANT
725
-  if(e > EXTRUDERS)
729
+  if (e > EXTRUDERS)
726
 #else
730
 #else
727
-  if(e >= EXTRUDERS)
731
+  if (e >= EXTRUDERS)
728
 #endif
732
 #endif
729
   {
733
   {
730
       SERIAL_ERROR_START;
734
       SERIAL_ERROR_START;
798
 
802
 
799
 /* Called to get the raw values into the the actual temperatures. The raw values are created in interrupt context,
803
 /* Called to get the raw values into the the actual temperatures. The raw values are created in interrupt context,
800
     and this function is called from normal context as it is too slow to run in interrupts and will block the stepper routine otherwise */
804
     and this function is called from normal context as it is too slow to run in interrupts and will block the stepper routine otherwise */
801
-static void updateTemperaturesFromRawValues()
802
-{
803
-    #ifdef HEATER_0_USES_MAX6675
804
-        current_temperature_raw[0] = read_max6675();
805
-    #endif
806
-    for(uint8_t e=0;e<EXTRUDERS;e++)
807
-    {
808
-        current_temperature[e] = analog2temp(current_temperature_raw[e], e);
809
-    }
810
-    current_temperature_bed = analog2tempBed(current_temperature_bed_raw);
811
-    #ifdef TEMP_SENSOR_1_AS_REDUNDANT
812
-      redundant_temperature = analog2temp(redundant_temperature_raw, 1);
813
-    #endif
814
-    #if HAS_FILAMENT_SENSOR
815
-      filament_width_meas = analog2widthFil();
816
-    #endif  
817
-    //Reset the watchdog after we know we have a temperature measurement.
818
-    watchdog_reset();
819
-
820
-    CRITICAL_SECTION_START;
821
-    temp_meas_ready = false;
822
-    CRITICAL_SECTION_END;
805
+static void updateTemperaturesFromRawValues() {
806
+  #ifdef HEATER_0_USES_MAX6675
807
+    current_temperature_raw[0] = read_max6675();
808
+  #endif
809
+  for(uint8_t e = 0; e < EXTRUDERS; e++) {
810
+    current_temperature[e] = analog2temp(current_temperature_raw[e], e);
811
+  }
812
+  current_temperature_bed = analog2tempBed(current_temperature_bed_raw);
813
+  #ifdef TEMP_SENSOR_1_AS_REDUNDANT
814
+    redundant_temperature = analog2temp(redundant_temperature_raw, 1);
815
+  #endif
816
+  #if HAS_FILAMENT_SENSOR
817
+    filament_width_meas = analog2widthFil();
818
+  #endif
819
+  //Reset the watchdog after we know we have a temperature measurement.
820
+  watchdog_reset();
821
+
822
+  CRITICAL_SECTION_START;
823
+  temp_meas_ready = false;
824
+  CRITICAL_SECTION_END;
823
 }
825
 }
824
 
826
 
825
 
827
 
867
     #endif //PIDTEMPBED
869
     #endif //PIDTEMPBED
868
   }
870
   }
869
 
871
 
870
-  #if defined(HEATER_0_PIN) && (HEATER_0_PIN > -1)
872
+  #if HAS_HEATER_0
871
     SET_OUTPUT(HEATER_0_PIN);
873
     SET_OUTPUT(HEATER_0_PIN);
872
   #endif
874
   #endif
873
-  #if defined(HEATER_1_PIN) && (HEATER_1_PIN > -1)
875
+  #if HAS_HEATER_1
874
     SET_OUTPUT(HEATER_1_PIN);
876
     SET_OUTPUT(HEATER_1_PIN);
875
   #endif
877
   #endif
876
-  #if defined(HEATER_2_PIN) && (HEATER_2_PIN > -1)
878
+  #if HAS_HEATER_2
877
     SET_OUTPUT(HEATER_2_PIN);
879
     SET_OUTPUT(HEATER_2_PIN);
878
   #endif
880
   #endif
879
-  #if defined(HEATER_3_PIN) && (HEATER_3_PIN > -1)
881
+  #if HAS_HEATER_3
880
     SET_OUTPUT(HEATER_3_PIN);
882
     SET_OUTPUT(HEATER_3_PIN);
881
   #endif
883
   #endif
882
-  #if defined(HEATER_BED_PIN) && (HEATER_BED_PIN > -1)
884
+  #if HAS_HEATER_BED
883
     SET_OUTPUT(HEATER_BED_PIN);
885
     SET_OUTPUT(HEATER_BED_PIN);
884
   #endif  
886
   #endif  
885
-  #if defined(FAN_PIN) && (FAN_PIN > -1)
887
+  #if PIN_EXISTS(FAN_PIN)
886
     SET_OUTPUT(FAN_PIN);
888
     SET_OUTPUT(FAN_PIN);
887
     #ifdef FAST_PWM_FAN
889
     #ifdef FAST_PWM_FAN
888
       setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
890
       setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
1130
   #if HAS_TEMP_BED
1132
   #if HAS_TEMP_BED
1131
     target_temperature_bed = 0;
1133
     target_temperature_bed = 0;
1132
     soft_pwm_bed = 0;
1134
     soft_pwm_bed = 0;
1133
-    #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
1135
+    #if HAS_HEATER_BED
1134
       WRITE_HEATER_BED(LOW);
1136
       WRITE_HEATER_BED(LOW);
1135
     #endif
1137
     #endif
1136
   #endif
1138
   #endif
1163
 }
1165
 }
1164
 
1166
 
1165
 void bed_max_temp_error(void) {
1167
 void bed_max_temp_error(void) {
1166
-  #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
1168
+  #if HAS_HEATER_BED
1167
     WRITE_HEATER_BED(0);
1169
     WRITE_HEATER_BED(0);
1168
   #endif
1170
   #endif
1169
   if (IsStopped() == false) {
1171
   if (IsStopped() == false) {
1232
 
1234
 
1233
 #endif //HEATER_0_USES_MAX6675
1235
 #endif //HEATER_0_USES_MAX6675
1234
 
1236
 
1237
+/**
1238
+ * Stages in the ISR loop
1239
+ */
1235
 enum TempState {
1240
 enum TempState {
1236
   PrepareTemp_0,
1241
   PrepareTemp_0,
1237
   MeasureTemp_0,
1242
   MeasureTemp_0,
1284
       #endif
1289
       #endif
1285
     #endif
1290
     #endif
1286
   #endif
1291
   #endif
1287
-  #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
1292
+  #if HAS_HEATER_BED
1288
     ISR_STATICS(BED);
1293
     ISR_STATICS(BED);
1289
   #endif
1294
   #endif
1290
 
1295
 
1316
         #endif
1321
         #endif
1317
       #endif
1322
       #endif
1318
 
1323
 
1319
-      #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
1324
+      #if HAS_HEATER_BED
1320
         soft_pwm_BED = soft_pwm_bed;
1325
         soft_pwm_BED = soft_pwm_bed;
1321
         WRITE_HEATER_BED(soft_pwm_BED > 0 ? 1 : 0);
1326
         WRITE_HEATER_BED(soft_pwm_BED > 0 ? 1 : 0);
1322
       #endif
1327
       #endif
1337
       #endif
1342
       #endif
1338
     #endif
1343
     #endif
1339
 
1344
 
1340
-    #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
1345
+    #if HAS_HEATER_BED
1341
       if (soft_pwm_BED < pwm_count) WRITE_HEATER_BED(0);
1346
       if (soft_pwm_BED < pwm_count) WRITE_HEATER_BED(0);
1342
     #endif
1347
     #endif
1343
 
1348
 
1398
           #endif
1403
           #endif
1399
         #endif
1404
         #endif
1400
       #endif
1405
       #endif
1401
-      #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
1406
+      #if HAS_HEATER_BED
1402
         _SLOW_PWM_ROUTINE(BED, soft_pwm_bed); // BED
1407
         _SLOW_PWM_ROUTINE(BED, soft_pwm_bed); // BED
1403
       #endif
1408
       #endif
1404
 
1409
 
1414
         #endif
1419
         #endif
1415
       #endif
1420
       #endif
1416
     #endif
1421
     #endif
1417
-    #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
1422
+    #if HAS_HEATER_BED
1418
       PWM_OFF_ROUTINE(BED); // BED
1423
       PWM_OFF_ROUTINE(BED); // BED
1419
     #endif
1424
     #endif
1420
 
1425
 
1445
           #endif
1450
           #endif
1446
         #endif
1451
         #endif
1447
       #endif
1452
       #endif
1448
-      #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 // BED
1453
+      #if HAS_HEATER_BED
1449
         if (state_timer_heater_BED > 0) state_timer_heater_BED--;
1454
         if (state_timer_heater_BED > 0) state_timer_heater_BED--;
1450
       #endif
1455
       #endif
1451
     } // (pwm_count % 64) == 0
1456
     } // (pwm_count % 64) == 0

Loading…
Cancel
Save