-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathPicoLedTarget.cpp
109 lines (93 loc) · 2.55 KB
/
PicoLedTarget.cpp
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
#include "PicoLed.hpp"
#include "PicoLedTarget.hpp"
#include <stdio.h>
using std::min;
namespace PicoLed {
PicoLedTarget::PicoLedTarget(uint numLeds, DataByte b1, DataByte b2, DataByte b3, DataByte b4): numLeds(numLeds), brightness(255)
{
bytes[0] = b1;
bytes[1] = b2;
bytes[2] = b3;
bytes[3] = b4;
}
PicoLedTarget::~PicoLedTarget() {
}
uint PicoLedTarget::getNumLeds() {
return numLeds;
}
uint8_t PicoLedTarget::getBrightness() {
return brightness;
}
void PicoLedTarget::setBrightness(uint8_t brightness) {
printf("Brightness: %u at %X\n", brightness, this);
this->brightness = brightness;
}
Color PicoLedTarget::getPixelColor(uint index) {
Color pixelColor = RGBW(0, 0, 0, 0);
uint32_t pixelData = getData(index);
for (uint b = 4; b-- > 0; ) {
switch (bytes[b]) {
case RED:
pixelColor.red = pixelData & 0xFF;
break;
case GREEN:
pixelColor.green = pixelData & 0xFF;
break;
case BLUE:
pixelColor.blue = pixelData & 0xFF;
break;
case WHITE:
pixelColor.white = pixelData & 0xFF;
break;
}
pixelData >>= 8;
}
return pixelColor;
}
void PicoLedTarget::setPixelColor(uint index, Color color) {
setData(index, getPixelData(color));
}
void PicoLedTarget::fill(Color color, uint first, uint count) {
uint32_t colorData = getPixelData(color);
uint last = (first + count);
if (last > numLeds) {
last = numLeds;
}
for (uint i = first; i < last; i++) {
setData(i, colorData);
}
}
uint32_t PicoLedTarget::getPixelData(Color color) {
uint32_t result = 0;
for (uint b = 0; b < 4; b++) {
result <<= 8;
switch (bytes[b]) {
case RED:
result |= color.red;
break;
case GREEN:
result |= color.green;
break;
case BLUE:
result |= color.blue;
break;
case WHITE:
result |= color.white;
break;
}
}
return result;
}
uint32_t PicoLedTarget::scalePixelData(uint32_t data, uint16_t scale) {
uint32_t dataA = (data & 0x00FF00FF) * scale;
uint32_t dataB = ((data >> 8) & 0x00FF00FF) * scale;
return ((dataA >> 8) & 0x00FF00FF | (dataB & 0xFF00FF00));
}
uint32_t PicoLedTarget::getData(uint index) {
return 0;
}
void PicoLedTarget::setData(uint index, uint32_t value) {
}
void PicoLedTarget::show() {
}
}