Browse Source

Redo HAS_* macros to fix define error

Scott Lahteine 9 years ago
parent
commit
1a7b0d9a37
1 changed files with 46 additions and 42 deletions
  1. 46
    42
      Marlin/temperature.cpp

+ 46
- 42
Marlin/temperature.cpp View File

@@ -53,20 +53,23 @@
53 53
   #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1 }
54 54
 #endif
55 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)
56
+#define HAS_TEMP_0 (defined(TEMP_0_PIN) && TEMP_0_PIN >= 0)
57
+#define HAS_TEMP_1 (defined(TEMP_1_PIN) && TEMP_1_PIN >= 0)
58
+#define HAS_TEMP_2 (defined(TEMP_2_PIN) && TEMP_2_PIN >= 0)
59
+#define HAS_TEMP_3 (defined(TEMP_3_PIN) && TEMP_3_PIN >= 0)
60
+#define HAS_TEMP_BED (defined(TEMP_BED_PIN) && TEMP_BED_PIN >= 0)
61
+#define HAS_FILAMENT_SENSOR (defined(FILAMENT_SENSOR) && defined(FILWIDTH_PIN) && FILWIDTH_PIN >= 0)
62
+#define HAS_HEATER_0 (defined(HEATER_0_PIN) && HEATER_0_PIN >= 0)
63
+#define HAS_HEATER_1 (defined(HEATER_1_PIN) && HEATER_1_PIN >= 0)
64
+#define HAS_HEATER_2 (defined(HEATER_2_PIN) && HEATER_2_PIN >= 0)
65
+#define HAS_HEATER_3 (defined(HEATER_3_PIN) && HEATER_3_PIN >= 0)
66
+#define HAS_HEATER_BED (defined(HEATER_BED_PIN) && HEATER_BED_PIN >= 0)
67
+#define HAS_AUTO_FAN_0 (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN >= 0)
68
+#define HAS_AUTO_FAN_1 (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN >= 0)
69
+#define HAS_AUTO_FAN_2 (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN >= 0)
70
+#define HAS_AUTO_FAN_3 (defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN >= 0)
71
+#define HAS_AUTO_FAN HAS_AUTO_FAN_0 || HAS_AUTO_FAN_1 || HAS_AUTO_FAN_2 || HAS_AUTO_FAN_3
72
+#define HAS_FAN (defined(FAN_PIN) && FAN_PIN >= 0)
70 73
 
71 74
 //===========================================================================
72 75
 //============================= public variables ============================
@@ -147,8 +150,7 @@ static volatile bool temp_meas_ready = false;
147 150
 #ifdef FAN_SOFT_PWM
148 151
   static unsigned char soft_pwm_fan;
149 152
 #endif
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)
153
+#if HAS_AUTO_FAN
152 154
   static unsigned long extruder_autofan_last_check;
153 155
 #endif  
154 156
 
@@ -227,8 +229,7 @@ void PID_autotune(float temp, int extruder, int ncycles)
227 229
   float Kp, Ki, Kd;
228 230
   float max = 0, min = 10000;
229 231
 
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)
232
+  #if HAS_AUTO_FAN
232 233
         unsigned long extruder_autofan_last_check = temp_millis;
233 234
   #endif
234 235
 
@@ -263,8 +264,7 @@ void PID_autotune(float temp, int extruder, int ncycles)
263 264
       max = max(max, input);
264 265
       min = min(min, input);
265 266
 
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)
267
+      #if HAS_AUTO_FAN
268 268
         if (ms > extruder_autofan_last_check + 2500) {
269 269
           checkExtruderAutoFans();
270 270
           extruder_autofan_last_check = ms;
@@ -387,19 +387,21 @@ int getHeaterPower(int heater) {
387 387
   return heater < 0 ? soft_pwm_bed : soft_pwm[heater];
388 388
 }
389 389
 
390
-#if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \
391
-    PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN)
390
+#if HAS_AUTO_FAN
392 391
 
393
-  #if PIN_EXISTS(FAN_PIN)
394
-    #if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN 
392
+  #if HAS_FAN
393
+    #if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN
395 394
        #error "You cannot set EXTRUDER_0_AUTO_FAN_PIN equal to FAN_PIN"
396 395
     #endif
397
-    #if EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN 
396
+    #if EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN
398 397
        #error "You cannot set EXTRUDER_1_AUTO_FAN_PIN equal to FAN_PIN"
399 398
     #endif
400
-    #if EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN 
399
+    #if EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN
401 400
        #error "You cannot set EXTRUDER_2_AUTO_FAN_PIN equal to FAN_PIN"
402 401
     #endif
402
+    #if EXTRUDER_3_AUTO_FAN_PIN == FAN_PIN
403
+       #error "You cannot set EXTRUDER_3_AUTO_FAN_PIN equal to FAN_PIN"
404
+    #endif
403 405
   #endif 
404 406
 
405 407
 void setExtruderAutoFanState(int pin, bool state)
@@ -416,20 +418,20 @@ void checkExtruderAutoFans()
416 418
   uint8_t fanState = 0;
417 419
 
418 420
   // which fan pins need to be turned on?      
419
-  #if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN)
421
+  #if HAS_AUTO_FAN_0
420 422
     if (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE) 
421 423
       fanState |= 1;
422 424
   #endif
423
-  #if PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN)
425
+  #if HAS_AUTO_FAN_1
424 426
     if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) 
425 427
     {
426
-      if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) 
428
+      if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN)
427 429
         fanState |= 1;
428 430
       else
429 431
         fanState |= 2;
430 432
     }
431 433
   #endif
432
-  #if PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN)
434
+  #if HAS_AUTO_FAN_2
433 435
     if (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE) 
434 436
     {
435 437
       if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) 
@@ -440,7 +442,7 @@ void checkExtruderAutoFans()
440 442
         fanState |= 4;
441 443
     }
442 444
   #endif
443
-  #if PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
445
+  #if HAS_AUTO_FAN_3
444 446
     if (current_temperature[3] > EXTRUDER_AUTO_FAN_TEMPERATURE) 
445 447
     {
446 448
       if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) 
@@ -455,19 +457,19 @@ void checkExtruderAutoFans()
455 457
   #endif
456 458
   
457 459
   // update extruder auto fan states
458
-  #if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN)
460
+  #if HAS_AUTO_FAN_0
459 461
     setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, (fanState & 1) != 0);
460 462
   #endif 
461
-  #if PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN)
463
+  #if HAS_AUTO_FAN_1
462 464
     if (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN)
463 465
       setExtruderAutoFanState(EXTRUDER_1_AUTO_FAN_PIN, (fanState & 2) != 0);
464 466
   #endif 
465
-  #if PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN)
467
+  #if HAS_AUTO_FAN_2
466 468
     if (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN
467 469
         && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN)
468 470
       setExtruderAutoFanState(EXTRUDER_2_AUTO_FAN_PIN, (fanState & 4) != 0);
469 471
   #endif
470
-  #if PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
472
+  #if HAS_AUTO_FAN_3
471 473
     if (EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN
472 474
         && EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN
473 475
         && EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_2_AUTO_FAN_PIN)
@@ -510,6 +512,9 @@ void checkExtruderAutoFans()
510 512
 #if HAS_HEATER_BED
511 513
   #define WRITE_HEATER_BED(v) WRITE(HEATER_BED_PIN, v)
512 514
 #endif
515
+#if HAS_FAN
516
+  #define WRITE_FAN(v) WRITE(FAN_PIN, v)
517
+#endif
513 518
 
514 519
 void manage_heater() {
515 520
 
@@ -631,8 +636,7 @@ void manage_heater() {
631 636
 
632 637
   } // Extruders Loop
633 638
 
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)
639
+  #if HAS_AUTO_FAN
636 640
     if (ms > extruder_autofan_last_check + 2500) { // only need to check fan state very infrequently
637 641
       checkExtruderAutoFans();
638 642
       extruder_autofan_last_check = ms;
@@ -884,7 +888,7 @@ void tp_init()
884 888
   #if HAS_HEATER_BED
885 889
     SET_OUTPUT(HEATER_BED_PIN);
886 890
   #endif  
887
-  #if PIN_EXISTS(FAN_PIN)
891
+  #if HAS_FAN
888 892
     SET_OUTPUT(FAN_PIN);
889 893
     #ifdef FAST_PWM_FAN
890 894
       setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
@@ -1327,7 +1331,7 @@ ISR(TIMER0_COMPB_vect) {
1327 1331
       #endif
1328 1332
       #ifdef FAN_SOFT_PWM
1329 1333
         soft_pwm_fan = fanSpeedSoftPwm / 2;
1330
-        WRITE(FAN_PIN, soft_pwm_fan > 0 ? 1 : 0);
1334
+        WRITE_FAN(soft_pwm_fan > 0 ? 1 : 0);
1331 1335
       #endif
1332 1336
     }
1333 1337
 
@@ -1347,7 +1351,7 @@ ISR(TIMER0_COMPB_vect) {
1347 1351
     #endif
1348 1352
 
1349 1353
     #ifdef FAN_SOFT_PWM
1350
-      if (soft_pwm_fan < pwm_count) WRITE(FAN_PIN, 0);
1354
+      if (soft_pwm_fan < pwm_count) WRITE_FAN(0);
1351 1355
     #endif
1352 1356
     
1353 1357
     pwm_count += (1 << SOFT_PWM_SCALE);
@@ -1426,9 +1430,9 @@ ISR(TIMER0_COMPB_vect) {
1426 1430
     #ifdef FAN_SOFT_PWM
1427 1431
       if (pwm_count == 0) {
1428 1432
         soft_pwm_fan = fanSpeedSoftPwm / 2;
1429
-        WRITE(FAN_PIN, soft_pwm_fan > 0 ? 1 : 0);
1433
+        WRITE_FAN(soft_pwm_fan > 0 ? 1 : 0);
1430 1434
       }
1431
-      if (soft_pwm_fan < pwm_count) WRITE(FAN_PIN, 0);
1435
+      if (soft_pwm_fan < pwm_count) WRITE_FAN(0);
1432 1436
     #endif //FAN_SOFT_PWM
1433 1437
 
1434 1438
     pwm_count += (1 << SOFT_PWM_SCALE);

Loading…
Cancel
Save