Browse Source

Further reduction when HOTENDS == 1

Scott Lahteine 8 years ago
parent
commit
ee0983ab57

+ 10
- 9
Marlin/Marlin_main.cpp View File

@@ -4365,7 +4365,7 @@ inline void gcode_M104() {
4365 4365
       SERIAL_PROTOCOL_F(thermalManager.degTargetBed(), 1);
4366 4366
     #endif
4367 4367
     #if HOTENDS > 1
4368
-      for (int8_t e = 0; e < HOTENDS; ++e) {
4368
+      HOTEND_LOOP() {
4369 4369
         SERIAL_PROTOCOLPGM(" T");
4370 4370
         SERIAL_PROTOCOL(e);
4371 4371
         SERIAL_PROTOCOLCHAR(':');
@@ -4391,7 +4391,7 @@ inline void gcode_M104() {
4391 4391
       SERIAL_PROTOCOL(thermalManager.getHeaterPower(target_extruder));
4392 4392
     #endif
4393 4393
     #if HOTENDS > 1
4394
-      for (int8_t e = 0; e < HOTENDS; ++e) {
4394
+      HOTEND_LOOP() {
4395 4395
         SERIAL_PROTOCOLPGM(" @");
4396 4396
         SERIAL_PROTOCOL(e);
4397 4397
         SERIAL_PROTOCOLCHAR(':');
@@ -4410,13 +4410,13 @@ inline void gcode_M104() {
4410 4410
         SERIAL_PROTOCOLPGM("C->");
4411 4411
         SERIAL_PROTOCOL_F(thermalManager.rawBedTemp() / OVERSAMPLENR, 0);
4412 4412
       #endif
4413
-      for (int8_t cur_hotend = 0; cur_hotend < HOTENDS; ++cur_hotend) {
4413
+      HOTEND_LOOP() {
4414 4414
         SERIAL_PROTOCOLPGM("  T");
4415
-        SERIAL_PROTOCOL(cur_hotend);
4415
+        SERIAL_PROTOCOL(e);
4416 4416
         SERIAL_PROTOCOLCHAR(':');
4417
-        SERIAL_PROTOCOL_F(thermalManager.degHotend(cur_hotend), 1);
4417
+        SERIAL_PROTOCOL_F(thermalManager.degHotend(e), 1);
4418 4418
         SERIAL_PROTOCOLPGM("C->");
4419
-        SERIAL_PROTOCOL_F(thermalManager.rawHotendTemp(cur_hotend) / OVERSAMPLENR, 0);
4419
+        SERIAL_PROTOCOL_F(thermalManager.rawHotendTemp(e) / OVERSAMPLENR, 0);
4420 4420
       }
4421 4421
     #endif
4422 4422
   }
@@ -5436,7 +5436,7 @@ inline void gcode_M206() {
5436 5436
 
5437 5437
     SERIAL_ECHO_START;
5438 5438
     SERIAL_ECHOPGM(MSG_HOTEND_OFFSET);
5439
-    for (int e = 0; e < HOTENDS; e++) {
5439
+    HOTEND_LOOP() {
5440 5440
       SERIAL_CHAR(' ');
5441 5441
       SERIAL_ECHO(hotend_offset[X_AXIS][e]);
5442 5442
       SERIAL_CHAR(',');
@@ -7968,8 +7968,9 @@ void prepare_move_to_destination() {
7968 7968
     float max_temp = 0.0;
7969 7969
     if (ELAPSED(millis(), next_status_led_update_ms)) {
7970 7970
       next_status_led_update_ms += 500; // Update every 0.5s
7971
-      for (int8_t cur_hotend = 0; cur_hotend < HOTENDS; ++cur_hotend)
7972
-        max_temp = max(max(max_temp, thermalManager.degHotend(cur_hotend)), thermalManager.degTargetHotend(cur_hotend));
7971
+      HOTEND_LOOP() {
7972
+        max_temp = max(max(max_temp, thermalManager.degHotend(e)), thermalManager.degTargetHotend(e));
7973
+      }
7973 7974
       #if HAS_TEMP_BED
7974 7975
         max_temp = max(max(max_temp, thermalManager.degTargetBed()), thermalManager.degBed());
7975 7976
       #endif

+ 8
- 8
Marlin/configuration_store.cpp View File

@@ -618,7 +618,7 @@ void Config_ResetDefault() {
618 618
 
619 619
   #if ENABLED(PIDTEMP)
620 620
     #if ENABLED(PID_PARAMS_PER_HOTEND)
621
-      for (uint8_t e = 0; e < HOTENDS; e++)
621
+      HOTEND_LOOP
622 622
     #else
623 623
       int e = 0; UNUSED(e); // only need to write once
624 624
     #endif
@@ -834,15 +834,15 @@ void Config_PrintSettings(bool forReplay) {
834 834
     #if ENABLED(PIDTEMP)
835 835
       #if HOTENDS > 1
836 836
         if (forReplay) {
837
-          for (uint8_t i = 0; i < HOTENDS; i++) {
837
+          HOTEND_LOOP() {
838 838
             CONFIG_ECHO_START;
839
-            SERIAL_ECHOPAIR("  M301 E", i);
840
-            SERIAL_ECHOPAIR(" P", PID_PARAM(Kp, i));
841
-            SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, i)));
842
-            SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, i)));
839
+            SERIAL_ECHOPAIR("  M301 E", e);
840
+            SERIAL_ECHOPAIR(" P", PID_PARAM(Kp, e));
841
+            SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, e)));
842
+            SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, e)));
843 843
             #if ENABLED(PID_ADD_EXTRUSION_RATE)
844
-              SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, i));
845
-              if (i == 0) SERIAL_ECHOPAIR(" L", lpq_len);
844
+              SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, e));
845
+              if (e == 0) SERIAL_ECHOPAIR(" L", lpq_len);
846 846
             #endif
847 847
             SERIAL_EOL;
848 848
           }

+ 1
- 1
Marlin/dogm_lcd_implementation.h View File

@@ -392,7 +392,7 @@ static void lcd_implementation_status_screen() {
392 392
   #endif
393 393
 
394 394
   // Extruders
395
-  for (int i = 0; i < HOTENDS; i++) _draw_heater_status(5 + i * 25, i);
395
+  HOTEND_LOOP() _draw_heater_status(5 + e * 25, e);
396 396
 
397 397
   // Heated bed
398 398
   #if HOTENDS < 4 && HAS_TEMP_BED

+ 25
- 16
Marlin/temperature.cpp View File

@@ -436,7 +436,7 @@ Temperature::Temperature() { }
436 436
 
437 437
 void Temperature::updatePID() {
438 438
   #if ENABLED(PIDTEMP)
439
-    for (int e = 0; e < HOTENDS; e++) {
439
+    HOTEND_LOOP() {
440 440
       temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e);
441 441
       #if ENABLED(PID_ADD_EXTRUSION_RATE)
442 442
         last_position[e] = 0;
@@ -465,12 +465,12 @@ int Temperature::getHeaterPower(int heater) {
465 465
       EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN ? 2 : 3
466 466
     };
467 467
     uint8_t fanState = 0;
468
-    for (int f = 0; f < HOTENDS; f++) {
469
-      if (current_temperature[f] > EXTRUDER_AUTO_FAN_TEMPERATURE)
470
-        SBI(fanState, fanBit[f]);
468
+    HOTEND_LOOP() {
469
+      if (current_temperature[e] > EXTRUDER_AUTO_FAN_TEMPERATURE)
470
+        SBI(fanState, fanBit[e]);
471 471
     }
472 472
     uint8_t fanDone = 0;
473
-    for (int f = 0; f <= 3; f++) {
473
+    for (int8_t f = 0; f <= 3; f++) {
474 474
       int8_t pin = fanPin[f];
475 475
       if (pin >= 0 && !TEST(fanDone, fanBit[f])) {
476 476
         unsigned char newFanSpeed = TEST(fanState, fanBit[f]) ? EXTRUDER_AUTO_FAN_SPEED : 0;
@@ -507,10 +507,16 @@ void Temperature::_temp_error(int e, const char* serial_msg, const char* lcd_msg
507 507
 }
508 508
 
509 509
 void Temperature::max_temp_error(uint8_t e) {
510
-  _temp_error(e, PSTR(MSG_T_MAXTEMP), PSTR(MSG_ERR_MAXTEMP));
510
+  #if HOTENDS == 1
511
+    UNUSED(e);
512
+  #endif
513
+  _temp_error(HOTEND_INDEX, PSTR(MSG_T_MAXTEMP), PSTR(MSG_ERR_MAXTEMP));
511 514
 }
512 515
 void Temperature::min_temp_error(uint8_t e) {
513
-  _temp_error(e, PSTR(MSG_T_MINTEMP), PSTR(MSG_ERR_MINTEMP));
516
+  #if HOTENDS == 1
517
+    UNUSED(e);
518
+  #endif
519
+  _temp_error(HOTEND_INDEX, PSTR(MSG_T_MINTEMP), PSTR(MSG_ERR_MINTEMP));
514 520
 }
515 521
 
516 522
 float Temperature::get_pid_output(int e) {
@@ -670,7 +676,7 @@ void Temperature::manage_heater() {
670 676
   #endif
671 677
 
672 678
   // Loop through all hotends
673
-  for (uint8_t e = 0; e < HOTENDS; e++) {
679
+  HOTEND_LOOP() {
674 680
 
675 681
     #if ENABLED(THERMAL_PROTECTION_HOTENDS)
676 682
       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);
@@ -877,7 +883,7 @@ void Temperature::updateTemperaturesFromRawValues() {
877 883
   #if ENABLED(HEATER_0_USES_MAX6675)
878 884
     current_temperature_raw[0] = read_max6675();
879 885
   #endif
880
-  for (uint8_t e = 0; e < HOTENDS; e++) {
886
+  HOTEND_LOOP() {
881 887
     current_temperature[e] = Temperature::analog2temp(current_temperature_raw[e], e);
882 888
   }
883 889
   current_temperature_bed = Temperature::analog2tempBed(current_temperature_bed_raw);
@@ -931,7 +937,7 @@ void Temperature::init() {
931 937
   #endif
932 938
 
933 939
   // Finish init of mult hotend arrays
934
-  for (int e = 0; e < HOTENDS; e++) {
940
+  HOTEND_LOOP() {
935 941
     // populate with the first value
936 942
     maxttemp[e] = maxttemp[0];
937 943
     #if ENABLED(PIDTEMP)
@@ -1138,13 +1144,16 @@ void Temperature::init() {
1138 1144
    * their target temperature by a configurable margin.
1139 1145
    * This is called when the temperature is set. (M104, M109)
1140 1146
    */
1141
-  void Temperature::start_watching_heater(int e) {
1142
-    if (degHotend(e) < degTargetHotend(e) - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1)) {
1143
-      watch_target_temp[e] = degHotend(e) + WATCH_TEMP_INCREASE;
1144
-      watch_heater_next_ms[e] = millis() + (WATCH_TEMP_PERIOD) * 1000UL;
1147
+  void Temperature::start_watching_heater(uint8_t e) {
1148
+    #if HOTENDS == 1
1149
+      UNUSED(e);
1150
+    #endif
1151
+    if (degHotend(HOTEND_INDEX) < degTargetHotend(HOTEND_INDEX) - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1)) {
1152
+      watch_target_temp[HOTEND_INDEX] = degHotend(HOTEND_INDEX) + WATCH_TEMP_INCREASE;
1153
+      watch_heater_next_ms[HOTEND_INDEX] = millis() + (WATCH_TEMP_PERIOD) * 1000UL;
1145 1154
     }
1146 1155
     else
1147
-      watch_heater_next_ms[e] = 0;
1156
+      watch_heater_next_ms[HOTEND_INDEX] = 0;
1148 1157
   }
1149 1158
 #endif
1150 1159
 
@@ -1222,7 +1231,7 @@ void Temperature::init() {
1222 1231
 #endif // THERMAL_PROTECTION_HOTENDS || THERMAL_PROTECTION_BED
1223 1232
 
1224 1233
 void Temperature::disable_all_heaters() {
1225
-  for (int i = 0; i < HOTENDS; i++) setTargetHotend(0, i);
1234
+  HOTEND_LOOP() setTargetHotend(0, e);
1226 1235
   setTargetBed(0);
1227 1236
 
1228 1237
   // If all heaters go down then for sure our print job has stopped

+ 28
- 28
Marlin/temperature.h View File

@@ -39,13 +39,13 @@
39 39
 #endif
40 40
 
41 41
 #if HOTENDS == 1
42
-  #define HOTEND_ARG 0
43
-  #define HOTEND_INDEX 0
44
-  #define EXTRUDER_ARG 0
42
+  #define HOTEND_LOOP() const uint8_t e = 0;
43
+  #define HOTEND_INDEX  0
44
+  #define EXTRUDER_IDX  0
45 45
 #else
46
-  #define HOTEND_ARG hotend
47
-  #define HOTEND_INDEX e
48
-  #define EXTRUDER_ARG active_extruder
46
+  #define HOTEND_LOOP() for (int8_t e = 0; e < HOTENDS; e++)
47
+  #define HOTEND_INDEX  e
48
+  #define EXTRUDER_IDX  active_extruder
49 49
 #endif
50 50
 
51 51
 class Temperature {
@@ -245,47 +245,47 @@ class Temperature {
245 245
     //inline so that there is no performance decrease.
246 246
     //deg=degreeCelsius
247 247
 
248
-    static float degHotend(uint8_t hotend) {
248
+    static float degHotend(uint8_t e) {
249 249
       #if HOTENDS == 1
250
-        UNUSED(hotend);
250
+        UNUSED(e);
251 251
       #endif
252
-      return current_temperature[HOTEND_ARG];
252
+      return current_temperature[HOTEND_INDEX];
253 253
     }
254 254
     static float degBed() { return current_temperature_bed; }
255 255
 
256 256
     #if ENABLED(SHOW_TEMP_ADC_VALUES)
257
-    static float rawHotendTemp(uint8_t hotend) {
257
+    static float rawHotendTemp(uint8_t e) {
258 258
       #if HOTENDS == 1
259
-        UNUSED(hotend);
259
+        UNUSED(e);
260 260
       #endif
261
-      return current_temperature_raw[HOTEND_ARG];
261
+      return current_temperature_raw[HOTEND_INDEX];
262 262
     }
263 263
     static float rawBedTemp() { return current_temperature_bed_raw; }
264 264
     #endif
265 265
 
266
-    static float degTargetHotend(uint8_t hotend) {
266
+    static float degTargetHotend(uint8_t e) {
267 267
       #if HOTENDS == 1
268
-        UNUSED(hotend);
268
+        UNUSED(e);
269 269
       #endif
270
-      return target_temperature[HOTEND_ARG];
270
+      return target_temperature[HOTEND_INDEX];
271 271
     }
272 272
     static float degTargetBed() { return target_temperature_bed; }
273 273
 
274 274
     #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
275
-      static void start_watching_heater(int e = 0);
275
+      static void start_watching_heater(uint8_t e = 0);
276 276
     #endif
277 277
 
278 278
     #if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
279 279
       static void start_watching_bed();
280 280
     #endif
281 281
 
282
-    static void setTargetHotend(const float& celsius, uint8_t hotend) {
282
+    static void setTargetHotend(const float& celsius, uint8_t e) {
283 283
       #if HOTENDS == 1
284
-        UNUSED(hotend);
284
+        UNUSED(e);
285 285
       #endif
286
-      target_temperature[HOTEND_ARG] = celsius;
286
+      target_temperature[HOTEND_INDEX] = celsius;
287 287
       #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
288
-        start_watching_heater(HOTEND_ARG);
288
+        start_watching_heater(HOTEND_INDEX);
289 289
       #endif
290 290
     }
291 291
 
@@ -296,19 +296,19 @@ class Temperature {
296 296
       #endif
297 297
     }
298 298
 
299
-    static bool isHeatingHotend(uint8_t hotend) {
299
+    static bool isHeatingHotend(uint8_t e) {
300 300
       #if HOTENDS == 1
301
-        UNUSED(hotend);
301
+        UNUSED(e);
302 302
       #endif
303
-      return target_temperature[HOTEND_ARG] > current_temperature[HOTEND_ARG];
303
+      return target_temperature[HOTEND_INDEX] > current_temperature[HOTEND_INDEX];
304 304
     }
305 305
     static bool isHeatingBed() { return target_temperature_bed > current_temperature_bed; }
306 306
 
307
-    static bool isCoolingHotend(uint8_t hotend) {
307
+    static bool isCoolingHotend(uint8_t e) {
308 308
       #if HOTENDS == 1
309
-        UNUSED(hotend);
309
+        UNUSED(e);
310 310
       #endif
311
-      return target_temperature[HOTEND_ARG] < current_temperature[HOTEND_ARG];
311
+      return target_temperature[HOTEND_INDEX] < current_temperature[HOTEND_INDEX];
312 312
     }
313 313
     static bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
314 314
 
@@ -338,8 +338,8 @@ class Temperature {
338 338
       #if ENABLED(AUTOTEMP)
339 339
         if (planner.autotemp_enabled) {
340 340
           planner.autotemp_enabled = false;
341
-          if (degTargetHotend(EXTRUDER_ARG) > planner.autotemp_min)
342
-            setTargetHotend(0, EXTRUDER_ARG);
341
+          if (degTargetHotend(EXTRUDER_IDX) > planner.autotemp_min)
342
+            setTargetHotend(0, EXTRUDER_IDX);
343 343
         }
344 344
       #endif
345 345
     }

Loading…
Cancel
Save