aboutsummaryrefslogtreecommitdiff
path: root/DakkarColor.h
blob: 30bfa648324ae4e4cb0fcf91dc1988c5aa7311fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// -*- mode: c++ -*- 
#pragma once
 
#include <Kaleidoscope-LEDControl.h>
 
class DakkarColorpublic 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)[Kaleidoscope.device().matrix_rows * Kaleidoscope.device().matrix_columns];
  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 layer, KeyAddr key_addr) {
    uint8_t index = map[layer][key_addr.toInt()];
    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.mostRecent();
    for (auto key_addr : KeyAddr::all()) {
      LEDControl.setCrgbAt(key_addr, getColor(layer,key_addr));
    }
  }
  void refreshAt(KeyAddr key_addr) final {
    LEDControl.setCrgbAt(key_addr, getColor(Layer.mostRecent(),key_addr));
  }
};