aboutsummaryrefslogtreecommitdiff
path: root/DakkarColor.h
diff options
context:
space:
mode:
Diffstat (limited to 'DakkarColor.h')
-rw-r--r--DakkarColor.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/DakkarColor.h b/DakkarColor.h
new file mode 100644
index 0000000..17a93cb
--- /dev/null
+++ b/DakkarColor.h
@@ -0,0 +1,50 @@
+#pragma once
+
+class DakkarColor: public kaleidoscope::plugin::LEDMode {
+public:
+ typedef const cRGB (*color_function)();
+
+ struct colorSrc {
+ enum { VALUE, FUNCTION };
+ uint8_t value_or_function;
+ union {
+ cRGB value;
+ color_function function;
+ } vf;
+ };
+
+ typedef const uint8_t (*color_index_map)[ROWS][COLS];
+ typedef const colorSrc *color_src_array;
+
+ DakkarColor(
+ const color_index_map _map,
+ const color_src_array _colors
+ ) : map(_map),
+ color_sources(_colors) {}
+private:
+ const color_index_map map;
+ const color_src_array color_sources;
+
+ cRGB getColor(uint8_t l, uint8_t r, uint8_t c) {
+ uint8_t index = map[l][r][c];
+ colorSrc color_src = color_sources[index];
+ if (color_src.value_or_function == colorSrc::VALUE) {
+ return color_src.vf.value;
+ }
+ else {
+ return color_src.vf.function();
+ }
+ }
+protected:
+ void update(void) final {
+ uint8_t layer = Layer.top();
+ for (uint8_t r = 0; r < ROWS; r++) {
+ for (uint8_t c = 0; c < COLS; c++) {
+ LEDControl.setCrgbAt(r, c, getColor(layer,r,c));
+ }
+ }
+ }
+ void refreshAt(byte r, byte c) final {
+ LEDControl.setCrgbAt(r, c, getColor(Layer.top(),r,c));
+ }
+};