From b7c9287d0f70dd1ce62e9cece1b5cdf78c1e695c Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 24 Nov 2016 10:10:59 +0100 Subject: [PATCH] Introduce a helper macro to compute the keymap size When one adds or removes a layer from a keymap, the keymap size has to be adjusted in the call to `Keyboardio.setup()`. This is easy to forget, so as a helper, introduce `KEYMAP_SIZE`, a macro that automatically computes the size at compile time. This way, one does not need to remember to update the size anywhere. Signed-off-by: Gergely Nagy --- examples/KeyboardioFirmware/KeyboardioFirmware.ino | 3 +-- src/KeyboardioFirmware.h | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/KeyboardioFirmware/KeyboardioFirmware.ino b/examples/KeyboardioFirmware/KeyboardioFirmware.ino index a83315a2..3a74e637 100644 --- a/examples/KeyboardioFirmware/KeyboardioFirmware.ino +++ b/examples/KeyboardioFirmware/KeyboardioFirmware.ino @@ -19,7 +19,6 @@ uint8_t primary_keymap = 0; uint8_t temporary_keymap = 0; -#define KEYMAPS 3 #define NUMPAD_KEYMAP 2 #define KEYMAP_LIST KEYMAP_QWERTY KEYMAP_GENERIC_FN2 KEYMAP_NUMPAD @@ -42,7 +41,7 @@ static LEDChaseEffect chaseEffect; static LEDNumlock numLockEffect (NUMPAD_KEYMAP); void setup() { - Keyboardio.setup(KEYMAPS); + Keyboardio.setup(KEYMAP_SIZE); bootAnimation(); } diff --git a/src/KeyboardioFirmware.h b/src/KeyboardioFirmware.h index e476fe03..a6e70781 100644 --- a/src/KeyboardioFirmware.h +++ b/src/KeyboardioFirmware.h @@ -33,6 +33,8 @@ extern uint8_t temporary_keymap; #define VERSION "locally-built" #endif +#define KEYMAP_SIZE (sizeof(keymaps) / ROWS / COLS / sizeof(Key)) + class Keyboardio_ { public: Keyboardio_(void);