diff --git a/plugins/Kaleidoscope-FingerPainter/src/kaleidoscope/plugin/FingerPainter.cpp b/plugins/Kaleidoscope-FingerPainter/src/kaleidoscope/plugin/FingerPainter.cpp index 2ed60776..015f5eb1 100644 --- a/plugins/Kaleidoscope-FingerPainter/src/kaleidoscope/plugin/FingerPainter.cpp +++ b/plugins/Kaleidoscope-FingerPainter/src/kaleidoscope/plugin/FingerPainter.cpp @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-FingerPainter -- On-the-fly keyboard painting. - * Copyright (C) 2017-2021 Keyboard.io, Inc + * Copyright (C) 2017-2022 Keyboard.io, Inc * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software @@ -89,6 +89,7 @@ EventHandlerResult FingerPainter::onKeyEvent(KeyEvent &event) { ::LEDPaletteTheme.updateColorIndexAtPosition(color_base_, Runtime.device().getLedIndex(event.addr), color_index); + Runtime.storage().commit(); return EventHandlerResult::EVENT_CONSUMED; } diff --git a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.cpp b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.cpp index 13cbd3b1..4d43d06e 100644 --- a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.cpp +++ b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.cpp @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-LED-Palette-Theme -- Palette-based LED theme foundation - * Copyright (C) 2017, 2018, 2019 Keyboard.io, Inc + * Copyright (C) 2017-2022 Keyboard.io, Inc * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software @@ -105,7 +105,21 @@ void LEDPaletteTheme::updateColorIndexAtPosition(uint16_t map_base, uint16_t pos indexes = (color_index << 4) + other; } Runtime.storage().update(map_base + position / 2, indexes); - Runtime.storage().commit(); +} + +void LEDPaletteTheme::updatePaletteColor(uint8_t palette_index, cRGB color) { + color.r ^= 0xff; + color.g ^= 0xff; + color.b ^= 0xff; + + Runtime.storage().put(palette_base_ + palette_index * sizeof(color), color); +} + +bool LEDPaletteTheme::isThemeUninitialized(uint16_t theme_base, uint8_t max_themes) { + bool paletteEmpty = Runtime.storage().isSliceUninitialized(palette_base_, 16 * sizeof(cRGB)); + bool themeEmpty = Runtime.storage().isSliceUninitialized(theme_base, max_themes * Runtime.device().led_count / 2); + + return paletteEmpty && themeEmpty; } EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) { @@ -135,11 +149,7 @@ EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) { cRGB color; ::Focus.read(color); - color.r ^= 0xff; - color.g ^= 0xff; - color.b ^= 0xff; - - Runtime.storage().put(palette_base_ + i * sizeof(color), color); + updatePaletteColor(i, color); i++; } Runtime.storage().commit(); diff --git a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.h b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.h index 44711dcd..715dc9a5 100644 --- a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.h +++ b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-LED-Palette-Theme -- Palette-based LED theme foundation - * Copyright (C) 2017, 2018 Keyboard.io, Inc + * Copyright (C) 2017-2022 Keyboard.io, Inc * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software @@ -37,6 +37,7 @@ class LEDPaletteTheme : public kaleidoscope::Plugin { static const cRGB lookupColorAtPosition(uint16_t theme_base, uint16_t position); static void updateColorIndexAtPosition(uint16_t theme_base, uint16_t position, uint8_t color_index); + static void updatePaletteColor(uint8_t palette_index, cRGB color); static const cRGB lookupPaletteColor(uint8_t palette_index); EventHandlerResult onFocusEvent(const char *command); @@ -44,6 +45,7 @@ class LEDPaletteTheme : public kaleidoscope::Plugin { const char *expected_command, uint16_t theme_base, uint8_t max_themes); + static bool isThemeUninitialized(uint16_t theme_base, uint8_t max_themes); private: static uint16_t palette_base_;