Browse Source

Only send breath request when the slider is released but show value change realtime.. fix breath typo in switchTheLight

Aubort Jean-Baptiste 6 years ago
parent
commit
65d4e391f3
2 changed files with 11 additions and 12 deletions
  1. 10 11
      main.js
  2. 1 1
      trigger.html

+ 10 - 11
main.js

@@ -204,22 +204,21 @@ function switchTheLight(red, green, blue) {
     var requestObject = new XMLHttpRequest();
     requestObject.open("POST", requestUrl, true);
     requestObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
-    requestObject.send("red=" + red + "&green=" + green + "&blue=" + blue + "&breath=" + breathValue);
+    requestObject.send("red=" + red + "&green=" + green + "&blue=" + blue + "&breathe=" + breathValue);
+}
+
+function changeBreathSpeed(){
+    document.getElementById("breathValue").innerText = slider.value;
 }
 
-//var lastBreathValue = 0;
 function setTheBreathSpeed() {
     "set strict";
     var breathValue = slider.value;
-    //if (Math.abs(breathValue - lastBreathValue) > 100) {
-        var requestUrl = "http://led.fixme.ch/rgb/";
-        var requestObject = new XMLHttpRequest();
-        requestObject.open("POST", requestUrl, true);
-        requestObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
-        requestObject.send("breathe=" + breathValue);
-    //    lastBreathValue = breathValue;
-    //}
-    document.getElementById("breathValue").innerText = breathValue;
+    var requestUrl = "http://led.fixme.ch/rgb/";
+    var requestObject = new XMLHttpRequest();
+    requestObject.open("POST", requestUrl, true);
+    requestObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+    requestObject.send("breathe=" + breathValue);
 }
 
 function switchTheLightColor(color) {

+ 1 - 1
trigger.html

@@ -61,7 +61,7 @@
         <br/>
         <div id="breathBox">
             <label for="breathSlider">Breath:</label>
-            <input type="range" value=0 min=0 max=5000 step=100 onchange="setTheBreathSpeed()" id="breathSlider" class="breathSlider">
+            <input type="range" value=0 min=0 max=5000 step=10 onchange="changeBreathSpeed()" onmouseup="setTheBreathSpeed()" id="breathSlider" class="breathSlider">
             <span id="breathValue">0</span>
         </div>
       </fieldset>