Selaa lähdekoodia

Same functionality as python app

emil 4 vuotta sitten
vanhempi
commit
fc14d0ab84
4 muutettua tiedostoa jossa 229 lisäystä ja 19 poistoa
  1. 72 0
      css/LEDs.css
  2. 41 10
      index.html
  3. 81 9
      js/LED.js
  4. 35 0
      res/settings.json

+ 72 - 0
css/LEDs.css

@@ -23,6 +23,14 @@ body {
     font-family: Helvetica, 'Raleway', sans-serif;
 }
 
+.topBar button:hover {
+    background-color: #2f2f3d;
+}
+
+.hide {
+    display: none;
+}
+
 .container {
     display: grid;
     grid-template-columns: 150px 1fr;
@@ -36,6 +44,7 @@ body {
     grid-row: 2/-1;
     grid-column: 2/-1;
     margin: 10px 10px;
+    height: 100%;
 
     grid-template-rows: 10vh auto auto 10vh;
     grid-template-columns: repeat(5, 1fr);
@@ -60,4 +69,67 @@ body {
     color: white;
     font-size: 40px;
     font-family: 'Roboto', sans-serif;
+}
+
+.animationsContainer button:hover {
+    background-color: #2f2f3d;
+}
+
+
+
+
+.settingsContainer {
+    margin: 10px;
+    display: grid;
+    grid-template-columns: repeat(5, 1fr);
+    grid-template-rows: 10vh 10vh 10vh 20vh 20vh 10vh;
+    grid-gap: 10px;
+}
+
+.settingsContainer h2 {
+    grid-column: 1/-1;
+    grid-row: 1/2;
+
+    color: white;
+    font-size: 50px;
+    align-self: center;
+    text-align: center;
+    font-family: 'Raleway', sans-serif;
+}
+
+.settingUnit p {
+    color: white;
+    font-family: 'Roboto', sans-serif;
+    text-align: center;
+    font-size: 28px;
+}
+
+.settingUnit input {
+    display: block;
+    margin: auto;
+    width: 95%;
+    border: none;
+    background-color: #47475b;
+    color: white;
+    height: 30px;
+    font-size: 20px;
+    font-family: 'Roboto', sans-serif;
+}
+
+.settingsContainer button {
+    border: solid #252531 2px;
+    border-radius: 10px;
+    background-color: #252531;
+    color: white;
+    font-size: 30px;
+    font-family: 'Roboto', sans-serif;
+}
+
+.settingsContainer button:hover {
+    background-color: #2f2f3d;
+}
+
+#set {
+    grid-row: -2/-1;
+    grid-column: -2/-1;
 }

+ 41 - 10
index.html

@@ -22,19 +22,50 @@
         </div>
 
         <div class="topBar">
-            <button>Animations</button>
-            <button>Settings</button>
+            <button onclick="topBarClick('animationsContainer')">Animations</button>
+            <button>Custom</button>
+            <button onclick="topBarClick('settingsContainer')">Settings</button>
         </div>
 
-        <div class="animationsContainer">
-            <h2>Animations</h2>
+        <div id="animationsContainer">
+            <div class="animationsContainer">
+                <h2>Animations</h2>
 
-            <button id="B" onclick="buttonPushAnimation('B')">Rainbow</button>
-            <button id="C" onclick="buttonPushAnimation('C')">Fill</button>
-            <button id="D" onclick="buttonPushAnimation('D')">Chasing</button>
-            <button id="E" onclick="buttonPushAnimation('E')">Random colors</button>
-            <button id="F" onclick="buttonPushAnimation('F')">Split RGB</button>
-            <button id="G" onclick="buttonPushAnimation('G')">Stardust</button>
+                <button id="B" onclick="buttonPushAnimation('B')">Rainbow</button>
+                <button id="C" onclick="buttonPushAnimation('C')">Fill</button>
+                <button id="D" onclick="buttonPushAnimation('D')">Chasing</button>
+                <button id="E" onclick="buttonPushAnimation('E')">Random colors</button>
+                <button id="F" onclick="buttonPushAnimation('F')">Split RGB</button>
+                <button id="G" onclick="buttonPushAnimation('G')">Stardust</button>
+            </div>
+        </div>
+
+        <div class="hide" id="settingsContainer">
+            <div class="settingsContainer">
+                <h2>Settings</h2>
+                <button onclick="setSpeed(1)">Speed 1</button>
+                <button onclick="setSpeed(10)">Speed 10</button>
+                <button onclick="setSpeed(100)">Speed 100</button>
+                <button onclick="setSpeed(500)">Speed 500</button>
+                <button onclick="setSpeed(1000)">Speed 1000</button>
+
+                <button onclick="setVar_1(0)">Setting 1: 0</button>
+                <button onclick="setVar_1(1)">Setting 1: 1</button>
+                <button onclick="setVar_1(2)">Setting 1: 2</button>
+                <button onclick="setVar_1(5)">Setting 1: 5</button>
+                <button onclick="setVar_1(10)">Setting 1: 10</button>
+
+                <div class="settingUnit">
+                    <p>Speed (ms/tick)</p>
+                    <input type="number" id="speed">
+                </div>
+                <div class="settingUnit">
+                    <p>Setting 1</p>
+                    <input type="number" id="var_1">
+                </div>
+
+                <button id="set" onclick="setSettings()">Set</button>
+            </div>
         </div>
 
     </div>

+ 81 - 9
js/LED.js

@@ -1,5 +1,16 @@
 let lastPushId = "C"
-const arduionoURL = "http://192.168.1.160"
+let arduionoURL
+let openSlide = "animationsContainer"
+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)
+});
 
 function buttonPushAnimation(id) {
     if (id !== lastPushId) {
@@ -7,18 +18,79 @@ function buttonPushAnimation(id) {
         document.getElementById(lastPushId).style.backgroundColor = "#252531"
         lastPushId = id
 
+        speed = data.animations[id].speed
+        var_1 = data.animations[id].var_1
+        document.getElementById("speed").value = speed
+        document.getElementById("var_1").value = var_1
         httpGetAsync(arduionoURL + "/" + id)
     }
 }
 
 
-function httpGetAsync(theUrl, callback)
-{
-    var xmlHttp = new XMLHttpRequest();
-    xmlHttp.onreadystatechange = function() {
-        if (xmlHttp.readyState === 4 && xmlHttp.status === 200)
-            callback(xmlHttp.responseText);
+function topBarClick(id) {
+    if (id !== openSlide) {
+        document.getElementById(id).classList.toggle("hide")
+        document.getElementById(openSlide).classList.toggle("hide")
+        openSlide = id
+    }
+}
+
+
+function setSpeed(value) {
+    if (value != speed) {
+        speed = value
+        document.getElementById("speed").value = value
+        try {
+            httpGetAsync(arduionoURL + "/y1:" + value + ":;")
+        } catch (e) {
+        }
+    }
+}
+
+
+function setVar_1(value) {
+    if (value != var_1) {
+        var_1 = value
+        document.getElementById("var_1").value = value
+        try {
+            httpGetAsync(arduionoURL + "/y2:" + value + ":;")
+        } catch (e) {
+        }
+    }
+}
+
+
+function setSettings() {
+    var nSpeed = document.getElementById("speed").value
+    var nVar_1 = document.getElementById("var_1").value
+    setSpeed(nSpeed)
+    setVar_1(nVar_1)
+}
+
+
+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);
+        }
     }
-    xmlHttp.open("GET", theUrl, true); // true for asynchronous
-    xmlHttp.send(null);
+    rawFile.send(null);
 }

+ 35 - 0
res/settings.json

@@ -0,0 +1,35 @@
+{
+  "animations": {
+    "A": {
+      "speed": 10000,
+      "var_1": 0
+    },
+    "B": {
+      "speed": 100,
+      "var_1": 5
+    },
+    "C": {
+      "speed": 100,
+      "var_1": 0
+    },
+    "D": {
+      "speed": 100,
+      "var_1": 0
+    },
+    "E": {
+      "speed": 100,
+      "var_1": 10
+    },
+    "F": {
+      "speed": 100,
+      "var_1": 0
+    },
+    "G": {
+      "speed": 50,
+      "var_1": 5
+    }
+  },
+  "settings": {
+    "ip": "http://192.168.1.160"
+  }
+}