mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
cc8185691a
%s/LedUdpDevice/ProviderUdp/g git mv LedUdpDevice.cpp ProviderUdp.cpp git mv LedUdpDevice.h ProviderUdp.h vi `grep -l LedHID *` %s/LedHIDDevice/ProviderHID/g git mv LedHIDDevice.cpp ProviderHID.cpp git mv LedHIDDevice.h ProviderHID.h vi `grep -l LedRs *` %s/LedRs232Device/ProviderRs232/g git mv LedRs232Device.cpp ProviderRs232.cpp git mv LedRs232Device.h ProviderRs232.h vi `grep -l LedSpi *` %s/LedSpiDevice/ProviderSpi/g git mv LedSpiDevice.cpp ProviderSpi.cpp git mv LedSpiDevice.h ProviderSpi.h
43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
|
|
// STL includes
|
|
#include <cstring>
|
|
#include <cstdio>
|
|
#include <iostream>
|
|
|
|
// hyperion local includes
|
|
#include "LedDeviceTpm2.h"
|
|
#include <json/json.h>
|
|
|
|
LedDeviceTpm2::LedDeviceTpm2(const Json::Value &deviceConfig)
|
|
: ProviderRs232(deviceConfig)
|
|
{
|
|
}
|
|
|
|
LedDevice* LedDeviceTpm2::construct(const Json::Value &deviceConfig)
|
|
{
|
|
return new LedDeviceTpm2(deviceConfig);
|
|
}
|
|
|
|
int LedDeviceTpm2::write(const std::vector<ColorRgb> &ledValues)
|
|
{
|
|
if (_ledBuffer.size() == 0)
|
|
{
|
|
_ledBuffer.resize(5 + 3*ledValues.size());
|
|
_ledBuffer[0] = 0xC9; // block-start byte
|
|
_ledBuffer[1] = 0xDA; // DATA frame
|
|
_ledBuffer[2] = ((3 * ledValues.size()) >> 8) & 0xFF; // frame size high byte
|
|
_ledBuffer[3] = (3 * ledValues.size()) & 0xFF; // frame size low byte
|
|
_ledBuffer.back() = 0x36; // block-end byte
|
|
}
|
|
|
|
// write data
|
|
memcpy(4 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
}
|
|
|
|
int LedDeviceTpm2::switchOff()
|
|
{
|
|
memset(4 + _ledBuffer.data(), 0, _ledBuffer.size() - 5);
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
}
|