hyperion.ng/libsrc/leddevice/LedDeviceAtmo.cpp
redPanther 4033de85ec Logging leds (#50)
* switch to new logger for folowing led devices:
LedDeviceAtmo
LedDeviceFactory
LedDeviceFadeCandy
LedDeviceHyperionUsbasp
LedDeviceLightpack-hidapi
LedDevicePiBlaster
LedDeviceWS281x
LedRs232Device

leddevice base class defines logger already as protected member _log

* migrate to new logger for led devices.
still todo:
LedDeviceWS2812b
LedDeviceWs2812SPI
LedDeviceTinkerforge
LedDeviceLightpack
LedDeviceMultiLightpack
2016-06-25 22:08:17 +02:00

39 lines
1.1 KiB
C++

// STL includes
#include <cstring>
#include <iostream>
// hyperion local includes
#include "LedDeviceAtmo.h"
LedDeviceAtmo::LedDeviceAtmo(const std::string& outputDevice, const unsigned baudrate) :
LedRs232Device(outputDevice, baudrate),
_ledBuffer(4 + 5*3) // 4-byte header, 5 RGB values
{
_ledBuffer[0] = 0xFF; // Startbyte
_ledBuffer[1] = 0x00; // StartChannel(Low)
_ledBuffer[2] = 0x00; // StartChannel(High)
_ledBuffer[3] = 0x0F; // Number of Databytes send (always! 15)
}
int LedDeviceAtmo::write(const std::vector<ColorRgb> &ledValues)
{
// The protocol is shomehow limited. we always need to send exactly 5 channels + header
// (19 bytes) for the hardware to recognize the data
if (ledValues.size() != 5)
{
Error( _log, "%d channels configured. This should always be 5!", ledValues.size());
return 0;
}
// write data
memcpy(4 + _ledBuffer.data(), ledValues.data(), ledValues.size() * sizeof(ColorRgb));
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}
int LedDeviceAtmo::switchOff()
{
memset(4 + _ledBuffer.data(), 0, _ledBuffer.size() - 4);
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}