|
|
@ -20,41 +20,41 @@
|
|
|
|
#include <Kaleidoscope-Heatmap.h>
|
|
|
|
#include <Kaleidoscope-Heatmap.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace KaleidoscopePlugins {
|
|
|
|
namespace KaleidoscopePlugins {
|
|
|
|
uint8_t Heatmap::heatmap[ROWS][COLS];
|
|
|
|
uint8_t Heatmap::heatmap[ROWS][COLS];
|
|
|
|
uint16_t Heatmap::totalKeys;
|
|
|
|
uint16_t Heatmap::totalKeys;
|
|
|
|
uint8_t Heatmap::highestCount;
|
|
|
|
uint8_t Heatmap::highestCount;
|
|
|
|
uint16_t Heatmap::updateDelay = 500;
|
|
|
|
uint16_t Heatmap::updateDelay = 500;
|
|
|
|
uint32_t Heatmap::endTime;
|
|
|
|
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}};
|
|
|
|
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}};
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
Heatmap::shiftStats (void) {
|
|
|
|
Heatmap::shiftStats (void) {
|
|
|
|
highestCount = totalKeys = 0;
|
|
|
|
highestCount = totalKeys = 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];
|
|
|
|
totalKeys += heatmap[r][c];
|
|
|
|
if (heatmap[r][c] > highestCount)
|
|
|
|
if (heatmap[r][c] > highestCount)
|
|
|
|
highestCount = heatmap[r][c];
|
|
|
|
highestCount = 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;
|
|
|
|
|
|
|
|
|
|
|
|
if (v <= 0) {
|
|
|
|
if (v <= 0) {
|
|
|
|
idx1 = idx2 = 0;
|
|
|
|
idx1 = idx2 = 0;
|
|
|
|
} else if (v >= 1) {
|
|
|
|
} else if (v >= 1) {
|
|
|
|
idx1 = idx2 = 3;
|
|
|
|
idx1 = idx2 = 3;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
float val = v * 3;
|
|
|
|
float val = v * 3;
|
|
|
|
idx1 = int(floor(val));
|
|
|
|
idx1 = int(floor(val));
|
|
|
|
idx2 = idx1 + 1;
|
|
|
|
idx2 = idx1 + 1;
|
|
|
|
fb = val - float(idx1);
|
|
|
|
fb = val - float(idx1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t r = (int)(((heatColors[idx2][0] - heatColors[idx1][0]) * fb + heatColors[idx1][0]) * 255);
|
|
|
|
uint8_t r = (int)(((heatColors[idx2][0] - heatColors[idx1][0]) * fb + heatColors[idx1][0]) * 255);
|
|
|
@ -62,57 +62,57 @@ namespace KaleidoscopePlugins {
|
|
|
|
uint8_t b = (int)(((heatColors[idx2][2] - heatColors[idx1][2]) * fb + heatColors[idx1][2]) * 255);
|
|
|
|
uint8_t b = (int)(((heatColors[idx2][2] - heatColors[idx1][2]) * fb + heatColors[idx1][2]) * 255);
|
|
|
|
|
|
|
|
|
|
|
|
return {b, g, r};
|
|
|
|
return {b, g, r};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 (this->eventHook);
|
|
|
|
loop_hook_use (this->loopHook);
|
|
|
|
loop_hook_use (this->loopHook);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Key
|
|
|
|
Key
|
|
|
|
Heatmap::eventHook (Key mappedKey, byte row, byte col, uint8_t keyState) {
|
|
|
|
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 (keyState & INJECTED)
|
|
|
|
return mappedKey;
|
|
|
|
return mappedKey;
|
|
|
|
|
|
|
|
|
|
|
|
// 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 (keyState))
|
|
|
|
return mappedKey;
|
|
|
|
return mappedKey;
|
|
|
|
|
|
|
|
|
|
|
|
totalKeys++;
|
|
|
|
totalKeys++;
|
|
|
|
heatmap[row][col]++;
|
|
|
|
heatmap[row][col]++;
|
|
|
|
if (heatmap[row][col] > highestCount)
|
|
|
|
if (heatmap[row][col] > highestCount)
|
|
|
|
highestCount = heatmap[row][col];
|
|
|
|
highestCount = heatmap[row][col];
|
|
|
|
|
|
|
|
|
|
|
|
return mappedKey;
|
|
|
|
return mappedKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
Heatmap::loopHook (bool postClear) {
|
|
|
|
Heatmap::loopHook (bool postClear) {
|
|
|
|
if (highestCount > 191 || totalKeys > 16000)
|
|
|
|
if (highestCount > 191 || totalKeys > 16000)
|
|
|
|
shiftStats();
|
|
|
|
shiftStats();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
Heatmap::update (void) {
|
|
|
|
Heatmap::update (void) {
|
|
|
|
if (endTime && (millis () > endTime))
|
|
|
|
if (endTime && (millis () > endTime))
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
endTime = millis () + updateDelay;
|
|
|
|
endTime = millis () + updateDelay;
|
|
|
|
|
|
|
|
|
|
|
|
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(totalKeys, 1);
|
|
|
|
float v = float(heatmap[r][c]) / cap;
|
|
|
|
float v = 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;
|
|
|
|
KaleidoscopePlugins::Heatmap HeatmapEffect;
|
|
|
|