mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
leddevice refactoring. code style and extension of baseclass to avoid dups (#174)
This commit is contained in:
@@ -14,16 +14,15 @@
|
||||
|
||||
LedDeviceAPA102::LedDeviceAPA102(const std::string& outputDevice, const unsigned baudrate)
|
||||
: LedSpiDevice(outputDevice, baudrate, 500000)
|
||||
, _ledBuffer(0)
|
||||
{
|
||||
}
|
||||
|
||||
int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
_mLedCount = ledValues.size();
|
||||
_ledCount = ledValues.size();
|
||||
const unsigned int startFrameSize = 4;
|
||||
const unsigned int endFrameSize = std::max<unsigned int>(((_mLedCount + 15) / 16), 4);
|
||||
const unsigned int APAbufferSize = (_mLedCount * 4) + startFrameSize + endFrameSize;
|
||||
const unsigned int endFrameSize = std::max<unsigned int>(((_ledCount + 15) / 16), 4);
|
||||
const unsigned int APAbufferSize = (_ledCount * 4) + startFrameSize + endFrameSize;
|
||||
|
||||
if(_ledBuffer.size() != APAbufferSize){
|
||||
_ledBuffer.resize(APAbufferSize, 0xFF);
|
||||
@@ -33,7 +32,7 @@ int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)
|
||||
_ledBuffer[3] = 0x00;
|
||||
}
|
||||
|
||||
for (unsigned iLed=0; iLed < _mLedCount; ++iLed) {
|
||||
for (signed iLed=0; iLed < _ledCount; ++iLed) {
|
||||
const ColorRgb& rgb = ledValues[iLed];
|
||||
_ledBuffer[4+iLed*4] = 0xFF;
|
||||
_ledBuffer[4+iLed*4+1] = rgb.red;
|
||||
@@ -46,5 +45,5 @@ int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)
|
||||
|
||||
int LedDeviceAPA102::switchOff()
|
||||
{
|
||||
return write(std::vector<ColorRgb>(_mLedCount, ColorRgb{0,0,0}));
|
||||
return write(std::vector<ColorRgb>(_ledCount, ColorRgb{0,0,0}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user