From 6111f5261f60410bda5bd1a7db98ad40d82e9cd3 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sun, 10 Feb 2019 17:07:22 +0000 Subject: move DakkarColor to its own file --- DakkarColor.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 DakkarColor.h (limited to 'DakkarColor.h') 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)); + } +}; -- cgit v1.2.3