mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Leddevice refactoring the next next part (#263)
* switch rs232 provider to completly async transfer * start of implementing a seperate init function for leddevices * rename setconfig to init * more fixes * implement missing code * fix code style * remove debug code * remove debug stuff * set loglevel to original state
This commit is contained in:
@@ -3,13 +3,17 @@
|
||||
LedDeviceTpm2net::LedDeviceTpm2net(const Json::Value &deviceConfig)
|
||||
: ProviderUdp()
|
||||
{
|
||||
setConfig(deviceConfig);
|
||||
_deviceReady = init(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceTpm2net::setConfig(const Json::Value &deviceConfig)
|
||||
bool LedDeviceTpm2net::init(const Json::Value &deviceConfig)
|
||||
{
|
||||
ProviderUdp::setConfig(deviceConfig, TPM2_DEFAULT_PORT, 104000);
|
||||
_LatchTime_ns = 104000;
|
||||
_port = TPM2_DEFAULT_PORT;
|
||||
ProviderUdp::init(deviceConfig);
|
||||
_tpm2_max = deviceConfig.get("max-packet", 170).asInt();
|
||||
_tpm2ByteCount = 3 * _ledCount;
|
||||
_tpm2TotalPackets = 1 + _tpm2ByteCount / _tpm2_max;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -24,13 +28,10 @@ LedDevice* LedDeviceTpm2net::construct(const Json::Value &deviceConfig)
|
||||
|
||||
int LedDeviceTpm2net::write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
uint8_t * _tpm2_buffer = (uint8_t*) malloc(_tpm2_max+7);
|
||||
uint8_t * tpm2_buffer = (uint8_t*) malloc(_tpm2_max+7);
|
||||
|
||||
int retVal = 0;
|
||||
|
||||
_tpm2ByteCount = 3 * _ledCount;
|
||||
_tpm2TotalPackets = 1 + _tpm2ByteCount / _tpm2_max;
|
||||
|
||||
int _thisPacketBytes = 0;
|
||||
_tpm2ThisPacket = 1;
|
||||
|
||||
@@ -43,21 +44,21 @@ int LedDeviceTpm2net::write(const std::vector<ColorRgb> &ledValues)
|
||||
_thisPacketBytes = (_tpm2ByteCount - rawIdx < _tpm2_max) ? _tpm2ByteCount % _tpm2_max : _tpm2_max;
|
||||
// is this the last packet? ? ^^ last packet : ^^ earlier packets
|
||||
|
||||
_tpm2_buffer[0] = 0x9c; // Packet start byte
|
||||
_tpm2_buffer[1] = 0xda; // Packet type Data frame
|
||||
_tpm2_buffer[2] = (_thisPacketBytes >> 8) & 0xff; // Frame size high
|
||||
_tpm2_buffer[3] = _thisPacketBytes & 0xff; // Frame size low
|
||||
_tpm2_buffer[4] = _tpm2ThisPacket++; // Packet Number
|
||||
_tpm2_buffer[5] = _tpm2TotalPackets; // Number of packets
|
||||
tpm2_buffer[0] = 0x9c; // Packet start byte
|
||||
tpm2_buffer[1] = 0xda; // Packet type Data frame
|
||||
tpm2_buffer[2] = (_thisPacketBytes >> 8) & 0xff; // Frame size high
|
||||
tpm2_buffer[3] = _thisPacketBytes & 0xff; // Frame size low
|
||||
tpm2_buffer[4] = _tpm2ThisPacket++; // Packet Number
|
||||
tpm2_buffer[5] = _tpm2TotalPackets; // Number of packets
|
||||
}
|
||||
|
||||
_tpm2_buffer [6 + rawIdx%_tpm2_max] = rawdata[rawIdx];
|
||||
tpm2_buffer [6 + rawIdx%_tpm2_max] = rawdata[rawIdx];
|
||||
|
||||
// is this the last byte of last packet || last byte of other packets
|
||||
if ( (rawIdx == _tpm2ByteCount-1) || (rawIdx %_tpm2_max == _tpm2_max-1) )
|
||||
{
|
||||
_tpm2_buffer [6 + rawIdx%_tpm2_max +1] = 0x36; // Packet end byte
|
||||
retVal &= writeBytes(_thisPacketBytes+7, _tpm2_buffer);
|
||||
tpm2_buffer [6 + rawIdx%_tpm2_max +1] = 0x36; // Packet end byte
|
||||
retVal &= writeBytes(_thisPacketBytes+7, tpm2_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user