Define keymap layers with CREATE_KEYMAP macro

This macro allows the definition of the LayerCount variable and the
keymaps[] array together. It shouldn't break old sketches, but this is
probably not all that's necessary; LayerCount still doesn't get
initialized outside the macro.
pull/244/head
Michael Richters 7 years ago
parent 50ac31d0f5
commit de39e20d78

@ -24,7 +24,7 @@
#include "Macros.h" #include "Macros.h"
/* *INDENT-OFF* */ /* *INDENT-OFF* */
const Key keymaps[][ROWS][COLS] PROGMEM = { CREATE_KEYMAP(
[0] = KEYMAP_STACKED [0] = KEYMAP_STACKED
( (
Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, 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, Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
M(M_APPCANCEL) M(M_APPCANCEL)
), ),
}; )
/* *INDENT-ON* */ /* *INDENT-ON* */
@ -66,6 +66,3 @@ void setup() {
void loop() { void loop() {
Kaleidoscope.loop(); Kaleidoscope.loop();
} }
// This line should always be at the end of the sketch file
#include <sketch-trailer.h>

@ -57,14 +57,13 @@
Key_KeymapNext_Momentary, Key_KeymapNext_Momentary \ Key_KeymapNext_Momentary, Key_KeymapNext_Momentary \
) )
const Key keymaps[][ROWS][COLS] PROGMEM = { CREATE_KEYMAP(
QWERTY, QWERTY,
GENERIC_FN2, GENERIC_FN2,
NUMPAD NUMPAD
)
};
static kaleidoscope::LEDSolidColor solidRed(60, 0, 0); static kaleidoscope::LEDSolidColor solidRed(60, 0, 0);
static kaleidoscope::LEDSolidColor solidOrange(60, 20, 0); static kaleidoscope::LEDSolidColor solidOrange(60, 20, 0);
static kaleidoscope::LEDSolidColor solidYellow(40, 35, 0); static kaleidoscope::LEDSolidColor solidYellow(40, 35, 0);
@ -104,6 +103,3 @@ void setup() {
void loop() { void loop() {
Kaleidoscope.loop(); Kaleidoscope.loop();
} }
// This line should always be at the end of the sketch file
#include <sketch-trailer.h>

@ -125,8 +125,8 @@ void Layer_::move(uint8_t layer) {
} }
void Layer_::on(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) { if (layer >= LayerCount) {
// Trying to turn on a layer that doesn't exist; abort
return; return;
} }

@ -4,9 +4,14 @@
#include "key_defs.h" #include "key_defs.h"
#include KALEIDOSCOPE_HARDWARE_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 // The total number of defined layers in the firmware sketch keymaps[] array
extern const uint8_t LayerCount; extern const uint8_t LayerCount;
class Layer_ { class Layer_ {
public: public:
Layer_(void); Layer_(void);

@ -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);
Loading…
Cancel
Save