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: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:broken]: https://img.shields.io/badge/broken-X-black.png?style=flat&colorA=e05d44&colorB=494e52
[st:experimental]: https://img.shields.io/badge/experimental----black.png?style=flat&colorA=dfb317&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.svg?style=flat&colorA=e05d44&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
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-Heatmap.h>
void setup (void) {
Kaleidoscope.setup (KEYMAP_SIZE);
Kaleidoscope.use (&HeatmapEffect, NULL);
void setup() {
USE_PLUGINS(&HeatmapEffect);
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
> 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
> heatmap incurs a significant performance penalty, and should not be done too

@ -22,28 +22,27 @@
const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED
(
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_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_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
Key_NoKey,
Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip,
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals,
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_NoKey
),
(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_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_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
Key_NoKey,
Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip,
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals,
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_NoKey),
};
void setup() {
Kaleidoscope.setup(KEYMAP_SIZE);
Kaleidoscope.use(&LEDControl, &HeatmapEffect, NULL);
USE_PLUGINS(&HeatmapEffect);
Kaleidoscope.setup();
HeatmapEffect.activate();
}

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

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

Loading…
Cancel
Save