Procházet zdrojové kódy

Add and apply REPEAT macro (#15829)

Scott Lahteine před 4 roky
rodič
revize
776632c503
No account linked to committer's email address

+ 12
- 41
Marlin/src/Marlin.cpp Zobrazit soubor

@@ -286,7 +286,8 @@ void quickstop_stepper() {
286 286
 }
287 287
 
288 288
 void enable_e_steppers() {
289
-  enable_E0(); enable_E1(); enable_E2(); enable_E3(); enable_E4(); enable_E5();
289
+  #define _ENA_E(N) enable_E##N();
290
+  REPEAT(E_STEPPERS, _ENA_E)
290 291
 }
291 292
 
292 293
 void enable_all_steppers() {
@@ -300,17 +301,14 @@ void enable_all_steppers() {
300 301
 }
301 302
 
302 303
 void disable_e_steppers() {
303
-  disable_E0(); disable_E1(); disable_E2(); disable_E3(); disable_E4(); disable_E5();
304
+  #define _DIS_E(N) disable_E##N();
305
+  REPEAT(E_STEPPERS, _DIS_E)
304 306
 }
305 307
 
306 308
 void disable_e_stepper(const uint8_t e) {
309
+  #define _CASE_DIS_E(N) case N: disable_E##N(); break;
307 310
   switch (e) {
308
-    case 0: disable_E0(); break;
309
-    case 1: disable_E1(); break;
310
-    case 2: disable_E2(); break;
311
-    case 3: disable_E3(); break;
312
-    case 4: disable_E4(); break;
313
-    case 5: disable_E5(); break;
311
+    REPEAT(EXTRUDERS, _CASE_DIS_E)
314 312
   }
315 313
 }
316 314
 
@@ -547,24 +545,11 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
547 545
       #else // !SWITCHING_EXTRUDER
548 546
         bool oldstatus;
549 547
         switch (active_extruder) {
550
-          default: oldstatus = E0_ENABLE_READ(); enable_E0(); break;
551
-          #if E_STEPPERS > 1
552
-            case 1: oldstatus = E1_ENABLE_READ(); enable_E1(); break;
553
-            #if E_STEPPERS > 2
554
-              case 2: oldstatus = E2_ENABLE_READ(); enable_E2(); break;
555
-              #if E_STEPPERS > 3
556
-                case 3: oldstatus = E3_ENABLE_READ(); enable_E3(); break;
557
-                #if E_STEPPERS > 4
558
-                  case 4: oldstatus = E4_ENABLE_READ(); enable_E4(); break;
559
-                  #if E_STEPPERS > 5
560
-                    case 5: oldstatus = E5_ENABLE_READ(); enable_E5(); break;
561
-                  #endif // E_STEPPERS > 5
562
-                #endif // E_STEPPERS > 4
563
-              #endif // E_STEPPERS > 3
564
-            #endif // E_STEPPERS > 2
565
-          #endif // E_STEPPERS > 1
548
+          default:
549
+          #define _CASE_EN(N) case N: oldstatus = E##N_ENABLE_READ(); enable_E##N(); break;
550
+          REPEAT(E_STEPPERS, _CASE_EN);
566 551
         }
567
-      #endif // !SWITCHING_EXTRUDER
552
+      #endif
568 553
 
569 554
       const float olde = current_position.e;
570 555
       current_position.e += EXTRUDER_RUNOUT_EXTRUDE;
@@ -585,22 +570,8 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
585 570
         }
586 571
       #else // !SWITCHING_EXTRUDER
587 572
         switch (active_extruder) {
588
-          case 0: E0_ENABLE_WRITE(oldstatus); break;
589
-          #if E_STEPPERS > 1
590
-            case 1: E1_ENABLE_WRITE(oldstatus); break;
591
-            #if E_STEPPERS > 2
592
-              case 2: E2_ENABLE_WRITE(oldstatus); break;
593
-              #if E_STEPPERS > 3
594
-                case 3: E3_ENABLE_WRITE(oldstatus); break;
595
-                #if E_STEPPERS > 4
596
-                  case 4: E4_ENABLE_WRITE(oldstatus); break;
597
-                  #if E_STEPPERS > 5
598
-                    case 5: E5_ENABLE_WRITE(oldstatus); break;
599
-                  #endif // E_STEPPERS > 5
600
-                #endif // E_STEPPERS > 4
601
-              #endif // E_STEPPERS > 3
602
-            #endif // E_STEPPERS > 2
603
-          #endif // E_STEPPERS > 1
573
+          #define _CASE_RESTORE(N) case N: E##N##_ENABLE_WRITE(oldstatus); break;
574
+          REPEAT(E_STEPPERS, _CASE_RESTORE);
604 575
         }
605 576
       #endif // !SWITCHING_EXTRUDER
606 577
 

+ 125
- 26
Marlin/src/core/macros.h Zobrazit soubor

@@ -165,6 +165,7 @@
165 165
 
166 166
 // Macros to support option testing
167 167
 #define _CAT(a,V...) a##V
168
+#define CAT(a,V...) _CAT(a,V)
168 169
 #define SWITCH_ENABLED_false 0
169 170
 #define SWITCH_ENABLED_true  1
170 171
 #define SWITCH_ENABLED_0     0
@@ -229,32 +230,6 @@
229 230
 #define _JOIN_1(O)         (O)
230 231
 #define JOIN_N(N,C,V...)   (DO(JOIN,C,LIST_N(N,V)))
231 232
 
232
-// Macros for adding
233
-#define INC_0 1
234
-#define INC_1 2
235
-#define INC_2 3
236
-#define INC_3 4
237
-#define INC_4 5
238
-#define INC_5 6
239
-#define INC_6 7
240
-#define INC_7 8
241
-#define INC_8 9
242
-#define INCREMENT_(n) INC_##n
243
-#define INCREMENT(n) INCREMENT_(n)
244
-
245
-// Macros for subtracting
246
-#define DEC_1 0
247
-#define DEC_2 1
248
-#define DEC_3 2
249
-#define DEC_4 3
250
-#define DEC_5 4
251
-#define DEC_6 5
252
-#define DEC_7 6
253
-#define DEC_8 7
254
-#define DEC_9 8
255
-#define DECREMENT_(n) DEC_##n
256
-#define DECREMENT(n) DECREMENT_(n)
257
-
258 233
 #define NOOP (void(0))
259 234
 
260 235
 #define CEILING(x,y) (((x) + (y) - 1) / (y))
@@ -346,3 +321,127 @@
346 321
   #define _MAX(V...)      _MAX_N(NUM_ARGS(V), V)
347 322
 
348 323
 #endif
324
+
325
+// Macros for adding
326
+#define INC_0 1
327
+#define INC_1 2
328
+#define INC_2 3
329
+#define INC_3 4
330
+#define INC_4 5
331
+#define INC_5 6
332
+#define INC_6 7
333
+#define INC_7 8
334
+#define INC_8 9
335
+#define INCREMENT_(n) INC_##n
336
+#define INCREMENT(n) INCREMENT_(n)
337
+
338
+#define ADD0(N)  N
339
+#define ADD1(N)  INCREMENT_(N)
340
+#define ADD2(N)  ADD1(ADD1(N))
341
+#define ADD3(N)  ADD1(ADD2(N))
342
+#define ADD4(N)  ADD2(ADD2(N))
343
+#define ADD5(N)  ADD2(ADD3(N))
344
+#define ADD6(N)  ADD3(ADD3(N))
345
+#define ADD7(N)  ADD3(ADD4(N))
346
+#define ADD8(N)  ADD4(ADD4(N))
347
+#define ADD9(N)  ADD4(ADD5(N))
348
+#define ADD10(N) ADD5(ADD5(N))
349
+
350
+// Macros for subtracting
351
+#define DEC_0 0
352
+#define DEC_1 0
353
+#define DEC_2 1
354
+#define DEC_3 2
355
+#define DEC_4 3
356
+#define DEC_5 4
357
+#define DEC_6 5
358
+#define DEC_7 6
359
+#define DEC_8 7
360
+#define DEC_9 8
361
+#define DECREMENT_(n) DEC_##n
362
+#define DECREMENT(n) DECREMENT_(n)
363
+
364
+#define SUB0(N)  N
365
+#define SUB1(N)  DECREMENT_(N)
366
+#define SUB2(N)  SUB1(SUB1(N))
367
+#define SUB3(N)  SUB1(SUB2(N))
368
+#define SUB4(N)  SUB2(SUB2(N))
369
+#define SUB5(N)  SUB2(SUB3(N))
370
+#define SUB6(N)  SUB3(SUB3(N))
371
+#define SUB7(N)  SUB3(SUB4(N))
372
+#define SUB8(N)  SUB4(SUB4(N))
373
+#define SUB9(N)  SUB4(SUB5(N))
374
+#define SUB10(N) SUB5(SUB5(N))
375
+
376
+//
377
+// Primitives supporting precompiler REPEAT
378
+//
379
+#define FIRST(a,...)    a
380
+#define SECOND(a,b,...) b
381
+
382
+// Defer expansion
383
+#define EMPTY()
384
+#define DEFER(M)  M EMPTY()
385
+#define DEFER2(M) M EMPTY EMPTY()()
386
+#define DEFER3(M) M EMPTY EMPTY EMPTY()()()
387
+#define DEFER4(M) M EMPTY EMPTY EMPTY EMPTY()()()()
388
+
389
+// Force define expansion
390
+#define EVAL(V...)     EVAL16(V)
391
+#define EVAL1024(V...) EVAL512(EVAL512(V))
392
+#define EVAL512(V...)  EVAL256(EVAL256(V))
393
+#define EVAL256(V...)  EVAL128(EVAL128(V))
394
+#define EVAL128(V...)  EVAL64(EVAL64(V))
395
+#define EVAL64(V...)   EVAL32(EVAL32(V))
396
+#define EVAL32(V...)   EVAL16(EVAL16(V))
397
+#define EVAL16(V...)   EVAL8(EVAL8(V))
398
+#define EVAL8(V...)    EVAL4(EVAL4(V))
399
+#define EVAL4(V...)    EVAL2(EVAL2(V))
400
+#define EVAL2(V...)    EVAL1(EVAL1(V))
401
+#define EVAL1(V...)    V
402
+
403
+#define IS_PROBE(V...) SECOND(V, 0)     // Get the second item passed, or 0
404
+#define PROBE() ~, 1                    // Second item will be 1 if this is passed
405
+#define _NOT_0 PROBE()
406
+#define NOT(x) IS_PROBE(_CAT(_NOT_, x)) // NOT('0') gets '1'. Anything else gets '0'.
407
+#define _BOOL(x) NOT(NOT(x))            // NOT('0') gets '0'. Anything else gets '1'.
408
+
409
+#define IF_ELSE(TF) _IF_ELSE(_BOOL(TF))
410
+#define _IF_ELSE(TF) _CAT(_IF_, TF)
411
+
412
+#define _IF_1(V...) V _IF_1_ELSE
413
+#define _IF_0(...)    _IF_0_ELSE
414
+
415
+#define _IF_1_ELSE(...)
416
+#define _IF_0_ELSE(V...) V
417
+
418
+#define HAS_ARGS(V...) _BOOL(FIRST(_END_OF_ARGUMENTS_ V)())
419
+#define _END_OF_ARGUMENTS_() 0
420
+
421
+//
422
+// REPEAT core macros. Recurse N times with ascending I.
423
+//
424
+
425
+// Call OP(I) N times with ascending counter.
426
+#define _REPEAT(_RPT_I,_RPT_N,_RPT_OP)                        \
427
+  _RPT_OP(_RPT_I)                                             \
428
+  IF_ELSE(SUB1(_RPT_N))                                       \
429
+    ( DEFER2(__REPEAT)()(ADD1(_RPT_I),SUB1(_RPT_N),_RPT_OP) ) \
430
+    ( /* Do nothing */ )
431
+#define __REPEAT() _REPEAT
432
+
433
+// Call OP(I, ...) N times with ascending counter.
434
+#define _REPEAT2(_RPT_I,_RPT_N,_RPT_OP,V...)                     \
435
+  _RPT_OP(_RPT_I,V)                                              \
436
+  IF_ELSE(SUB1(_RPT_N))                                          \
437
+    ( DEFER2(__REPEAT2)()(ADD1(_RPT_I),SUB1(_RPT_N),_RPT_OP,V) ) \
438
+    ( /* Do nothing */ )
439
+#define __REPEAT2() _REPEAT2
440
+
441
+// Repeat a macro passing S...N-1.
442
+#define REPEAT_S(S,N,OP)        EVAL(_REPEAT(S,SUB##S(N),OP))
443
+#define REPEAT(N,OP)            REPEAT_S(0,N,OP)
444
+
445
+// Repeat a macro passing 0...N-1 plus additional arguments.
446
+#define REPEAT2_S(S,N,OP,V...)  EVAL(_REPEAT2(S,SUB##S(N),OP,V))
447
+#define REPEAT2(N,OP,V...)      REPEAT2_S(0,N,OP,V)

+ 3
- 17
Marlin/src/feature/controllerfan.cpp Zobrazit soubor

@@ -56,23 +56,9 @@ void controllerfan_update() {
56 56
           || Z3_ENABLE_READ() == Z_ENABLE_ON
57 57
         #endif
58 58
         #if E_STEPPERS
59
-          || E0_ENABLE_READ() == E_ENABLE_ON
60
-          #if E_STEPPERS > 1
61
-            || E1_ENABLE_READ() == E_ENABLE_ON
62
-            #if E_STEPPERS > 2
63
-              || E2_ENABLE_READ() == E_ENABLE_ON
64
-              #if E_STEPPERS > 3
65
-                || E3_ENABLE_READ() == E_ENABLE_ON
66
-                #if E_STEPPERS > 4
67
-                  || E4_ENABLE_READ() == E_ENABLE_ON
68
-                  #if E_STEPPERS > 5
69
-                    || E5_ENABLE_READ() == E_ENABLE_ON
70
-                  #endif // E_STEPPERS > 5
71
-                #endif // E_STEPPERS > 4
72
-              #endif // E_STEPPERS > 3
73
-            #endif // E_STEPPERS > 2
74
-          #endif // E_STEPPERS > 1
75
-        #endif // E_STEPPERS
59
+          #define _OR_ENABLED_E(N) || E##N##_ENABLE_READ() == E_ENABLE_ON
60
+          REPEAT(E_STEPPERS, _OR_ENABLED_E)
61
+        #endif
76 62
     ) {
77 63
       lastMotorOn = ms; //... set time to NOW so the fan will turn on
78 64
     }

+ 13
- 27
Marlin/src/feature/power.cpp Zobrazit soubor

@@ -59,33 +59,19 @@ bool Power::is_power_needed() {
59 59
     #if HAS_HEATED_BED
60 60
       || thermalManager.temp_bed.soft_pwm_amount > 0
61 61
     #endif
62
-      #if HAS_X2_ENABLE
63
-        || X2_ENABLE_READ() == X_ENABLE_ON
64
-      #endif
65
-      #if HAS_Y2_ENABLE
66
-        || Y2_ENABLE_READ() == Y_ENABLE_ON
67
-      #endif
68
-      #if HAS_Z2_ENABLE
69
-        || Z2_ENABLE_READ() == Z_ENABLE_ON
70
-      #endif
71
-      #if E_STEPPERS
72
-        || E0_ENABLE_READ() == E_ENABLE_ON
73
-        #if E_STEPPERS > 1
74
-          || E1_ENABLE_READ() == E_ENABLE_ON
75
-          #if E_STEPPERS > 2
76
-            || E2_ENABLE_READ() == E_ENABLE_ON
77
-            #if E_STEPPERS > 3
78
-              || E3_ENABLE_READ() == E_ENABLE_ON
79
-              #if E_STEPPERS > 4
80
-                || E4_ENABLE_READ() == E_ENABLE_ON
81
-                #if E_STEPPERS > 5
82
-                  || E5_ENABLE_READ() == E_ENABLE_ON
83
-                #endif // E_STEPPERS > 5
84
-              #endif // E_STEPPERS > 4
85
-            #endif // E_STEPPERS > 3
86
-          #endif // E_STEPPERS > 2
87
-        #endif // E_STEPPERS > 1
88
-      #endif // E_STEPPERS
62
+    #if HAS_X2_ENABLE
63
+      || X2_ENABLE_READ() == X_ENABLE_ON
64
+    #endif
65
+    #if HAS_Y2_ENABLE
66
+      || Y2_ENABLE_READ() == Y_ENABLE_ON
67
+    #endif
68
+    #if HAS_Z2_ENABLE
69
+      || Z2_ENABLE_READ() == Z_ENABLE_ON
70
+    #endif
71
+    #if E_STEPPERS
72
+      #define _OR_ENABLED_E(N) || E##N##_ENABLE_READ() == E_ENABLE_ON
73
+      REPEAT(E_STEPPERS, _OR_ENABLED_E)
74
+    #endif
89 75
   ) return true;
90 76
 
91 77
   HOTEND_LOOP() if (thermalManager.degTargetHotend(e) > 0) return true;

+ 1
- 14
Marlin/src/gcode/feature/mixing/M163-M165.cpp Zobrazit soubor

@@ -79,20 +79,7 @@ void GcodeSuite::M164() {
79 79
     // Get mixing parameters from the GCode
80 80
     // The total "must" be 1.0 (but it will be normalized)
81 81
     // If no mix factors are given, the old mix is preserved
82
-    const char mixing_codes[] = { 'A', 'B'
83
-      #if MIXING_STEPPERS > 2
84
-        , 'C'
85
-        #if MIXING_STEPPERS > 3
86
-          , 'D'
87
-          #if MIXING_STEPPERS > 4
88
-            , 'H'
89
-            #if MIXING_STEPPERS > 5
90
-              , 'I'
91
-            #endif // MIXING_STEPPERS > 5
92
-          #endif // MIXING_STEPPERS > 4
93
-        #endif // MIXING_STEPPERS > 3
94
-      #endif // MIXING_STEPPERS > 2
95
-    };
82
+    const char mixing_codes[] = { LIST_N(MIXING_STEPPERS, 'A', 'B', 'C', 'D', 'H', 'I') };
96 83
     uint8_t mix_bits = 0;
97 84
     MIXER_STEPPER_LOOP(i) {
98 85
       if (parser.seenval(mixing_codes[i])) {

+ 1
- 1
Marlin/src/inc/Conditionals_post.h Zobrazit soubor

@@ -1017,7 +1017,7 @@
1017 1017
 #define HAS_TEMP_ADC_BED HAS_ADC_TEST(BED)
1018 1018
 #define HAS_TEMP_ADC_CHAMBER HAS_ADC_TEST(CHAMBER)
1019 1019
 
1020
-#define HAS_TEMP_HOTEND (HAS_TEMP_ADC_0 || ENABLED(HEATER_0_USES_MAX6675))
1020
+#define HAS_TEMP_HOTEND (HOTENDS > 0 && (HAS_TEMP_ADC_0 || ENABLED(HEATER_0_USES_MAX6675)))
1021 1021
 #define HAS_TEMP_BED HAS_TEMP_ADC_BED
1022 1022
 #define HAS_TEMP_CHAMBER HAS_TEMP_ADC_CHAMBER
1023 1023
 #define HAS_HEATED_CHAMBER (HAS_TEMP_CHAMBER && PIN_EXISTS(HEATER_CHAMBER))

+ 2
- 16
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/temperature_screen.cpp Zobrazit soubor

@@ -85,22 +85,8 @@ bool TemperatureScreen::onTouchHeld(uint8_t tag) {
85 85
     case 11: UI_INCREMENT(TargetFan_percent, FAN0); break;
86 86
     #endif
87 87
     case 30:
88
-      setTargetTemp_celsius(0,E0);
89
-      #if HOTENDS > 1
90
-        setTargetTemp_celsius(0,E1);
91
-        #if HOTENDS > 2
92
-          setTargetTemp_celsius(0,E2);
93
-          #if HOTENDS > 3
94
-            setTargetTemp_celsius(0,E3);
95
-            #if HOTENDS > 4
96
-              setTargetTemp_celsius(0,E4);
97
-              #if HOTENDS > 5
98
-                setTargetTemp_celsius(0,E5);
99
-              #endif
100
-            #endif
101
-          #endif
102
-        #endif
103
-      #endif
88
+      #define _HOTEND_OFF(N) setTargetTemp_celsius(0,E##N);
89
+      REPEAT(HOTENDS, _HOTEND_OFF);
104 90
       #if HAS_HEATED_BED
105 91
         setTargetTemp_celsius(0,BED);
106 92
       #endif

+ 4
- 2
Marlin/src/lcd/menu/menu_configuration.cpp Zobrazit soubor

@@ -277,8 +277,10 @@ void menu_advanced_settings();
277 277
 #if DISABLED(SLIM_LCD_MENUS)
278 278
 
279 279
   void _menu_configuration_preheat_settings(const uint8_t material) {
280
-    #define MINTEMP_ALL _MIN(LIST_N(HOTENDS, HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP, HEATER_4_MINTEMP, HEATER_5_MINTEMP), 999)
281
-    #define MAXTEMP_ALL _MAX(LIST_N(HOTENDS, HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP, HEATER_5_MAXTEMP), 0)
280
+    #define _MINTEMP_ITEM(N) HEATER_##N##_MINTEMP,
281
+    #define _MAXTEMP_ITEM(N) HEATER_##N##_MAXTEMP,
282
+    #define MINTEMP_ALL _MIN(REPEAT(HOTENDS, _MINTEMP_ITEM) 999)
283
+    #define MAXTEMP_ALL _MAX(REPEAT(HOTENDS, _MAXTEMP_ITEM) 0)
282 284
     START_MENU();
283 285
     BACK_ITEM(MSG_CONFIGURATION);
284 286
     EDIT_ITEM(percent, MSG_FAN_SPEED, &ui.preheat_fan_speed[material], 0, 255);

+ 4
- 2
Marlin/src/lcd/menu/menu_mixer.cpp Zobrazit soubor

@@ -158,10 +158,11 @@ void lcd_mixer_mix_edit() {
158 158
 
159 159
   #if CHANNEL_MIX_EDITING
160 160
 
161
-    #define EDIT_COLOR(N) EDIT_ITEM_FAST(float52, MSG_MIX_COMPONENT_##N, &mixer.collector[N-1], 0, 10);
162
-
163 161
     START_MENU();
164 162
     BACK_ITEM(MSG_MIXER);
163
+
164
+    #define EDIT_COLOR(N) EDIT_ITEM_FAST(float52, MSG_MIX_COMPONENT_##N, &mixer.collector[N-1], 0, 10);
165
+
165 166
     EDIT_COLOR(1);
166 167
     EDIT_COLOR(2);
167 168
     #if MIXING_STEPPERS > 2
@@ -176,6 +177,7 @@ void lcd_mixer_mix_edit() {
176 177
         #endif
177 178
       #endif
178 179
     #endif
180
+
179 181
     ACTION_ITEM(MSG_CYCLE_MIX, _lcd_mixer_cycle_mix);
180 182
     ACTION_ITEM(MSG_COMMIT_VTOOL, _lcd_mixer_commit_vtool);
181 183
     END_MENU();

+ 21
- 110
Marlin/src/module/planner.cpp Zobrazit soubor

@@ -1924,121 +1924,32 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
1924 1924
 
1925 1925
       #if ENABLED(DISABLE_INACTIVE_EXTRUDER) // Enable only the selected extruder
1926 1926
 
1927
-        #define DISABLE_IDLE_E(N) if (!g_uc_extruder_last_move[N]) disable_E##N();
1928
-
1929 1927
         for (uint8_t i = 0; i < EXTRUDERS; i++)
1930 1928
           if (g_uc_extruder_last_move[i] > 0) g_uc_extruder_last_move[i]--;
1931 1929
 
1932
-        switch (extruder) {
1933
-          case 0:
1934
-            #if EXTRUDERS > 1
1935
-              DISABLE_IDLE_E(1);
1936
-              #if EXTRUDERS > 2
1937
-                DISABLE_IDLE_E(2);
1938
-                #if EXTRUDERS > 3
1939
-                  DISABLE_IDLE_E(3);
1940
-                  #if EXTRUDERS > 4
1941
-                    DISABLE_IDLE_E(4);
1942
-                    #if EXTRUDERS > 5
1943
-                      DISABLE_IDLE_E(5);
1944
-                    #endif // EXTRUDERS > 5
1945
-                  #endif // EXTRUDERS > 4
1946
-                #endif // EXTRUDERS > 3
1947
-              #endif // EXTRUDERS > 2
1948
-            #endif // EXTRUDERS > 1
1949
-            enable_E0();
1950
-            g_uc_extruder_last_move[0] = (BLOCK_BUFFER_SIZE) * 2;
1951
-            #if HAS_DUPLICATION_MODE
1952
-              if (extruder_duplication_enabled) {
1953
-                enable_E1();
1954
-                g_uc_extruder_last_move[1] = (BLOCK_BUFFER_SIZE) * 2;
1955
-              }
1956
-            #endif
1957
-          break;
1958
-          #if EXTRUDERS > 1
1959
-            case 1:
1960
-              DISABLE_IDLE_E(0);
1961
-              #if EXTRUDERS > 2
1962
-                DISABLE_IDLE_E(2);
1963
-                #if EXTRUDERS > 3
1964
-                  DISABLE_IDLE_E(3);
1965
-                  #if EXTRUDERS > 4
1966
-                    DISABLE_IDLE_E(4);
1967
-                    #if EXTRUDERS > 5
1968
-                      DISABLE_IDLE_E(5);
1969
-                    #endif // EXTRUDERS > 5
1970
-                  #endif // EXTRUDERS > 4
1971
-                #endif // EXTRUDERS > 3
1972
-              #endif // EXTRUDERS > 2
1973
-              enable_E1();
1974
-              g_uc_extruder_last_move[1] = (BLOCK_BUFFER_SIZE) * 2;
1975
-            break;
1976
-            #if EXTRUDERS > 2
1977
-              case 2:
1978
-                DISABLE_IDLE_E(0);
1979
-                DISABLE_IDLE_E(1);
1980
-                #if EXTRUDERS > 3
1981
-                  DISABLE_IDLE_E(3);
1982
-                  #if EXTRUDERS > 4
1983
-                    DISABLE_IDLE_E(4);
1984
-                    #if EXTRUDERS > 5
1985
-                      DISABLE_IDLE_E(5);
1986
-                    #endif
1987
-                  #endif
1988
-                #endif
1989
-                enable_E2();
1990
-                g_uc_extruder_last_move[2] = (BLOCK_BUFFER_SIZE) * 2;
1991
-              break;
1992
-              #if EXTRUDERS > 3
1993
-                case 3:
1994
-                  DISABLE_IDLE_E(0);
1995
-                  DISABLE_IDLE_E(1);
1996
-                  DISABLE_IDLE_E(2);
1997
-                  #if EXTRUDERS > 4
1998
-                    DISABLE_IDLE_E(4);
1999
-                    #if EXTRUDERS > 5
2000
-                      DISABLE_IDLE_E(5);
2001
-                    #endif
2002
-                  #endif
2003
-                  enable_E3();
2004
-                  g_uc_extruder_last_move[3] = (BLOCK_BUFFER_SIZE) * 2;
2005
-                break;
2006
-                #if EXTRUDERS > 4
2007
-                  case 4:
2008
-                    DISABLE_IDLE_E(0);
2009
-                    DISABLE_IDLE_E(1);
2010
-                    DISABLE_IDLE_E(2);
2011
-                    DISABLE_IDLE_E(3);
2012
-                    #if EXTRUDERS > 5
2013
-                      DISABLE_IDLE_E(5);
2014
-                    #endif
2015
-                    enable_E4();
2016
-                    g_uc_extruder_last_move[4] = (BLOCK_BUFFER_SIZE) * 2;
2017
-                  break;
2018
-                  #if EXTRUDERS > 5
2019
-                    case 5:
2020
-                      DISABLE_IDLE_E(0);
2021
-                      DISABLE_IDLE_E(1);
2022
-                      DISABLE_IDLE_E(2);
2023
-                      DISABLE_IDLE_E(3);
2024
-                      DISABLE_IDLE_E(4);
2025
-                      enable_E5();
2026
-                      g_uc_extruder_last_move[5] = (BLOCK_BUFFER_SIZE) * 2;
2027
-                    break;
2028
-                  #endif // EXTRUDERS > 5
2029
-                #endif // EXTRUDERS > 4
2030
-              #endif // EXTRUDERS > 3
2031
-            #endif // EXTRUDERS > 2
2032
-          #endif // EXTRUDERS > 1
2033
-        }
1930
+        #if HAS_DUPLICATION_MODE
1931
+          if (extruder_duplication_enabled && extruder == 0) {
1932
+            enable_E1();
1933
+            g_uc_extruder_last_move[1] = (BLOCK_BUFFER_SIZE) * 2;
1934
+          }
1935
+        #endif
1936
+
1937
+        #define ENABLE_ONE_E(N) do{ \
1938
+          if (extruder == N) { \
1939
+            enable_E##N(); \
1940
+            g_uc_extruder_last_move[N] = (BLOCK_BUFFER_SIZE) * 2; \
1941
+          } \
1942
+          else if (!g_uc_extruder_last_move[N]) \
1943
+            disable_E##N(); \
1944
+        }while(0);
1945
+
2034 1946
       #else
2035
-        enable_E0();
2036
-        enable_E1();
2037
-        enable_E2();
2038
-        enable_E3();
2039
-        enable_E4();
2040
-        enable_E5();
1947
+
1948
+        #define ENABLE_ONE_E(N) enable_E##N();
1949
+
2041 1950
       #endif
1951
+
1952
+      REPEAT(EXTRUDERS, ENABLE_ONE_E);
2042 1953
     }
2043 1954
   #endif // EXTRUDERS
2044 1955
 

+ 33
- 131
Marlin/src/module/temperature.cpp Zobrazit soubor

@@ -628,31 +628,31 @@ int16_t Temperature::getHeaterPower(const heater_ind_t heater_id) {
628 628
   #define CHAMBER_FAN_INDEX HOTENDS
629 629
 
630 630
   void Temperature::checkExtruderAutoFans() {
631
-    #define _EFAN(A,B) _EFANOVERLAP(A,B) ? B :
631
+    #define _EFAN(B,A) _EFANOVERLAP(A,B) ? B :
632 632
     static const uint8_t fanBit[] PROGMEM = {
633 633
       0
634 634
       #if HOTENDS > 1
635
-        , _EFAN(1,0) 1
636
-      #endif
637
-      #if HOTENDS > 2
638
-        , _EFAN(2,0) _EFAN(2,1) 2
639
-      #endif
640
-      #if HOTENDS > 3
641
-        , _EFAN(3,0) _EFAN(3,1) _EFAN(3,2) 3
642
-      #endif
643
-      #if HOTENDS > 4
644
-        , _EFAN(4,0) _EFAN(4,1) _EFAN(4,2) _EFAN(4,3) 4
645
-      #endif
646
-      #if HOTENDS > 5
647
-        , _EFAN(5,0) _EFAN(5,1) _EFAN(5,2) _EFAN(5,3) _EFAN(5,4) 5
635
+        , REPEAT2(1,_EFAN,1) 1
636
+        #if HOTENDS > 2
637
+          , REPEAT2(2,_EFAN,2) 2
638
+          #if HOTENDS > 3
639
+            , REPEAT2(3,_EFAN,3) 3
640
+            #if HOTENDS > 4
641
+              , REPEAT2(4,_EFAN,4) 4
642
+              #if HOTENDS > 5
643
+                , REPEAT2(5,_EFAN,5) 5
644
+              #endif
645
+            #endif
646
+          #endif
647
+        #endif
648 648
       #endif
649 649
       #if HAS_AUTO_CHAMBER_FAN
650 650
         #define _CFAN(B) _FANOVERLAP(CHAMBER,B) ? B :
651
-        , _CFAN(0) _CFAN(1) _CFAN(2) _CFAN(3) _CFAN(4) _CFAN(5) 6
651
+        , REPEAT(HOTENDS,_CFAN) (HOTENDS)
652 652
       #endif
653 653
     };
654
-    uint8_t fanState = 0;
655 654
 
655
+    uint8_t fanState = 0;
656 656
     HOTEND_LOOP()
657 657
       if (temp_hotend[e].celsius >= EXTRUDER_AUTO_FAN_TEMPERATURE)
658 658
         SBI(fanState, pgm_read_byte(&fanBit[e]));
@@ -1953,22 +1953,7 @@ void Temperature::disable_all_heaters() {
1953 1953
   }
1954 1954
 
1955 1955
   #if HAS_TEMP_HOTEND
1956
-    DISABLE_HEATER(0);
1957
-    #if HOTENDS > 1
1958
-      DISABLE_HEATER(1);
1959
-      #if HOTENDS > 2
1960
-        DISABLE_HEATER(2);
1961
-        #if HOTENDS > 3
1962
-          DISABLE_HEATER(3);
1963
-          #if HOTENDS > 4
1964
-            DISABLE_HEATER(4);
1965
-            #if HOTENDS > 5
1966
-              DISABLE_HEATER(5);
1967
-            #endif // HOTENDS > 5
1968
-          #endif // HOTENDS > 4
1969
-        #endif // HOTENDS > 3
1970
-      #endif // HOTENDS > 2
1971
-    #endif // HOTENDS > 1
1956
+    REPEAT(HOTENDS, DISABLE_HEATER);
1972 1957
   #endif
1973 1958
 
1974 1959
   #if HAS_HEATED_BED
@@ -2223,22 +2208,14 @@ void Temperature::readings_ready() {
2223 2208
         TEMPDIR(0)
2224 2209
       #endif
2225 2210
       #if HOTENDS > 1
2211
+        #define _TEMPDIR(N) , TEMPDIR(N)
2226 2212
         #if ENABLED(HEATER_1_USES_MAX6675)
2227 2213
           , 0
2228 2214
         #else
2229
-          , TEMPDIR(1)
2215
+          _TEMPDIR(1)
2230 2216
         #endif
2231 2217
         #if HOTENDS > 2
2232
-          , TEMPDIR(2)
2233
-          #if HOTENDS > 3
2234
-            , TEMPDIR(3)
2235
-            #if HOTENDS > 4
2236
-              , TEMPDIR(4)
2237
-              #if HOTENDS > 5
2238
-                , TEMPDIR(5)
2239
-              #endif // HOTENDS > 5
2240
-            #endif // HOTENDS > 4
2241
-          #endif // HOTENDS > 3
2218
+          REPEAT_S(2, HOTENDS, _TEMPDIR)
2242 2219
         #endif // HOTENDS > 2
2243 2220
       #endif // HOTENDS > 1
2244 2221
     };
@@ -2391,24 +2368,9 @@ void Temperature::isr() {
2391 2368
       pwm_count_tmp -= 127;
2392 2369
 
2393 2370
       #if HOTENDS
2394
-        #define _PWM_MOD_E(N) _PWM_MOD(N,soft_pwm_hotend[N],temp_hotend[N])
2395
-        _PWM_MOD_E(0);
2396
-        #if HOTENDS > 1
2397
-          _PWM_MOD_E(1);
2398
-          #if HOTENDS > 2
2399
-            _PWM_MOD_E(2);
2400
-            #if HOTENDS > 3
2401
-              _PWM_MOD_E(3);
2402
-              #if HOTENDS > 4
2403
-                _PWM_MOD_E(4);
2404
-                #if HOTENDS > 5
2405
-                  _PWM_MOD_E(5);
2406
-                #endif // HOTENDS > 5
2407
-              #endif // HOTENDS > 4
2408
-            #endif // HOTENDS > 3
2409
-          #endif // HOTENDS > 2
2410
-        #endif // HOTENDS > 1
2411
-      #endif // HOTENDS
2371
+        #define _PWM_MOD_E(N) _PWM_MOD(N,soft_pwm_hotend[N],temp_hotend[N]);
2372
+        REPEAT(HOTENDS, _PWM_MOD_E);
2373
+      #endif
2412 2374
 
2413 2375
       #if HAS_HEATED_BED
2414 2376
         _PWM_MOD(BED,soft_pwm_bed,temp_bed);
@@ -2438,24 +2400,9 @@ void Temperature::isr() {
2438 2400
     else {
2439 2401
       #define _PWM_LOW(N,S) do{ if (S.count <= pwm_count_tmp) WRITE_HEATER_##N(LOW); }while(0)
2440 2402
       #if HOTENDS
2441
-        #define _PWM_LOW_E(N) _PWM_LOW(N, soft_pwm_hotend[N])
2442
-        _PWM_LOW_E(0);
2443
-        #if HOTENDS > 1
2444
-          _PWM_LOW_E(1);
2445
-          #if HOTENDS > 2
2446
-            _PWM_LOW_E(2);
2447
-            #if HOTENDS > 3
2448
-              _PWM_LOW_E(3);
2449
-              #if HOTENDS > 4
2450
-                _PWM_LOW_E(4);
2451
-                #if HOTENDS > 5
2452
-                  _PWM_LOW_E(5);
2453
-                #endif // HOTENDS > 5
2454
-              #endif // HOTENDS > 4
2455
-            #endif // HOTENDS > 3
2456
-          #endif // HOTENDS > 2
2457
-        #endif // HOTENDS > 1
2458
-      #endif // HOTENDS
2403
+        #define _PWM_LOW_E(N) _PWM_LOW(N, soft_pwm_hotend[N]);
2404
+        REPEAT(HOTENDS, _PWM_LOW_E);
2405
+      #endif
2459 2406
 
2460 2407
       #if HAS_HEATED_BED
2461 2408
         _PWM_LOW(BED, soft_pwm_bed);
@@ -2504,24 +2451,9 @@ void Temperature::isr() {
2504 2451
     if (slow_pwm_count == 0) {
2505 2452
 
2506 2453
       #if HOTENDS
2507
-        #define _SLOW_PWM_E(N) _SLOW_PWM(N, soft_pwm_hotend[N], temp_hotend[N])
2508
-        _SLOW_PWM_E(0);
2509
-        #if HOTENDS > 1
2510
-          _SLOW_PWM_E(1);
2511
-          #if HOTENDS > 2
2512
-            _SLOW_PWM_E(2);
2513
-            #if HOTENDS > 3
2514
-              _SLOW_PWM_E(3);
2515
-              #if HOTENDS > 4
2516
-                _SLOW_PWM_E(4);
2517
-                #if HOTENDS > 5
2518
-                  _SLOW_PWM_E(5);
2519
-                #endif // HOTENDS > 5
2520
-              #endif // HOTENDS > 4
2521
-            #endif // HOTENDS > 3
2522
-          #endif // HOTENDS > 2
2523
-        #endif // HOTENDS > 1
2524
-      #endif // HOTENDS
2454
+        #define _SLOW_PWM_E(N) _SLOW_PWM(N, soft_pwm_hotend[N], temp_hotend[N]);
2455
+        REPEAT(HOTENDS, _SLOW_PWM_E);
2456
+      #endif
2525 2457
 
2526 2458
       #if HAS_HEATED_BED
2527 2459
         _SLOW_PWM(BED, soft_pwm_bed, temp_bed);
@@ -2531,23 +2463,8 @@ void Temperature::isr() {
2531 2463
 
2532 2464
     #if HOTENDS
2533 2465
       #define _PWM_OFF_E(N) _PWM_OFF(N, soft_pwm_hotend[N]);
2534
-      _PWM_OFF_E(0);
2535
-      #if HOTENDS > 1
2536
-        _PWM_OFF_E(1);
2537
-        #if HOTENDS > 2
2538
-          _PWM_OFF_E(2);
2539
-          #if HOTENDS > 3
2540
-            _PWM_OFF_E(3);
2541
-            #if HOTENDS > 4
2542
-              _PWM_OFF_E(4);
2543
-              #if HOTENDS > 5
2544
-                _PWM_OFF_E(5);
2545
-              #endif // HOTENDS > 5
2546
-            #endif // HOTENDS > 4
2547
-          #endif // HOTENDS > 3
2548
-        #endif // HOTENDS > 2
2549
-      #endif // HOTENDS > 1
2550
-    #endif // HOTENDS
2466
+      REPEAT(HOTENDS, _PWM_OFF_E);
2467
+    #endif
2551 2468
 
2552 2469
     #if HAS_HEATED_BED
2553 2470
       _PWM_OFF(BED, soft_pwm_bed);
@@ -2598,23 +2515,8 @@ void Temperature::isr() {
2598 2515
       slow_pwm_count &= 0x7F;
2599 2516
 
2600 2517
       #if HOTENDS
2601
-        soft_pwm_hotend[0].dec();
2602
-        #if HOTENDS > 1
2603
-          soft_pwm_hotend[1].dec();
2604
-          #if HOTENDS > 2
2605
-            soft_pwm_hotend[2].dec();
2606
-            #if HOTENDS > 3
2607
-              soft_pwm_hotend[3].dec();
2608
-              #if HOTENDS > 4
2609
-                soft_pwm_hotend[4].dec();
2610
-                #if HOTENDS > 5
2611
-                  soft_pwm_hotend[5].dec();
2612
-                #endif // HOTENDS > 5
2613
-              #endif // HOTENDS > 4
2614
-            #endif // HOTENDS > 3
2615
-          #endif // HOTENDS > 2
2616
-        #endif // HOTENDS > 1
2617
-      #endif // HOTENDS
2518
+        HOTEND_LOOP() soft_pwm_hotend[e].dec();
2519
+      #endif
2618 2520
       #if HAS_HEATED_BED
2619 2521
         soft_pwm_bed.dec();
2620 2522
       #endif

Loading…
Zrušit
Uložit