Commit | Line | Data |
---|---|---|
03b67a73 TW |
1 | package kaka.cakelight; |
2 | ||
03b67a73 | 3 | public class LedFrame { |
ed56b145 TW |
4 | private byte[] bytes; |
5 | private int roff = 0, goff = 2, boff = 1; // Color values are stored as RBG, which is what the LED list takes. | |
03b67a73 TW |
6 | |
7 | public static LedFrame from(Configuration config) { | |
8 | LedFrame frame = new LedFrame(); | |
ed56b145 | 9 | frame.bytes = new byte[config.leds.getCount() * 3]; |
03b67a73 TW |
10 | return frame; |
11 | } | |
12 | ||
ed56b145 TW |
13 | public void fillColor(int r, int g, int b) { |
14 | for (int i = 0; i < bytes.length; i += 3) { | |
15 | bytes[i + roff] = (byte)r; | |
16 | bytes[i + goff] = (byte)g; | |
17 | bytes[i + boff] = (byte)b; | |
18 | } | |
19 | } | |
20 | ||
21 | public void fillColor(Color color) { | |
22 | fillColor(color.r(), color.g(), color.b()); | |
23 | } | |
24 | ||
03b67a73 | 25 | public void setLedColor(int led, Color color) { |
ed56b145 TW |
26 | int offset = led * 3; |
27 | bytes[offset + roff] = (byte)color.r(); | |
28 | bytes[offset + goff] = (byte)color.g(); | |
29 | bytes[offset + boff] = (byte)color.b(); | |
03b67a73 TW |
30 | } |
31 | ||
32 | public Color getLedColor(int led) { | |
ed56b145 TW |
33 | int offset = led * 3; |
34 | return Color.rgb( | |
35 | bytes[offset + roff] & 0xff, | |
36 | bytes[offset + goff] & 0xff, | |
37 | bytes[offset + boff] & 0xff | |
38 | ); | |
39 | } | |
40 | ||
41 | public byte[] getBytes() { | |
42 | return bytes; | |
03b67a73 TW |
43 | } |
44 | } |