From 96cc58038fd750dc1027cc56226bc4c3c6018bd2 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Thu, 11 Jun 2020 21:47:06 +0200 Subject: [PATCH] Allow different Nanoleaf panel numbering sequence (Feature req.#827) --- assets/webconfig/i18n/de.json | 8 ++ assets/webconfig/i18n/en.json | 8 ++ .../leddevice/dev_net/LedDeviceNanoleaf.cpp | 83 ++++++++++++++++--- libsrc/leddevice/dev_net/LedDeviceNanoleaf.h | 10 ++- libsrc/leddevice/schemas/schema-nanoleaf.json | 43 +++++++++- 5 files changed, 137 insertions(+), 15 deletions(-) diff --git a/assets/webconfig/i18n/de.json b/assets/webconfig/i18n/de.json index 43c637496..b68c60bb1 100644 --- a/assets/webconfig/i18n/de.json +++ b/assets/webconfig/i18n/de.json @@ -487,6 +487,10 @@ "edt_dev_spec_clientKey_title": "Clientkey", "edt_dev_spec_printTimeStamp_title" : "Mit Zeitstempel", "edt_dev_spec_groupId_title": "Gruppen ID", + "edt_dev_spec_panelorganisation_title" : "Nummerierungsreihenfolge der Panels", + "edt_dev_spec_order_top_down_title" : "1.", + "edt_dev_spec_order_left_right_title" : "2.", + "edt_dev_spec_panel_start_position" : "Startpanel [0-max Panels]", "edt_conf_general_enable_title": "Aktiviert", "edt_conf_general_enable_expl": "Wenn aktiviert, ist die Komponente aktiv.", "edt_conf_general_priority_title": "Priorität", @@ -522,6 +526,10 @@ "edt_conf_enum_dl_informational": "informativ", "edt_conf_enum_dl_verbose": "sehr detailiert", "edt_conf_enum_custom": "Benutzerdefiniert", + "edt_conf_enum_bottom_up": "von unten nach oben", + "edt_conf_enum_top_down": "von oben nach unten", + "edt_conf_enum_right_left": "von rechts and links", + "edt_conf_enum_left_right": "von links nach rechts", "edt_conf_gen_heading_title": "Allgemeine Einstellungen", "edt_conf_gen_name_title": "Name der Konfiguration", "edt_conf_gen_name_expl": "Der Name wird verwendet, um Hyperion besser zu identifizieren. (Hilfreich bei mehreren Instanzen)", diff --git a/assets/webconfig/i18n/en.json b/assets/webconfig/i18n/en.json index d4355d493..45204d4c6 100644 --- a/assets/webconfig/i18n/en.json +++ b/assets/webconfig/i18n/en.json @@ -488,6 +488,10 @@ "edt_dev_spec_printTimeStamp_title" : "Add timestamp", "edt_dev_spec_clientKey_title" : "Clientkey", "edt_dev_spec_groupId_title" : "Group Id", + "edt_dev_spec_panelorganisation_title" : "Panel numbering sequence", + "edt_dev_spec_order_top_down_title" : "1.", + "edt_dev_spec_order_left_right_title" : "2.", + "edt_dev_spec_panel_start_position" : "Startpanel [0-max panels]", "edt_conf_general_enable_title" : "Activate", "edt_conf_general_enable_expl" : "If checked, the component is enabled.", "edt_conf_general_priority_title" : "Priority channel", @@ -523,6 +527,10 @@ "edt_conf_enum_dl_informational": "Informational", "edt_conf_enum_dl_verbose": "Verbose", "edt_conf_enum_custom": "Custom", + "edt_conf_enum_bottom_up": "Bottom up", + "edt_conf_enum_top_down": "Top down", + "edt_conf_enum_right_left": "Right to left", + "edt_conf_enum_left_right": "Left to right", "edt_conf_gen_heading_title" : "General Settings", "edt_conf_gen_name_title" : "Configuration name", "edt_conf_gen_name_expl" : "A user defined name which is used to detect Hyperion. (Helpful with more than one Hyperion instance)", diff --git a/libsrc/leddevice/dev_net/LedDeviceNanoleaf.cpp b/libsrc/leddevice/dev_net/LedDeviceNanoleaf.cpp index deef1860e..50e0fbd0c 100644 --- a/libsrc/leddevice/dev_net/LedDeviceNanoleaf.cpp +++ b/libsrc/leddevice/dev_net/LedDeviceNanoleaf.cpp @@ -21,6 +21,10 @@ static const char CONFIG_ADDRESS[] = "host"; //static const char CONFIG_PORT[] = "port"; static const char CONFIG_AUTH_TOKEN[] ="token"; +static const char CONFIG_PANEL_ORDER_TOP_DOWN[] ="panelOrderTopDown"; +static const char CONFIG_PANEL_ORDER_LEFT_RIGHT[] ="panelOrderLeftRight"; +static const char CONFIG_PANEL_START_POS[] ="panelStartPos"; + // Panel configuration settings static const char PANEL_LAYOUT[] = "layout"; static const char PANEL_NUM[] = "numPanels"; @@ -83,6 +87,10 @@ LedDeviceNanoleaf::LedDeviceNanoleaf(const QJsonObject &deviceConfig) : ProviderUdp() ,_restApi(nullptr) ,_apiPort(API_DEFAULT_PORT) + ,_topDown(true) + ,_leftRight(true) + ,_startPos(0) + ,_endPos(0) ,_extControlVersion (EXTCTRLVER_V2), _panelLedCount(0) { @@ -131,6 +139,20 @@ bool LedDeviceNanoleaf::init(const QJsonObject &deviceConfig) Debug(_log, "RefreshTime : %d", _refreshTimerInterval_ms); Debug(_log, "LatchTime : %d", this->getLatchTime()); + // Read panel organisation configuration + + if ( deviceConfig[ CONFIG_PANEL_ORDER_TOP_DOWN ].isString() ) + _topDown = deviceConfig[ CONFIG_PANEL_ORDER_TOP_DOWN ].toString().toInt() == 0 ? true : false; + else + _topDown = deviceConfig[ CONFIG_PANEL_ORDER_TOP_DOWN ].toInt() == 0 ? true : false; + + if ( deviceConfig[ CONFIG_PANEL_ORDER_LEFT_RIGHT ].isString() ) + _leftRight = deviceConfig[ CONFIG_PANEL_ORDER_LEFT_RIGHT ].toString().toInt() == 0 ? true : false; + else + _leftRight = deviceConfig[ CONFIG_PANEL_ORDER_LEFT_RIGHT ].toInt() == 0 ? true : false; + + _startPos = deviceConfig[ CONFIG_PANEL_START_POS ].toInt(0); + // TODO: Allow to handle port dynamically //Set hostname as per configuration and_defaultHost default port @@ -229,17 +251,37 @@ bool LedDeviceNanoleaf::initLedsConfiguration() } } - // Sort panels top down, left right + // Travers panels top down for(auto posY = panelMap.crbegin(); posY != panelMap.crend(); ++posY) { - // posY.first is the first key - for(auto const &posX : posY->second) + // Sort panels left to right + if ( _leftRight ) + { + for( auto posX = posY->second.cbegin(); posX != posY->second.cend(); ++posX) + { + DebugIf(verbose3, _log, "panelMap[%u][%u]=%u", posY->first, posX->first, posX->second ); + + if ( _topDown ) + _panelIds.push_back(posX->second); + else + _panelIds.push_front(posX->second); + } + } + else { - // posX.first is the second key, posX.second is the data - DebugIf(verbose3, _log, "panelMap[%u][%u]=%u", posY->first, posX.first, posX.second ); - _panelIds.push_back(posX.second); + // Sort panels right to left + for( auto posX = posY->second.crbegin(); posX != posY->second.crend(); ++posX) + { + DebugIf(verbose3, _log, "panelMap[%u][%u]=%u", posY->first, posX->first, posX->second ); + + if ( _topDown ) + _panelIds.push_back(posX->second); + else + _panelIds.push_front(posX->second); + } } } + this->_panelLedCount = static_cast(_panelIds.size()); _devConfig["hardwareLedCount"] = static_cast(_panelLedCount); @@ -248,6 +290,13 @@ bool LedDeviceNanoleaf::initLedsConfiguration() // Check. if enough panels were found. uint configuredLedCount = this->getLedCount(); + _endPos = _startPos + configuredLedCount - 1; + + Debug(_log, "Sort Top>Down : %d", _topDown); + Debug(_log, "Sort Left>Right: %d", _leftRight); + Debug(_log, "Start Panel Pos: %u", _startPos); + Debug(_log, "End Panel Pos : %u", _endPos); + if (_panelLedCount < configuredLedCount ) { QString errorReason = QString("Not enough panels [%1] for configured LEDs [%2] found!") @@ -260,19 +309,27 @@ bool LedDeviceNanoleaf::initLedsConfiguration() { if ( _panelLedCount > this->getLedCount() ) { - Warning(_log, "Nanoleaf: More panels [%u] than configured LEDs [%u].", _panelLedCount, configuredLedCount ); + Info(_log, "Nanoleaf: More panels [%u] than configured LEDs [%u].", _panelLedCount, configuredLedCount ); + } + + // Check, if start position + number of configured LEDs is greater than number of panels available + if ( _endPos >= _panelLedCount ) + { + QString errorReason = QString("Start panel [%1] out of range. Start panel position can be max [%2] given [%3] panel available!") + .arg(_startPos).arg(_panelLedCount-configuredLedCount).arg(_panelLedCount); + + this->setInError(errorReason); + isInitOK = false; } } } Debug(_log, "[%d]", isInitOK); + + isInitOK = false; + return isInitOK; } -//bool LedDeviceNanoleaf::initRestAPI() -//{ -// return initRestAPI ( _hostname,_api_port ); -//} - bool LedDeviceNanoleaf::initRestAPI(const QString &hostname, const int port, const QString &token ) { Debug(_log, ""); @@ -506,7 +563,7 @@ int LedDeviceNanoleaf::write(const std::vector & ledValues) lowByte = static_cast(panelID & 0xFF); // Set panels configured - if( panelCounter < this->getLedCount() ) { + if( panelCounter >= _startPos && panelCounter <= _endPos ) { color = static_cast(ledValues.at(panelCounter)); } else diff --git a/libsrc/leddevice/dev_net/LedDeviceNanoleaf.h b/libsrc/leddevice/dev_net/LedDeviceNanoleaf.h index 8646d4690..4e9de4c0c 100644 --- a/libsrc/leddevice/dev_net/LedDeviceNanoleaf.h +++ b/libsrc/leddevice/dev_net/LedDeviceNanoleaf.h @@ -209,6 +209,11 @@ class LedDeviceNanoleaf : public ProviderUdp int _apiPort; QString _authToken; + bool _topDown; + bool _leftRight; + uint _startPos; + uint _endPos; + //Nanoleaf device details QString _deviceModel; QString _deviceFirmwareVersion; @@ -218,7 +223,10 @@ class LedDeviceNanoleaf : public ProviderUdp uint _panelLedCount; /// Array of the panel ids. - std::vector _panelIds; + QVector _panelIds; + + + }; #endif // LEDEVICENANOLEAF_H diff --git a/libsrc/leddevice/schemas/schema-nanoleaf.json b/libsrc/leddevice/schemas/schema-nanoleaf.json index 4bf6e39d2..8d3b7247b 100644 --- a/libsrc/leddevice/schemas/schema-nanoleaf.json +++ b/libsrc/leddevice/schemas/schema-nanoleaf.json @@ -11,7 +11,48 @@ "type": "string", "title":"edt_dev_auth_key_title", "propertyOrder" : 2 - } + }, + "title": { + "type" : "object", + "title":"edt_dev_spec_panelorganisation_title", + "access" : "advanced", + "propertyOrder" : 3 + }, + "panelOrderTopDown": { + "type": "integer", + "title":"edt_dev_spec_order_top_down_title", + "enum" : [0, 1], + "default" : 0, + "options" : { + "enum_titles" : ["edt_conf_enum_top_down", "edt_conf_enum_bottom_up"] + }, + "minimum" : 0, + "maximum" : 1, + "access" : "advanced", + "propertyOrder" : 4 + }, + "panelOrderLeftRight": { + "type": "integer", + "title":"edt_dev_spec_order_left_right_title", + "enum" : [0, 1], + "default" : 0, + "options" : { + "enum_titles" : ["edt_conf_enum_left_right", "edt_conf_enum_right_left"] + }, + "minimum" : 0, + "maximum" : 1, + "access" : "advanced", + "propertyOrder" : 5 + }, + "panelStartPos": { + "type": "integer", + "title":"edt_dev_spec_panel_start_position", + "step": 1, + "minimum" : 0, + "default": 0, + "access" : "advanced", + "propertyOrder" : 6 + } }, "additionalProperties": true }