From 50ac31d0f560b5f65745598846e6afb8434a68c6 Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Mon, 13 Nov 2017 15:02:58 -0600 Subject: [PATCH] Added a "sketch-trailer.h" header file This file is meant to be included in sketch files in order to make data available to Kaleidoscope functions. In particular, the size of the keymaps[] array (i.e. the number of defined layers), which is needed in order to prevent reading uninitialized memory past the end of that array due to Key_KeymapNext_Momentary. --- examples/AppSwitcher/AppSwitcher.ino | 8 +++----- examples/Kaleidoscope/Kaleidoscope.ino | 8 +++----- src/sketch-trailer.h | 6 ++++++ 3 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 src/sketch-trailer.h diff --git a/examples/AppSwitcher/AppSwitcher.ino b/examples/AppSwitcher/AppSwitcher.ino index eb385cc4..6b561632 100644 --- a/examples/AppSwitcher/AppSwitcher.ino +++ b/examples/AppSwitcher/AppSwitcher.ino @@ -46,11 +46,6 @@ const Key keymaps[][ROWS][COLS] PROGMEM = { }; /* *INDENT-ON* */ -// Calculate the number of layers defined in the "keymaps[]" array -// above for use elsewhere in Kaleidoscope. Don't remove or modify -// this line; it's used to prevent reading past the end of the array! -const uint8_t LayerCount PROGMEM = sizeof(keymaps) / sizeof(*keymaps); - const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { switch (macroIndex) { @@ -71,3 +66,6 @@ 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 b5f10424..eae88d7f 100644 --- a/examples/Kaleidoscope/Kaleidoscope.ino +++ b/examples/Kaleidoscope/Kaleidoscope.ino @@ -65,11 +65,6 @@ const Key keymaps[][ROWS][COLS] PROGMEM = { }; -// Calculate the number of layers defined in the "keymaps[]" array -// above for use elsewhere in Kaleidoscope. Don't remove or modify -// this line; it's used to prevent reading past the end of the array! -const uint8_t LayerCount PROGMEM = sizeof(keymaps) / sizeof(*keymaps); - static kaleidoscope::LEDSolidColor solidRed(60, 0, 0); static kaleidoscope::LEDSolidColor solidOrange(60, 20, 0); static kaleidoscope::LEDSolidColor solidYellow(40, 35, 0); @@ -109,3 +104,6 @@ void setup() { void loop() { Kaleidoscope.loop(); } + +// This line should always be at the end of the sketch file +#include diff --git a/src/sketch-trailer.h b/src/sketch-trailer.h new file mode 100644 index 00000000..9a928920 --- /dev/null +++ b/src/sketch-trailer.h @@ -0,0 +1,6 @@ +#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);