From 2a10ef955d225764dd8960b5911a3fe7c7554287 Mon Sep 17 00:00:00 2001 From: LordGrey <48840279+Lord-Grey@users.noreply.github.com> Date: Mon, 20 Sep 2021 09:36:59 +0200 Subject: [PATCH] Limit maximum LEDs number for WLED and UDP-Raw (#1334) * Have maximum 490 LEDs configured for WLED and UDP-Raw * Add additional Warning --- assets/webconfig/i18n/en.json | 1 + assets/webconfig/js/content_leds.js | 30 ++++++++++++- libsrc/leddevice/dev_net/LedDeviceUdpRaw.cpp | 47 +++++++++++++++++++- libsrc/leddevice/dev_net/LedDeviceUdpRaw.h | 8 ++++ libsrc/leddevice/dev_net/LedDeviceWled.cpp | 13 +++++- 5 files changed, 94 insertions(+), 5 deletions(-) diff --git a/assets/webconfig/i18n/en.json b/assets/webconfig/i18n/en.json index 4a8d712f..f35b6fd0 100644 --- a/assets/webconfig/i18n/en.json +++ b/assets/webconfig/i18n/en.json @@ -57,6 +57,7 @@ "conf_leds_device_intro": "Hyperion supports a lot of controllers to transmit data to your target device. Select a LED controller out of the sorted list and configure it. We have chosen the best default settings for each device.", "conf_leds_error_hwled_gt_layout": "The hardware LED count ($1) is greater than LEDs configured via layout ($2),
$3 {{plural:$3|LED|LEDs}} will stay black if you continue.", "conf_leds_error_hwled_lt_layout": "The hardware LED count ($1) is less than LEDs configured via layout ($2).
The number of LEDs configured in the layout must not exceed the available LEDs", + "conf_leds_error_hwled_gt_maxled": "The hardware LED count ($1) is greater than the maximum number of LEDs supported by the device ($2).
The hardware LED count is set to ($3).", "conf_leds_info_ws281x": "Hyperion must run with 'root' privileges for this controller type!", "conf_leds_layout_advanced": "Advanced Settings", "conf_leds_layout_blacklist_num_title": "Number of LEDs", diff --git a/assets/webconfig/js/content_leds.js b/assets/webconfig/js/content_leds.js index 19545e7f..d10d487d 100755 --- a/assets/webconfig/js/content_leds.js +++ b/assets/webconfig/js/content_leds.js @@ -943,6 +943,11 @@ $(document).ready(function () { params = { host: host, filter: "info" }; getProperties_device(ledType, host, params); break; + + case "udpraw": + getProperties_device(ledType, host, params); + break; + default: } } @@ -1579,11 +1584,11 @@ async function identify_device(type, params) { function updateElements(ledType, key) { if (devicesProperties[ledType][key]) { + var hardwareLedCount = 1; switch (ledType) { case "cololight": var ledProperties = devicesProperties[ledType][key]; - var hardwareLedCount = 1; if (ledProperties) { hardwareLedCount = ledProperties.ledCount; } @@ -1592,8 +1597,14 @@ function updateElements(ledType, key) { case "wled": var ledProperties = devicesProperties[ledType][key]; - if (ledProperties && ledProperties.leds) { + if (ledProperties && ledProperties.leds && ledProperties.maxLedCount) { hardwareLedCount = ledProperties.leds.count; + var maxLedCount = ledProperties.maxLedCount + if (hardwareLedCount > maxLedCount) + { + showInfoDialog('warning', $.i18n("conf_leds_config_warning"), $.i18n('conf_leds_error_hwled_gt_maxled', hardwareLedCount, maxLedCount, maxLedCount)); + hardwareLedCount = maxLedCount; + } } conf_editor.getEditor("root.generalOptions.hardwareLedCount").setValue(hardwareLedCount); break; @@ -1615,6 +1626,21 @@ function updateElements(ledType, key) { break; + case "udpraw": + var ledProperties = devicesProperties[ledType][key]; + + if (ledProperties && ledProperties.maxLedCount) { + hardwareLedCount = conf_editor.getEditor("root.generalOptions.hardwareLedCount").getValue(); + var maxLedCount = ledProperties.maxLedCount + if (hardwareLedCount > maxLedCount) + { + showInfoDialog('warning', $.i18n("conf_leds_config_warning"), $.i18n('conf_leds_error_hwled_gt_maxled', hardwareLedCount, maxLedCount, maxLedCount)); + hardwareLedCount = maxLedCount; + } + updateJsonEditorRange(conf_editor, "root.generalOptions", "hardwareLedCount", 1, maxLedCount, hardwareLedCount); + } + break; + case "atmo": case "karate": var ledProperties = devicesProperties[ledType][key]; diff --git a/libsrc/leddevice/dev_net/LedDeviceUdpRaw.cpp b/libsrc/leddevice/dev_net/LedDeviceUdpRaw.cpp index 6d6a2cb8..d6e83b8b 100644 --- a/libsrc/leddevice/dev_net/LedDeviceUdpRaw.cpp +++ b/libsrc/leddevice/dev_net/LedDeviceUdpRaw.cpp @@ -1,6 +1,14 @@ #include "LedDeviceUdpRaw.h" +// Constants +namespace { + +const bool verbose = false; + const ushort RAW_DEFAULT_PORT=5568; +const int UDP_MAX_LED_NUM = 490; + +} //End of constants LedDeviceUdpRaw::LedDeviceUdpRaw(const QJsonObject &deviceConfig) : ProviderUdp(deviceConfig) @@ -16,8 +24,28 @@ bool LedDeviceUdpRaw::init(const QJsonObject &deviceConfig) { _port = RAW_DEFAULT_PORT; - // Initialise sub-class - bool isInitOK = ProviderUdp::init(deviceConfig); + bool isInitOK = false; + if ( LedDevice::init(deviceConfig) ) + { + // Initialise LedDevice configuration and execution environment + int configuredLedCount = this->getLedCount(); + Debug(_log, "DeviceType : %s", QSTRING_CSTR( this->getActiveDeviceType() )); + Debug(_log, "LedCount : %d", configuredLedCount); + Debug(_log, "ColorOrder : %s", QSTRING_CSTR( this->getColorOrder() )); + Debug(_log, "LatchTime : %d", this->getLatchTime()); + + if (configuredLedCount > UDP_MAX_LED_NUM) + { + QString errorReason = QString("Device type %1 can only be run with maximum %2 LEDs!").arg(this->getActiveDeviceType()).arg(UDP_MAX_LED_NUM); + this->setInError ( errorReason ); + isInitOK = false; + } + else + { + // Initialise sub-class + isInitOK = ProviderUdp::init(deviceConfig); + } + } return isInitOK; } @@ -27,3 +55,18 @@ int LedDeviceUdpRaw::write(const std::vector &ledValues) return writeBytes(_ledRGBCount, dataPtr); } + +QJsonObject LedDeviceUdpRaw::getProperties(const QJsonObject& params) +{ + DebugIf(verbose, _log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData() ); + QJsonObject properties; + + QJsonObject propertiesDetails; + propertiesDetails.insert("maxLedCount", UDP_MAX_LED_NUM); + + properties.insert("properties", propertiesDetails); + + DebugIf(verbose, _log, "properties: [%s]", QString(QJsonDocument(properties).toJson(QJsonDocument::Compact)).toUtf8().constData() ); + + return properties; +} diff --git a/libsrc/leddevice/dev_net/LedDeviceUdpRaw.h b/libsrc/leddevice/dev_net/LedDeviceUdpRaw.h index 5fe89d46..9e7d8210 100644 --- a/libsrc/leddevice/dev_net/LedDeviceUdpRaw.h +++ b/libsrc/leddevice/dev_net/LedDeviceUdpRaw.h @@ -26,6 +26,14 @@ public: /// static LedDevice* construct(const QJsonObject &deviceConfig); + /// + /// @brief Get a UDP-Raw 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; + protected: /// diff --git a/libsrc/leddevice/dev_net/LedDeviceWled.cpp b/libsrc/leddevice/dev_net/LedDeviceWled.cpp index a2139342..45ad2d31 100644 --- a/libsrc/leddevice/dev_net/LedDeviceWled.cpp +++ b/libsrc/leddevice/dev_net/LedDeviceWled.cpp @@ -21,6 +21,7 @@ const char CONFIG_SYNC_OVERWRITE[] = "overwriteSync"; // UDP elements const quint16 STREAM_DEFAULT_PORT = 19446; +const int UDP_MAX_LED_NUM = 490; // WLED JSON-API elements const int API_DEFAULT_PORT = -1; //Use default port per communication scheme @@ -81,6 +82,13 @@ bool LedDeviceWled::init(const QJsonObject &deviceConfig) Debug(_log, "ColorOrder : %s", QSTRING_CSTR( this->getColorOrder() )); Debug(_log, "LatchTime : %d", this->getLatchTime()); + if (configuredLedCount > UDP_MAX_LED_NUM) + { + QString errorReason = QString("Device type %1 can only be run with maximum %2 LEDs!").arg(this->getActiveDeviceType()).arg(UDP_MAX_LED_NUM); + this->setInError ( errorReason ); + return false; + } + _isRestoreOrigState = _devConfig[CONFIG_RESTORE_STATE].toBool(DEFAULT_IS_RESTORE_STATE); _isSyncOverwrite = _devConfig[CONFIG_SYNC_OVERWRITE].toBool(DEFAULT_IS_SYNC_OVERWRITE); _isBrightnessOverwrite = _devConfig[CONFIG_BRIGHTNESS_OVERWRITE].toBool(DEFAULT_IS_BRIGHTNESS_OVERWRITE); @@ -348,7 +356,10 @@ QJsonObject LedDeviceWled::getProperties(const QJsonObject& params) Warning (_log, "%s get properties failed with error: '%s'", QSTRING_CSTR(_activeDeviceType), QSTRING_CSTR(response.getErrorReason())); } - properties.insert("properties", response.getBody().object()); + QJsonObject propertiesDetails = response.getBody().object(); + propertiesDetails.insert("maxLedCount", UDP_MAX_LED_NUM); + + properties.insert("properties", propertiesDetails); DebugIf(verbose, _log, "properties: [%s]", QString(QJsonDocument(properties).toJson(QJsonDocument::Compact)).toUtf8().constData() ); }