2015-02-04 21:49:33 +01:00
|
|
|
// hyperion local includes
|
|
|
|
#include "LedDeviceAtmo.h"
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDeviceAtmo::LedDeviceAtmo(const Json::Value &deviceConfig)
|
|
|
|
: LedRs232Device(deviceConfig)
|
2015-02-04 21:49:33 +01:00
|
|
|
{
|
2016-08-14 10:46:44 +02:00
|
|
|
_ledBuffer.resize(4 + 5*3); // 4-byte header, 5 RGB values
|
2015-02-04 21:49:33 +01:00
|
|
|
_ledBuffer[0] = 0xFF; // Startbyte
|
|
|
|
_ledBuffer[1] = 0x00; // StartChannel(Low)
|
|
|
|
_ledBuffer[2] = 0x00; // StartChannel(High)
|
|
|
|
_ledBuffer[3] = 0x0F; // Number of Databytes send (always! 15)
|
|
|
|
}
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDevice* LedDeviceAtmo::construct(const Json::Value &deviceConfig)
|
|
|
|
{
|
|
|
|
return new LedDeviceAtmo(deviceConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-04 21:49:33 +01:00
|
|
|
int LedDeviceAtmo::write(const std::vector<ColorRgb> &ledValues)
|
|
|
|
{
|
2015-02-23 15:53:05 +01:00
|
|
|
// 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)
|
|
|
|
{
|
2016-06-25 22:08:17 +02:00
|
|
|
Error( _log, "%d channels configured. This should always be 5!", ledValues.size());
|
|
|
|
return 0;
|
2015-02-23 15:53:05 +01:00
|
|
|
}
|
2015-02-04 21:49:33 +01:00
|
|
|
|
|
|
|
// write data
|
2015-02-23 15:53:05 +01:00
|
|
|
memcpy(4 + _ledBuffer.data(), ledValues.data(), ledValues.size() * sizeof(ColorRgb));
|
2015-02-04 21:49:33 +01:00
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
int LedDeviceAtmo::switchOff()
|
|
|
|
{
|
|
|
|
memset(4 + _ledBuffer.data(), 0, _ledBuffer.size() - 4);
|
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
|
|
}
|