Webui: extend led hardware config + connection lost page (#226)

* split content and js
tune leds config

* implement connection lost page

* split js/html in huebridge

* add js action for connection lost

* extend led config
make connection loss nicer

* tune led code
add menu entry for grabber

* more tuning of webui

* switch back to botstrap textarea
add v4l to components

* add icon

* extend schema for jsoneditor

* implement ledcolors streaming with 4fps

* implement component state
This commit is contained in:
redPanther
2016-09-07 20:10:37 +02:00
committed by GitHub
parent 4c6a4a1f93
commit 2beccb0912
35 changed files with 675 additions and 279 deletions

View File

@@ -46,7 +46,10 @@ JsonClientConnection::JsonClientConnection(QTcpSocket *socket)
// connect internal signals and slots
connect(_socket, SIGNAL(disconnected()), this, SLOT(socketClosed()));
connect(_socket, SIGNAL(readyRead()), this, SLOT(readData()));
connect( _hyperion, SIGNAL(componentStateChanged(hyperion::Components,bool)), this, SLOT(componentStateChanged(hyperion::Components,bool)));
connect(_hyperion, SIGNAL(componentStateChanged(hyperion::Components,bool)), this, SLOT(componentStateChanged(hyperion::Components,bool)));
_timer_ledcolors.setSingleShot(false);
connect(&_timer_ledcolors, SIGNAL(timeout()), this, SLOT(streamLedcolorsUpdate()));
}
@@ -644,6 +647,18 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &, const st
info["ledDevices"]["available"].append(dev.first);
}
// get components
info["components"] = Json::Value(Json::arrayValue);
std::map<hyperion::Components, bool> components = _hyperion->getComponentRegister().getRegister();
for(auto comp : components)
{
Json::Value item;
item["id"] = comp.first;
item["name"] = hyperion::componentToIdString(comp.first);
item["title"] = hyperion::componentToString(comp.first);
item["enabled"] = comp.second;
info["components"].append(item);
}
// Add Hyperion Version, build time
//Json::Value & version =
@@ -977,29 +992,30 @@ void JsonClientConnection::handleComponentStateCommand(const Json::Value& messag
}
}
void JsonClientConnection::handleLedColorsCommand(const Json::Value&, const std::string &command, const int tan)
void JsonClientConnection::handleLedColorsCommand(const Json::Value& message, 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);
std::string subcommand = message.get("subcommand","").asString();
_streaming_leds_reply["success"] = true;
_streaming_leds_reply["command"] = command;
_streaming_leds_reply["tan"] = tan;
const PriorityMuxer::InputInfo & priorityInfo = _hyperion->getPriorityInfo(_hyperion->getCurrentPriority());
std::vector<ColorRgb> ledBuffer = priorityInfo.ledColors;
for (ColorRgb& color : ledBuffer)
if (subcommand == "ledstream-start")
{
int idx = leds.size();
Json::Value & item = leds[idx];
item["index"] = idx;
item["red"] = color.red;
item["green"] = color.green;
item["blue"] = color.blue;
_streaming_leds_reply["command"] = command+"-ledstream-update";
_timer_ledcolors.start(125);
}
// send the result
sendMessage(result);
else if (subcommand == "ledstream-stop")
{
_timer_ledcolors.stop();
}
else
{
sendErrorReply("unknown subcommand",command,tan);
return;
}
sendSuccessReply(command+"-"+subcommand,tan);
}
void JsonClientConnection::handleNotImplemented()
@@ -1137,3 +1153,27 @@ bool JsonClientConnection::checkJson(const Json::Value & message, const QString
return true;
}
void JsonClientConnection::streamLedcolorsUpdate()
{
Json::Value & leds = _streaming_leds_reply["result"] = Json::Value(Json::arrayValue);
const PriorityMuxer::InputInfo & priorityInfo = _hyperion->getPriorityInfo(_hyperion->getCurrentPriority());
std::vector<ColorRgb> 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(_streaming_leds_reply);
}

View File

@@ -42,6 +42,7 @@ public:
public slots:
void componentStateChanged(const hyperion::Components component, bool enable);
void streamLedcolorsUpdate();
signals:
///
@@ -61,6 +62,7 @@ private slots:
///
void socketClosed();
private:
///
/// Handle an incoming JSON message
@@ -173,7 +175,7 @@ private:
///
/// @param message the incoming message
///
void handleLedColorsCommand(const Json::Value &, const std::string &command, const int tan);
void handleLedColorsCommand(const Json::Value & message, const std::string &command, const int tan);
///
/// Handle an incoming JSON message of unknown type
@@ -251,5 +253,7 @@ private:
///
QTimer _timer_ledcolors;
Json::Value _streaming_leds_reply;
};

View File

@@ -13,7 +13,7 @@
"subcommand": {
"type" : "string",
"required" : true,
"enum" : ["ledstream_stop","ledstream_start","testled","imagestream_start","imagestream_stop"]
"enum" : ["ledstream-stop","ledstream-start","testled","imagestream-start","imagestream-stop"]
},
"oneshot": {
"type" : "bool"