Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand palette to 24 colors #1418

Merged
merged 6 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 < 16; 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 @@ -41,13 +41,13 @@ class DefaultPalette : public Plugin {
// clang-format off

#define PALETTE(p0, p1, p2, p3, p4, p5, p6, p7, \
p8, p9, pa, pb, pc, pd, pe, pf) \
p8, p9, pa, pb, pc, pd, pe, ...) \
namespace kaleidoscope { \
namespace plugin { \
namespace ledpalette { \
const cRGB palette[] PROGMEM = { \
p0, p1, p2, p3, p4, p5, p6, p7, \
p8, p9, pa, pb, pc, pd, pe, pf \
p8, p9, pa, pb, pc, pd, pe, ##__VA_ARGS__ \
}; \
bool palette_defined = true; \
} /* defaultcolormap */ \
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(16 * 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_, 16 * 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 < 16; 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 < 16 && !::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
Loading