Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit df7341a

Browse files
committed
untested support for the P9813 chip
1 parent 66a4d02 commit df7341a

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

libsrc/leddevice/LedDeviceP9813.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,35 @@ int LedDeviceP9813::write(const std::vector<ColorRgb> &ledValues)
2222
{
2323
mLedCount = ledValues.size();
2424

25-
const unsigned dataLen = ledValues.size() * sizeof(ColorRgb);
26-
const uint8_t * dataPtr = reinterpret_cast<const uint8_t *>(ledValues.data());
25+
const unsigned dataLen = ledValues.size() * 4 + 8;
26+
uint8_t data[dataLen];
2727

28-
return writeBytes(dataLen, dataPtr);
28+
memset(data, 0x00, dataLen);
29+
30+
int j = 4;
31+
for (unsigned i = 0; i < mLedCount; i++){
32+
data[j++] = calculateChecksum(ledValues[i]);
33+
data[j++] = ledValues[i].blue;
34+
data[j++] = ledValues[i].green;
35+
data[j++] = ledValues[i].red;
36+
}
37+
38+
return writeBytes(dataLen, data);
2939
}
3040

3141
int LedDeviceP9813::switchOff()
3242
{
3343
return write(std::vector<ColorRgb>(mLedCount, ColorRgb{0,0,0}));
3444
}
45+
46+
const uint8_t LedDeviceP9813::calculateChecksum(const ColorRgb color)
47+
{
48+
uint8_t res = 0;
49+
50+
res |= (uint8_t)0x03 << 6;
51+
res |= (uint8_t)(~(color.blue >> 6) & 0x03) << 4;
52+
res |= (uint8_t)(~(color.green >> 6) & 0x03) << 2;
53+
res |= (uint8_t)(~(color.red >> 6) & 0x03);
54+
55+
return res;
56+
}

libsrc/leddevice/LedDeviceP9813.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ class LedDeviceP9813 : public LedSpiDevice
3636

3737
/// the number of leds
3838
size_t mLedCount;
39+
const uint8_t calculateChecksum(const ColorRgb color);
3940
};

0 commit comments

Comments
 (0)