make astyle

pull/389/head
Jesse Vincent 8 years ago
parent 0fc32dbd94
commit f4b49c30b6
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -24,72 +24,72 @@
namespace Example {
class TestLEDMode : public LEDMode {
public:
TestLEDMode () {};
virtual void begin (void) final;
virtual void update (void) final;
public:
TestLEDMode() {};
virtual void begin(void) final;
virtual void update(void) final;
static bool focusHook (const char *command);
static bool focusHook(const char *command);
private:
static uint16_t mapBase;
private:
static uint16_t mapBase;
};
uint16_t TestLEDMode::mapBase;
void
TestLEDMode::begin (void) {
LEDMode::begin ();
mapBase = LEDPaletteTheme.reserveThemes (1);
TestLEDMode::begin(void) {
LEDMode::begin();
mapBase = LEDPaletteTheme.reserveThemes(1);
}
void
TestLEDMode::update (void) {
LEDPaletteTheme.update (mapBase, 0);
TestLEDMode::update(void) {
LEDPaletteTheme.update(mapBase, 0);
}
bool
TestLEDMode::focusHook (const char *command) {
return LEDPaletteTheme.themeFocusHandler (command, PSTR ("testLedMode.map"),
mapBase, 1);
TestLEDMode::focusHook(const char *command) {
return LEDPaletteTheme.themeFocusHandler(command, PSTR("testLedMode.map"),
mapBase, 1);
}
};
Example::TestLEDMode TestLEDMode;
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 () {
Serial.begin (9600);
Kaleidoscope.use (&Focus, &LEDPaletteTheme, &TestLEDMode, &EEPROMSettings, NULL);
Kaleidoscope.setup ();
void setup() {
Serial.begin(9600);
Kaleidoscope.use(&Focus, &LEDPaletteTheme, &TestLEDMode, &EEPROMSettings, NULL);
Kaleidoscope.setup();
EEPROMSettings.seal ();
TestLEDMode.activate ();
EEPROMSettings.seal();
TestLEDMode.activate();
Focus.addHook (FOCUS_HOOK_LEDPALETTETHEME);
Focus.addHook (FOCUS_HOOK(TestLEDMode.focusHook, "testLEDMode.map"));
Focus.addHook(FOCUS_HOOK_LEDPALETTETHEME);
Focus.addHook(FOCUS_HOOK(TestLEDMode.focusHook, "testLEDMode.map"));
}
void loop () {
Kaleidoscope.loop ();
void loop() {
Kaleidoscope.loop();
}

@ -26,149 +26,149 @@ namespace KaleidoscopePlugins {
uint16_t LEDPaletteTheme::paletteBase;
uint8_t LEDPaletteTheme::transparentIndex = 15;
LEDPaletteTheme::LEDPaletteTheme (void) {
LEDPaletteTheme::LEDPaletteTheme(void) {
}
void
LEDPaletteTheme::begin (void) {
USE_PLUGINS (&::EEPROMSettings);
LEDPaletteTheme::begin(void) {
USE_PLUGINS(&::EEPROMSettings);
if (!paletteBase)
paletteBase = ::EEPROMSettings.requestSlice (16 * sizeof (cRGB));
if (!paletteBase)
paletteBase = ::EEPROMSettings.requestSlice(16 * sizeof(cRGB));
}
uint16_t
LEDPaletteTheme::reserveThemes (uint8_t maxThemes) {
return ::EEPROMSettings.requestSlice (maxThemes * ROWS * COLS / 2);
LEDPaletteTheme::reserveThemes(uint8_t maxThemes) {
return ::EEPROMSettings.requestSlice(maxThemes * ROWS * COLS / 2);
}
void
LEDPaletteTheme::update (uint16_t themeBase, uint8_t theme) {
uint16_t mapBase = themeBase + (theme * ROWS * COLS / 2);
for (uint16_t loc = 0; loc < ROWS * COLS; loc++) {
cRGB color;
LEDPaletteTheme::update(uint16_t themeBase, uint8_t theme) {
uint16_t mapBase = themeBase + (theme * ROWS * COLS / 2);
for (uint16_t loc = 0; loc < ROWS * COLS; loc++) {
cRGB color;
if (!lookupColor (mapBase, loc, &color))
continue;
if (!lookupColor(mapBase, loc, &color))
continue;
LEDControl.led_set_crgb_at (loc, color);
LEDControl.led_set_crgb_at(loc, color);
}
}
}
const uint8_t
LEDPaletteTheme::lookupColorIndex (uint16_t mapBase, uint16_t loc) {
uint8_t colorIndex;
LEDPaletteTheme::lookupColorIndex(uint16_t mapBase, uint16_t loc) {
uint8_t colorIndex;
colorIndex = EEPROM.read (mapBase + loc / 2);
if (loc % 2)
colorIndex &= ~0xf0;
else
colorIndex >>= 4;
colorIndex = EEPROM.read(mapBase + loc / 2);
if (loc % 2)
colorIndex &= ~0xf0;
else
colorIndex >>= 4;
return colorIndex;
return colorIndex;
}
const bool
LEDPaletteTheme::lookupColor (uint16_t mapBase, uint16_t loc, cRGB *color) {
uint8_t colorIndex = lookupColorIndex (mapBase, loc);
LEDPaletteTheme::lookupColor(uint16_t mapBase, uint16_t loc, cRGB *color) {
uint8_t colorIndex = lookupColorIndex(mapBase, loc);
if (colorIndex == transparentIndex)
return false;
if (colorIndex == transparentIndex)
return false;
EEPROM.get (paletteBase + colorIndex * sizeof (cRGB), *color);
EEPROM.get(paletteBase + colorIndex * sizeof(cRGB), *color);
return true;
return true;
}
const cRGB
LEDPaletteTheme::lookupColor (uint8_t index) {
cRGB color;
LEDPaletteTheme::lookupColor(uint8_t index) {
cRGB color;
EEPROM.get (paletteBase + index * sizeof (cRGB), color);
return color;
EEPROM.get(paletteBase + index * sizeof(cRGB), color);
return color;
}
void
LEDPaletteTheme::updateColor (uint16_t mapBase, uint16_t loc, uint8_t index) {
uint8_t indexes;
indexes = EEPROM.read (mapBase + loc / 2);
if (loc % 2) {
uint8_t other = indexes >> 4;
indexes = (other << 4) + index;
} else {
uint8_t other = indexes & ~0xf0;
indexes = (index << 4) + other;
}
EEPROM.update (mapBase + loc / 2, indexes);
LEDPaletteTheme::updateColor(uint16_t mapBase, uint16_t loc, uint8_t index) {
uint8_t indexes;
indexes = EEPROM.read(mapBase + loc / 2);
if (loc % 2) {
uint8_t other = indexes >> 4;
indexes = (other << 4) + index;
} else {
uint8_t other = indexes & ~0xf0;
indexes = (index << 4) + other;
}
EEPROM.update(mapBase + loc / 2, indexes);
}
bool
LEDPaletteTheme::paletteFocusHook (const char *command) {
if (strcmp_P (command, PSTR ("palette")) != 0)
return false;
if (Serial.peek () == '\n') {
for (uint8_t i = 0; i < 16; i++) {
cRGB color;
EEPROM.get (paletteBase + i * sizeof (color), color);
::Focus.printColor (color.r, color.g, color.b);
::Focus.printSpace ();
}
Serial.println ();
return true;
LEDPaletteTheme::paletteFocusHook(const char *command) {
if (strcmp_P(command, PSTR("palette")) != 0)
return false;
if (Serial.peek() == '\n') {
for (uint8_t i = 0; i < 16; i++) {
cRGB color;
EEPROM.get(paletteBase + i * sizeof(color), color);
::Focus.printColor(color.r, color.g, color.b);
::Focus.printSpace();
}
Serial.println();
return true;
}
uint8_t i = 0;
while (i < 16 && Serial.peek() != '\n') {
cRGB color;
uint8_t i = 0;
while (i < 16 && Serial.peek() != '\n') {
cRGB color;
color.r = Serial.parseInt ();
color.g = Serial.parseInt ();
color.b = Serial.parseInt ();
color.r = Serial.parseInt();
color.g = Serial.parseInt();
color.b = Serial.parseInt();
EEPROM.put (paletteBase + i * sizeof (color), color);
i++;
}
EEPROM.put(paletteBase + i * sizeof(color), color);
i++;
}
return true;
return true;
}
bool
LEDPaletteTheme::themeFocusHandler (const char *command, const char *expectedCommand,
uint16_t themeBase, uint8_t maxThemes) {
if (strcmp_P (command, expectedCommand) != 0)
return false;
uint16_t maxIndex = (maxThemes * ROWS * COLS) / 2;
if (Serial.peek () == '\n') {
for (uint16_t loc = 0; loc < maxIndex; loc++) {
uint8_t indexes = EEPROM.read (themeBase + loc);
::Focus.printNumber (indexes >> 4);
::Focus.printSpace ();
::Focus.printNumber (indexes & ~0xf0);
::Focus.printSpace ();
}
Serial.println ();
return true;
}
LEDPaletteTheme::themeFocusHandler(const char *command, const char *expectedCommand,
uint16_t themeBase, uint8_t maxThemes) {
if (strcmp_P(command, expectedCommand) != 0)
return false;
uint16_t loc = 0;
uint16_t maxIndex = (maxThemes * ROWS * COLS) / 2;
while ((Serial.peek () != '\n') && (loc < maxIndex)) {
uint8_t idx1 = Serial.parseInt ();
uint8_t idx2 = Serial.parseInt ();
uint8_t indexes = (idx1 << 4) + idx2;
if (Serial.peek() == '\n') {
for (uint16_t loc = 0; loc < maxIndex; loc++) {
uint8_t indexes = EEPROM.read(themeBase + loc);
EEPROM.update (themeBase + loc, indexes);
loc++;
::Focus.printNumber(indexes >> 4);
::Focus.printSpace();
::Focus.printNumber(indexes & ~0xf0);
::Focus.printSpace();
}
Serial.println();
return true;
}
uint16_t loc = 0;
while ((Serial.peek() != '\n') && (loc < maxIndex)) {
uint8_t idx1 = Serial.parseInt();
uint8_t idx2 = Serial.parseInt();
uint8_t indexes = (idx1 << 4) + idx2;
EEPROM.update(themeBase + loc, indexes);
loc++;
}
return true;
}
};

@ -23,27 +23,27 @@
namespace KaleidoscopePlugins {
class LEDPaletteTheme : public KaleidoscopePlugin {
public:
LEDPaletteTheme (void);
public:
LEDPaletteTheme(void);
virtual void begin (void) final;
virtual void begin(void) final;
static uint16_t reserveThemes (uint8_t maxThemes);
static void update (uint16_t themeBase, uint8_t theme);
static uint16_t reserveThemes(uint8_t maxThemes);
static void update(uint16_t themeBase, uint8_t theme);
static const uint8_t lookupColorIndex (uint16_t mapBase, uint16_t loc);
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 const uint8_t lookupColorIndex(uint16_t mapBase, uint16_t loc);
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 themeFocusHandler (const char *command, const char *expectedCommand,
uint16_t themeBase, uint8_t maxThemes);
static bool paletteFocusHook(const char *command);
static bool themeFocusHandler(const char *command, const char *expectedCommand,
uint16_t themeBase, uint8_t maxThemes);
static uint8_t transparentIndex;
static uint8_t transparentIndex;
private:
static uint16_t paletteBase;
private:
static uint16_t paletteBase;
};
};

Loading…
Cancel
Save