Kaleidoscope Style Guide conformance

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 8 years ago
parent be19287112
commit 95b34d4eb0

@ -5,9 +5,9 @@
[travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-Heatmap.svg?branch=master [travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-Heatmap.svg?branch=master
[travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-Heatmap [travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-Heatmap
[st:stable]: https://img.shields.io/badge/stable-✔-black.png?style=flat&colorA=44cc11&colorB=494e52 [st:stable]: https://img.shields.io/badge/stable-✔-black.svg?style=flat&colorA=44cc11&colorB=494e52
[st:broken]: https://img.shields.io/badge/broken-X-black.png?style=flat&colorA=e05d44&colorB=494e52 [st:broken]: https://img.shields.io/badge/broken-X-black.svg?style=flat&colorA=e05d44&colorB=494e52
[st:experimental]: https://img.shields.io/badge/experimental----black.png?style=flat&colorA=dfb317&colorB=494e52 [st:experimental]: https://img.shields.io/badge/experimental----black.svg?style=flat&colorA=dfb317&colorB=494e52
The `Heatmap` plugin provides a LED effect, that displays a heatmap on the The `Heatmap` plugin provides a LED effect, that displays a heatmap on the
keyboard. The LEDs under each key will have a color according to how much use keyboard. The LEDs under each key will have a color according to how much use
@ -26,9 +26,10 @@ include the header, and make sure the plugin is in use:
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-Heatmap.h> #include <Kaleidoscope-Heatmap.h>
void setup (void) { void setup() {
Kaleidoscope.setup (KEYMAP_SIZE); USE_PLUGINS(&HeatmapEffect);
Kaleidoscope.use (&HeatmapEffect, NULL);
Kaleidoscope.setup ();
} }
``` ```
@ -48,7 +49,7 @@ The plugin provides two methods on the `HeatmapEffect` object:
> `setup()` method of the Sketch, or in macros that are meant to switch to the > `setup()` method of the Sketch, or in macros that are meant to switch to the
> heatmap effect, no matter where we are in the list. > heatmap effect, no matter where we are in the list.
### `.timeOut` ### `.update_delay`
> The number of milliseconds to wait between updating the heatmap. Updating the > The number of milliseconds to wait between updating the heatmap. Updating the
> heatmap incurs a significant performance penalty, and should not be done too > heatmap incurs a significant performance penalty, and should not be done too

@ -22,8 +22,7 @@
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED [0] = KEYMAP_STACKED
( (Key_LEDEffectNext, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext,
Key_LEDEffectNext, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext,
Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab,
Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G,
Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape, Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
@ -37,13 +36,13 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_NoKey Key_NoKey),
),
}; };
void setup() { void setup() {
Kaleidoscope.setup(KEYMAP_SIZE); USE_PLUGINS(&HeatmapEffect);
Kaleidoscope.use(&LEDControl, &HeatmapEffect, NULL);
Kaleidoscope.setup();
HeatmapEffect.activate(); HeatmapEffect.activate();
} }

@ -19,30 +19,29 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-Heatmap.h> #include <Kaleidoscope-Heatmap.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
uint8_t Heatmap::heatmap[ROWS][COLS];
uint16_t Heatmap::totalKeys;
uint8_t Heatmap::highestCount;
uint16_t Heatmap::updateDelay = 500;
uint32_t Heatmap::endTime;
const float Heatmap::heatColors[][3] = {{0.0, 0.0, 0.0}, {0.1, 1, 0.1}, {1, 1, 0.1}, {1, 0.1, 0.1}}; uint8_t Heatmap::heatmap_[ROWS][COLS];
uint16_t Heatmap::total_keys_;
uint8_t Heatmap::highest_count_;
uint16_t Heatmap::update_delay = 500;
uint32_t Heatmap::end_time_;
void const float Heatmap::heat_colors_[][3] = {{0.0, 0.0, 0.0}, {0.1, 1, 0.1}, {1, 1, 0.1}, {1, 0.1, 0.1}};
Heatmap::shiftStats(void) {
highestCount = totalKeys = 0; void Heatmap::shiftStats(void) {
highest_count_ = total_keys_ = 0;
for (uint8_t r = 0; r < ROWS; r++) { for (uint8_t r = 0; r < ROWS; r++) {
for (uint8_t c = 0; c < COLS; c++) { for (uint8_t c = 0; c < COLS; c++) {
heatmap[r][c] = heatmap[r][c] >> 1; heatmap_[r][c] = heatmap_[r][c] >> 1;
totalKeys += heatmap[r][c]; total_keys_ += heatmap_[r][c];
if (heatmap[r][c] > highestCount) if (heatmap_[r][c] > highest_count_)
highestCount = heatmap[r][c]; highest_count_ = heatmap_[r][c];
} }
} }
} }
cRGB cRGB Heatmap::computeColor(float v) {
Heatmap::computeColor(float v) {
float fb = 0; float fb = 0;
uint8_t idx1, idx2; uint8_t idx1, idx2;
@ -52,14 +51,14 @@ Heatmap::computeColor(float v) {
idx1 = idx2 = 3; idx1 = idx2 = 3;
} else { } else {
float val = v * 3; float val = v * 3;
idx1 = int(floor(val)); idx1 = static_cast<int>(floor(val));
idx2 = idx1 + 1; idx2 = idx1 + 1;
fb = val - float(idx1); fb = val - static_cast<float>(idx1);
} }
uint8_t r = (int)(((heatColors[idx2][0] - heatColors[idx1][0]) * fb + heatColors[idx1][0]) * 255); uint8_t r = static_cast<uint8_t>(((heat_colors_[idx2][0] - heat_colors_[idx1][0]) * fb + heat_colors_[idx1][0]) * 255);
uint8_t g = (int)(((heatColors[idx2][1] - heatColors[idx1][1]) * fb + heatColors[idx1][1]) * 255); uint8_t g = static_cast<uint8_t>(((heat_colors_[idx2][1] - heat_colors_[idx1][1]) * fb + heat_colors_[idx1][1]) * 255);
uint8_t b = (int)(((heatColors[idx2][2] - heatColors[idx1][2]) * fb + heatColors[idx1][2]) * 255); uint8_t b = static_cast<uint8_t>(((heat_colors_[idx2][2] - heat_colors_[idx1][2]) * fb + heat_colors_[idx1][2]) * 255);
return {b, g, r}; return {b, g, r};
} }
@ -67,52 +66,51 @@ Heatmap::computeColor(float v) {
Heatmap::Heatmap(void) { Heatmap::Heatmap(void) {
} }
void void Heatmap::begin(void) {
Heatmap::begin(void) {
LEDControl.mode_add(this); LEDControl.mode_add(this);
event_handler_hook_use(this->eventHook); event_handler_hook_use(eventHook);
loop_hook_use(this->loopHook); loop_hook_use(loopHook);
} }
Key Key Heatmap::eventHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
Heatmap::eventHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
// if it is a synthetic key, skip it. // if it is a synthetic key, skip it.
if (keyState & INJECTED) if (key_state & INJECTED)
return mappedKey; return mapped_key;
// if the key is not toggled on, return. // if the key is not toggled on, return.
if (!key_toggled_on(keyState)) if (!key_toggled_on(key_state))
return mappedKey; return mapped_key;
totalKeys++; total_keys_++;
heatmap[row][col]++; heatmap_[row][col]++;
if (heatmap[row][col] > highestCount) if (heatmap_[row][col] > highest_count_)
highestCount = heatmap[row][col]; highest_count_ = heatmap_[row][col];
return mappedKey; return mapped_key;
} }
void void
Heatmap::loopHook(bool postClear) { Heatmap::loopHook(bool is_post_clear) {
if (highestCount > 191 || totalKeys > 16000) if (highest_count_ > 191 || total_keys_ > 16000)
shiftStats(); shiftStats();
} }
void void
Heatmap::update(void) { Heatmap::update(void) {
if (endTime && (millis() > endTime)) if (end_time_ && (millis() > end_time_))
return; return;
endTime = millis() + updateDelay; end_time_ = millis() + update_delay;
for (uint8_t r = 0; r < ROWS; r++) { for (uint8_t r = 0; r < ROWS; r++) {
for (uint8_t c = 0; c < COLS; c++) { for (uint8_t c = 0; c < COLS; c++) {
uint8_t cap = max(totalKeys, 1); uint8_t cap = max(total_keys_, 1);
float v = float(heatmap[r][c]) / cap; float v = static_cast<float>(heatmap_[r][c]) / cap;
LEDControl.led_set_crgb_at(r, c, computeColor(v)); LEDControl.led_set_crgb_at(r, c, computeColor(v));
} }
} }
} }
};
KaleidoscopePlugins::Heatmap HeatmapEffect; }
kaleidoscope::Heatmap HeatmapEffect;

@ -21,30 +21,29 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
class Heatmap : public LEDMode { class Heatmap : public LEDMode {
public: public:
Heatmap(void); Heatmap(void);
void begin(void) final; static uint16_t update_delay;
static uint16_t updateDelay;
virtual void update(void) final; void begin(void) final;
void update(void) final;
private: private:
static uint8_t heatmap[ROWS][COLS]; static uint8_t heatmap_[ROWS][COLS];
static uint16_t totalKeys; static uint16_t total_keys_;
static uint8_t highestCount; static uint8_t highest_count_;
static uint32_t endTime; static uint32_t end_time_;
static const float heatColors[][3]; static const float heat_colors_[][3];
static void shiftStats(void); static void shiftStats(void);
static cRGB computeColor(float v); static cRGB computeColor(float v);
static Key eventHook(Key mappedKey, byte row, byte col, uint8_t keyState); static Key eventHook(Key mapped_key, byte row, byte col, uint8_t key_state);
static void loopHook(bool postClear); static void loopHook(bool is_post_clear);
};
}; };
}
extern KaleidoscopePlugins::Heatmap HeatmapEffect; extern kaleidoscope::Heatmap HeatmapEffect;

Loading…
Cancel
Save