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
75 lines
2.0 KiB
C++
75 lines
2.0 KiB
C++
|
|
// STL includes
|
|
#include <cstring>
|
|
#include <cstdio>
|
|
#include <iostream>
|
|
|
|
// Linux includes
|
|
#include <fcntl.h>
|
|
#include <sys/ioctl.h>
|
|
|
|
// hyperion local includes
|
|
#include "LedDeviceAdalightApa102.h"
|
|
|
|
LedDeviceAdalightApa102::LedDeviceAdalightApa102(const Json::Value &deviceConfig)
|
|
: LedDeviceAdalight(deviceConfig)
|
|
{
|
|
}
|
|
|
|
LedDevice* LedDeviceAdalightApa102::construct(const Json::Value &deviceConfig)
|
|
{
|
|
return new LedDeviceAdalightApa102(deviceConfig);
|
|
}
|
|
|
|
|
|
//comparing to ws2801 adalight, the following changes were needed:
|
|
// 1- differnt data frame (4 bytes instead of 3)
|
|
// 2 - in order to accomodate point 1 above, number of leds sent to adalight is increased by 1/3rd
|
|
int LedDeviceAdalightApa102::write(const std::vector<ColorRgb> & ledValues)
|
|
{
|
|
_ledCount = ledValues.size();
|
|
const unsigned int startFrameSize = 4;
|
|
const unsigned int endFrameSize = std::max<unsigned int>(((_ledCount + 15) / 16), 4);
|
|
const unsigned int mLedCount = (_ledCount * 4) + startFrameSize + endFrameSize;
|
|
if(_ledBuffer.size() != mLedCount+6){
|
|
_ledBuffer.resize(mLedCount+6, 0x00);
|
|
_ledBuffer[0] = 'A';
|
|
_ledBuffer[1] = 'd';
|
|
_ledBuffer[2] = 'a';
|
|
_ledBuffer[3] = (((unsigned int)(ledValues.size())) >> 8) & 0xFF; // LED count high byte
|
|
_ledBuffer[4] = ((unsigned int)(ledValues.size())) & 0xFF; // LED count low byte
|
|
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
|
|
}
|
|
|
|
for (signed iLed=1; iLed<=_ledCount; iLed++) {
|
|
const ColorRgb& rgb = ledValues[iLed-1];
|
|
_ledBuffer[iLed*4+6] = 0xFF;
|
|
_ledBuffer[iLed*4+1+6] = rgb.red;
|
|
_ledBuffer[iLed*4+2+6] = rgb.green;
|
|
_ledBuffer[iLed*4+3+6] = rgb.blue;
|
|
}
|
|
|
|
// restart the timer
|
|
_timer.start();
|
|
|
|
// write data
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
}
|
|
|
|
int LedDeviceAdalightApa102::switchOff()
|
|
{
|
|
for (signed iLed=1; iLed<=_ledCount; iLed++) {
|
|
_ledBuffer[iLed*4+6] = 0xFF;
|
|
_ledBuffer[iLed*4+1+6] = 0x00;
|
|
_ledBuffer[iLed*4+2+6] = 0x00;
|
|
_ledBuffer[iLed*4+3+6] = 0x00;
|
|
}
|
|
|
|
// restart the timer
|
|
_timer.start();
|
|
|
|
// write data
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
|
|
}
|