Kaleidoscope Style Guide conformance

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 8 years ago
parent 57cf6cbab7
commit dd7c20a4ee

@ -22,7 +22,8 @@
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-Focus.h> #include <Kaleidoscope-Focus.h>
namespace Example { namespace example {
class TestLEDMode : public LEDMode { class TestLEDMode : public LEDMode {
public: public:
TestLEDMode() {} TestLEDMode() {}
@ -32,30 +33,30 @@ class TestLEDMode : public LEDMode {
static bool focusHook(const char *command); static bool focusHook(const char *command);
private: private:
static uint16_t mapBase; static uint16_t map_base_;
}; };
uint16_t TestLEDMode::mapBase; uint16_t TestLEDMode::map_base_;
void void
TestLEDMode::begin(void) { TestLEDMode::begin(void) {
LEDMode::begin(); LEDMode::begin();
mapBase = LEDPaletteTheme.reserveThemes(1); map_base_ = LEDPaletteTheme.reserveThemes(1);
} }
void void
TestLEDMode::update(void) { TestLEDMode::update(void) {
LEDPaletteTheme.update(mapBase, 0); LEDPaletteTheme.updateHandler(map_base_, 0);
} }
bool bool
TestLEDMode::focusHook(const char *command) { TestLEDMode::focusHook(const char *command) {
return LEDPaletteTheme.themeFocusHandler(command, PSTR("testLedMode.map"), return LEDPaletteTheme.themeFocusHandler(command, PSTR("testLedMode.map"), map_base_, 1);
mapBase, 1); }
} }
};
Example::TestLEDMode TestLEDMode; example::TestLEDMode TestLEDMode;
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED [0] = KEYMAP_STACKED
@ -74,13 +75,14 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_NoKey Key_NoKey),
),
}; };
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
Kaleidoscope.use(&Focus, &LEDPaletteTheme, &TestLEDMode, &EEPROMSettings, NULL);
USE_PLUGINS(&Focus, &LEDPaletteTheme, &TestLEDMode, &EEPROMSettings);
Kaleidoscope.setup(); Kaleidoscope.setup();
EEPROMSettings.seal(); EEPROMSettings.seal();

@ -21,91 +21,82 @@
#include <Kaleidoscope-Focus.h> #include <Kaleidoscope-Focus.h>
#include <EEPROM.h> #include <EEPROM.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
uint16_t LEDPaletteTheme::paletteBase; uint16_t LEDPaletteTheme::palette_base_;
uint8_t LEDPaletteTheme::transparentIndex = 15; uint8_t LEDPaletteTheme::transparent_index = 15;
LEDPaletteTheme::LEDPaletteTheme(void) { LEDPaletteTheme::LEDPaletteTheme(void) {
} }
void void LEDPaletteTheme::begin(void) {
LEDPaletteTheme::begin(void) {
USE_PLUGINS(&::EEPROMSettings); USE_PLUGINS(&::EEPROMSettings);
if (!paletteBase) if (!palette_base_)
paletteBase = ::EEPROMSettings.requestSlice(16 * sizeof(cRGB)); palette_base_ = ::EEPROMSettings.requestSlice(16 * sizeof(cRGB));
} }
uint16_t uint16_t LEDPaletteTheme::reserveThemes(uint8_t max_themes) {
LEDPaletteTheme::reserveThemes(uint8_t maxThemes) { return ::EEPROMSettings.requestSlice(max_themes * ROWS * COLS / 2);
return ::EEPROMSettings.requestSlice(maxThemes * ROWS * COLS / 2);
} }
void void LEDPaletteTheme::updateHandler(uint16_t theme_base, uint8_t theme) {
LEDPaletteTheme::update(uint16_t themeBase, uint8_t theme) { uint16_t map_base = theme_base + (theme * ROWS * COLS / 2);
uint16_t mapBase = themeBase + (theme * ROWS * COLS / 2); for (uint16_t pos = 0; pos < ROWS * COLS; pos++) {
for (uint16_t loc = 0; loc < ROWS * COLS; loc++) {
cRGB color; cRGB color;
if (!lookupColor(mapBase, loc, &color)) if (!lookupColorAtPosition(theme_base, pos, &color))
continue; continue;
LEDControl.led_set_crgb_at(loc, color); LEDControl.led_set_crgb_at(pos, color);
} }
} }
const uint8_t const uint8_t LEDPaletteTheme::lookupColorIndexAtPosition(uint16_t map_base, uint16_t position) {
LEDPaletteTheme::lookupColorIndex(uint16_t mapBase, uint16_t loc) { uint8_t color_index;
uint8_t colorIndex;
colorIndex = EEPROM.read(mapBase + loc / 2); color_index = EEPROM.read(map_base + position / 2);
if (loc % 2) if (position % 2)
colorIndex &= ~0xf0; color_index &= ~0xf0;
else else
colorIndex >>= 4; color_index >>= 4;
return colorIndex; return color_index;
} }
const bool const bool LEDPaletteTheme::lookupColorAtPosition(uint16_t map_base, uint16_t position, cRGB *color) {
LEDPaletteTheme::lookupColor(uint16_t mapBase, uint16_t loc, cRGB *color) { uint8_t color_index = lookupColorIndexAtPosition(map_base, position);
uint8_t colorIndex = lookupColorIndex(mapBase, loc);
if (colorIndex == transparentIndex) if (color_index == transparent_index)
return false; return false;
EEPROM.get(paletteBase + colorIndex * sizeof(cRGB), *color); *color = lookupPaletteColor(color_index);
return true; return true;
} }
const cRGB const cRGB LEDPaletteTheme::lookupPaletteColor(uint8_t color_index) {
LEDPaletteTheme::lookupColor(uint8_t index) {
cRGB color; cRGB color;
EEPROM.get(paletteBase + index * sizeof(cRGB), color); EEPROM.get(palette_base_ + color_index * sizeof(cRGB), color);
return color; return color;
} }
void void LEDPaletteTheme::updateColorIndexAtPosition(uint16_t map_base, uint16_t position, uint8_t color_index) {
LEDPaletteTheme::updateColor(uint16_t mapBase, uint16_t loc, uint8_t index) {
uint8_t indexes; uint8_t indexes;
indexes = EEPROM.read(mapBase + loc / 2); indexes = EEPROM.read(map_base + position / 2);
if (loc % 2) { if (position % 2) {
uint8_t other = indexes >> 4; uint8_t other = indexes >> 4;
indexes = (other << 4) + index; indexes = (other << 4) + color_index;
} else { } else {
uint8_t other = indexes & ~0xf0; uint8_t other = indexes & ~0xf0;
indexes = (index << 4) + other; indexes = (color_index << 4) + other;
} }
EEPROM.update(mapBase + loc / 2, indexes); EEPROM.update(map_base + position / 2, indexes);
} }
bool bool LEDPaletteTheme::paletteFocusHook(const char *command) {
LEDPaletteTheme::paletteFocusHook(const char *command) {
if (strcmp_P(command, PSTR("palette")) != 0) if (strcmp_P(command, PSTR("palette")) != 0)
return false; return false;
@ -113,7 +104,7 @@ LEDPaletteTheme::paletteFocusHook(const char *command) {
for (uint8_t i = 0; i < 16; i++) { for (uint8_t i = 0; i < 16; i++) {
cRGB color; cRGB color;
EEPROM.get(paletteBase + i * sizeof(color), color); EEPROM.get(palette_base_ + i * sizeof(color), color);
::Focus.printColor(color.r, color.g, color.b); ::Focus.printColor(color.r, color.g, color.b);
::Focus.printSpace(); ::Focus.printSpace();
} }
@ -129,24 +120,23 @@ LEDPaletteTheme::paletteFocusHook(const char *command) {
color.g = Serial.parseInt(); color.g = Serial.parseInt();
color.b = Serial.parseInt(); color.b = Serial.parseInt();
EEPROM.put(paletteBase + i * sizeof(color), color); EEPROM.put(palette_base_ + i * sizeof(color), color);
i++; i++;
} }
return true; return true;
} }
bool bool LEDPaletteTheme::themeFocusHandler(const char *command, const char *expected_command,
LEDPaletteTheme::themeFocusHandler(const char *command, const char *expectedCommand, uint16_t theme_base, uint8_t max_themes) {
uint16_t themeBase, uint8_t maxThemes) { if (strcmp_P(command, expected_command) != 0)
if (strcmp_P(command, expectedCommand) != 0)
return false; return false;
uint16_t maxIndex = (maxThemes * ROWS * COLS) / 2; uint16_t max_index = (max_themes * ROWS * COLS) / 2;
if (Serial.peek() == '\n') { if (Serial.peek() == '\n') {
for (uint16_t loc = 0; loc < maxIndex; loc++) { for (uint16_t pos = 0; pos < max_index; pos++) {
uint8_t indexes = EEPROM.read(themeBase + loc); uint8_t indexes = EEPROM.read(theme_base + pos);
::Focus.printNumber(indexes >> 4); ::Focus.printNumber(indexes >> 4);
::Focus.printSpace(); ::Focus.printSpace();
@ -157,20 +147,20 @@ LEDPaletteTheme::themeFocusHandler(const char *command, const char *expectedComm
return true; return true;
} }
uint16_t loc = 0; uint16_t pos = 0;
while ((Serial.peek() != '\n') && (loc < maxIndex)) { while ((Serial.peek() != '\n') && (pos < max_index)) {
uint8_t idx1 = Serial.parseInt(); uint8_t idx1 = Serial.parseInt();
uint8_t idx2 = Serial.parseInt(); uint8_t idx2 = Serial.parseInt();
uint8_t indexes = (idx1 << 4) + idx2; uint8_t indexes = (idx1 << 4) + idx2;
EEPROM.update(themeBase + loc, indexes); EEPROM.update(theme_base + pos, indexes);
loc++; pos++;
} }
return true; return true;
} }
}; }
KaleidoscopePlugins::LEDPaletteTheme LEDPaletteTheme; kaleidoscope::LEDPaletteTheme LEDPaletteTheme;

@ -21,33 +21,36 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
class LEDPaletteTheme : public KaleidoscopePlugin { class LEDPaletteTheme : public KaleidoscopePlugin {
public: public:
LEDPaletteTheme(void); LEDPaletteTheme(void);
void begin(void) final; void begin(void) final;
static uint16_t reserveThemes(uint8_t maxThemes); static uint16_t reserveThemes(uint8_t max_themes);
static void update(uint16_t themeBase, uint8_t theme); static void updateHandler(uint16_t theme_base, uint8_t theme);
static const uint8_t lookupColorIndexAtPosition(uint16_t theme_base, uint16_t position);
static const bool lookupColorAtPosition(uint16_t theme_base, uint16_t position, cRGB *color);
static void updateColorIndexAtPosition(uint16_t theme_base, uint16_t position, uint8_t color_index);
static const uint8_t lookupColorIndex(uint16_t mapBase, uint16_t loc); static const cRGB lookupPaletteColor(uint8_t palette_index);
static const cRGB lookupColor(uint8_t index);
static const bool lookupColor(uint16_t mapBase, uint16_t loc, cRGB *color);
static void updateColor(uint16_t mapBase, uint16_t loc, uint8_t index);
static bool paletteFocusHook(const char *command); static bool paletteFocusHook(const char *command);
static bool themeFocusHandler(const char *command, const char *expectedCommand, static bool themeFocusHandler(const char *command, const char *expected_command,
uint16_t themeBase, uint8_t maxThemes); uint16_t theme_base, uint8_t max_themes);
static uint8_t transparentIndex; static uint8_t transparent_index;
private: private:
static uint16_t paletteBase; static uint16_t palette_base_;
};
}; };
extern KaleidoscopePlugins::LEDPaletteTheme LEDPaletteTheme; }
extern kaleidoscope::LEDPaletteTheme LEDPaletteTheme;
#define FOCUS_HOOK_LEDPALETTETHEME \ #define FOCUS_HOOK_LEDPALETTETHEME \
FOCUS_HOOK(LEDPaletteTheme.paletteFocusHook, \ FOCUS_HOOK(LEDPaletteTheme.paletteFocusHook, \

Loading…
Cancel
Save