astyle with current project style guidelines

pull/389/head
Jesse Vincent 7 years ago
parent 0489fd9196
commit 17487f9c26
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -21,33 +21,33 @@
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
),
[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
),
};
void setup () {
Kaleidoscope.setup (KEYMAP_SIZE);
Kaleidoscope.use (&LEDControl, &HeatmapEffect, NULL);
void setup() {
Kaleidoscope.setup(KEYMAP_SIZE);
Kaleidoscope.use(&LEDControl, &HeatmapEffect, NULL);
HeatmapEffect.activate ();
HeatmapEffect.activate();
}
void loop () {
Kaleidoscope.loop ();
void loop() {
Kaleidoscope.loop();
}

@ -29,89 +29,89 @@ 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}};
void
Heatmap::shiftStats (void) {
highestCount = totalKeys = 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::shiftStats(void) {
highestCount = totalKeys = 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];
}
}
}
cRGB
Heatmap::computeColor (float v) {
float fb = 0;
uint8_t idx1, idx2;
if (v <= 0) {
idx1 = idx2 = 0;
} else if (v >= 1) {
idx1 = idx2 = 3;
} else {
float val = v * 3;
idx1 = int(floor(val));
idx2 = idx1 + 1;
fb = val - 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);
return {b, g, r};
Heatmap::computeColor(float v) {
float fb = 0;
uint8_t idx1, idx2;
if (v <= 0) {
idx1 = idx2 = 0;
} else if (v >= 1) {
idx1 = idx2 = 3;
} else {
float val = v * 3;
idx1 = int(floor(val));
idx2 = idx1 + 1;
fb = val - 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);
return {b, g, r};
}
Heatmap::Heatmap (void) {
Heatmap::Heatmap(void) {
}
void
Heatmap::begin (void) {
LEDControl.mode_add (this);
event_handler_hook_use (this->eventHook);
loop_hook_use (this->loopHook);
Heatmap::begin(void) {
LEDControl.mode_add(this);
event_handler_hook_use(this->eventHook);
loop_hook_use(this->loopHook);
}
Key
Heatmap::eventHook (Key mappedKey, byte row, byte col, uint8_t keyState) {
// if it is a synthetic key, skip it.
if (keyState & INJECTED)
return mappedKey;
Heatmap::eventHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
// if it is a synthetic key, skip it.
if (keyState & INJECTED)
return mappedKey;
// if the key is not toggled on, return.
if (!key_toggled_on (keyState))
return mappedKey;
// if the key is not toggled on, return.
if (!key_toggled_on(keyState))
return mappedKey;
totalKeys++;
heatmap[row][col]++;
if (heatmap[row][col] > highestCount)
highestCount = heatmap[row][col];
totalKeys++;
heatmap[row][col]++;
if (heatmap[row][col] > highestCount)
highestCount = heatmap[row][col];
return mappedKey;
return mappedKey;
}
void
Heatmap::loopHook (bool postClear) {
if (highestCount > 191 || totalKeys > 16000)
shiftStats();
Heatmap::loopHook(bool postClear) {
if (highestCount > 191 || totalKeys > 16000)
shiftStats();
}
void
Heatmap::update (void) {
if (endTime && (millis () > endTime))
return;
endTime = millis () + updateDelay;
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;
LEDControl.led_set_crgb_at (r, c, computeColor (v));
}
Heatmap::update(void) {
if (endTime && (millis() > endTime))
return;
endTime = millis() + updateDelay;
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;
LEDControl.led_set_crgb_at(r, c, computeColor(v));
}
}
}
};

@ -23,27 +23,27 @@
namespace KaleidoscopePlugins {
class Heatmap : public LEDMode {
public:
Heatmap (void);
public:
Heatmap(void);
virtual void begin (void) final;
virtual void begin(void) final;
static uint16_t updateDelay;
static uint16_t updateDelay;
virtual void update (void) final;
private:
static uint8_t heatmap[ROWS][COLS];
static uint16_t totalKeys;
static uint8_t highestCount;
static uint32_t endTime;
virtual void update(void) final;
private:
static uint8_t heatmap[ROWS][COLS];
static uint16_t totalKeys;
static uint8_t highestCount;
static uint32_t endTime;
static const float heatColors[][3];
static const float heatColors[][3];
static void shiftStats (void);
static cRGB computeColor (float v);
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 mappedKey, byte row, byte col, uint8_t keyState);
static void loopHook(bool postClear);
};
};

Loading…
Cancel
Save