Skip to content

Commit

Permalink
Merge pull request #4186 from thinkyhead/rc_array_macros
Browse files Browse the repository at this point in the history
Simplified variable-size array macros
  • Loading branch information
thinkyhead authored Jul 2, 2016
2 parents ac4f235 + e650a75 commit 77a923d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
26 changes: 4 additions & 22 deletions Marlin/Conditionals.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,32 +552,14 @@
/**
* ARRAY_BY_EXTRUDERS based on EXTRUDERS
*/
#if EXTRUDERS > 3
#define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2, v3, v4 }
#elif EXTRUDERS > 2
#define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2, v3 }
#elif EXTRUDERS > 1
#define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2 }
#else
#define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1 }
#endif

#define ARRAY_BY_EXTRUDERS1(v1) ARRAY_BY_EXTRUDERS(v1, v1, v1, v1)
#define ARRAY_BY_EXTRUDERS(args...) ARRAY_N(EXTRUDERS, args)
#define ARRAY_BY_EXTRUDERS1(v1) ARRAY_BY_EXTRUDERS(v1, v1, v1, v1, v1, v1)

/**
* ARRAY_BY_HOTENDS based on HOTENDS
*/
#if HOTENDS > 3
#define ARRAY_BY_HOTENDS(v1, v2, v3, v4) { v1, v2, v3, v4 }
#elif HOTENDS > 2
#define ARRAY_BY_HOTENDS(v1, v2, v3, v4) { v1, v2, v3 }
#elif HOTENDS > 1
#define ARRAY_BY_HOTENDS(v1, v2, v3, v4) { v1, v2 }
#else
#define ARRAY_BY_HOTENDS(v1, v2, v3, v4) { v1 }
#endif

#define ARRAY_BY_HOTENDS1(v1) ARRAY_BY_HOTENDS(v1, v1, v1, v1)
#define ARRAY_BY_HOTENDS(args...) ARRAY_N(HOTENDS, args)
#define ARRAY_BY_HOTENDS1(v1) ARRAY_BY_HOTENDS(v1, v1, v1, v1, v1, v1)

/**
* Z_DUAL_ENDSTOPS endstop reassignment
Expand Down
11 changes: 11 additions & 0 deletions Marlin/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@
#define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-')
#define COUNT(a) (sizeof(a)/sizeof(*a))

// Macros for initializing arrays
#define ARRAY_6(v1, v2, v3, v4, v5, v6, args...) { v1, v2, v3, v4, v5, v6 }
#define ARRAY_5(v1, v2, v3, v4, v5, args...) { v1, v2, v3, v4, v5 }
#define ARRAY_4(v1, v2, v3, v4, args...) { v1, v2, v3, v4 }
#define ARRAY_3(v1, v2, v3, args...) { v1, v2, v3 }
#define ARRAY_2(v1, v2, args...) { v1, v2 }
#define ARRAY_1(v1, args...) { v1 }

#define _ARRAY_N(N, args...) ARRAY_ ##N(args)
#define ARRAY_N(N, args...) _ARRAY_N(N, args)

// Macros for adding
#define INC_0 1
#define INC_1 2
Expand Down

0 comments on commit 77a923d

Please sign in to comment.