Sfoglia il codice sorgente

Clarify thermal_runaway_protection

- Add comments documenting `thermal_runaway_protection`
- Add an enum for the thermal runaway states
- Add macros for temperature helper functions
- Fix a glitch with the z probe sled in homeaxis
Scott Lahteine 10 anni fa
parent
commit
e96df67630
4 ha cambiato i file con 115 aggiunte e 140 eliminazioni
  1. 29
    30
      Marlin/Marlin_main.cpp
  2. 2
    2
      Marlin/planner.cpp
  3. 68
    78
      Marlin/temperature.cpp
  4. 16
    30
      Marlin/temperature.h

+ 29
- 30
Marlin/Marlin_main.cpp Vedi File

@@ -1460,7 +1460,7 @@ static void homeaxis(int axis) {
1460 1460
     sync_plan_position();
1461 1461
 
1462 1462
     // Engage Servo endstop if enabled
1463
-    #ifdef SERVO_ENDSTOPS && !defined(Z_PROBE_SLED)
1463
+    #if defined(SERVO_ENDSTOPS) && !defined(Z_PROBE_SLED)
1464 1464
 
1465 1465
       #if SERVO_LEVELING
1466 1466
         if (axis == Z_AXIS) engage_z_probe(); else
@@ -2781,7 +2781,7 @@ inline void gcode_M42() {
2781 2781
       }
2782 2782
     }
2783 2783
 
2784
-    #if defined(FAN_PIN) && FAN_PIN > -1
2784
+    #if HAS_FAN
2785 2785
       if (pin_number == FAN_PIN) fanSpeed = pin_status;
2786 2786
     #endif
2787 2787
 
@@ -3067,17 +3067,17 @@ inline void gcode_M104() {
3067 3067
 inline void gcode_M105() {
3068 3068
   if (setTargetedHotend(105)) return;
3069 3069
 
3070
-  #if defined(TEMP_0_PIN) && TEMP_0_PIN > -1
3070
+  #if HAS_TEMP_0
3071 3071
     SERIAL_PROTOCOLPGM("ok T:");
3072 3072
     SERIAL_PROTOCOL_F(degHotend(tmp_extruder),1);
3073 3073
     SERIAL_PROTOCOLPGM(" /");
3074 3074
     SERIAL_PROTOCOL_F(degTargetHotend(tmp_extruder),1);
3075
-    #if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1
3075
+    #if HAS_TEMP_BED
3076 3076
       SERIAL_PROTOCOLPGM(" B:");
3077 3077
       SERIAL_PROTOCOL_F(degBed(),1);
3078 3078
       SERIAL_PROTOCOLPGM(" /");
3079 3079
       SERIAL_PROTOCOL_F(degTargetBed(),1);
3080
-    #endif //TEMP_BED_PIN
3080
+    #endif
3081 3081
     for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder) {
3082 3082
       SERIAL_PROTOCOLPGM(" T");
3083 3083
       SERIAL_PROTOCOL(cur_extruder);
@@ -3108,7 +3108,7 @@ inline void gcode_M105() {
3108 3108
   #endif
3109 3109
 
3110 3110
   #ifdef SHOW_TEMP_ADC_VALUES
3111
-    #if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1
3111
+    #if HAS_TEMP_BED
3112 3112
       SERIAL_PROTOCOLPGM("    ADC B:");
3113 3113
       SERIAL_PROTOCOL_F(degBed(),1);
3114 3114
       SERIAL_PROTOCOLPGM("C->");
@@ -3124,10 +3124,10 @@ inline void gcode_M105() {
3124 3124
     }
3125 3125
   #endif
3126 3126
 
3127
-  SERIAL_PROTOCOLLN("");
3127
+  SERIAL_EOL;
3128 3128
 }
3129 3129
 
3130
-#if defined(FAN_PIN) && FAN_PIN > -1
3130
+#if HAS_FAN
3131 3131
 
3132 3132
   /**
3133 3133
    * M106: Set Fan Speed
@@ -3139,7 +3139,7 @@ inline void gcode_M105() {
3139 3139
    */
3140 3140
   inline void gcode_M107() { fanSpeed = 0; }
3141 3141
 
3142
-#endif //FAN_PIN
3142
+#endif // HAS_FAN
3143 3143
 
3144 3144
 /**
3145 3145
  * M109: Wait for extruder(s) to reach temperature
@@ -3197,10 +3197,10 @@ inline void gcode_M109() {
3197 3197
             SERIAL_PROTOCOLLN( timetemp );
3198 3198
           }
3199 3199
           else {
3200
-            SERIAL_PROTOCOLLN( "?" );
3200
+            SERIAL_PROTOCOLLNPGM("?");
3201 3201
           }
3202 3202
         #else
3203
-          SERIAL_PROTOCOLLN("");
3203
+          SERIAL_EOL;
3204 3204
         #endif
3205 3205
         timetemp = millis();
3206 3206
       }
@@ -3223,7 +3223,7 @@ inline void gcode_M109() {
3223 3223
   starttime = previous_millis_cmd = millis();
3224 3224
 }
3225 3225
 
3226
-#if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1
3226
+#if HAS_TEMP_BED
3227 3227
 
3228 3228
   /**
3229 3229
    * M190: Sxxx Wait for bed current temp to reach target temp. Waits only when heating
@@ -3251,7 +3251,7 @@ inline void gcode_M109() {
3251 3251
         SERIAL_PROTOCOL((int)active_extruder);
3252 3252
         SERIAL_PROTOCOLPGM(" B:");
3253 3253
         SERIAL_PROTOCOL_F(degBed(), 1);
3254
-        SERIAL_PROTOCOLLN("");
3254
+        SERIAL_EOL;
3255 3255
       }
3256 3256
       manage_heater();
3257 3257
       manage_inactivity();
@@ -3452,27 +3452,26 @@ inline void gcode_M114() {
3452 3452
   SERIAL_PROTOCOLPGM(" Z:");
3453 3453
   SERIAL_PROTOCOL(float(st_get_position(Z_AXIS))/axis_steps_per_unit[Z_AXIS]);
3454 3454
 
3455
-  SERIAL_PROTOCOLLN("");
3455
+  SERIAL_EOL;
3456 3456
 
3457 3457
   #ifdef SCARA
3458 3458
     SERIAL_PROTOCOLPGM("SCARA Theta:");
3459 3459
     SERIAL_PROTOCOL(delta[X_AXIS]);
3460 3460
     SERIAL_PROTOCOLPGM("   Psi+Theta:");
3461 3461
     SERIAL_PROTOCOL(delta[Y_AXIS]);
3462
-    SERIAL_PROTOCOLLN("");
3462
+    SERIAL_EOL;
3463 3463
     
3464 3464
     SERIAL_PROTOCOLPGM("SCARA Cal - Theta:");
3465 3465
     SERIAL_PROTOCOL(delta[X_AXIS]+home_offset[X_AXIS]);
3466 3466
     SERIAL_PROTOCOLPGM("   Psi+Theta (90):");
3467 3467
     SERIAL_PROTOCOL(delta[Y_AXIS]-delta[X_AXIS]-90+home_offset[Y_AXIS]);
3468
-    SERIAL_PROTOCOLLN("");
3468
+    SERIAL_EOL;
3469 3469
     
3470 3470
     SERIAL_PROTOCOLPGM("SCARA step Cal - Theta:");
3471 3471
     SERIAL_PROTOCOL(delta[X_AXIS]/90*axis_steps_per_unit[X_AXIS]);
3472 3472
     SERIAL_PROTOCOLPGM("   Psi+Theta:");
3473 3473
     SERIAL_PROTOCOL((delta[Y_AXIS]-delta[X_AXIS])/90*axis_steps_per_unit[Y_AXIS]);
3474
-    SERIAL_PROTOCOLLN("");
3475
-    SERIAL_PROTOCOLLN("");
3474
+    SERIAL_EOL; SERIAL_EOL;
3476 3475
   #endif
3477 3476
 }
3478 3477
 
@@ -3915,7 +3914,7 @@ inline void gcode_M226() {
3915 3914
       SERIAL_PROTOCOL(servo_index);
3916 3915
       SERIAL_PROTOCOL(": ");
3917 3916
       SERIAL_PROTOCOL(servos[servo_index].read());
3918
-      SERIAL_PROTOCOLLN("");
3917
+      SERIAL_EOL;
3919 3918
     }
3920 3919
   }
3921 3920
 
@@ -3983,7 +3982,7 @@ inline void gcode_M226() {
3983 3982
         //Kc does not have scaling applied above, or in resetting defaults
3984 3983
         SERIAL_PROTOCOL(PID_PARAM(Kc, e));
3985 3984
       #endif
3986
-      SERIAL_PROTOCOLLN("");    
3985
+      SERIAL_EOL;    
3987 3986
     }
3988 3987
     else {
3989 3988
       SERIAL_ECHO_START;
@@ -4008,7 +4007,7 @@ inline void gcode_M226() {
4008 4007
     SERIAL_PROTOCOL(unscalePID_i(bedKi));
4009 4008
     SERIAL_PROTOCOL(" d:");
4010 4009
     SERIAL_PROTOCOL(unscalePID_d(bedKd));
4011
-    SERIAL_PROTOCOLLN("");
4010
+    SERIAL_EOL;
4012 4011
   }
4013 4012
 
4014 4013
 #endif // PIDTEMPBED
@@ -4058,7 +4057,7 @@ inline void gcode_M226() {
4058 4057
     if (code_seen('C')) lcd_setcontrast(code_value_long() & 0x3F);
4059 4058
     SERIAL_PROTOCOLPGM("lcd contrast value: ");
4060 4059
     SERIAL_PROTOCOL(lcd_contrast);
4061
-    SERIAL_PROTOCOLLN("");
4060
+    SERIAL_EOL;
4062 4061
   }
4063 4062
 
4064 4063
 #endif // DOGLCD
@@ -4331,7 +4330,7 @@ inline void gcode_M503() {
4331 4330
         zprobe_zoffset = -value; // compare w/ line 278 of ConfigurationStore.cpp
4332 4331
         SERIAL_ECHO_START;
4333 4332
         SERIAL_ECHOLNPGM(MSG_ZPROBE_ZOFFSET " " MSG_OK);
4334
-        SERIAL_PROTOCOLLN("");
4333
+        SERIAL_EOL;
4335 4334
       }
4336 4335
       else {
4337 4336
         SERIAL_ECHO_START;
@@ -4340,14 +4339,14 @@ inline void gcode_M503() {
4340 4339
         SERIAL_ECHO(Z_PROBE_OFFSET_RANGE_MIN);
4341 4340
         SERIAL_ECHOPGM(MSG_Z_MAX);
4342 4341
         SERIAL_ECHO(Z_PROBE_OFFSET_RANGE_MAX);
4343
-        SERIAL_PROTOCOLLN("");
4342
+        SERIAL_EOL;
4344 4343
       }
4345 4344
     }
4346 4345
     else {
4347 4346
       SERIAL_ECHO_START;
4348 4347
       SERIAL_ECHOLNPGM(MSG_ZPROBE_ZOFFSET " : ");
4349 4348
       SERIAL_ECHO(-zprobe_zoffset);
4350
-      SERIAL_PROTOCOLLN("");
4349
+      SERIAL_EOL;
4351 4350
     }
4352 4351
   }
4353 4352
 
@@ -4852,20 +4851,20 @@ void process_commands() {
4852 4851
         gcode_M109();
4853 4852
         break;
4854 4853
 
4855
-      #if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1
4854
+      #if HAS_TEMP_BED
4856 4855
         case 190: // M190 - Wait for bed heater to reach target.
4857 4856
           gcode_M190();
4858 4857
           break;
4859
-      #endif //TEMP_BED_PIN
4858
+      #endif // HAS_TEMP_BED
4860 4859
 
4861
-      #if defined(FAN_PIN) && FAN_PIN > -1
4860
+      #if HAS_FAN
4862 4861
         case 106: //M106 Fan On
4863 4862
           gcode_M106();
4864 4863
           break;
4865 4864
         case 107: //M107 Fan Off
4866 4865
           gcode_M107();
4867 4866
           break;
4868
-      #endif //FAN_PIN
4867
+      #endif // HAS_FAN
4869 4868
 
4870 4869
       #ifdef BARICUDA
4871 4870
         // PWM for HEATER_1_PIN
@@ -5704,7 +5703,7 @@ void handle_status_leds(void) {
5704 5703
        max_temp = max(max_temp, degHotend(cur_extruder));
5705 5704
        max_temp = max(max_temp, degTargetHotend(cur_extruder));
5706 5705
     }
5707
-    #if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1
5706
+    #if HAS_TEMP_BED
5708 5707
       max_temp = max(max_temp, degTargetBed());
5709 5708
       max_temp = max(max_temp, degBed());
5710 5709
     #endif

+ 2
- 2
Marlin/planner.cpp Vedi File

@@ -427,7 +427,7 @@ void check_axes_activity() {
427 427
     disable_e3();
428 428
   }
429 429
 
430
-  #if defined(FAN_PIN) && FAN_PIN > -1 // HAS_FAN
430
+  #if HAS_FAN
431 431
     #ifdef FAN_KICKSTART_TIME
432 432
       static unsigned long fan_kick_end;
433 433
       if (tail_fan_speed) {
@@ -447,7 +447,7 @@ void check_axes_activity() {
447 447
     #else
448 448
       analogWrite(FAN_PIN, tail_fan_speed);
449 449
     #endif //!FAN_SOFT_PWM
450
-  #endif //FAN_PIN > -1
450
+  #endif // HAS_FAN
451 451
 
452 452
   #ifdef AUTOTEMP
453 453
     getHighESpeed();

+ 68
- 78
Marlin/temperature.cpp Vedi File

@@ -1,5 +1,5 @@
1 1
 /*
2
-  temperature.c - temperature control
2
+  temperature.cpp - temperature control
3 3
   Part of Marlin
4 4
   
5 5
  Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
@@ -16,18 +16,7 @@
16 16
  
17 17
  You should have received a copy of the GNU General Public License
18 18
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
- */
20
-
21
-/*
22
- This firmware is a mashup between Sprinter and grbl.
23
-  (https://github.com/kliment/Sprinter)
24
-  (https://github.com/simen/grbl/tree)
25
- 
26
- It has preliminary support for Matthew Roberts advance algorithm 
27
-    http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
28
-
29
- */
30
-
19
+*/
31 20
 
32 21
 #include "Marlin.h"
33 22
 #include "ultralcd.h"
@@ -87,14 +76,15 @@ unsigned char soft_pwm_bed;
87 76
 #define HAS_HEATER_THERMAL_PROTECTION (defined(THERMAL_RUNAWAY_PROTECTION_PERIOD) && THERMAL_RUNAWAY_PROTECTION_PERIOD > 0)
88 77
 #define HAS_BED_THERMAL_PROTECTION (defined(THERMAL_RUNAWAY_PROTECTION_BED_PERIOD) && THERMAL_RUNAWAY_PROTECTION_BED_PERIOD > 0 && TEMP_SENSOR_BED != 0)
89 78
 #if HAS_HEATER_THERMAL_PROTECTION || HAS_BED_THERMAL_PROTECTION
79
+  enum TRState { TRInactive, TRFirstHeating, TRStable };
90 80
   static bool thermal_runaway = false;
91
-  void thermal_runaway_protection(int *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
81
+  void thermal_runaway_protection(TRState *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
92 82
   #if HAS_HEATER_THERMAL_PROTECTION
93
-    static int thermal_runaway_state_machine[4]; // = {0,0,0,0};
83
+    static TRState thermal_runaway_state_machine[4] = { TRInactive, TRInactive, TRInactive, TRInactive };
94 84
     static unsigned long thermal_runaway_timer[4]; // = {0,0,0,0};
95 85
   #endif
96 86
   #if HAS_BED_THERMAL_PROTECTION
97
-    static int thermal_runaway_bed_state_machine;
87
+    static TRState thermal_runaway_bed_state_machine = { TRInactive, TRInactive, TRInactive, TRInactive };
98 88
     static unsigned long thermal_runaway_bed_timer;
99 89
   #endif
100 90
 #endif
@@ -238,7 +228,7 @@ void PID_autotune(float temp, int extruder, int ncycles)
238 228
     soft_pwm[extruder] = bias = d = PID_MAX / 2;
239 229
 
240 230
   // PID Tuning loop
241
-  for(;;) {
231
+  for (;;) {
242 232
 
243 233
     unsigned long ms = millis();
244 234
 
@@ -609,7 +599,7 @@ void manage_heater() {
609 599
   // Loop through all extruders
610 600
   for (int e = 0; e < EXTRUDERS; e++) {
611 601
 
612
-    #if defined (THERMAL_RUNAWAY_PROTECTION_PERIOD) && THERMAL_RUNAWAY_PROTECTION_PERIOD > 0
602
+    #if HAS_HEATER_THERMAL_PROTECTION
613 603
       thermal_runaway_protection(&thermal_runaway_state_machine[e], &thermal_runaway_timer[e], current_temperature[e], target_temperature[e], e, THERMAL_RUNAWAY_PROTECTION_PERIOD, THERMAL_RUNAWAY_PROTECTION_HYSTERESIS);
614 604
     #endif
615 605
 
@@ -637,7 +627,7 @@ void manage_heater() {
637 627
         disable_heater();
638 628
         _temp_error(0, PSTR(MSG_EXTRUDER_SWITCHED_OFF), PSTR(MSG_ERR_REDUNDANT_TEMP));
639 629
       }
640
-    #endif //TEMP_SENSOR_1_AS_REDUNDANT
630
+    #endif // TEMP_SENSOR_1_AS_REDUNDANT
641 631
 
642 632
   } // Extruders Loop
643 633
 
@@ -1014,69 +1004,69 @@ void setWatch() {
1014 1004
 }
1015 1005
 
1016 1006
 #if HAS_HEATER_THERMAL_PROTECTION || HAS_BED_THERMAL_PROTECTION
1017
-void thermal_runaway_protection(int *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc)
1018
-{
1019
-/*
1020
-      SERIAL_ECHO_START;
1021
-      SERIAL_ECHO("Thermal Thermal Runaway Running. Heater ID:");
1022
-      SERIAL_ECHO(heater_id);
1023
-      SERIAL_ECHO(" ;  State:");
1024
-      SERIAL_ECHO(*state);
1025
-      SERIAL_ECHO(" ;  Timer:");
1026
-      SERIAL_ECHO(*timer);
1027
-      SERIAL_ECHO(" ;  Temperature:");
1028
-      SERIAL_ECHO(temperature);
1029
-      SERIAL_ECHO(" ;  Target Temp:");
1030
-      SERIAL_ECHO(target_temperature);
1031
-      SERIAL_ECHOLN("");    
1032
-*/
1033
-  if ((target_temperature == 0) || thermal_runaway)
1034
-  {
1035
-    *state = 0;
1036
-    *timer = 0;
1037
-    return;
1038
-  }
1039
-  switch (*state)
1040
-  {
1041
-    case 0: // "Heater Inactive" state
1042
-      if (target_temperature > 0) *state = 1;
1043
-      break;
1044
-    case 1: // "First Heating" state
1045
-      if (temperature >= target_temperature) *state = 2;
1046
-      break;
1047
-    case 2: // "Temperature Stable" state
1048
-    {
1049
-      unsigned long ms = millis();
1050
-      if (temperature >= (target_temperature - hysteresis_degc))
1051
-      {
1052
-        *timer = ms;
1053
-      } 
1054
-      else if ( (ms - *timer) > ((unsigned long) period_seconds) * 1000)
1007
+
1008
+  void thermal_runaway_protection(TRState *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc) {
1009
+    /*
1010
+        SERIAL_ECHO_START;
1011
+        SERIAL_ECHO("Thermal Thermal Runaway Running. Heater ID:");
1012
+        SERIAL_ECHO(heater_id);
1013
+        SERIAL_ECHO(" ;  State:");
1014
+        SERIAL_ECHO(*state);
1015
+        SERIAL_ECHO(" ;  Timer:");
1016
+        SERIAL_ECHO(*timer);
1017
+        SERIAL_ECHO(" ;  Temperature:");
1018
+        SERIAL_ECHO(temperature);
1019
+        SERIAL_ECHO(" ;  Target Temp:");
1020
+        SERIAL_ECHO(target_temperature);
1021
+        SERIAL_ECHOLN("");    
1022
+    */
1023
+    if (target_temperature == 0 || thermal_runaway) {
1024
+      *state = TRInactive;
1025
+      *timer = 0;
1026
+      return;
1027
+    }
1028
+
1029
+    switch (*state) {
1030
+      // Inactive state waits for a target temperature, then 
1031
+      case TRInactive:
1032
+        if (target_temperature > 0) *state = TRFirstHeating;
1033
+        break;
1034
+      // When first heating, wait for the temperature to be reached then go to Stable state
1035
+      case TRFirstHeating:
1036
+        if (temperature >= target_temperature) *state = TRStable;
1037
+        break;
1038
+      // While the temperature is stable watch for a bad temperature
1039
+      case TRStable:
1055 1040
       {
1056
-        SERIAL_ERROR_START;
1057
-        SERIAL_ERRORLNPGM(MSG_THERMAL_RUNAWAY_STOP);
1058
-        SERIAL_ERRORLN((int)heater_id);
1059
-        LCD_ALERTMESSAGEPGM(MSG_THERMAL_RUNAWAY); // translatable
1060
-        thermal_runaway = true;
1061
-        while(1)
1062
-        {
1063
-          disable_heater();
1064
-          disable_x();
1065
-          disable_y();
1066
-          disable_z();
1067
-          disable_e0();
1068
-          disable_e1();
1069
-          disable_e2();
1070
-          disable_e3();
1071
-          manage_heater();
1072
-          lcd_update();
1041
+        // Whenever the current temperature is over the target (-hysteresis) restart the timer
1042
+        if (temperature >= target_temperature - hysteresis_degc) {
1043
+          *timer = millis();
1073 1044
         }
1074
-      }
1075
-    } break;
1045
+        // If the timer goes too long without a reset, trigger shutdown
1046
+        else if (millis() > *timer + period_seconds * 1000UL) {
1047
+          SERIAL_ERROR_START;
1048
+          SERIAL_ERRORLNPGM(MSG_THERMAL_RUNAWAY_STOP);
1049
+          SERIAL_ERRORLN((int)heater_id);
1050
+          LCD_ALERTMESSAGEPGM(MSG_THERMAL_RUNAWAY);
1051
+          thermal_runaway = true;
1052
+          for (;;) {
1053
+            disable_heater();
1054
+            disable_x();
1055
+            disable_y();
1056
+            disable_z();
1057
+            disable_e0();
1058
+            disable_e1();
1059
+            disable_e2();
1060
+            disable_e3();
1061
+            manage_heater();
1062
+            lcd_update();
1063
+          }
1064
+        }
1065
+      } break;
1066
+    }
1076 1067
   }
1077
-}
1078
-#endif //THERMAL_RUNAWAY_PROTECTION_PERIOD
1079 1068
 
1069
+#endif // HAS_HEATER_THERMAL_PROTECTION
1080 1070
 
1081 1071
 void disable_heater() {
1082 1072
   for (int i=0; i<EXTRUDERS; i++) setTargetHotend(0, i);

+ 16
- 30
Marlin/temperature.h Vedi File

@@ -18,8 +18,8 @@
18 18
   along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
19 19
 */
20 20
 
21
-#ifndef temperature_h
22
-#define temperature_h 
21
+#ifndef TEMPERATURE_H
22
+#define TEMPERATURE_H 
23 23
 
24 24
 #include "Marlin.h"
25 25
 #include "planner.h"
@@ -105,40 +105,27 @@ FORCE_INLINE bool isHeatingBed() { return target_temperature_bed > current_tempe
105 105
 FORCE_INLINE bool isCoolingHotend(uint8_t extruder) { return target_temperature[extruder] < current_temperature[extruder]; }
106 106
 FORCE_INLINE bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
107 107
 
108
-#define degHotend0() degHotend(0)
109
-#define degTargetHotend0() degTargetHotend(0)
110
-#define setTargetHotend0(_celsius) setTargetHotend((_celsius), 0)
111
-#define isHeatingHotend0() isHeatingHotend(0)
112
-#define isCoolingHotend0() isCoolingHotend(0)
108
+#define HOTEND_ROUTINES(NR) \
109
+  FORCE_INLINE float degHotend##NR() { return degHotend(NR); } \
110
+  FORCE_INLINE float degTargetHotend##NR() { return degTargetHotend(NR); } \
111
+  FORCE_INLINE void setTargetHotend##NR(const float c) { setTargetHotend(c, NR); } \
112
+  FORCE_INLINE bool isHeatingHotend##NR() { return isHeatingHotend(NR); } \
113
+  FORCE_INLINE bool isCoolingHotend##NR() { return isCoolingHotend(NR); }
114
+HOTEND_ROUTINES(0);
113 115
 #if EXTRUDERS > 1
114
-  #define degHotend1() degHotend(1)
115
-  #define degTargetHotend1() degTargetHotend(1)
116
-  #define setTargetHotend1(_celsius) setTargetHotend((_celsius), 1)
117
-  #define isHeatingHotend1() isHeatingHotend(1)
118
-  #define isCoolingHotend1() isCoolingHotend(1)
116
+  HOTEND_ROUTINES(1);
119 117
 #else
120
-  #define setTargetHotend1(_celsius) do{}while(0)
118
+  #define setTargetHotend1(c) do{}while(0)
121 119
 #endif
122 120
 #if EXTRUDERS > 2
123
-  #define degHotend2() degHotend(2)
124
-  #define degTargetHotend2() degTargetHotend(2)
125
-  #define setTargetHotend2(_celsius) setTargetHotend((_celsius), 2)
126
-  #define isHeatingHotend2() isHeatingHotend(2)
127
-  #define isCoolingHotend2() isCoolingHotend(2)
121
+  HOTEND_ROUTINES(2);
128 122
 #else
129
-  #define setTargetHotend2(_celsius) do{}while(0)
123
+  #define setTargetHotend2(c) do{}while(0)
130 124
 #endif
131 125
 #if EXTRUDERS > 3
132
-  #define degHotend3() degHotend(3)
133
-  #define degTargetHotend3() degTargetHotend(3)
134
-  #define setTargetHotend3(_celsius) setTargetHotend((_celsius), 3)
135
-  #define isHeatingHotend3() isHeatingHotend(3)
136
-  #define isCoolingHotend3() isCoolingHotend(3)
126
+  HOTEND_ROUTINES(3);
137 127
 #else
138
-  #define setTargetHotend3(_celsius) do{}while(0)
139
-#endif
140
-#if EXTRUDERS > 4
141
-  #error Invalid number of extruders
128
+  #define setTargetHotend3(c) do{}while(0)
142 129
 #endif
143 130
 
144 131
 int getHeaterPower(int heater);
@@ -161,5 +148,4 @@ FORCE_INLINE void autotempShutdown() {
161 148
   #endif
162 149
 }
163 150
 
164
-
165
-#endif
151
+#endif // TEMPERATURE_H

Loading…
Annulla
Salva