mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
d679affeb4
* 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
54 lines
1.3 KiB
C++
54 lines
1.3 KiB
C++
// STL includes
|
|
#include <cstring>
|
|
#include <cstdio>
|
|
#include <iostream>
|
|
|
|
// Linux includes
|
|
#include <fcntl.h>
|
|
#include <sys/ioctl.h>
|
|
|
|
// hyperion local includes
|
|
#include "LedDeviceLpd6803.h"
|
|
|
|
LedDeviceLpd6803::LedDeviceLpd6803(const Json::Value &deviceConfig)
|
|
: LedSpiDevice(deviceConfig)
|
|
{
|
|
}
|
|
|
|
LedDevice* LedDeviceLpd6803::construct(const Json::Value &deviceConfig)
|
|
{
|
|
return new LedDeviceLpd6803(deviceConfig);
|
|
}
|
|
|
|
int LedDeviceLpd6803::write(const std::vector<ColorRgb> &ledValues)
|
|
{
|
|
unsigned messageLength = 4 + 2*ledValues.size() + ledValues.size()/8 + 1;
|
|
// Reconfigure if the current connfiguration does not match the required configuration
|
|
if (messageLength != _ledBuffer.size())
|
|
{
|
|
// Initialise the buffer
|
|
_ledBuffer.resize(messageLength, 0x00);
|
|
}
|
|
|
|
// Copy the colors from the ColorRgb vector to the Ldp6803 data vector
|
|
for (unsigned iLed=0; iLed<ledValues.size(); ++iLed)
|
|
{
|
|
const ColorRgb& rgb = ledValues[iLed];
|
|
|
|
_ledBuffer[4 + 2 * iLed] = 0x80 | ((rgb.red & 0xf8) >> 1) | (rgb.green >> 6);
|
|
_ledBuffer[5 + 2 * iLed] = ((rgb.green & 0x38) << 2) | (rgb.blue >> 3);
|
|
}
|
|
|
|
// Write the data
|
|
if (writeBytes(_ledBuffer.size(), _ledBuffer.data()) < 0)
|
|
{
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int LedDeviceLpd6803::switchOff()
|
|
{
|
|
return write(std::vector<ColorRgb>(_ledBuffer.size(), ColorRgb{0,0,0}));
|
|
}
|