mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Rewrote the class to make it work with apa102 led strips
Former-commit-id: 9f63b95fb635b15e550d9368c7c8dbc632572bc5
This commit is contained in:
parent
a4bcdcc10a
commit
63d0f6652e
@ -13,35 +13,30 @@
|
||||
|
||||
LedDeviceAPA102::LedDeviceAPA102(const std::string& outputDevice, const unsigned baudrate) :
|
||||
LedSpiDevice(outputDevice, baudrate, 500000),
|
||||
mLedCount(0)
|
||||
_ledBuffer(0)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
mLedCount = ledValues.size();
|
||||
|
||||
const unsigned dataLen = 8 + (ledValues.size() * (sizeof(ColorRgb) + 1));
|
||||
const uint8_t data[dataLen] = { 0x00, 0x00, 0x00, 0x00 };
|
||||
int position = 4;
|
||||
for (ColorRgb* rgb : ledValues ){
|
||||
data[i++] = 0xFF;
|
||||
data[i++] = rgb.red;
|
||||
data[i++] = rgb.green;
|
||||
data[i++] = rgb.blue;
|
||||
const unsigned int mLedCount = (ledValues.size() * 4) + 8;
|
||||
if(_ledBuffer.size() != mLedCount){
|
||||
_ledBuffer.resize(mLedCount, 0x00);
|
||||
}
|
||||
|
||||
// Write end frame
|
||||
data[i++] = 0xFF;
|
||||
data[i++] = 0xFF;
|
||||
data[i++] = 0xFF;
|
||||
data[i++] = 0xFF;
|
||||
for (unsigned iLed=1; iLed<=ledValues.size(); ++iLed) {
|
||||
const ColorRgb& rgb = ledValues[iLed];
|
||||
_ledBuffer[iLed*4] = 0xFF;
|
||||
_ledBuffer[iLed*4+1] = rgb.red;
|
||||
_ledBuffer[iLed*4+2] = rgb.green;
|
||||
_ledBuffer[iLed*4+3] = rgb.blue;
|
||||
}
|
||||
|
||||
return writeBytes(dataLen, data);
|
||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||
}
|
||||
|
||||
int LedDeviceAPA102::switchOff()
|
||||
{
|
||||
return write(std::vector<ColorRgb>(mLedCount, ColorRgb{0,0,0}));
|
||||
return write(std::vector<ColorRgb>(_ledBuffer.size(), ColorRgb{0,0,0}));
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
/// the number of leds (needed when switching off)
|
||||
size_t mLedCount;
|
||||
/// The buffer containing the packed RGB values
|
||||
std::vector<uint8_t> _ledBuffer;
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user