Browse Source

Overridable Options - Part 9 (PR#2561)

Apply `ENABLED` / `DISABLED` macros to temperature-related files.
Scott Lahteine 9 years ago
parent
commit
51e89a269c
2 changed files with 77 additions and 77 deletions
  1. 65
    65
      Marlin/temperature.cpp
  2. 12
    12
      Marlin/temperature.h

+ 65
- 65
Marlin/temperature.cpp View File

34
   #define K2 (1.0-K1)
34
   #define K2 (1.0-K1)
35
 #endif
35
 #endif
36
 
36
 
37
-#if defined(PIDTEMPBED) || defined(PIDTEMP)
37
+#if ENABLED(PIDTEMPBED) || ENABLED(PIDTEMP)
38
   #define PID_dT ((OVERSAMPLENR * 12.0)/(F_CPU / 64.0 / 256.0))
38
   #define PID_dT ((OVERSAMPLENR * 12.0)/(F_CPU / 64.0 / 256.0))
39
 #endif
39
 #endif
40
 
40
 
48
 float current_temperature[4] = { 0.0 };
48
 float current_temperature[4] = { 0.0 };
49
 int current_temperature_bed_raw = 0;
49
 int current_temperature_bed_raw = 0;
50
 float current_temperature_bed = 0.0;
50
 float current_temperature_bed = 0.0;
51
-#ifdef TEMP_SENSOR_1_AS_REDUNDANT
51
+#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
52
   int redundant_temperature_raw = 0;
52
   int redundant_temperature_raw = 0;
53
   float redundant_temperature = 0.0;
53
   float redundant_temperature = 0.0;
54
 #endif
54
 #endif
55
 
55
 
56
-#ifdef PIDTEMPBED
56
+#if ENABLED(PIDTEMPBED)
57
   float bedKp=DEFAULT_bedKp;
57
   float bedKp=DEFAULT_bedKp;
58
   float bedKi=(DEFAULT_bedKi*PID_dT);
58
   float bedKi=(DEFAULT_bedKi*PID_dT);
59
   float bedKd=(DEFAULT_bedKd/PID_dT);
59
   float bedKd=(DEFAULT_bedKd/PID_dT);
60
 #endif //PIDTEMPBED
60
 #endif //PIDTEMPBED
61
   
61
   
62
-#ifdef FAN_SOFT_PWM
62
+#if ENABLED(FAN_SOFT_PWM)
63
   unsigned char fanSpeedSoftPwm;
63
   unsigned char fanSpeedSoftPwm;
64
 #endif
64
 #endif
65
 
65
 
66
 unsigned char soft_pwm_bed;
66
 unsigned char soft_pwm_bed;
67
   
67
   
68
-#ifdef BABYSTEPPING
68
+#if ENABLED(BABYSTEPPING)
69
   volatile int babystepsTodo[3] = { 0 };
69
   volatile int babystepsTodo[3] = { 0 };
70
 #endif
70
 #endif
71
 
71
 
72
-#ifdef FILAMENT_SENSOR
72
+#if ENABLED(FILAMENT_SENSOR)
73
   int current_raw_filwidth = 0;  //Holds measured filament diameter - one extruder only
73
   int current_raw_filwidth = 0;  //Holds measured filament diameter - one extruder only
74
 #endif  
74
 #endif  
75
 
75
 
76
-#if defined(THERMAL_PROTECTION_HOTENDS) || defined(THERMAL_PROTECTION_BED)
76
+#if ENABLED(THERMAL_PROTECTION_HOTENDS) || ENABLED(THERMAL_PROTECTION_BED)
77
   enum TRState { TRReset, TRInactive, TRFirstHeating, TRStable, TRRunaway };
77
   enum TRState { TRReset, TRInactive, TRFirstHeating, TRStable, TRRunaway };
78
   void thermal_runaway_protection(TRState *state, millis_t *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
78
   void thermal_runaway_protection(TRState *state, millis_t *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
79
-  #ifdef THERMAL_PROTECTION_HOTENDS
79
+  #if ENABLED(THERMAL_PROTECTION_HOTENDS)
80
     static TRState thermal_runaway_state_machine[4] = { TRReset, TRReset, TRReset, TRReset };
80
     static TRState thermal_runaway_state_machine[4] = { TRReset, TRReset, TRReset, TRReset };
81
     static millis_t thermal_runaway_timer[4]; // = {0,0,0,0};
81
     static millis_t thermal_runaway_timer[4]; // = {0,0,0,0};
82
   #endif
82
   #endif
83
-  #if defined(THERMAL_PROTECTION_BED) && TEMP_SENSOR_BED != 0
83
+  #if ENABLED(THERMAL_PROTECTION_BED) && TEMP_SENSOR_BED != 0
84
     static TRState thermal_runaway_bed_state_machine = TRReset;
84
     static TRState thermal_runaway_bed_state_machine = TRReset;
85
     static millis_t thermal_runaway_bed_timer;
85
     static millis_t thermal_runaway_bed_timer;
86
   #endif
86
   #endif
92
 
92
 
93
 static volatile bool temp_meas_ready = false;
93
 static volatile bool temp_meas_ready = false;
94
 
94
 
95
-#ifdef PIDTEMP
95
+#if ENABLED(PIDTEMP)
96
   //static cannot be external:
96
   //static cannot be external:
97
   static float temp_iState[EXTRUDERS] = { 0 };
97
   static float temp_iState[EXTRUDERS] = { 0 };
98
   static float temp_dState[EXTRUDERS] = { 0 };
98
   static float temp_dState[EXTRUDERS] = { 0 };
105
   static float temp_iState_max[EXTRUDERS];
105
   static float temp_iState_max[EXTRUDERS];
106
   static bool pid_reset[EXTRUDERS];
106
   static bool pid_reset[EXTRUDERS];
107
 #endif //PIDTEMP
107
 #endif //PIDTEMP
108
-#ifdef PIDTEMPBED
108
+#if ENABLED(PIDTEMPBED)
109
   //static cannot be external:
109
   //static cannot be external:
110
   static float temp_iState_bed = { 0 };
110
   static float temp_iState_bed = { 0 };
111
   static float temp_dState_bed = { 0 };
111
   static float temp_dState_bed = { 0 };
121
 #endif //PIDTEMPBED
121
 #endif //PIDTEMPBED
122
   static unsigned char soft_pwm[EXTRUDERS];
122
   static unsigned char soft_pwm[EXTRUDERS];
123
 
123
 
124
-#ifdef FAN_SOFT_PWM
124
+#if ENABLED(FAN_SOFT_PWM)
125
   static unsigned char soft_pwm_fan;
125
   static unsigned char soft_pwm_fan;
126
 #endif
126
 #endif
127
 #if HAS_AUTO_FAN
127
 #if HAS_AUTO_FAN
128
   static millis_t next_auto_fan_check_ms;
128
   static millis_t next_auto_fan_check_ms;
129
 #endif  
129
 #endif  
130
 
130
 
131
-#ifdef PIDTEMP
132
-  #ifdef PID_PARAMS_PER_EXTRUDER
131
+#if ENABLED(PIDTEMP)
132
+  #if ENABLED(PID_PARAMS_PER_EXTRUDER)
133
     float Kp[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Kp);
133
     float Kp[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Kp);
134
     float Ki[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Ki*PID_dT);
134
     float Ki[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Ki*PID_dT);
135
     float Kd[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Kd / PID_dT);
135
     float Kd[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Kd / PID_dT);
136
-    #ifdef PID_ADD_EXTRUSION_RATE
136
+    #if ENABLED(PID_ADD_EXTRUSION_RATE)
137
       float Kc[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Kc);
137
       float Kc[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Kc);
138
     #endif // PID_ADD_EXTRUSION_RATE
138
     #endif // PID_ADD_EXTRUSION_RATE
139
   #else //PID_PARAMS_PER_EXTRUDER
139
   #else //PID_PARAMS_PER_EXTRUDER
140
     float Kp = DEFAULT_Kp;
140
     float Kp = DEFAULT_Kp;
141
     float Ki = DEFAULT_Ki * PID_dT;
141
     float Ki = DEFAULT_Ki * PID_dT;
142
     float Kd = DEFAULT_Kd / PID_dT;
142
     float Kd = DEFAULT_Kd / PID_dT;
143
-    #ifdef PID_ADD_EXTRUSION_RATE
143
+    #if ENABLED(PID_ADD_EXTRUSION_RATE)
144
       float Kc = DEFAULT_Kc;
144
       float Kc = DEFAULT_Kc;
145
     #endif // PID_ADD_EXTRUSION_RATE
145
     #endif // PID_ADD_EXTRUSION_RATE
146
   #endif // PID_PARAMS_PER_EXTRUDER
146
   #endif // PID_PARAMS_PER_EXTRUDER
158
   static int bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP;
158
   static int bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP;
159
 #endif
159
 #endif
160
 
160
 
161
-#ifdef TEMP_SENSOR_1_AS_REDUNDANT
161
+#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
162
   static void *heater_ttbl_map[2] = {(void *)HEATER_0_TEMPTABLE, (void *)HEATER_1_TEMPTABLE };
162
   static void *heater_ttbl_map[2] = {(void *)HEATER_0_TEMPTABLE, (void *)HEATER_1_TEMPTABLE };
163
   static uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN };
163
   static uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN };
164
 #else
164
 #else
170
 static float analog2tempBed(int raw);
170
 static float analog2tempBed(int raw);
171
 static void updateTemperaturesFromRawValues();
171
 static void updateTemperaturesFromRawValues();
172
 
172
 
173
-#ifdef THERMAL_PROTECTION_HOTENDS
173
+#if ENABLED(THERMAL_PROTECTION_HOTENDS)
174
   int watch_target_temp[EXTRUDERS] = { 0 };
174
   int watch_target_temp[EXTRUDERS] = { 0 };
175
   millis_t watch_heater_next_ms[EXTRUDERS] = { 0 };
175
   millis_t watch_heater_next_ms[EXTRUDERS] = { 0 };
176
 #endif
176
 #endif
179
   #define SOFT_PWM_SCALE 0
179
   #define SOFT_PWM_SCALE 0
180
 #endif
180
 #endif
181
 
181
 
182
-#ifdef FILAMENT_SENSOR
182
+#if ENABLED(FILAMENT_SENSOR)
183
   static int meas_shift_index;  //used to point to a delayed sample in buffer for filament width sensor
183
   static int meas_shift_index;  //used to point to a delayed sample in buffer for filament width sensor
184
 #endif
184
 #endif
185
 
185
 
186
-#ifdef HEATER_0_USES_MAX6675
186
+#if ENABLED(HEATER_0_USES_MAX6675)
187
   static int read_max6675();
187
   static int read_max6675();
188
 #endif
188
 #endif
189
 
189
 
354
 }
354
 }
355
 
355
 
356
 void updatePID() {
356
 void updatePID() {
357
-  #ifdef PIDTEMP
357
+  #if ENABLED(PIDTEMP)
358
     for (int e = 0; e < EXTRUDERS; e++) {
358
     for (int e = 0; e < EXTRUDERS; e++) {
359
       temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e);
359
       temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e);
360
     }
360
     }
361
   #endif
361
   #endif
362
-  #ifdef PIDTEMPBED
362
+  #if ENABLED(PIDTEMPBED)
363
     temp_iState_max_bed = PID_BED_INTEGRAL_DRIVE_MAX / bedKi;
363
     temp_iState_max_bed = PID_BED_INTEGRAL_DRIVE_MAX / bedKi;
364
   #endif
364
   #endif
365
 }
365
 }
453
     SERIAL_ERRORPGM(MSG_STOPPED_HEATER);
453
     SERIAL_ERRORPGM(MSG_STOPPED_HEATER);
454
     if (e >= 0) SERIAL_ERRORLN((int)e); else SERIAL_ERRORLNPGM(MSG_HEATER_BED);
454
     if (e >= 0) SERIAL_ERRORLN((int)e); else SERIAL_ERRORLNPGM(MSG_HEATER_BED);
455
   }
455
   }
456
-  #ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE
456
+  #if DISABLED(BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE)
457
     if (!killed) {
457
     if (!killed) {
458
       Running = false;
458
       Running = false;
459
       killed = true;
459
       killed = true;
473
 
473
 
474
 float get_pid_output(int e) {
474
 float get_pid_output(int e) {
475
   float pid_output;
475
   float pid_output;
476
-  #ifdef PIDTEMP
477
-    #ifndef PID_OPENLOOP
476
+  #if ENABLED(PIDTEMP)
477
+    #if DISABLED(PID_OPENLOOP)
478
       pid_error[e] = target_temperature[e] - current_temperature[e];
478
       pid_error[e] = target_temperature[e] - current_temperature[e];
479
       dTerm[e] = K2 * PID_PARAM(Kd,e) * (current_temperature[e] - temp_dState[e]) + K1 * dTerm[e];
479
       dTerm[e] = K2 * PID_PARAM(Kd,e) * (current_temperature[e] - temp_dState[e]) + K1 * dTerm[e];
480
       temp_dState[e] = current_temperature[e];
480
       temp_dState[e] = current_temperature[e];
510
       pid_output = constrain(target_temperature[e], 0, PID_MAX);
510
       pid_output = constrain(target_temperature[e], 0, PID_MAX);
511
     #endif //PID_OPENLOOP
511
     #endif //PID_OPENLOOP
512
 
512
 
513
-    #ifdef PID_DEBUG
513
+    #if ENABLED(PID_DEBUG)
514
       SERIAL_ECHO_START;
514
       SERIAL_ECHO_START;
515
       SERIAL_ECHO(MSG_PID_DEBUG);
515
       SERIAL_ECHO(MSG_PID_DEBUG);
516
       SERIAL_ECHO(e);
516
       SERIAL_ECHO(e);
533
   return pid_output;
533
   return pid_output;
534
 }
534
 }
535
 
535
 
536
-#ifdef PIDTEMPBED
536
+#if ENABLED(PIDTEMPBED)
537
   float get_pid_output_bed() {
537
   float get_pid_output_bed() {
538
     float pid_output;
538
     float pid_output;
539
-    #ifndef PID_OPENLOOP
539
+    #if DISABLED(PID_OPENLOOP)
540
       pid_error_bed = target_temperature_bed - current_temperature_bed;
540
       pid_error_bed = target_temperature_bed - current_temperature_bed;
541
       pTerm_bed = bedKp * pid_error_bed;
541
       pTerm_bed = bedKp * pid_error_bed;
542
       temp_iState_bed += pid_error_bed;
542
       temp_iState_bed += pid_error_bed;
559
       pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER);
559
       pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER);
560
     #endif // PID_OPENLOOP
560
     #endif // PID_OPENLOOP
561
 
561
 
562
-    #ifdef PID_BED_DEBUG
562
+    #if ENABLED(PID_BED_DEBUG)
563
       SERIAL_ECHO_START;
563
       SERIAL_ECHO_START;
564
       SERIAL_ECHO(" PID_BED_DEBUG ");
564
       SERIAL_ECHO(" PID_BED_DEBUG ");
565
       SERIAL_ECHO(": Input ");
565
       SERIAL_ECHO(": Input ");
592
 
592
 
593
   updateTemperaturesFromRawValues();
593
   updateTemperaturesFromRawValues();
594
 
594
 
595
-  #ifdef HEATER_0_USES_MAX6675
595
+  #if ENABLED(HEATER_0_USES_MAX6675)
596
     float ct = current_temperature[0];
596
     float ct = current_temperature[0];
597
     if (ct > min(HEATER_0_MAXTEMP, 1023)) max_temp_error(0);
597
     if (ct > min(HEATER_0_MAXTEMP, 1023)) max_temp_error(0);
598
     if (ct < max(HEATER_0_MINTEMP, 0.01)) min_temp_error(0);
598
     if (ct < max(HEATER_0_MINTEMP, 0.01)) min_temp_error(0);
599
   #endif
599
   #endif
600
 
600
 
601
-  #if defined(THERMAL_PROTECTION_HOTENDS) || !defined(PIDTEMPBED) || HAS_AUTO_FAN
601
+  #if ENABLED(THERMAL_PROTECTION_HOTENDS) || DISABLED(PIDTEMPBED) || HAS_AUTO_FAN
602
     millis_t ms = millis();
602
     millis_t ms = millis();
603
   #endif
603
   #endif
604
 
604
 
605
   // Loop through all extruders
605
   // Loop through all extruders
606
   for (int e = 0; e < EXTRUDERS; e++) {
606
   for (int e = 0; e < EXTRUDERS; e++) {
607
 
607
 
608
-    #ifdef THERMAL_PROTECTION_HOTENDS
608
+    #if ENABLED(THERMAL_PROTECTION_HOTENDS)
609
       thermal_runaway_protection(&thermal_runaway_state_machine[e], &thermal_runaway_timer[e], current_temperature[e], target_temperature[e], e, THERMAL_PROTECTION_PERIOD, THERMAL_PROTECTION_HYSTERESIS);
609
       thermal_runaway_protection(&thermal_runaway_state_machine[e], &thermal_runaway_timer[e], current_temperature[e], target_temperature[e], e, THERMAL_PROTECTION_PERIOD, THERMAL_PROTECTION_HYSTERESIS);
610
     #endif
610
     #endif
611
 
611
 
615
     soft_pwm[e] = current_temperature[e] > minttemp[e] && current_temperature[e] < maxttemp[e] ? (int)pid_output >> 1 : 0;
615
     soft_pwm[e] = current_temperature[e] > minttemp[e] && current_temperature[e] < maxttemp[e] ? (int)pid_output >> 1 : 0;
616
 
616
 
617
     // Check if the temperature is failing to increase
617
     // Check if the temperature is failing to increase
618
-    #ifdef THERMAL_PROTECTION_HOTENDS
618
+    #if ENABLED(THERMAL_PROTECTION_HOTENDS)
619
 
619
 
620
       // Is it time to check this extruder's heater?
620
       // Is it time to check this extruder's heater?
621
       if (watch_heater_next_ms[e] && ms > watch_heater_next_ms[e]) {
621
       if (watch_heater_next_ms[e] && ms > watch_heater_next_ms[e]) {
632
 
632
 
633
     #endif // THERMAL_PROTECTION_HOTENDS
633
     #endif // THERMAL_PROTECTION_HOTENDS
634
 
634
 
635
-    #ifdef TEMP_SENSOR_1_AS_REDUNDANT
635
+    #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
636
       if (fabs(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF) {
636
       if (fabs(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF) {
637
         _temp_error(0, PSTR(MSG_EXTRUDER_SWITCHED_OFF), PSTR(MSG_ERR_REDUNDANT_TEMP));
637
         _temp_error(0, PSTR(MSG_EXTRUDER_SWITCHED_OFF), PSTR(MSG_ERR_REDUNDANT_TEMP));
638
       }
638
       }
648
   #endif       
648
   #endif       
649
 
649
 
650
   // Control the extruder rate based on the width sensor
650
   // Control the extruder rate based on the width sensor
651
-  #ifdef FILAMENT_SENSOR
651
+  #if ENABLED(FILAMENT_SENSOR)
652
     if (filament_sensor) {
652
     if (filament_sensor) {
653
       meas_shift_index = delay_index1 - meas_delay_cm;
653
       meas_shift_index = delay_index1 - meas_delay_cm;
654
       if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
654
       if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
662
     }
662
     }
663
   #endif //FILAMENT_SENSOR
663
   #endif //FILAMENT_SENSOR
664
 
664
 
665
-  #ifndef PIDTEMPBED
665
+  #if DISABLED(PIDTEMPBED)
666
     if (ms < next_bed_check_ms) return;
666
     if (ms < next_bed_check_ms) return;
667
     next_bed_check_ms = ms + BED_CHECK_INTERVAL;
667
     next_bed_check_ms = ms + BED_CHECK_INTERVAL;
668
   #endif
668
   #endif
669
 
669
 
670
   #if TEMP_SENSOR_BED != 0
670
   #if TEMP_SENSOR_BED != 0
671
   
671
   
672
-    #ifdef THERMAL_PROTECTION_BED
672
+    #if ENABLED(THERMAL_PROTECTION_BED)
673
       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);
673
       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);
674
     #endif
674
     #endif
675
 
675
 
676
-    #ifdef PIDTEMPBED
676
+    #if ENABLED(PIDTEMPBED)
677
       float pid_output = get_pid_output_bed();
677
       float pid_output = get_pid_output_bed();
678
 
678
 
679
       soft_pwm_bed = current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP ? (int)pid_output >> 1 : 0;
679
       soft_pwm_bed = current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP ? (int)pid_output >> 1 : 0;
680
 
680
 
681
-    #elif defined(BED_LIMIT_SWITCHING)
681
+    #elif ENABLED(BED_LIMIT_SWITCHING)
682
       // Check if temperature is within the correct band
682
       // Check if temperature is within the correct band
683
       if (current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP) {
683
       if (current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP) {
684
         if (current_temperature_bed >= target_temperature_bed + BED_HYSTERESIS)
684
         if (current_temperature_bed >= target_temperature_bed + BED_HYSTERESIS)
707
 // Derived from RepRap FiveD extruder::getTemperature()
707
 // Derived from RepRap FiveD extruder::getTemperature()
708
 // For hot end temperature measurement.
708
 // For hot end temperature measurement.
709
 static float analog2temp(int raw, uint8_t e) {
709
 static float analog2temp(int raw, uint8_t e) {
710
-  #ifdef TEMP_SENSOR_1_AS_REDUNDANT
710
+  #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
711
     if (e > EXTRUDERS)
711
     if (e > EXTRUDERS)
712
   #else
712
   #else
713
     if (e >= EXTRUDERS)
713
     if (e >= EXTRUDERS)
720
       return 0.0;
720
       return 0.0;
721
     } 
721
     } 
722
 
722
 
723
-  #ifdef HEATER_0_USES_MAX6675
723
+  #if ENABLED(HEATER_0_USES_MAX6675)
724
     if (e == 0) return 0.25 * raw;
724
     if (e == 0) return 0.25 * raw;
725
   #endif
725
   #endif
726
 
726
 
750
 // Derived from RepRap FiveD extruder::getTemperature()
750
 // Derived from RepRap FiveD extruder::getTemperature()
751
 // For bed temperature measurement.
751
 // For bed temperature measurement.
752
 static float analog2tempBed(int raw) {
752
 static float analog2tempBed(int raw) {
753
-  #ifdef BED_USES_THERMISTOR
753
+  #if ENABLED(BED_USES_THERMISTOR)
754
     float celsius = 0;
754
     float celsius = 0;
755
     byte i;
755
     byte i;
756
 
756
 
778
 /* Called to get the raw values into the the actual temperatures. The raw values are created in interrupt context,
778
 /* Called to get the raw values into the the actual temperatures. The raw values are created in interrupt context,
779
     and this function is called from normal context as it is too slow to run in interrupts and will block the stepper routine otherwise */
779
     and this function is called from normal context as it is too slow to run in interrupts and will block the stepper routine otherwise */
780
 static void updateTemperaturesFromRawValues() {
780
 static void updateTemperaturesFromRawValues() {
781
-  #ifdef HEATER_0_USES_MAX6675
781
+  #if ENABLED(HEATER_0_USES_MAX6675)
782
     current_temperature_raw[0] = read_max6675();
782
     current_temperature_raw[0] = read_max6675();
783
   #endif
783
   #endif
784
   for (uint8_t e = 0; e < EXTRUDERS; e++) {
784
   for (uint8_t e = 0; e < EXTRUDERS; e++) {
785
     current_temperature[e] = analog2temp(current_temperature_raw[e], e);
785
     current_temperature[e] = analog2temp(current_temperature_raw[e], e);
786
   }
786
   }
787
   current_temperature_bed = analog2tempBed(current_temperature_bed_raw);
787
   current_temperature_bed = analog2tempBed(current_temperature_bed_raw);
788
-  #ifdef TEMP_SENSOR_1_AS_REDUNDANT
788
+  #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
789
     redundant_temperature = analog2temp(redundant_temperature_raw, 1);
789
     redundant_temperature = analog2temp(redundant_temperature_raw, 1);
790
   #endif
790
   #endif
791
   #if HAS_FILAMENT_SENSOR
791
   #if HAS_FILAMENT_SENSOR
800
 }
800
 }
801
 
801
 
802
 
802
 
803
-#ifdef FILAMENT_SENSOR
803
+#if ENABLED(FILAMENT_SENSOR)
804
 
804
 
805
   // Convert raw Filament Width to millimeters
805
   // Convert raw Filament Width to millimeters
806
   float analog2widthFil() {
806
   float analog2widthFil() {
834
   for (int e = 0; e < EXTRUDERS; e++) {
834
   for (int e = 0; e < EXTRUDERS; e++) {
835
     // populate with the first value 
835
     // populate with the first value 
836
     maxttemp[e] = maxttemp[0];
836
     maxttemp[e] = maxttemp[0];
837
-    #ifdef PIDTEMP
837
+    #if ENABLED(PIDTEMP)
838
       temp_iState_min[e] = 0.0;
838
       temp_iState_min[e] = 0.0;
839
       temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e);
839
       temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e);
840
     #endif //PIDTEMP
840
     #endif //PIDTEMP
841
-    #ifdef PIDTEMPBED
841
+    #if ENABLED(PIDTEMPBED)
842
       temp_iState_min_bed = 0.0;
842
       temp_iState_min_bed = 0.0;
843
       temp_iState_max_bed = PID_BED_INTEGRAL_DRIVE_MAX / bedKi;
843
       temp_iState_max_bed = PID_BED_INTEGRAL_DRIVE_MAX / bedKi;
844
     #endif //PIDTEMPBED
844
     #endif //PIDTEMPBED
861
   #endif  
861
   #endif  
862
   #if HAS_FAN
862
   #if HAS_FAN
863
     SET_OUTPUT(FAN_PIN);
863
     SET_OUTPUT(FAN_PIN);
864
-    #ifdef FAST_PWM_FAN
864
+    #if ENABLED(FAST_PWM_FAN)
865
       setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
865
       setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
866
     #endif
866
     #endif
867
-    #ifdef FAN_SOFT_PWM
867
+    #if ENABLED(FAN_SOFT_PWM)
868
       soft_pwm_fan = fanSpeedSoftPwm / 2;
868
       soft_pwm_fan = fanSpeedSoftPwm / 2;
869
     #endif
869
     #endif
870
   #endif
870
   #endif
871
 
871
 
872
-  #ifdef HEATER_0_USES_MAX6675
872
+  #if ENABLED(HEATER_0_USES_MAX6675)
873
 
873
 
874
-    #ifndef SDSUPPORT
874
+    #if DISABLED(SDSUPPORT)
875
       OUT_WRITE(SCK_PIN, LOW);
875
       OUT_WRITE(SCK_PIN, LOW);
876
       OUT_WRITE(MOSI_PIN, HIGH);
876
       OUT_WRITE(MOSI_PIN, HIGH);
877
       OUT_WRITE(MISO_PIN, HIGH);
877
       OUT_WRITE(MISO_PIN, HIGH);
1004
   #endif //BED_MAXTEMP
1004
   #endif //BED_MAXTEMP
1005
 }
1005
 }
1006
 
1006
 
1007
-#ifdef THERMAL_PROTECTION_HOTENDS
1007
+#if ENABLED(THERMAL_PROTECTION_HOTENDS)
1008
   /**
1008
   /**
1009
    * Start Heating Sanity Check for hotends that are below
1009
    * Start Heating Sanity Check for hotends that are below
1010
    * their target temperature by a configurable margin.
1010
    * their target temperature by a configurable margin.
1020
   }
1020
   }
1021
 #endif
1021
 #endif
1022
 
1022
 
1023
-#if defined(THERMAL_PROTECTION_HOTENDS) || defined(THERMAL_PROTECTION_BED)
1023
+#if ENABLED(THERMAL_PROTECTION_HOTENDS) || ENABLED(THERMAL_PROTECTION_BED)
1024
 
1024
 
1025
   void thermal_runaway_protection(TRState *state, millis_t *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc) {
1025
   void thermal_runaway_protection(TRState *state, millis_t *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc) {
1026
 
1026
 
1115
   #endif
1115
   #endif
1116
 }
1116
 }
1117
 
1117
 
1118
-#ifdef HEATER_0_USES_MAX6675
1118
+#if ENABLED(HEATER_0_USES_MAX6675)
1119
   #define MAX6675_HEAT_INTERVAL 250u
1119
   #define MAX6675_HEAT_INTERVAL 250u
1120
   static millis_t next_max6675_ms = 0;
1120
   static millis_t next_max6675_ms = 0;
1121
   int max6675_temp = 2000;
1121
   int max6675_temp = 2000;
1196
 static unsigned long raw_temp_bed_value = 0;
1196
 static unsigned long raw_temp_bed_value = 0;
1197
 
1197
 
1198
 static void set_current_temp_raw() {
1198
 static void set_current_temp_raw() {
1199
-  #if HAS_TEMP_0 && !defined(HEATER_0_USES_MAX6675)
1199
+  #if HAS_TEMP_0 && DISABLED(HEATER_0_USES_MAX6675)
1200
     current_temperature_raw[0] = raw_temp_value[0];
1200
     current_temperature_raw[0] = raw_temp_value[0];
1201
   #endif
1201
   #endif
1202
   #if HAS_TEMP_1
1202
   #if HAS_TEMP_1
1203
-    #ifdef TEMP_SENSOR_1_AS_REDUNDANT
1203
+    #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
1204
       redundant_temperature_raw = raw_temp_value[1];
1204
       redundant_temperature_raw = raw_temp_value[1];
1205
     #else
1205
     #else
1206
       current_temperature_raw[1] = raw_temp_value[1];
1206
       current_temperature_raw[1] = raw_temp_value[1];
1230
   static unsigned char pwm_count = BIT(SOFT_PWM_SCALE);
1230
   static unsigned char pwm_count = BIT(SOFT_PWM_SCALE);
1231
 
1231
 
1232
   // Static members for each heater
1232
   // Static members for each heater
1233
-  #ifdef SLOW_PWM_HEATERS
1233
+  #if ENABLED(SLOW_PWM_HEATERS)
1234
     static unsigned char slow_pwm_count = 0;
1234
     static unsigned char slow_pwm_count = 0;
1235
     #define ISR_STATICS(n) \
1235
     #define ISR_STATICS(n) \
1236
       static unsigned char soft_pwm_ ## n; \
1236
       static unsigned char soft_pwm_ ## n; \
1242
 
1242
 
1243
   // Statics per heater
1243
   // Statics per heater
1244
   ISR_STATICS(0);
1244
   ISR_STATICS(0);
1245
-  #if (EXTRUDERS > 1) || defined(HEATERS_PARALLEL)
1245
+  #if (EXTRUDERS > 1) || ENABLED(HEATERS_PARALLEL)
1246
     ISR_STATICS(1);
1246
     ISR_STATICS(1);
1247
     #if EXTRUDERS > 2
1247
     #if EXTRUDERS > 2
1248
       ISR_STATICS(2);
1248
       ISR_STATICS(2);
1259
     static unsigned long raw_filwidth_value = 0;
1259
     static unsigned long raw_filwidth_value = 0;
1260
   #endif
1260
   #endif
1261
   
1261
   
1262
-  #ifndef SLOW_PWM_HEATERS
1262
+  #if DISABLED(SLOW_PWM_HEATERS)
1263
     /**
1263
     /**
1264
      * standard PWM modulation
1264
      * standard PWM modulation
1265
      */
1265
      */
1287
         soft_pwm_BED = soft_pwm_bed;
1287
         soft_pwm_BED = soft_pwm_bed;
1288
         WRITE_HEATER_BED(soft_pwm_BED > 0 ? 1 : 0);
1288
         WRITE_HEATER_BED(soft_pwm_BED > 0 ? 1 : 0);
1289
       #endif
1289
       #endif
1290
-      #ifdef FAN_SOFT_PWM
1290
+      #if ENABLED(FAN_SOFT_PWM)
1291
         soft_pwm_fan = fanSpeedSoftPwm / 2;
1291
         soft_pwm_fan = fanSpeedSoftPwm / 2;
1292
         WRITE_FAN(soft_pwm_fan > 0 ? 1 : 0);
1292
         WRITE_FAN(soft_pwm_fan > 0 ? 1 : 0);
1293
       #endif
1293
       #endif
1308
       if (soft_pwm_BED < pwm_count) WRITE_HEATER_BED(0);
1308
       if (soft_pwm_BED < pwm_count) WRITE_HEATER_BED(0);
1309
     #endif
1309
     #endif
1310
 
1310
 
1311
-    #ifdef FAN_SOFT_PWM
1311
+    #if ENABLED(FAN_SOFT_PWM)
1312
       if (soft_pwm_fan < pwm_count) WRITE_FAN(0);
1312
       if (soft_pwm_fan < pwm_count) WRITE_FAN(0);
1313
     #endif
1313
     #endif
1314
     
1314
     
1385
       PWM_OFF_ROUTINE(BED); // BED
1385
       PWM_OFF_ROUTINE(BED); // BED
1386
     #endif
1386
     #endif
1387
 
1387
 
1388
-    #ifdef FAN_SOFT_PWM
1388
+    #if ENABLED(FAN_SOFT_PWM)
1389
       if (pwm_count == 0) {
1389
       if (pwm_count == 0) {
1390
         soft_pwm_fan = fanSpeedSoftPwm / 2;
1390
         soft_pwm_fan = fanSpeedSoftPwm / 2;
1391
         WRITE_FAN(soft_pwm_fan > 0 ? 1 : 0);
1391
         WRITE_FAN(soft_pwm_fan > 0 ? 1 : 0);
1540
     for (int i = 0; i < 4; i++) raw_temp_value[i] = 0;
1540
     for (int i = 0; i < 4; i++) raw_temp_value[i] = 0;
1541
     raw_temp_bed_value = 0;
1541
     raw_temp_bed_value = 0;
1542
 
1542
 
1543
-    #if HAS_TEMP_0 && !defined(HEATER_0_USES_MAX6675)
1543
+    #if HAS_TEMP_0 && DISABLED(HEATER_0_USES_MAX6675)
1544
       #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
1544
       #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
1545
         #define GE0 <=
1545
         #define GE0 <=
1546
       #else
1546
       #else
1592
 
1592
 
1593
   } // temp_count >= OVERSAMPLENR
1593
   } // temp_count >= OVERSAMPLENR
1594
 
1594
 
1595
-  #ifdef BABYSTEPPING
1595
+  #if ENABLED(BABYSTEPPING)
1596
     for (uint8_t axis = X_AXIS; axis <= Z_AXIS; axis++) {
1596
     for (uint8_t axis = X_AXIS; axis <= Z_AXIS; axis++) {
1597
       int curTodo = babystepsTodo[axis]; //get rid of volatile for performance
1597
       int curTodo = babystepsTodo[axis]; //get rid of volatile for performance
1598
      
1598
      
1608
   #endif //BABYSTEPPING
1608
   #endif //BABYSTEPPING
1609
 }
1609
 }
1610
 
1610
 
1611
-#ifdef PIDTEMP
1611
+#if ENABLED(PIDTEMP)
1612
   // Apply the scale factors to the PID values
1612
   // Apply the scale factors to the PID values
1613
   float scalePID_i(float i)   { return i * PID_dT; }
1613
   float scalePID_i(float i)   { return i * PID_dT; }
1614
   float unscalePID_i(float i) { return i / PID_dT; }
1614
   float unscalePID_i(float i) { return i / PID_dT; }

+ 12
- 12
Marlin/temperature.h View File

23
 
23
 
24
 #include "Marlin.h"
24
 #include "Marlin.h"
25
 #include "planner.h"
25
 #include "planner.h"
26
-#ifdef PID_ADD_EXTRUSION_RATE
26
+#if ENABLED(PID_ADD_EXTRUSION_RATE)
27
   #include "stepper.h"
27
   #include "stepper.h"
28
 #endif
28
 #endif
29
 
29
 
31
 void tp_init();  //initialize the heating
31
 void tp_init();  //initialize the heating
32
 void manage_heater(); //it is critical that this is called periodically.
32
 void manage_heater(); //it is critical that this is called periodically.
33
 
33
 
34
-#ifdef FILAMENT_SENSOR
34
+#if ENABLED(FILAMENT_SENSOR)
35
 // For converting raw Filament Width to milimeters 
35
 // For converting raw Filament Width to milimeters 
36
  float analog2widthFil(); 
36
  float analog2widthFil(); 
37
  
37
  
43
 // do not use these routines and variables outside of temperature.cpp
43
 // do not use these routines and variables outside of temperature.cpp
44
 extern int target_temperature[4];  
44
 extern int target_temperature[4];  
45
 extern float current_temperature[4];
45
 extern float current_temperature[4];
46
-#ifdef SHOW_TEMP_ADC_VALUES
46
+#if ENABLED(SHOW_TEMP_ADC_VALUES)
47
   extern int current_temperature_raw[4];
47
   extern int current_temperature_raw[4];
48
   extern int current_temperature_bed_raw;
48
   extern int current_temperature_bed_raw;
49
 #endif
49
 #endif
50
 extern int target_temperature_bed;
50
 extern int target_temperature_bed;
51
 extern float current_temperature_bed;
51
 extern float current_temperature_bed;
52
-#ifdef TEMP_SENSOR_1_AS_REDUNDANT
52
+#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
53
   extern float redundant_temperature;
53
   extern float redundant_temperature;
54
 #endif
54
 #endif
55
 
55
 
57
   extern unsigned char soft_pwm_bed;
57
   extern unsigned char soft_pwm_bed;
58
 #endif
58
 #endif
59
 
59
 
60
-#ifdef PIDTEMP
60
+#if ENABLED(PIDTEMP)
61
 
61
 
62
-  #ifdef PID_PARAMS_PER_EXTRUDER
62
+  #if ENABLED(PID_PARAMS_PER_EXTRUDER)
63
     extern float Kp[EXTRUDERS], Ki[EXTRUDERS], Kd[EXTRUDERS], Kc[EXTRUDERS]; // one param per extruder
63
     extern float Kp[EXTRUDERS], Ki[EXTRUDERS], Kd[EXTRUDERS], Kc[EXTRUDERS]; // one param per extruder
64
     #define PID_PARAM(param,e) param[e] // use macro to point to array value
64
     #define PID_PARAM(param,e) param[e] // use macro to point to array value
65
   #else
65
   #else
73
 
73
 
74
 #endif
74
 #endif
75
 
75
 
76
-#ifdef PIDTEMPBED
76
+#if ENABLED(PIDTEMPBED)
77
   extern float bedKp,bedKi,bedKd;
77
   extern float bedKp,bedKi,bedKd;
78
 #endif
78
 #endif
79
   
79
   
80
-#ifdef BABYSTEPPING
80
+#if ENABLED(BABYSTEPPING)
81
   extern volatile int babystepsTodo[3];
81
   extern volatile int babystepsTodo[3];
82
 #endif
82
 #endif
83
   
83
   
88
 FORCE_INLINE float degHotend(uint8_t extruder) { return current_temperature[extruder]; }
88
 FORCE_INLINE float degHotend(uint8_t extruder) { return current_temperature[extruder]; }
89
 FORCE_INLINE float degBed() { return current_temperature_bed; }
89
 FORCE_INLINE float degBed() { return current_temperature_bed; }
90
 
90
 
91
-#ifdef SHOW_TEMP_ADC_VALUES
91
+#if ENABLED(SHOW_TEMP_ADC_VALUES)
92
   FORCE_INLINE float rawHotendTemp(uint8_t extruder) { return current_temperature_raw[extruder]; }
92
   FORCE_INLINE float rawHotendTemp(uint8_t extruder) { return current_temperature_raw[extruder]; }
93
   FORCE_INLINE float rawBedTemp() { return current_temperature_bed_raw; }
93
   FORCE_INLINE float rawBedTemp() { return current_temperature_bed_raw; }
94
 #endif
94
 #endif
96
 FORCE_INLINE float degTargetHotend(uint8_t extruder) { return target_temperature[extruder]; }
96
 FORCE_INLINE float degTargetHotend(uint8_t extruder) { return target_temperature[extruder]; }
97
 FORCE_INLINE float degTargetBed() { return target_temperature_bed; }
97
 FORCE_INLINE float degTargetBed() { return target_temperature_bed; }
98
 
98
 
99
-#ifdef THERMAL_PROTECTION_HOTENDS
99
+#if ENABLED(THERMAL_PROTECTION_HOTENDS)
100
   void start_watching_heater(int e=0);
100
   void start_watching_heater(int e=0);
101
 #endif
101
 #endif
102
 
102
 
103
 FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) {
103
 FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) {
104
   target_temperature[extruder] = celsius;
104
   target_temperature[extruder] = celsius;
105
-  #ifdef THERMAL_PROTECTION_HOTENDS
105
+  #if ENABLED(THERMAL_PROTECTION_HOTENDS)
106
     start_watching_heater(extruder);
106
     start_watching_heater(extruder);
107
   #endif
107
   #endif
108
 }
108
 }
147
 void checkExtruderAutoFans();
147
 void checkExtruderAutoFans();
148
 
148
 
149
 FORCE_INLINE void autotempShutdown() {
149
 FORCE_INLINE void autotempShutdown() {
150
-  #ifdef AUTOTEMP
150
+  #if ENABLED(AUTOTEMP)
151
     if (autotemp_enabled) {
151
     if (autotemp_enabled) {
152
       autotemp_enabled = false;
152
       autotemp_enabled = false;
153
       if (degTargetHotend(active_extruder) > autotemp_min)
153
       if (degTargetHotend(active_extruder) > autotemp_min)

Loading…
Cancel
Save