hyperion.ng/libsrc/leddevice/LedDeviceSedu.cpp
redPanther d679affeb4 Leddevice rework2 (#193)
* commit debug code to save it due to merge

* migrate first devices to new device registry and configure on runtime

* fadecandy and rs232 resets device if config is set

* try to hunt crash on osx

* test commit if this works with osx

* refactor spi devices

* cleanup

* refactor leddevices file, tinkerforge and ws2812b

* refactor raw usb devices

* refactor udp devices

* - add tpm2net driver
- remove old udp driver from build (files left in place for reference for new udp driver)
- json serverinfo shows available leddevices

* finish rework part 2 of leddevices

* add schemas for leddevices.
currently only compiled in, but not usedx
2016-08-23 20:07:12 +02:00

68 lines
1.4 KiB
C++

// STL includes
#include <cstring>
#include <cstdio>
#include <iostream>
// Linux includes
#include <fcntl.h>
#include <sys/ioctl.h>
// hyperion local includes
#include "LedDeviceSedu.h"
struct FrameSpec
{
uint8_t id;
size_t size;
};
LedDeviceSedu::LedDeviceSedu(const Json::Value &deviceConfig)
: LedRs232Device(deviceConfig)
{
// empty
}
LedDevice* LedDeviceSedu::construct(const Json::Value &deviceConfig)
{
return new LedDeviceSedu(deviceConfig);
}
int LedDeviceSedu::write(const std::vector<ColorRgb> &ledValues)
{
if (_ledBuffer.size() == 0)
{
std::vector<FrameSpec> frameSpecs{{0xA1, 256}, {0xA2, 512}, {0xB0, 768}, {0xB1, 1536}, {0xB2, 3072} };
const unsigned reqColorChannels = ledValues.size() * sizeof(ColorRgb);
for (const FrameSpec& frameSpec : frameSpecs)
{
if (reqColorChannels <= frameSpec.size)
{
_ledBuffer.clear();
_ledBuffer.resize(frameSpec.size + 3, 0);
_ledBuffer[0] = 0x5A;
_ledBuffer[1] = frameSpec.id;
_ledBuffer.back() = 0xA5;
break;
}
}
if (_ledBuffer.size() == 0)
{
Warning(_log, "More rgb-channels required then available");
return -1;
}
}
memcpy(_ledBuffer.data()+2, ledValues.data(), ledValues.size() * sizeof(ColorRgb));
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}
int LedDeviceSedu::switchOff()
{
memset(_ledBuffer.data()+2, 0, _ledBuffer.size()-3);
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}