Skip to content

Commit

Permalink
Define palette size only once
Browse files Browse the repository at this point in the history
Signed-off-by: Evy Bongers <[email protected]>
  • Loading branch information
EvyBongers committed Apr 21, 2024
1 parent 7aef9b7 commit 96d61e5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ __attribute__((weak)) extern bool palette_defined = false;
void DefaultPalette::setup() {
if (!ledpalette::palette_defined) return;

for (uint8_t i = 0; i < 24; i++) {
for (uint8_t i = 0; i < LEDPaletteTheme::getPaletteSize(); i++) {
cRGB color;

color.r = pgm_read_byte(&(ledpalette::palette[i].r));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ namespace kaleidoscope {
namespace plugin {

uint16_t LEDPaletteTheme::palette_base_;
uint8_t LEDPaletteTheme::palette_size_ = 24;

uint16_t LEDPaletteTheme::reserveThemes(uint8_t max_themes) {
if (!palette_base_)
palette_base_ = ::EEPROMSettings.requestSlice(24 * sizeof(cRGB));
palette_base_ = ::EEPROMSettings.requestSlice(palette_size_ * sizeof(cRGB));

return ::EEPROMSettings.requestSlice(max_themes * Runtime.device().led_count / 2);
}
Expand Down Expand Up @@ -116,12 +117,16 @@ void LEDPaletteTheme::updatePaletteColor(uint8_t palette_index, cRGB color) {
}

bool LEDPaletteTheme::isThemeUninitialized(uint16_t theme_base, uint8_t max_themes) {
bool paletteEmpty = Runtime.storage().isSliceUninitialized(palette_base_, 24 * sizeof(cRGB));
bool paletteEmpty = Runtime.storage().isSliceUninitialized(palette_base_, palette_size_ * sizeof(cRGB));
bool themeEmpty = Runtime.storage().isSliceUninitialized(theme_base, max_themes * Runtime.device().led_count / 2);

return paletteEmpty && themeEmpty;
}

uint8_t LEDPaletteTheme::getPaletteSize() {
return LEDPaletteTheme::palette_size_;
}

EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *input) {
if (!Runtime.has_leds)
return EventHandlerResult::OK;
Expand All @@ -135,7 +140,7 @@ EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *input) {
return EventHandlerResult::OK;

if (::Focus.isEOL()) {
for (uint8_t i = 0; i < 24; i++) {
for (uint8_t i = 0; i < palette_size_; i++) {
cRGB color;

color = lookupPaletteColor(i);
Expand All @@ -145,7 +150,7 @@ EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *input) {
}

uint8_t i = 0;
while (i < 24 && !::Focus.isEOL()) {
while (i < palette_size_ && !::Focus.isEOL()) {
cRGB color;

::Focus.read(color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ class LEDPaletteTheme : public kaleidoscope::Plugin {
uint8_t max_themes);
static bool isThemeUninitialized(uint16_t theme_base, uint8_t max_themes);

static uint8_t getPaletteSize();

private:
static uint16_t palette_base_;
static uint8_t palette_size_;
};

} // namespace plugin
Expand Down

0 comments on commit 96d61e5

Please sign in to comment.