Skydimo as own device (#1800)

* Skydimo as own device type

* Skydimo updates
This commit is contained in:
LordGrey
2024-11-15 18:37:17 +01:00
committed by GitHub
parent 5cb3076698
commit 27f74af4e3
10 changed files with 198 additions and 24 deletions

View File

@@ -59,10 +59,6 @@ bool LedDeviceAdalight::init(const QJsonObject &deviceConfig)
Debug( _log, "Adalight driver uses standard Adalight protocol");
break;
case Adalight::SKYDIMO:
Debug( _log, "Adalight driver uses Skydimo protocol");
break;
default:
Error( _log, "Adalight driver - unsupported protocol");
return false;
@@ -92,18 +88,6 @@ void LedDeviceAdalight::prepareHeader()
}
}
break;
case Adalight::SKYDIMO:
{
_bufferLength = static_cast<qint64>(HEADER_SIZE + _ledRGBCount);
_ledBuffer.resize(static_cast<size_t>(_bufferLength), 0x00);
_ledBuffer[0] = 'A';
_ledBuffer[1] = 'd';
_ledBuffer[2] = 'a';
_ledBuffer[3] = 0;
_ledBuffer[4] = 0;
_ledBuffer[5] = static_cast<quint8>(_ledCount);
}
break;
case Adalight::AWA:
{
_bufferLength = static_cast<qint64>(HEADER_SIZE + _ledRGBCount + 8);

View File

@@ -10,8 +10,7 @@ typedef enum ProtocolType
{
ADA = 0,
LBAPA,
AWA,
SKYDIMO
AWA
} PROTOCOLTYPE;
}

View File

@@ -0,0 +1,68 @@
#include "LedDeviceSkydimo.h"
#include "utils/Logger.h"
#include <QtEndian>
// Constants
namespace {
constexpr int HEADER_SIZE {6};
} //End of constants
LedDeviceSkydimo::LedDeviceSkydimo(const QJsonObject &deviceConfig)
: ProviderRs232(deviceConfig)
{
}
LedDevice* LedDeviceSkydimo::construct(const QJsonObject &deviceConfig)
{
return new LedDeviceSkydimo(deviceConfig);
}
bool LedDeviceSkydimo::init(const QJsonObject &deviceConfig)
{
bool isInitOK = false;
// Initialise sub-class
if ( ProviderRs232::init(deviceConfig) )
{
prepareHeader();
isInitOK = true;
}
return isInitOK;
}
void LedDeviceSkydimo::prepareHeader()
{
_bufferLength = static_cast<qint64>(HEADER_SIZE + _ledRGBCount);
_ledBuffer.resize(static_cast<size_t>(_bufferLength), 0x00);
_ledBuffer[0] = 'A';
_ledBuffer[1] = 'd';
_ledBuffer[2] = 'a';
_ledBuffer[3] = 0;
_ledBuffer[4] = 0;
_ledBuffer[5] = static_cast<quint8>(_ledCount);
Debug( _log, "Skydimo header for %d leds (size: %d): %c%c%c 0x%02x 0x%02x 0x%02x", _ledCount, _ledBuffer.size(),
_ledBuffer[0], _ledBuffer[1], _ledBuffer[2], _ledBuffer[3], _ledBuffer[4], _ledBuffer[5] );
}
int LedDeviceSkydimo::write(const std::vector<ColorRgb> & ledValues)
{
if (_ledCount != ledValues.size())
{
Warning(_log, "Skydimo LED count has changed (old: %d, new: %d). Rebuilding header.", _ledCount, ledValues.size());
_ledCount = static_cast<uint>(ledValues.size());
_ledRGBCount = _ledCount * 3;
prepareHeader();
}
if (_bufferLength > static_cast<qint64>(_ledBuffer.size()))
{
Warning(_log, "Skydimo buffer's size has changed. Skipping refresh.");
return 0;
}
return writeBytes(_bufferLength, _ledBuffer.data());
}

View File

@@ -0,0 +1,56 @@
#ifndef LEDEVICESKYDIMO_H
#define LEDEVICESKYDIMO_H
// hyperion includes
#include "ProviderRs232.h"
///
/// Implementation of the LedDevice interface for writing to a Skydimo LED-device.
///
class LedDeviceSkydimo : public ProviderRs232
{
Q_OBJECT
public:
///
/// @brief Constructs a Skydimo LED-device
///
/// @param deviceConfig Device's configuration as JSON-Object
///
explicit LedDeviceSkydimo(const QJsonObject &deviceConfig);
///
/// @brief Constructs the LED-device
///
/// @param[in] deviceConfig Device's configuration as JSON-Object
/// @return LedDevice constructed
static LedDevice* construct(const QJsonObject &deviceConfig);
private:
///
/// @brief Initialise the device's configuration
///
/// @param[in] deviceConfig the JSON device configuration
/// @return True, if success
///
bool init(const QJsonObject &deviceConfig) override;
///
/// @brief Prepare the protocol's header
///
void prepareHeader();
///
/// @brief Writes the RGB-Color values to the LEDs.
///
/// @param[in] ledValues The RGB-color per LED
/// @return Zero on success, else negative
///
int write(const std::vector<ColorRgb> & ledValues) override;
qint64 _bufferLength;
};
#endif // LEDEVICESKYDIMO_H