Refactor LED-Device handling in UI and make element naming consistent

This commit is contained in:
Lord-Grey 2021-05-19 10:51:45 +02:00
parent 80d60c2406
commit 8d8ee8b3cd
10 changed files with 173 additions and 115 deletions

View File

@ -40,7 +40,7 @@
<div class="bs-callout bs-callout-info" style="margin-top:0px"><h4 data-i18n="dashboard_infobox_label_title">Information</h4><span data-i18n="conf_leds_device_info_log"> In case your LEDs do not work, check here for errors: </span> <a onclick="SwitchToMenuItem('MenuItemLogging')" data-i18n="main_menu_logging_token" style="cursor:pointer"></a></div>
</div>
<div class="panel-footer" style="text-align:right">
<button id='btn_test_controller' class="btn btn-primary hidden" disabled data-toggle="tooltip" data-placement="top" title="Identify configured device by lighting it up">
<button id='btn_test_controller' class="btn btn-primary" disabled data-toggle="tooltip" data-placement="top" title="Identify configured device by lighting it up">
<i class="fa fa-fw fa-save"></i><span data-i18n="wiz_identify">Identify/Test</span>
</button>
<button id='btn_submit_controller' class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="Save the device's connectivity configuration">

View File

@ -564,13 +564,11 @@ $(document).ready(function () {
// toggle live video
$('#leds_prev_toggle_live_video').off().on("click", function () {
setClassByBool('#leds_prev_toggle_live_video', window.imageStreamActive, "btn-success", "btn-danger");
if (window.imageStreamActive)
{
if (window.imageStreamActive) {
requestLedImageStop();
imageCanvasNodeCtx.clear();
}
else
{
else {
requestLedImageStart();
}
});
@ -703,6 +701,8 @@ $(document).ready(function () {
var hwLedCountDefault = 1;
var colorOrderDefault = "rgb";
$('#btn_test_controller').hide();
switch (ledType) {
case "cololight":
case "wled":
@ -771,11 +771,38 @@ $(document).ready(function () {
});
conf_editor.on('change', function () {
//Check, if device can be identified/tested and/or saved
// //Check, if device can be identified/tested and/or saved
var canIdentify = false;
var canSave = false;
switch (ledType) {
case "atmoorb":
case "fadecandy":
case "tinkerforge":
case "tpm2net":
case "udpe131":
case "udpartnet":
case "udph801":
case "udpraw":
var host = conf_editor.getEditor("root.specificOptions.host").getValue();
if (host !== "") {
canSave = true;
}
break;
case "philipshue":
var host = conf_editor.getEditor("root.specificOptions.host").getValue();
var username = conf_editor.getEditor("root.specificOptions.username").getValue();
if (host !== "" && username != "") {
var useEntertainmentAPI = conf_editor.getEditor("root.specificOptions.useEntertainmentAPI").getValue();
var clientkey = conf_editor.getEditor("root.specificOptions.clientkey").getValue();
if (!useEntertainmentAPI || clientkey !== "") {
canSave = true;
}
}
break;
case "cololight":
case "wled":
var hostList = conf_editor.getEditor("root.specificOptions.hostList").getValue();
@ -799,50 +826,20 @@ $(document).ready(function () {
}
}
break;
case "adalight":
var output = conf_editor.getEditor("root.specificOptions.output").getValue();
if (output !== "NONE" && output !== "SELECT" && output !== "") {
canIdentify = true;
}
case "atmo":
case "dmx":
case "karate":
case "sedu":
case "tpm2":
case "apa102":
case "apa104":
case "ws2801":
case "lpd6803":
case "lpd8806":
case "p9813":
case "sk6812spi":
case "sk6822spi":
case "sk9822":
case "ws2812spi":
case "piblaster":
var output = conf_editor.getEditor("root.specificOptions.output").getValue();
if (output !== "NONE" && output !== "SELECT" && output !== "") {
canSave = true;
}
break;
default:
canIdentify = false;
canSave = true;
}
if (!conf_editor.validate().length) {
if (canIdentify) {
$("#btn_test_controller").removeClass('hidden');
$("#btn_test_controller").show();
$('#btn_test_controller').attr('disabled', false);
}
else {
} else {
$('#btn_test_controller').hide();
$('#btn_test_controller').attr('disabled', true);
}
var hardwareLedCount = conf_editor.getEditor("root.generalOptions.hardwareLedCount").getValue();
if (hardwareLedCount < 1) {
} else {
canSave = false;
}
@ -854,7 +851,7 @@ $(document).ready(function () {
else {
$('#btn_submit_controller').attr('disabled', true);
}
}
window.readOnlyMode ? $('#btn_cl_save').attr('disabled', true) : $('#btn_submit').attr('disabled', false);
window.readOnlyMode ? $('#btn_ma_save').attr('disabled', true) : $('#btn_submit').attr('disabled', false);
window.readOnlyMode ? $('#leds_custom_save').attr('disabled', true) : $('#btn_submit').attr('disabled', false);
@ -890,9 +887,9 @@ $(document).ready(function () {
conf_editor.getEditor(specOptPath + "host").setValue(val);
break;
}
}
showAllDeviceInputOptions("hostList", showOptions);
}
});
conf_editor.watch('root.specificOptions.host', () => {
@ -904,8 +901,10 @@ $(document).ready(function () {
else {
let params = {};
switch (ledType) {
case "cololight":
params = { host: host };
getProperties_device(ledType, host, params);
break;
case "nanoleaf":
@ -914,33 +913,70 @@ $(document).ready(function () {
return;
}
params = { host: host, token: token };
getProperties_device(ledType, host, params);
break;
case "wled":
params = { host: host, filter: "info" };
getProperties_device(ledType, host, params);
break;
default:
}
getProperties_device(ledType, host, params);
}
});
conf_editor.watch('root.specificOptions.output', () => {
var output = conf_editor.getEditor("root.specificOptions.output").getValue();
if (output === "NONE" || output === "SELECT" || output === "") {
$('#btn_submit_controller').attr('disabled', true);
$('#btn_test_controller').attr('disabled', true);
$('#btn_test_controller').hide();
conf_editor.getEditor("root.generalOptions.hardwareLedCount").setValue(1);
showAllDeviceInputOptions("output", false);
}
else {
showAllDeviceInputOptions("output", true);
let params = {};
var canIdentify = false;
switch (ledType) {
case "adalight":
canIdentify = true;
break;
case "atmo":
case "karate":
params = { serialPort: output };
getProperties_device(ledType, output, params);
break;
case "dmx":
case "sedu":
case "tpm2":
case "apa102":
case "apa104":
case "ws2801":
case "lpd6803":
case "lpd8806":
case "p9813":
case "sk6812spi":
case "sk6822spi":
case "sk9822":
case "ws2812spi":
case "piblaster":
default:
}
if (!conf_editor.validate().length) {
if (canIdentify) {
$("#btn_test_controller").show();
$('#btn_test_controller').attr('disabled', false);
} else {
$('#btn_test_controller').hide();
$('#btn_test_controller').attr('disabled', true);
}
if (!window.readOnlyMode) {
$('#btn_submit_controller').attr('disabled', false);
}
}
}
});
@ -1233,6 +1269,8 @@ function saveLedConfig(genDefLayout = false) {
break;
}
//Rewrite whole LED & Layout configuration, in case changes were done accross tabs and no default layout
if (genDefLayout !== true) {
result.ledConfig = getLedConfig();
@ -1439,6 +1477,9 @@ var updateSelectList = function (ledType, discoveryInfo) {
};
async function discover_device(ledType, params) {
$('#btn_submit_controller').attr('disabled', true);
const result = await requestLedDeviceDiscovery(ledType, params);
var discoveryResult;
@ -1479,6 +1520,7 @@ async function getProperties_device(ledType, key, params) {
}
else {
$('#btn_submit_controller').attr('disabled', true);
$('#btn_test_controller').attr('disabled', true);
}
}
}

View File

@ -391,12 +391,30 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config)
Warning(_log, "Instance [%u]: HwLedCount/Layout mismatch! Setting Hardware LED count to number of LEDs configured via layout", _instance);
hwLedcount = layoutLedCount;
newDeviceConfig["hardwareLedCount"] = hwLedcount;
config["device"] = newDeviceConfig;
migrated = true;
}
}
}
if (newDeviceConfig.contains("type"))
{
QString type = newDeviceConfig["type"].toString();
if (type == "atmoorb" || type == "fadecandy" || type == "philipshue" )
{
if (newDeviceConfig.contains("output"))
{
newDeviceConfig["host"] = newDeviceConfig["output"].toString();
newDeviceConfig.remove("output");
migrated = true;
}
}
}
if (migrated)
{
config["device"] = newDeviceConfig;
Debug(_log, "LED-Device records migrated");
}
}
if (config.contains("grabberV4L2"))

View File

@ -147,7 +147,6 @@
"ledBlacklist": {
"type": "array",
"title": "conf_leds_layout_blacklist_rules_title",
"minimum": 1,
"uniqueItems": true,
"items": {
"type": "object",

View File

@ -50,7 +50,7 @@ bool LedDeviceAtmoOrb::init(const QJsonObject &deviceConfig)
if ( LedDevice::init(deviceConfig) )
{
_multicastGroup = deviceConfig["output"].toString(MULTICAST_GROUP_DEFAULT_ADDRESS);
_multicastGroup = deviceConfig["host"].toString(MULTICAST_GROUP_DEFAULT_ADDRESS);
_multiCastGroupPort = static_cast<quint16>(deviceConfig["port"].toInt(MULTICAST_GROUP_DEFAULT_PORT));
_useOrbSmoothing = deviceConfig["useOrbSmoothing"].toBool(false);
_skipSmoothingDiff = deviceConfig["skipSmoothingDiff"].toInt(0);

View File

@ -55,7 +55,7 @@ bool LedDeviceFadeCandy::init(const QJsonObject& deviceConfig)
}
else
{
_host = deviceConfig["output"].toString("127.0.0.1");
_host = deviceConfig["host"].toString("127.0.0.1");
_port = deviceConfig["port"].toInt(STREAM_DEFAULT_PORT);
//If host not configured the init fails

View File

@ -12,7 +12,7 @@ namespace {
bool verbose = false;
// Configuration settings
const char CONFIG_ADDRESS[] = "output";
const char CONFIG_ADDRESS[] = "host";
//const char CONFIG_PORT[] = "port";
const char CONFIG_USERNAME[] = "username";
const char CONFIG_CLIENTKEY[] = "clientkey";

View File

@ -16,11 +16,10 @@
"access": "advanced",
"propertyOrder": 2
},
"output": {
"host": {
"type": "string",
"title": "edt_dev_spec_multicastGroup_title",
"default": "239.255.255.250",
"access": "expert",
"propertyOrder": 3
},
"port": {

View File

@ -2,7 +2,7 @@
"type":"object",
"required":true,
"properties": {
"output" : {
"host": {
"type": "string",
"title": "edt_dev_spec_targetIp_title",
"default": "127.0.0.1",

View File

@ -2,7 +2,7 @@
"type": "object",
"required": true,
"properties": {
"output": {
"host": {
"type": "string",
"title": "edt_dev_spec_targetIp_title",
"default": "",