leddevice refactoring. code style and extension of baseclass to avoid dups (#174)

This commit is contained in:
redPanther
2016-08-14 10:46:44 +02:00
committed by GitHub
parent bc0c9c469f
commit 97181fa83c
63 changed files with 483 additions and 533 deletions

View File

@@ -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}));
}