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