|
@@ -1,5 +1,6 @@
|
|
var rawContent;
|
|
var rawContent;
|
|
var data = [];
|
|
var data = [];
|
|
|
|
+var update = [];
|
|
var loading = false;
|
|
var loading = false;
|
|
var websock;
|
|
var websock;
|
|
|
|
|
|
@@ -18,15 +19,15 @@ function GetData() {
|
|
return;
|
|
return;
|
|
loading = true;
|
|
loading = true;
|
|
return fetch("/data")
|
|
return fetch("/data")
|
|
- .then(function(result) {
|
|
|
|
- return result.text().then(function(text) {
|
|
|
|
|
|
+ .then(function (result) {
|
|
|
|
+ return result.text().then(function (text) {
|
|
rawContent = text;
|
|
rawContent = text;
|
|
data = ConvertData(rawContent);
|
|
data = ConvertData(rawContent);
|
|
loading = false;
|
|
loading = false;
|
|
});
|
|
});
|
|
})
|
|
})
|
|
- .catch(function() {
|
|
|
|
- loading = false;
|
|
|
|
|
|
+ .catch(function () {
|
|
|
|
+ loading = false;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -79,48 +80,48 @@ function SaveSettings() {
|
|
}
|
|
}
|
|
|
|
|
|
function LoadSettings(rawSettings) {
|
|
function LoadSettings(rawSettings) {
|
|
- if(rawSettings == null){
|
|
|
|
- var tmpsettings = JSON.parse(window.localStorage.getItem('settings'));
|
|
|
|
- if (tmpsettings == null)
|
|
|
|
- return;
|
|
|
|
- settings = tmpsettings;
|
|
|
|
- }else{
|
|
|
|
- settings = rawSettings;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- document.getElementById("modOffset").value = settings.modOffset;
|
|
|
|
- document.getElementById("inputOffset").value = settings.inputOffset;
|
|
|
|
- document.getElementById("updateInterval").value = settings.updateInterval;
|
|
|
|
- document.getElementById("checkoptions-0").checked = settings.autoupdate;
|
|
|
|
- document.getElementById("checkoptions-1").checked = settings.emulateMaster;
|
|
|
|
- SetAutoUpdate();
|
|
|
|
|
|
+ if (rawSettings == null) {
|
|
|
|
+ var tmpsettings = JSON.parse(window.localStorage.getItem('settings'));
|
|
|
|
+ if (tmpsettings == null)
|
|
|
|
+ return;
|
|
|
|
+ settings = tmpsettings;
|
|
|
|
+ } else {
|
|
|
|
+ settings = rawSettings;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ document.getElementById("modOffset").value = settings.modOffset;
|
|
|
|
+ document.getElementById("inputOffset").value = settings.inputOffset;
|
|
|
|
+ document.getElementById("updateInterval").value = settings.updateInterval;
|
|
|
|
+ document.getElementById("checkoptions-0").checked = settings.autoupdate;
|
|
|
|
+ document.getElementById("checkoptions-1").checked = settings.emulateMaster;
|
|
|
|
+ SetAutoUpdate();
|
|
}
|
|
}
|
|
|
|
|
|
-function SaveSettingsOnDevice(){
|
|
|
|
- SaveSettings();
|
|
|
|
- var urlEncodedSettings = encodeURI(JSON.stringify(settings));
|
|
|
|
- var url = "/config?key=settings&value="+urlEncodedSettings;
|
|
|
|
|
|
+function SaveSettingsOnDevice() {
|
|
|
|
+ SaveSettings();
|
|
|
|
+ var urlEncodedSettings = encodeURI(JSON.stringify(settings));
|
|
|
|
+ var url = "/config?key=settings&value=" + urlEncodedSettings;
|
|
|
|
|
|
- fetch(url)
|
|
|
|
- .then(function(result) {
|
|
|
|
- result.text().then(function(text) {
|
|
|
|
|
|
+ fetch(url)
|
|
|
|
+ .then(function (result) {
|
|
|
|
+ result.text().then(function (text) {
|
|
alert("Saved")
|
|
alert("Saved")
|
|
});
|
|
});
|
|
})
|
|
})
|
|
- .catch(function() {
|
|
|
|
|
|
+ .catch(function () {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-function LoadSettingsFromDevice(){
|
|
|
|
- fetch("/config?key=settings")
|
|
|
|
- .then(function(result) {
|
|
|
|
- return result.text().then(function(text) {
|
|
|
|
|
|
+function LoadSettingsFromDevice() {
|
|
|
|
+ fetch("/config?key=settings")
|
|
|
|
+ .then(function (result) {
|
|
|
|
+ return result.text().then(function (text) {
|
|
var settingsraw = JSON.parse(decodeURI(text));
|
|
var settingsraw = JSON.parse(decodeURI(text));
|
|
LoadSettings(settingsraw);
|
|
LoadSettings(settingsraw);
|
|
});
|
|
});
|
|
})
|
|
})
|
|
- .catch(function() {
|
|
|
|
- loading = false;
|
|
|
|
|
|
+ .catch(function () {
|
|
|
|
+ loading = false;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -133,7 +134,7 @@ function SetAutoUpdate() {
|
|
return;
|
|
return;
|
|
DoUpdate();
|
|
DoUpdate();
|
|
}
|
|
}
|
|
- }, settings.updateInterval*1000);
|
|
|
|
|
|
+ }, settings.updateInterval * 1000);
|
|
}
|
|
}
|
|
|
|
|
|
function DoUpdate() {
|
|
function DoUpdate() {
|
|
@@ -145,18 +146,42 @@ function DoUpdate() {
|
|
}
|
|
}
|
|
|
|
|
|
function StartSocket() {
|
|
function StartSocket() {
|
|
- websock = new WebSocket('ws://' + window.location.hostname + ':81/');
|
|
|
|
- websock.onopen = function(evt) { console.log('websock open'); };
|
|
|
|
- websock.onclose = function(evt) { console.log('websock close'); };
|
|
|
|
- websock.onerror = function(evt) { console.log(evt); };
|
|
|
|
- websock.onmessage = function(evt) {
|
|
|
|
- console.log(evt);
|
|
|
|
- switch(evt.data){
|
|
|
|
- case "update":
|
|
|
|
- DoUpdate();
|
|
|
|
- break;
|
|
|
|
|
|
+ websock = new WebSocket('ws://' + window.location.hostname + ':81/');
|
|
|
|
+ websock.onopen = function (evt) { console.log('websock open'); };
|
|
|
|
+ websock.onclose = function (evt) { console.log('websock close'); };
|
|
|
|
+ websock.onerror = function (evt) { console.log(evt); };
|
|
|
|
+ websock.onmessage = function (evt) {
|
|
|
|
+ console.log(evt);
|
|
|
|
+ switch (evt.data) {
|
|
|
|
+ case "update":
|
|
|
|
+ DoUpdate();
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ var data = evt.data;
|
|
|
|
+ update = data.split(";");
|
|
|
|
+ UpdateData(update);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function UpdateData(update) {
|
|
|
|
+ update.forEach(u => {
|
|
|
|
+ if (u != '') {
|
|
|
|
+ var tmp = u.split('|');
|
|
|
|
+ var module = tmp[0];
|
|
|
|
+ if (tmp[1] != null) {
|
|
|
|
+ tmp = tmp[1].split(':');
|
|
|
|
+ var input = tmp[0];
|
|
|
|
+
|
|
|
|
+ if (tmp[1] != null) {
|
|
|
|
+ var value = tmp[1];
|
|
|
|
+ data.find(d => d.module == module && d.input == input).data = (value == "1");
|
|
}
|
|
}
|
|
- };
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ RenderData(data);
|
|
}
|
|
}
|
|
|
|
|
|
LoadSettings();
|
|
LoadSettings();
|