Simple web interface
authorArjen Baart <arjen@andromeda.nl>
Sun, 2 Feb 2020 13:32:49 +0000 (14:32 +0100)
committerArjen Baart <arjen@andromeda.nl>
Sun, 2 Feb 2020 13:32:49 +0000 (14:32 +0100)
.gitignore [new file with mode: 0644]
web/lightcontrol.js [new file with mode: 0644]
web/lightcontrol.php [new file with mode: 0644]
web/slider.html

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..5f70486
--- /dev/null
@@ -0,0 +1,2 @@
+Makefile.in
+.*.swp
diff --git a/web/lightcontrol.js b/web/lightcontrol.js
new file mode 100644 (file)
index 0000000..8d2a6f7
--- /dev/null
@@ -0,0 +1,39 @@
+var xmlHttp;
+
+function lightcontrol_callback()
+{
+   if (xmlHttp.readyState == 4)
+   {
+      //alert("HTTP response text " + xmlHttp.responseText.split(" "));
+      lightcolors = xmlHttp.responseText.split(" ");
+      //alert("Red = " + lightcolors[0]);
+      redbox = document.getElementById("red");
+      redbox.value = lightcolors[0];
+      greenbox = document.getElementById("green");
+      greenbox.value = lightcolors[1];
+      bluebox = document.getElementById("blue");
+      bluebox.value = lightcolors[2];
+      whitebox = document.getElementById("white");
+      whitebox.value = lightcolors[3];
+   }
+}
+
+function lightcontrol()
+{
+  xmlHttp.onreadystatechange=lightcontrol_callback;
+  xmlHttp.open("GET","lightcontrol.php",true);
+  xmlHttp.send(null);
+}
+
+function _init()
+{
+   xmlHttp=new XMLHttpRequest();
+   lightcontrol();
+}
+
+function change_light(color, value)
+{
+  xmlHttp.onreadystatechange=lightcontrol_callback;
+  xmlHttp.open("GET","lightcontrol.php?" + color + "=" + value, true);
+  xmlHttp.send(null);
+}
diff --git a/web/lightcontrol.php b/web/lightcontrol.php
new file mode 100644 (file)
index 0000000..fd57769
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+ini_set('display_errors', 'On');
+
+// Store the last error/warning message in $php_errormsg.
+ini_set('track_errors', 'On');
+
+// Disable the inclusion of HTML tags in error messages.
+ini_set('html_errors', 'Off');
+
+$lightparameters = "";
+
+if (isset($_GET['red']))
+{
+   $lightparameters .= " -r " . $_GET['red'];
+}
+
+if (isset($_GET['green']))
+{
+   $lightparameters .= " -g " . $_GET['green'];
+}
+
+if (isset($_GET['blue']))
+{
+   $lightparameters .= " -b " . $_GET['blue'];
+}
+
+if (isset($_GET['white']))
+{
+   $lightparameters .= " -w " . $_GET['white'];
+}
+
+if ($lightparameters != "")
+{
+   system("/usr/local/bin/lightcontrol " . $lightparameters);
+}
+
+$output = system('/usr/local/bin/lightcontrol -l', $return);
+#echo $output;
+?>
index d36f922..157af22 100644 (file)
@@ -3,17 +3,29 @@
 <html xmlns="http://www.w3.org/1999/xhtml"
       xml:lang="en">
   <head>
-    <title>SVG in XHTML Example</title>
+    <title>Light control</title>
     <link rel='stylesheet' type='text/css' href='webif.css'/>
+
+  <script type="text/ecmascript" src="lightcontrol.js">
+  </script>
+
   </head>
-  <body>
-    <h1>Animation with Ecmascript</h1>
+
+  <body onLoad="_init()">
+    <h1>Light control</h1>
+
+<form>
+   Red  <input type='text' id='red' onChange='change_light("red", this.value)'/><br/>
+   Green  <input type='text' id='green' onChange='change_light("green", this.value)'/><br/>
+   Blue  <input type='text' id='blue' onChange='change_light("blue", this.value)'/><br/>
+   White  <input type='text' id='white' onChange='change_light("white", this.value)'/><br/>
+</form>
+
     <p>
 
 <svg width="1024" height="768" version="1.1"
      xmlns="http://www.w3.org/2000/svg"
-     xmlns:xlink="http://www.w3.org/1999/xlink"
-     onload="StartAnimation(evt)" >
+     xmlns:xlink="http://www.w3.org/1999/xlink" >
 
   <script type="text/ecmascript"><![CDATA[
     var slide_white;