|
|
@@ -6,11 +6,15 @@ let data
|
|
|
let var_1 = 0
|
|
|
let speed = 100
|
|
|
|
|
|
-readTextFile("./res/settings.json", function(text){
|
|
|
- data = JSON.parse(text);
|
|
|
- arduionoURL = data.settings.ip
|
|
|
- console.log(data)
|
|
|
-});
|
|
|
+fetch("./res/settings.json")
|
|
|
+ .then(response => response.json())
|
|
|
+ .then(json => {
|
|
|
+ console.log(json)
|
|
|
+ //data = JSON.parse(json)
|
|
|
+ data = json
|
|
|
+ arduionoURL = data.settings.ip
|
|
|
+ console.log(data)
|
|
|
+ })
|
|
|
|
|
|
function buttonPushAnimation(id) {
|
|
|
if (id !== lastPushId) {
|
|
|
@@ -24,7 +28,7 @@ function buttonPushAnimation(id) {
|
|
|
var_1 = data.animations[id].var_1
|
|
|
document.getElementById("speed").value = speed
|
|
|
document.getElementById("var_1").value = var_1
|
|
|
- httpGetAsync(arduionoURL + "/" + id)
|
|
|
+ httpGet(arduionoURL + "/" + id)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -42,10 +46,7 @@ function setSpeed(value) {
|
|
|
if (value !== speed) {
|
|
|
speed = value
|
|
|
document.getElementById("speed").value = value
|
|
|
- try {
|
|
|
- httpGetAsync(arduionoURL + "/y1:" + value + ":;")
|
|
|
- } catch (e) {
|
|
|
- }
|
|
|
+ httpGet(arduionoURL + "/y1:" + value + ":;")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -70,29 +71,16 @@ function setSettings() {
|
|
|
}
|
|
|
|
|
|
|
|
|
-function httpGetAsync(theUrl, callback) {
|
|
|
- try {
|
|
|
- var xmlHttp = new XMLHttpRequest();
|
|
|
-
|
|
|
- xmlHttp.onreadystatechange = function () {
|
|
|
- if (xmlHttp.readyState === 4 && xmlHttp.status === 200)
|
|
|
- callback(xmlHttp.responseText);
|
|
|
- }
|
|
|
- xmlHttp.open("GET", theUrl, true); // true for asynchronous
|
|
|
- xmlHttp.send(null);
|
|
|
- } catch (e) {
|
|
|
- console.log(e)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-function readTextFile(file, callback) {
|
|
|
- var rawFile = new XMLHttpRequest();
|
|
|
- rawFile.overrideMimeType("application/json");
|
|
|
- rawFile.open("GET", file, true);
|
|
|
- rawFile.onreadystatechange = function() {
|
|
|
- if (rawFile.readyState === 4 && rawFile.status === "200") {
|
|
|
- callback(rawFile.responseText);
|
|
|
- }
|
|
|
- }
|
|
|
- rawFile.send(null);
|
|
|
+function httpGet(theUrl, callback) {
|
|
|
+ fetch(theUrl, {
|
|
|
+ method: "POST"
|
|
|
+ })
|
|
|
+ .then(response => {
|
|
|
+ if (!response.ok) {
|
|
|
+ console.dir("Something went wrong with request: ", response)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(error => {
|
|
|
+ console.log(error)
|
|
|
+ })
|
|
|
}
|