Browse Source

Simplified variable-size array macros

Scott Lahteine 8 years ago
parent
commit
e650a75b88
2 changed files with 15 additions and 22 deletions
  1. 4
    22
      Marlin/Conditionals.h
  2. 11
    0
      Marlin/macros.h

+ 4
- 22
Marlin/Conditionals.h View File

@@ -552,32 +552,14 @@
552 552
   /**
553 553
    * ARRAY_BY_EXTRUDERS based on EXTRUDERS
554 554
    */
555
-  #if EXTRUDERS > 3
556
-    #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2, v3, v4 }
557
-  #elif EXTRUDERS > 2
558
-    #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2, v3 }
559
-  #elif EXTRUDERS > 1
560
-    #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2 }
561
-  #else
562
-    #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1 }
563
-  #endif
564
-
565
-  #define ARRAY_BY_EXTRUDERS1(v1) ARRAY_BY_EXTRUDERS(v1, v1, v1, v1)
555
+  #define ARRAY_BY_EXTRUDERS(args...) ARRAY_N(EXTRUDERS, args)
556
+  #define ARRAY_BY_EXTRUDERS1(v1) ARRAY_BY_EXTRUDERS(v1, v1, v1, v1, v1, v1)
566 557
 
567 558
   /**
568 559
    * ARRAY_BY_HOTENDS based on HOTENDS
569 560
    */
570
-  #if HOTENDS > 3
571
-    #define ARRAY_BY_HOTENDS(v1, v2, v3, v4) { v1, v2, v3, v4 }
572
-  #elif HOTENDS > 2
573
-    #define ARRAY_BY_HOTENDS(v1, v2, v3, v4) { v1, v2, v3 }
574
-  #elif HOTENDS > 1
575
-    #define ARRAY_BY_HOTENDS(v1, v2, v3, v4) { v1, v2 }
576
-  #else
577
-    #define ARRAY_BY_HOTENDS(v1, v2, v3, v4) { v1 }
578
-  #endif
579
-
580
-  #define ARRAY_BY_HOTENDS1(v1) ARRAY_BY_HOTENDS(v1, v1, v1, v1)
561
+  #define ARRAY_BY_HOTENDS(args...) ARRAY_N(HOTENDS, args)
562
+  #define ARRAY_BY_HOTENDS1(v1) ARRAY_BY_HOTENDS(v1, v1, v1, v1, v1, v1)
581 563
 
582 564
   /**
583 565
    * Z_DUAL_ENDSTOPS endstop reassignment

+ 11
- 0
Marlin/macros.h View File

@@ -55,6 +55,17 @@
55 55
 #define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-')
56 56
 #define COUNT(a) (sizeof(a)/sizeof(*a))
57 57
 
58
+// Macros for initializing arrays
59
+#define ARRAY_6(v1, v2, v3, v4, v5, v6, args...) { v1, v2, v3, v4, v5, v6 }
60
+#define ARRAY_5(v1, v2, v3, v4, v5, args...)     { v1, v2, v3, v4, v5 }
61
+#define ARRAY_4(v1, v2, v3, v4, args...)         { v1, v2, v3, v4 }
62
+#define ARRAY_3(v1, v2, v3, args...)             { v1, v2, v3 }
63
+#define ARRAY_2(v1, v2, args...)                 { v1, v2 }
64
+#define ARRAY_1(v1, args...)                     { v1 }
65
+
66
+#define _ARRAY_N(N, args...) ARRAY_ ##N(args)
67
+#define ARRAY_N(N, args...) _ARRAY_N(N, args)
68
+
58 69
 // Macros for adding
59 70
 #define INC_0 1
60 71
 #define INC_1 2

Loading…
Cancel
Save