diff --git a/examples/AppSwitcher/AppSwitcher.ino b/examples/AppSwitcher/AppSwitcher.ino index 6b561632..aecb1242 100644 --- a/examples/AppSwitcher/AppSwitcher.ino +++ b/examples/AppSwitcher/AppSwitcher.ino @@ -24,7 +24,7 @@ #include "Macros.h" /* *INDENT-OFF* */ -const Key keymaps[][ROWS][COLS] PROGMEM = { +CREATE_KEYMAP( [0] = KEYMAP_STACKED ( Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, @@ -43,7 +43,7 @@ const Key keymaps[][ROWS][COLS] PROGMEM = { Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, M(M_APPCANCEL) ), -}; + ) /* *INDENT-ON* */ @@ -66,6 +66,3 @@ void setup() { void loop() { Kaleidoscope.loop(); } - -// This line should always be at the end of the sketch file -#include diff --git a/examples/Kaleidoscope/Kaleidoscope.ino b/examples/Kaleidoscope/Kaleidoscope.ino index eae88d7f..1964e08d 100644 --- a/examples/Kaleidoscope/Kaleidoscope.ino +++ b/examples/Kaleidoscope/Kaleidoscope.ino @@ -57,14 +57,13 @@ Key_KeymapNext_Momentary, Key_KeymapNext_Momentary \ ) -const Key keymaps[][ROWS][COLS] PROGMEM = { +CREATE_KEYMAP( QWERTY, GENERIC_FN2, NUMPAD +) -}; - static kaleidoscope::LEDSolidColor solidRed(60, 0, 0); static kaleidoscope::LEDSolidColor solidOrange(60, 20, 0); static kaleidoscope::LEDSolidColor solidYellow(40, 35, 0); @@ -104,6 +103,3 @@ void setup() { void loop() { Kaleidoscope.loop(); } - -// This line should always be at the end of the sketch file -#include diff --git a/src/layers.cpp b/src/layers.cpp index 88f43c80..7bfe05ab 100644 --- a/src/layers.cpp +++ b/src/layers.cpp @@ -125,8 +125,8 @@ void Layer_::move(uint8_t layer) { } void Layer_::on(uint8_t layer) { + // If we're trying to turn on a layer that doesn't exist; abort if (layer >= LayerCount) { - // Trying to turn on a layer that doesn't exist; abort return; } diff --git a/src/layers.h b/src/layers.h index d3f3b994..19512477 100644 --- a/src/layers.h +++ b/src/layers.h @@ -4,9 +4,14 @@ #include "key_defs.h" #include KALEIDOSCOPE_HARDWARE_H +#define CREATE_KEYMAP(layers...) \ + const Key keymaps[][ROWS][COLS] PROGMEM = { layers }; \ + const uint8_t LayerCount = sizeof(keymaps) / sizeof(*keymaps); + // The total number of defined layers in the firmware sketch keymaps[] array extern const uint8_t LayerCount; + class Layer_ { public: Layer_(void); diff --git a/src/sketch-trailer.h b/src/sketch-trailer.h deleted file mode 100644 index 9a928920..00000000 --- a/src/sketch-trailer.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -// Calculate the number of layers defined in the "keymaps[]" -// array. This needs to be included in the sketch after "keymaps" is -// defined -const uint8_t LayerCount PROGMEM = sizeof(keymaps) / sizeof(*keymaps);