LEDDevices - WLED enhancements and minor fixes (#1204)

* Yeelight minor updates

* Add Timeout to REST API

* LEDDevice - Correct storeState

* Add WaitTime function

* Always show HW-LEDCount for configuration

* WLED - New features ("live" support, storing state and identification)

* Yeelight - Refactoring

* Cololight - Refactoring

* Karate - getProperties Support

* Atmo - getProperties Support

* AtmoOrb - refactoring

* Nanoleaf - Refactoring, New "Shapes" considerations

* PhilipHue - Minor corrections

* Update Changelog
This commit is contained in:
LordGrey
2021-03-19 22:52:04 +01:00
committed by GitHub
parent 956edf9e78
commit 41af5c1b9e
20 changed files with 609 additions and 257 deletions

View File

@@ -1,6 +1,10 @@
// hyperion local includes
#include "LedDeviceAtmo.h"
namespace {
const bool verbose = false;
} //End of constants
LedDeviceAtmo::LedDeviceAtmo(const QJsonObject &deviceConfig)
: ProviderRs232(deviceConfig)
{
@@ -43,3 +47,20 @@ int LedDeviceAtmo::write(const std::vector<ColorRgb> &ledValues)
memcpy(4 + _ledBuffer.data(), ledValues.data(), _ledCount * sizeof(ColorRgb));
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}
QJsonObject LedDeviceAtmo::getProperties(const QJsonObject& params)
{
DebugIf(verbose, _log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData());
QJsonObject properties;
QString serialPort = params["serialPort"].toString("");
QJsonObject propertiesDetails;
QJsonArray possibleLedCounts = { 5 };
propertiesDetails.insert("ledCount", possibleLedCounts);
properties.insert("properties", propertiesDetails);
DebugIf(verbose, _log, "properties: [%s]", QString(QJsonDocument(properties).toJson(QJsonDocument::Compact)).toUtf8().constData());
return properties;
}

View File

@@ -23,6 +23,14 @@ public:
///
static LedDevice* construct(const QJsonObject &deviceConfig);
///
/// @brief Get a Atmo device's resource properties
///
/// @param[in] params Parameters to query device
/// @return A JSON structure holding the device's properties
///
QJsonObject getProperties(const QJsonObject& params) override;
private:
///

View File

@@ -1,27 +1,31 @@
// hyperion local includes
#include "LedDeviceKarate.h"
LedDeviceKarate::LedDeviceKarate(const QJsonObject &deviceConfig)
namespace {
const bool verbose = false;
} //End of constants
LedDeviceKarate::LedDeviceKarate(const QJsonObject& deviceConfig)
: ProviderRs232(deviceConfig)
{
}
LedDevice* LedDeviceKarate::construct(const QJsonObject &deviceConfig)
LedDevice* LedDeviceKarate::construct(const QJsonObject& deviceConfig)
{
return new LedDeviceKarate(deviceConfig);
}
bool LedDeviceKarate::init(const QJsonObject &deviceConfig)
bool LedDeviceKarate::init(const QJsonObject& deviceConfig)
{
bool isInitOK = false;
// Initialise sub-class
if ( ProviderRs232::init(deviceConfig) )
if (ProviderRs232::init(deviceConfig))
{
if (_ledCount != 8 && _ledCount != 16)
{
//Error( _log, "%d channels configured. This should always be 16!", _ledCount);
QString errortext = QString ("%1 channels configured. This should always be 8 or 16!").arg(_ledCount);
QString errortext = QString("%1 channels configured. This should always be 8 or 16!").arg(_ledCount);
this->setInError(errortext);
isInitOK = false;
}
@@ -33,8 +37,8 @@ bool LedDeviceKarate::init(const QJsonObject &deviceConfig)
_ledBuffer[2] = 0x00; // Checksum
_ledBuffer[3] = _ledCount * 3; // Number of Databytes send
Debug( _log, "Karatelight header for %d leds: 0x%02x 0x%02x 0x%02x 0x%02x", _ledCount,
_ledBuffer[0], _ledBuffer[1], _ledBuffer[2], _ledBuffer[3] );
Debug(_log, "Karatelight header for %d leds: 0x%02x 0x%02x 0x%02x 0x%02x", _ledCount,
_ledBuffer[0], _ledBuffer[1], _ledBuffer[2], _ledBuffer[3]);
isInitOK = true;
}
@@ -42,20 +46,37 @@ bool LedDeviceKarate::init(const QJsonObject &deviceConfig)
return isInitOK;
}
int LedDeviceKarate::write(const std::vector<ColorRgb> &ledValues)
int LedDeviceKarate::write(const std::vector<ColorRgb>& ledValues)
{
for (signed iLed=0; iLed< static_cast<int>(_ledCount); iLed++)
{
const ColorRgb& rgb = ledValues[iLed];
_ledBuffer[iLed*3+4] = rgb.green;
_ledBuffer[iLed*3+5] = rgb.blue;
_ledBuffer[iLed*3+6] = rgb.red;
}
for (signed iLed = 0; iLed < static_cast<int>(_ledCount); iLed++)
{
const ColorRgb& rgb = ledValues[iLed];
_ledBuffer[iLed * 3 + 4] = rgb.green;
_ledBuffer[iLed * 3 + 5] = rgb.blue;
_ledBuffer[iLed * 3 + 6] = rgb.red;
}
// Calc Checksum
_ledBuffer[2] = _ledBuffer[0] ^ _ledBuffer[1];
for (unsigned int i = 3; i < _ledBuffer.size(); i++)
_ledBuffer[2] ^= _ledBuffer[i];
_ledBuffer[2] = _ledBuffer[0] ^ _ledBuffer[1];
for (unsigned int i = 3; i < _ledBuffer.size(); i++)
_ledBuffer[2] ^= _ledBuffer[i];
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}
QJsonObject LedDeviceKarate::getProperties(const QJsonObject& params)
{
DebugIf(verbose, _log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData());
QJsonObject properties;
QString serialPort = params["serialPort"].toString("");
QJsonObject propertiesDetails;
QJsonArray possibleLedCounts = { 16, 8 };
propertiesDetails.insert("ledCount", possibleLedCounts);
properties.insert("properties", propertiesDetails);
DebugIf(verbose, _log, "properties: [%s]", QString(QJsonDocument(properties).toJson(QJsonDocument::Compact)).toUtf8().constData());
return properties;
}

View File

@@ -26,6 +26,14 @@ public:
/// @return LedDevice constructed
static LedDevice* construct(const QJsonObject &deviceConfig);
///
/// @brief Get a Karate device's resource properties
///
/// @param[in] params Parameters to query device
/// @return A JSON structure holding the device's properties
///
QJsonObject getProperties(const QJsonObject& params) override;
private:
///