forked from jdlien/Kaleidoscope-LEDEffect-FunctionalColor
/
Kaleidoscope-LEDEffect-FunctionalColor.h
171 lines (131 loc) · 4.46 KB
/
Kaleidoscope-LEDEffect-FunctionalColor.h
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#pragma once
#include "Kaleidoscope-LEDControl.h"
#include "Kaleidoscope-MouseKeys.h"
#include "colors.h"
namespace kaleidoscope {
// This is the color-brightness-version of the plugin
//
class LEDFunctionalColorCB : public LEDMode {
public:
typedef byte & (*CBLookup)(const Key &);
LEDFunctionalColorCB(uint8_t fLayer,
CBLookup cbLookup,
cRGB *palette,
uint8_t nPaletteEntries);
LEDFunctionalColorCB(void);
uint8_t functionLayer = 2;
// Note: Only use the methods below if you need runtime configuration
// of key paletteId/brightness and palette colors. Else
// assign appropriate initial values when defining the palette
// in the sketch. This allows Arduino to omit the setter methods
// from the firmware binary and thus safes some flash memory.
// Dims a palette color
//
void dimPalette(byte brightness);
// Sets color and overlay brightness for all palette entries
//
void setAllPalette(const cRGB &color, byte brightness = 255);
// Set color and overlay brightness for an individual palette entry
//
void setPaletteEntryColor(byte paletteId, const cRGB &color, byte brightness = 255);
// Set the palette entry id and the overlay brightness for an individual
// key (or key group)
//
void setKeyColor(const Key &k, byte paletteId, byte brightness = 255);
private:
uint16_t current_key = 0;
uint16_t current_row = 0;
uint16_t current_col = 0;
uint16_t current_color = 0;
uint8_t last_layer = 0;
cRGB *palette_ = nullptr;
uint8_t nPaletteEntries_ = 0;
CBLookup cbLookup_ = nullptr;
protected:
void onActivate(void) final;
void update(void) final;
cRGB dim(cRGB color, byte brightness);
void setKeyLed(uint8_t r, uint8_t c);
};
#define FC_CB_COLOR_LIST(ID) \
colorBrightness_##ID
#define FC_CB_START_COLOR_LIST(NAME) \
byte &FC_CB_COLOR_LIST(NAME)(const Key &k) { \
switch(k.raw) {
#define FC_CB_END_COLOR_LIST \
default: \
{ \
static byte defaultColorId = 0 /* or any default index */; \
return defaultColorId; \
} \
break; \
} \
}
// case (Key_##KEY).raw:
#define FC_CB_COLOR(KEY, PALETTE_ID) \
case (Key_##KEY).keyCode << 8 | (Key_##KEY).flags: \
{ \
static byte colorId = (PALETTE_ID << 4) | 0 /* start with default brightness */; \
return colorId; \
} \
break;
#define FC_CB_SHARE_COLOR(KEY) \
case (Key_##KEY).keyCode << 8 | (Key_##KEY).flags:
#define FC_CB_PALETTE_SIZE(PALETTE) \
sizeof(PALETTE)/sizeof(cRGB)
#define FC_CB_PALETTE(palette) palette, FC_CB_PALETTE_SIZE(palette)
// This is the color-brightness-version of the plugin
//
class LEDFunctionalColorRGB : public LEDMode {
public:
typedef cRGB & (*RGBLookup)(const Key &);
LEDFunctionalColorRGB(uint8_t fLayer,
RGBLookup rgbLookup);
LEDFunctionalColorRGB(void);
uint8_t functionLayer = 2;
// Note: Only use the methods below if you need runtime configuration
// of key paletteId/brightness and palette colors. Else
// assign appropriate initial values when defining the palette
// in the sketch. This allows Arduino to omit the setter methods
// from the firmware binary and thus safes some flash memory.
// Set the palette entry id and the overlay brightness for an individual
// key (or key group)
//
void setKeyColor(const Key &k, const cRGB &color);
private:
uint16_t current_key = 0;
uint16_t current_row = 0;
uint16_t current_col = 0;
uint16_t current_color = 0;
uint8_t last_layer = 0;
RGBLookup rgbLookup_ = nullptr;
protected:
void onActivate(void) final;
void update(void) final;
void setKeyLed(uint8_t r, uint8_t c);
};
#define FC_RGB_COLOR_LIST(ID) \
cRGBLookup_##ID
#define FC_RGB_START_COLOR_LIST(NAME) \
cRGB &FC_RGB_COLOR_LIST(NAME)(const Key &k) { \
switch(k.raw) {
#define FC_RGB_END_COLOR_LIST \
default: \
{ \
static cRGB defaultColor = CRGB(0, 0, 0) /* or any default color */; \
return defaultColor; \
} \
break; \
} \
}
// case (Key_##KEY).raw:
#define FC_RGB_COLOR(KEY, COLOR) \
case (Key_##KEY).keyCode << 8 | (Key_##KEY).flags: \
{ \
static cRGB color = COLOR; \
return color; \
} \
break;
#define FC_RGB_SHARE_COLOR(KEY) \
case (Key_##KEY).keyCode << 8 | (Key_##KEY).flags:
}