Browse Source

Further reduction when HOTENDS == 1

Scott Lahteine 8 years ago
parent
commit
ee0983ab57

+ 10
- 9
Marlin/Marlin_main.cpp View File

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

+ 8
- 8
Marlin/configuration_store.cpp View File

618
 
618
 
619
   #if ENABLED(PIDTEMP)
619
   #if ENABLED(PIDTEMP)
620
     #if ENABLED(PID_PARAMS_PER_HOTEND)
620
     #if ENABLED(PID_PARAMS_PER_HOTEND)
621
-      for (uint8_t e = 0; e < HOTENDS; e++)
621
+      HOTEND_LOOP
622
     #else
622
     #else
623
       int e = 0; UNUSED(e); // only need to write once
623
       int e = 0; UNUSED(e); // only need to write once
624
     #endif
624
     #endif
834
     #if ENABLED(PIDTEMP)
834
     #if ENABLED(PIDTEMP)
835
       #if HOTENDS > 1
835
       #if HOTENDS > 1
836
         if (forReplay) {
836
         if (forReplay) {
837
-          for (uint8_t i = 0; i < HOTENDS; i++) {
837
+          HOTEND_LOOP() {
838
             CONFIG_ECHO_START;
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
             #if ENABLED(PID_ADD_EXTRUSION_RATE)
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
             #endif
846
             #endif
847
             SERIAL_EOL;
847
             SERIAL_EOL;
848
           }
848
           }

+ 1
- 1
Marlin/dogm_lcd_implementation.h View File

392
   #endif
392
   #endif
393
 
393
 
394
   // Extruders
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
   // Heated bed
397
   // Heated bed
398
   #if HOTENDS < 4 && HAS_TEMP_BED
398
   #if HOTENDS < 4 && HAS_TEMP_BED

+ 25
- 16
Marlin/temperature.cpp View File

436
 
436
 
437
 void Temperature::updatePID() {
437
 void Temperature::updatePID() {
438
   #if ENABLED(PIDTEMP)
438
   #if ENABLED(PIDTEMP)
439
-    for (int e = 0; e < HOTENDS; e++) {
439
+    HOTEND_LOOP() {
440
       temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e);
440
       temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e);
441
       #if ENABLED(PID_ADD_EXTRUSION_RATE)
441
       #if ENABLED(PID_ADD_EXTRUSION_RATE)
442
         last_position[e] = 0;
442
         last_position[e] = 0;
465
       EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN ? 2 : 3
465
       EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN ? 2 : 3
466
     };
466
     };
467
     uint8_t fanState = 0;
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
     uint8_t fanDone = 0;
472
     uint8_t fanDone = 0;
473
-    for (int f = 0; f <= 3; f++) {
473
+    for (int8_t f = 0; f <= 3; f++) {
474
       int8_t pin = fanPin[f];
474
       int8_t pin = fanPin[f];
475
       if (pin >= 0 && !TEST(fanDone, fanBit[f])) {
475
       if (pin >= 0 && !TEST(fanDone, fanBit[f])) {
476
         unsigned char newFanSpeed = TEST(fanState, fanBit[f]) ? EXTRUDER_AUTO_FAN_SPEED : 0;
476
         unsigned char newFanSpeed = TEST(fanState, fanBit[f]) ? EXTRUDER_AUTO_FAN_SPEED : 0;
507
 }
507
 }
508
 
508
 
509
 void Temperature::max_temp_error(uint8_t e) {
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
 void Temperature::min_temp_error(uint8_t e) {
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
 float Temperature::get_pid_output(int e) {
522
 float Temperature::get_pid_output(int e) {
670
   #endif
676
   #endif
671
 
677
 
672
   // Loop through all hotends
678
   // Loop through all hotends
673
-  for (uint8_t e = 0; e < HOTENDS; e++) {
679
+  HOTEND_LOOP() {
674
 
680
 
675
     #if ENABLED(THERMAL_PROTECTION_HOTENDS)
681
     #if ENABLED(THERMAL_PROTECTION_HOTENDS)
676
       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);
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
   #if ENABLED(HEATER_0_USES_MAX6675)
883
   #if ENABLED(HEATER_0_USES_MAX6675)
878
     current_temperature_raw[0] = read_max6675();
884
     current_temperature_raw[0] = read_max6675();
879
   #endif
885
   #endif
880
-  for (uint8_t e = 0; e < HOTENDS; e++) {
886
+  HOTEND_LOOP() {
881
     current_temperature[e] = Temperature::analog2temp(current_temperature_raw[e], e);
887
     current_temperature[e] = Temperature::analog2temp(current_temperature_raw[e], e);
882
   }
888
   }
883
   current_temperature_bed = Temperature::analog2tempBed(current_temperature_bed_raw);
889
   current_temperature_bed = Temperature::analog2tempBed(current_temperature_bed_raw);
931
   #endif
937
   #endif
932
 
938
 
933
   // Finish init of mult hotend arrays
939
   // Finish init of mult hotend arrays
934
-  for (int e = 0; e < HOTENDS; e++) {
940
+  HOTEND_LOOP() {
935
     // populate with the first value
941
     // populate with the first value
936
     maxttemp[e] = maxttemp[0];
942
     maxttemp[e] = maxttemp[0];
937
     #if ENABLED(PIDTEMP)
943
     #if ENABLED(PIDTEMP)
1138
    * their target temperature by a configurable margin.
1144
    * their target temperature by a configurable margin.
1139
    * This is called when the temperature is set. (M104, M109)
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
     else
1155
     else
1147
-      watch_heater_next_ms[e] = 0;
1156
+      watch_heater_next_ms[HOTEND_INDEX] = 0;
1148
   }
1157
   }
1149
 #endif
1158
 #endif
1150
 
1159
 
1222
 #endif // THERMAL_PROTECTION_HOTENDS || THERMAL_PROTECTION_BED
1231
 #endif // THERMAL_PROTECTION_HOTENDS || THERMAL_PROTECTION_BED
1223
 
1232
 
1224
 void Temperature::disable_all_heaters() {
1233
 void Temperature::disable_all_heaters() {
1225
-  for (int i = 0; i < HOTENDS; i++) setTargetHotend(0, i);
1234
+  HOTEND_LOOP() setTargetHotend(0, e);
1226
   setTargetBed(0);
1235
   setTargetBed(0);
1227
 
1236
 
1228
   // If all heaters go down then for sure our print job has stopped
1237
   // If all heaters go down then for sure our print job has stopped

+ 28
- 28
Marlin/temperature.h View File

39
 #endif
39
 #endif
40
 
40
 
41
 #if HOTENDS == 1
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
 #else
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
 #endif
49
 #endif
50
 
50
 
51
 class Temperature {
51
 class Temperature {
245
     //inline so that there is no performance decrease.
245
     //inline so that there is no performance decrease.
246
     //deg=degreeCelsius
246
     //deg=degreeCelsius
247
 
247
 
248
-    static float degHotend(uint8_t hotend) {
248
+    static float degHotend(uint8_t e) {
249
       #if HOTENDS == 1
249
       #if HOTENDS == 1
250
-        UNUSED(hotend);
250
+        UNUSED(e);
251
       #endif
251
       #endif
252
-      return current_temperature[HOTEND_ARG];
252
+      return current_temperature[HOTEND_INDEX];
253
     }
253
     }
254
     static float degBed() { return current_temperature_bed; }
254
     static float degBed() { return current_temperature_bed; }
255
 
255
 
256
     #if ENABLED(SHOW_TEMP_ADC_VALUES)
256
     #if ENABLED(SHOW_TEMP_ADC_VALUES)
257
-    static float rawHotendTemp(uint8_t hotend) {
257
+    static float rawHotendTemp(uint8_t e) {
258
       #if HOTENDS == 1
258
       #if HOTENDS == 1
259
-        UNUSED(hotend);
259
+        UNUSED(e);
260
       #endif
260
       #endif
261
-      return current_temperature_raw[HOTEND_ARG];
261
+      return current_temperature_raw[HOTEND_INDEX];
262
     }
262
     }
263
     static float rawBedTemp() { return current_temperature_bed_raw; }
263
     static float rawBedTemp() { return current_temperature_bed_raw; }
264
     #endif
264
     #endif
265
 
265
 
266
-    static float degTargetHotend(uint8_t hotend) {
266
+    static float degTargetHotend(uint8_t e) {
267
       #if HOTENDS == 1
267
       #if HOTENDS == 1
268
-        UNUSED(hotend);
268
+        UNUSED(e);
269
       #endif
269
       #endif
270
-      return target_temperature[HOTEND_ARG];
270
+      return target_temperature[HOTEND_INDEX];
271
     }
271
     }
272
     static float degTargetBed() { return target_temperature_bed; }
272
     static float degTargetBed() { return target_temperature_bed; }
273
 
273
 
274
     #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
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
     #endif
276
     #endif
277
 
277
 
278
     #if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
278
     #if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
279
       static void start_watching_bed();
279
       static void start_watching_bed();
280
     #endif
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
       #if HOTENDS == 1
283
       #if HOTENDS == 1
284
-        UNUSED(hotend);
284
+        UNUSED(e);
285
       #endif
285
       #endif
286
-      target_temperature[HOTEND_ARG] = celsius;
286
+      target_temperature[HOTEND_INDEX] = celsius;
287
       #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
287
       #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
288
-        start_watching_heater(HOTEND_ARG);
288
+        start_watching_heater(HOTEND_INDEX);
289
       #endif
289
       #endif
290
     }
290
     }
291
 
291
 
296
       #endif
296
       #endif
297
     }
297
     }
298
 
298
 
299
-    static bool isHeatingHotend(uint8_t hotend) {
299
+    static bool isHeatingHotend(uint8_t e) {
300
       #if HOTENDS == 1
300
       #if HOTENDS == 1
301
-        UNUSED(hotend);
301
+        UNUSED(e);
302
       #endif
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
     static bool isHeatingBed() { return target_temperature_bed > current_temperature_bed; }
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
       #if HOTENDS == 1
308
       #if HOTENDS == 1
309
-        UNUSED(hotend);
309
+        UNUSED(e);
310
       #endif
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
     static bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
313
     static bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
314
 
314
 
338
       #if ENABLED(AUTOTEMP)
338
       #if ENABLED(AUTOTEMP)
339
         if (planner.autotemp_enabled) {
339
         if (planner.autotemp_enabled) {
340
           planner.autotemp_enabled = false;
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
       #endif
344
       #endif
345
     }
345
     }

Loading…
Cancel
Save