From bbffa078fd4441d5803e53b36704ebcdf1125136 Mon Sep 17 00:00:00 2001 From: redPanther Date: Mon, 5 Sep 2016 17:26:29 +0200 Subject: [PATCH] Webui: view led configuration + lights (#223) * make hyperion websocket api event based * implement new websocket handling for generalconf * migrate all webui stuff to new event based websocket api some cleanup ... now all html templates are in content refactoring of web stuff * add hyperionport to global start impl. removing advanced key * separate dashboard serverinfo is updated every 3 seconds automatily add input selection cleanup and remove not needed stuff * prepare infrastructure for server sided file execution * webui minor fixes * fix compile * implement led layout view with live colors * live led vies * fix general conf unrigister ledcolors request, when not on leds.html * fix compiler warning * prepare realtime ledview and enhance ui --- assets/webconfig/content/effects.html | 6 +- assets/webconfig/content/generalconf.html | 45 ++++--- assets/webconfig/content/input_selection.html | 21 ++- assets/webconfig/content/leds.html | 125 ++++++++++++++++++ assets/webconfig/index.html | 21 +-- assets/webconfig/js/hyperion.js | 21 ++- assets/webconfig/js/ui_utils.js | 31 +++++ include/hyperion/Hyperion.h | 1 + libsrc/jsonserver/JsonClientConnection.cpp | 27 ++++ libsrc/jsonserver/JsonClientConnection.h | 11 +- libsrc/jsonserver/JsonSchemas.qrc | 1 + .../jsonserver/schema/schema-ledcolors.json | 27 ++++ libsrc/jsonserver/schema/schema.json | 2 +- test/TestConfigFile.cpp | 5 +- 14 files changed, 292 insertions(+), 52 deletions(-) create mode 100644 assets/webconfig/content/leds.html create mode 100644 libsrc/jsonserver/schema/schema-ledcolors.json diff --git a/assets/webconfig/content/effects.html b/assets/webconfig/content/effects.html index 6139942c..d3d7f570 100644 --- a/assets/webconfig/content/effects.html +++ b/assets/webconfig/content/effects.html @@ -1,7 +1,7 @@ 
-
-
-

Effects

+
+
+

Effects

The Effects remote enables you to set an effect for testing or demonstration purposes. Don't forget to stop it afterwards.

diff --git a/assets/webconfig/content/generalconf.html b/assets/webconfig/content/generalconf.html index b766b288..94201f57 100644 --- a/assets/webconfig/content/generalconf.html +++ b/assets/webconfig/content/generalconf.html @@ -17,7 +17,8 @@ diff --git a/assets/webconfig/index.html b/assets/webconfig/index.html index 06461a69..a6de6454 100644 --- a/assets/webconfig/index.html +++ b/assets/webconfig/index.html @@ -202,6 +202,7 @@ @@ -261,15 +262,16 @@ $(document).ready( function() { initWebSocket(); bindNavToContent("#load_dashboard","dashboard",true); - bindNavToContent("#load_lighttest","lighttest"); - bindNavToContent("#load_effects","effects"); - bindNavToContent("#load_components","remote_components"); - bindNavToContent("#load_input_selection","input_selection"); - bindNavToContent("#load_huebridge","huebridge"); - bindNavToContent("#load_support","support"); - bindNavToContent("#load_confKodi","kodiconf"); - bindNavToContent("#load_update","update"); - bindNavToContent("#load_confGeneral","generalconf"); + bindNavToContent("#load_lighttest","lighttest",false); + bindNavToContent("#load_effects","effects",false); + bindNavToContent("#load_components","remote_components",false); + bindNavToContent("#load_input_selection","input_selection",false); + bindNavToContent("#load_huebridge","huebridge",false); + bindNavToContent("#load_support","support",false); + bindNavToContent("#load_confKodi","kodiconf",false); + bindNavToContent("#load_update","update",false); + bindNavToContent("#load_confGeneral","generalconf",false); + bindNavToContent("#load_confLeds","leds",false); //Change all Checkboxes to Switches $("[type='checkbox']").bootstrapSwitch(); @@ -313,7 +315,6 @@ $('#error_dialog .modal-body').html(event.reason); $('#error_dialog').modal('show'); }); - }); $(function(){ diff --git a/assets/webconfig/js/hyperion.js b/assets/webconfig/js/hyperion.js index b5931152..f67f915e 100644 --- a/assets/webconfig/js/hyperion.js +++ b/assets/webconfig/js/hyperion.js @@ -26,19 +26,23 @@ var currentVersion; var cleanCurrentVersion; var latestVersion; var cleanLatestVersion; -var parsedServerInfoJSON; -var parsedUpdateJSON; -var parsedConfSchemaJSON; +var parsedServerInfoJSON = {}; +var parsedUpdateJSON = {}; +var parsedConfSchemaJSON = {}; +var parsedConfJSON = {}; var hyperionport = 19444; var websocket = null; var hyperion = {}; var wsTan = 1; var cronId = 0; +var ledStreamActive=false; + // function cron() { requestServerInfo(); + $(hyperion).trigger({type:"cron"}); } // init websocket to hyperion and bind socket events to jquery events of $(hyperion) object @@ -54,7 +58,7 @@ function initWebSocket() websocket.onopen = function (event) { $(hyperion).trigger({type:"open"}); - cronId = window.setInterval(cron,3000); + cronId = window.setInterval(cron,2000); }; websocket.onclose = function (event) { @@ -130,6 +134,14 @@ function requestServerConfigSchema() { websocket.send('{"command":"config", "tan":'+wsTan+',"subcommand":"getschema"}'); } +function requestServerConfig() { + websocket.send('{"command":"config", "tan":'+wsTan+',"subcommand":"getconfig"}'); +} + +function requestLedColorsStart() { + websocket.send('{"command":"ledcolors", "tan":'+wsTan+',"subcommand":"ledstream_start"}'); +} + function requestPriorityClear() { websocket.send('{"command":"clear", "tan":'+wsTan+', "priority":1}'); } @@ -142,7 +154,6 @@ function requestSetColor(r,g,b) { websocket.send('{"command":"color", "tan":'+wsTan+', "color":['+r+','+g+','+b+'], "priority":1}'); } - function requestSetComponentState(comp, state){ state_str = state?"true":"false"; websocket.send('{"command":"componentstate", "tan":'+wsTan+',"componentstate":{"component":"'+comp+'","state":'+state_str+'}}'); diff --git a/assets/webconfig/js/ui_utils.js b/assets/webconfig/js/ui_utils.js index bf41668f..ae43b188 100644 --- a/assets/webconfig/js/ui_utils.js +++ b/assets/webconfig/js/ui_utils.js @@ -10,3 +10,34 @@ function bindNavToContent(containerId, fileName, loadNow) $("#page-wrapper").load("/content/"+fileName+".html"); } } + + +function toggleClass(obj,class1,class2) +{ + if ( $(obj).hasClass(class1)) + { + $(obj).removeClass(class1); + $(obj).addClass(class2); + } + else + { + $(obj).removeClass(class2); + $(obj).addClass(class1); + } +} + + +function setClassByBool(obj,enable,class1,class2) +{ + if (enable) + { + $(obj).removeClass(class1); + $(obj).addClass(class2); + } + else + { + $(obj).removeClass(class2); + $(obj).addClass(class1); + } +} + diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index 8dcfbf7f..0be1d25e 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -90,6 +90,7 @@ public: /// @return The current priority /// int getCurrentPriority() const; + /// /// Returns a list of active priorities /// diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index ba961e0e..1fd65737 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -273,6 +273,8 @@ void JsonClientConnection::handleMessage(const std::string &messageString) handleConfigCommand(message, command, tan); else if (command == "componentstate") handleComponentStateCommand(message, command, tan); + else if (command == "ledcolors") + handleLedColorsCommand(message, command, tan); else handleNotImplemented(); } @@ -975,6 +977,31 @@ void JsonClientConnection::handleComponentStateCommand(const Json::Value& messag } } +void JsonClientConnection::handleLedColorsCommand(const Json::Value&, const std::string &command, const int tan) +{ + // create result + Json::Value result; + result["success"] = true; + result["command"] = command; + result["tan"] = tan; + Json::Value & leds = result["result"] = Json::Value(Json::arrayValue); + + const PriorityMuxer::InputInfo & priorityInfo = _hyperion->getPriorityInfo(_hyperion->getCurrentPriority()); + std::vector ledBuffer = priorityInfo.ledColors; + + for (ColorRgb& color : ledBuffer) + { + int idx = leds.size(); + Json::Value & item = leds[idx]; + item["index"] = idx; + item["red"] = color.red; + item["green"] = color.green; + item["blue"] = color.blue; + } + // send the result + sendMessage(result); +} + void JsonClientConnection::handleNotImplemented() { sendErrorReply("Command not implemented"); diff --git a/libsrc/jsonserver/JsonClientConnection.h b/libsrc/jsonserver/JsonClientConnection.h index 2e81e0cf..8e4a49a1 100644 --- a/libsrc/jsonserver/JsonClientConnection.h +++ b/libsrc/jsonserver/JsonClientConnection.h @@ -169,6 +169,12 @@ private: /// void handleComponentStateCommand(const Json::Value & message, const std::string &command, const int tan); + /// Handle an incoming JSON Led Colors message + /// + /// @param message the incoming message + /// + void handleLedColorsCommand(const Json::Value &, const std::string &command, const int tan); + /// /// Handle an incoming JSON message of unknown type /// @@ -222,7 +228,6 @@ private: /// bool checkJson(const Json::Value & message, const QString &schemaResource, std::string & errors, bool ignoreRequired = false); -private: /// The TCP-Socket that is connected tot the Json-client QTcpSocket * _socket; @@ -243,4 +248,8 @@ private: /// Flag if forwarder is enabled bool _forwarder_enabled; + + /// + QTimer _timer_ledcolors; + }; diff --git a/libsrc/jsonserver/JsonSchemas.qrc b/libsrc/jsonserver/JsonSchemas.qrc index 433d1d47..05059608 100644 --- a/libsrc/jsonserver/JsonSchemas.qrc +++ b/libsrc/jsonserver/JsonSchemas.qrc @@ -14,5 +14,6 @@ schema/schema-sourceselect.json schema/schema-config.json schema/schema-componentstate.json + schema/schema-ledcolors.json diff --git a/libsrc/jsonserver/schema/schema-ledcolors.json b/libsrc/jsonserver/schema/schema-ledcolors.json new file mode 100644 index 00000000..ff92f097 --- /dev/null +++ b/libsrc/jsonserver/schema/schema-ledcolors.json @@ -0,0 +1,27 @@ +{ + "type":"object", + "required":true, + "properties":{ + "command": { + "type" : "string", + "required" : true, + "enum" : ["ledcolors"] + }, + "tan" : { + "type" : "integer" + }, + "subcommand": { + "type" : "string", + "required" : true, + "enum" : ["ledstream_stop","ledstream_start","testled","imagestream_start","imagestream_stop"] + }, + "oneshot": { + "type" : "bool" + }, + "interval": { + "type" : "integer" + } + }, + + "additionalProperties": false +} diff --git a/libsrc/jsonserver/schema/schema.json b/libsrc/jsonserver/schema/schema.json index 68b1c987..a20f101e 100644 --- a/libsrc/jsonserver/schema/schema.json +++ b/libsrc/jsonserver/schema/schema.json @@ -5,7 +5,7 @@ "command": { "type" : "string", "required" : true, - "enum" : ["color", "image", "effect", "serverinfo", "clear", "clearall", "transform", "correction", "temperature", "adjustment", "sourceselect", "config", "componentstate"] + "enum" : ["color", "image", "effect", "serverinfo", "clear", "clearall", "transform", "correction", "temperature", "adjustment", "sourceselect", "config", "componentstate", "ledcolors"] } } } diff --git a/test/TestConfigFile.cpp b/test/TestConfigFile.cpp index 00c1d23b..4bdde4cc 100644 --- a/test/TestConfigFile.cpp +++ b/test/TestConfigFile.cpp @@ -94,14 +94,13 @@ int main(int argc, char** argv) { if (loadConfig(configFile)) std::cout << "PASSED" << std::endl; - exit(0); + return 0; } catch (std::runtime_error exception) { std::cout << "FAILED" << std::endl; std::cout << exception.what() << std::endl; - exit(1); } - return 0; + return 1; }