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"
/* *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 <sketch-trailer.h>

@ -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 <sketch-trailer.h>

@ -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;
}

@ -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);

@ -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