Inital commit. master
authorAndreas Schiermeier <as@ccc504j.site>
Sat, 16 May 2015 22:01:53 +0000 (00:01 +0200)
committerAndreas Schiermeier <as@ccc504j.site>
Sat, 16 May 2015 22:01:53 +0000 (00:01 +0200)
Deckenlicht/99-ledstripe.rules [new file with mode: 0644]
Deckenlicht/Deckenlicht.ino [new file with mode: 0644]
Deckenlicht/ledcolor.sh [new file with mode: 0755]
LIRC/lirc.sh [new file with mode: 0755]

diff --git a/Deckenlicht/99-ledstripe.rules b/Deckenlicht/99-ledstripe.rules
new file mode 100644 (file)
index 0000000..f87da43
--- /dev/null
@@ -0,0 +1 @@
+KERNEL=="tty*", SUBSYSTEM=="tty", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="0001", ATTRS{serial}=="6493234373835111F0B1", GROUP="www-data", MODE="0660", SYMLINK+="ledstripe", RUN+="/bin/stty -F /dev/ledstripe 9600 -hupcl"
diff --git a/Deckenlicht/Deckenlicht.ino b/Deckenlicht/Deckenlicht.ino
new file mode 100644 (file)
index 0000000..e1e9c09
--- /dev/null
@@ -0,0 +1,79 @@
+
+#define ledRed 9
+#define ledGreen 10
+#define ledBlue 11
+
+#define RED 0
+#define GREEN 1
+#define BLUE 2
+
+#define cnt_0_to_127 ((counter%256)/2)
+#define cnt_127_to_0 (127 - cnt_0_to_127)
+#define cnt_0_to_63  (cnt_0_to_127/2)
+#define cnt_63_to_0  (63 - cnt_0_to_63)
+
+
+byte rgb[] = { 0, 80, 160 };
+byte nextStaticRGB[] = { 0, 0, 0 };
+
+byte staticAvailable = 0;
+byte serialRGBPos = RED;
+unsigned long lastSerialDataTS = 0;
+
+short counter = 0;
+
+void setup()  { 
+  Serial.begin(9600);
+}
+
+void loop()  {
+    if (Serial.available() > 0) {
+      if (lastSerialDataTS + 1000 < millis()) {
+        serialRGBPos = RED;
+      }
+      lastSerialDataTS = millis();
+      nextStaticRGB[serialRGBPos++] = Serial.read();
+      if ( serialRGBPos > BLUE) {
+        rgb[RED] = nextStaticRGB[RED];
+        rgb[GREEN] = nextStaticRGB[GREEN];
+        rgb[BLUE] = nextStaticRGB[BLUE];
+        serialRGBPos = RED;
+      }
+      staticAvailable = nextStaticRGB[RED] | nextStaticRGB[GREEN] | nextStaticRGB[BLUE];
+    }
+
+    if (staticAvailable == 0) {
+      if (counter < 256){ // blue -> violett
+        rgb[RED] = cnt_0_to_63;
+        rgb[GREEN] = 0;
+        rgb[BLUE] = 128 + cnt_127_to_0;
+      }else if (counter < 2*256) { // violett -> red
+        rgb[RED] = 64 + cnt_0_to_63;
+        rgb[GREEN] = 0;
+        rgb[BLUE] = cnt_127_to_0;
+      }else if (counter < 3*256){ // red -> yellow
+        rgb[RED] = 64 + cnt_63_to_0;
+        rgb[GREEN] = cnt_0_to_63;
+        rgb[BLUE] = 0;
+      }else if (counter < 4*256){ // yellow -> green
+        rgb[RED] = cnt_63_to_0;
+        rgb[GREEN] = 64 + cnt_0_to_63;
+        rgb[BLUE] = 0;
+      }else if (counter < 5*256){ // green -> turquoise
+        rgb[RED] = 0;
+        rgb[GREEN] = 64 + cnt_63_to_0;
+        rgb[BLUE] = cnt_0_to_127;
+      }else if (counter < 6*256){ // turquoise -> blue
+        rgb[RED] = 0;
+        rgb[GREEN] = cnt_63_to_0;
+        rgb[BLUE] = 128 + cnt_0_to_127;
+      }
+      else counter = 0;
+      counter += 1;
+    }
+    analogWrite(ledRed, rgb[RED]); 
+    analogWrite(ledGreen, rgb[GREEN]); 
+    analogWrite(ledBlue, rgb[BLUE]); 
+    delay(15);
+}
+
diff --git a/Deckenlicht/ledcolor.sh b/Deckenlicht/ledcolor.sh
new file mode 100755 (executable)
index 0000000..af0c01d
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+## cat > /etc/udev/rules.d/99-ledstripe.rules <'EOF#
+#
+# KERNEL=="tty*", SUBSYSTEM=="tty", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="0001", ATTRS{serial}=="6493234373835111F0B1", GROUP="www-data", MODE="0660", SYMLINK+="ledstripe", RUN+="/bin/stty -F /dev/ledstripe 9600 -hupcl"
+#
+
+cat <<'EOF'
+Content-Type: text/html
+
+<!doctype html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <title>LEDSTRIP COLOR</title>
+</head>
+<body>
+EOF
+
+color='#000000'
+# http://192.168.2.12/cgi-bin/ledcolor.sh?color=%23ff00ff
+case "${QUERY_STRING}" in
+  color=%23[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])
+    color="#${QUERY_STRING:9}"
+    echo -en "\x${QUERY_STRING:9:2}\x${QUERY_STRING:11:2}\x${QUERY_STRING:13:2}" > /dev/ledstripe
+  ;;
+esac
+
+cat <<EOF
+<form method="GET"><input type="color" name="color" value="${color}"><input type="submit"></form>
+</form>
+</body>
+</html>
+EOF
+
diff --git a/LIRC/lirc.sh b/LIRC/lirc.sh
new file mode 100755 (executable)
index 0000000..ad32d31
--- /dev/null
@@ -0,0 +1,110 @@
+#!/bin/bash
+
+LIRC_IP="192.168.2.12"
+LIRC_PORT="8765"
+
+cat <<'EOF'
+Content-Type: text/html
+
+<!doctype html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <title>LIRC</title>
+</head>
+<body>
+EOF
+
+# set -x; exec 2>&1
+
+# http://192.168.2.12/cgi-bin/lirc.sh
+cmd="LIST"
+
+if [ -n "${PATH_INFO#/}" ]
+then
+  if [ -z "${QUERY_STRING}" ]
+  then
+    # http://192.168.2.12/cgi-bin/lirc.sh/MOODLAMP
+    cmd="LIST ${PATH_INFO#/}"
+  else
+    # http://192.168.2.12/cgi-bin/lirc.sh/MOODLAMP?PAUSE
+    cmd="SEND_ONCE ${PATH_INFO#/} ${QUERY_STRING}"
+  fi
+fi
+
+exec 10<> /dev/tcp/${LIRC_IP}/${LIRC_PORT}
+
+echo "${cmd}" >&10
+
+data_n=-1
+wait_for_n=0
+relistcmds=0
+while read -u 10 -a response 
+do
+
+  # echo '<li>'"${response[@]}"'</li>'
+
+  if [ $data_n -gt 0 ]
+  then
+
+    link="${SCRIPT_NAME}"
+
+    if [ -z "${PATH_INFO#/}" ]
+    then
+      # generate links to remotes
+      link+="/${response[0]}"
+    else
+      # generate links to commands for a specific remote
+      link+="/${PATH_INFO#/}?${response[1]}"
+    fi
+
+    echo '<li><a href="'${link}'">'${link##*/}'</a></li>'
+
+    let data_n--
+    continue
+  fi
+
+  case "${response[@]}" in
+    "BEGIN"|"SUCCESS"|"LIST"*)
+      : do noting
+      ;;
+    "SEND_ONCE "*)
+      relistcmds=1
+      ;;
+    "DATA")
+      wait_for_n=1
+      continue
+      ;;
+    [0-9]*)
+      if [ $wait_for_n -eq 1 ]
+      then
+        data_n="${response[0]}"
+        wait_for_n=0
+      fi
+      ;;
+    "END")
+      if [ $relistcmds -eq 1 ]
+      then
+        relistcmds=0
+        echo "LIST ${PATH_INFO#/}" >&10
+      else
+        break
+      fi
+      ;;
+    "ERROR"|*)
+      break
+      ;;
+  esac
+  wait_for_n=0
+
+done
+
+exec 10>&-
+
+echo '<hr/><li><a href="'${SCRIPT_NAME}'">START</a></li>'
+
+cat <<'EOF'
+</body>
+</html>
+EOF
+