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