From b7de3e97ad8be6e4ea3990f0d193630816a4697c Mon Sep 17 00:00:00 2001 From: root Date: Fri, 30 Nov 2018 20:47:20 +0000 Subject: [PATCH] init repo --- Arduino/speakerSwitch.ino | 81 ++++++++++++++++++++++++++++++++++++++ index.tpl | 53 +++++++++++++++++++++++++ speakerSwitch.py | 49 +++++++++++++++++++++++ static/main.css | 21 ++++++++++ static/simple-grid.min.css | 1 + 5 files changed, 205 insertions(+) create mode 100644 Arduino/speakerSwitch.ino create mode 100644 index.tpl create mode 100644 speakerSwitch.py create mode 100644 static/main.css create mode 100644 static/simple-grid.min.css diff --git a/Arduino/speakerSwitch.ino b/Arduino/speakerSwitch.ino new file mode 100644 index 0000000..e3131b3 --- /dev/null +++ b/Arduino/speakerSwitch.ino @@ -0,0 +1,81 @@ +#include "Arduino.h" + +const byte numChars = 32; +char receivedChars[numChars]; // an array to store the received data + +boolean newData = false; + +void setup() { + Serial.begin(9600); + + + pinMode(A0, OUTPUT); + pinMode(A1, OUTPUT); + pinMode(A2, OUTPUT); + pinMode(A3, OUTPUT); + pinMode(A4, OUTPUT); + pinMode(A5, OUTPUT); + + Serial.println("mc8051.de Speaker Switch"); +} + +void loop() { + recvWithEndMarker(); + + + if (newData == true) { + newData = false; + + if (strcmp(receivedChars, "ch00-l-0") == 0) { + digitalWrite(A0, LOW); + } else if (strcmp(receivedChars, "ch00-l-1") == 0) { + digitalWrite(A0, HIGH); + } else if (strcmp(receivedChars, "ch00-r-0") == 0) { + digitalWrite(A3, LOW); + } else if (strcmp(receivedChars, "ch00-r-1") == 0) { + digitalWrite(A3, HIGH); + } else if (strcmp(receivedChars, "ch01-l-0") == 0) { + digitalWrite(A1, LOW); + } else if (strcmp(receivedChars, "ch01-l-1") == 0) { + digitalWrite(A1, HIGH); + } else if (strcmp(receivedChars, "ch01-r-0") == 0) { + digitalWrite(A4, LOW); + } else if (strcmp(receivedChars, "ch01-r-1") == 0) { + digitalWrite(A4, HIGH); + } else if (strcmp(receivedChars, "ch02-l-0") == 0) { + digitalWrite(A2, LOW); + } else if (strcmp(receivedChars, "ch02-l-1") == 0) { + digitalWrite(A2, HIGH); + } else if (strcmp(receivedChars, "ch02-r-0") == 0) { + digitalWrite(A5, LOW); + } else if (strcmp(receivedChars, "ch02-r-1") == 0) { + digitalWrite(A5, HIGH); + } else { + Serial.print("Unknown command "); + Serial.println(receivedChars); + } + } +} + +void recvWithEndMarker() { + static byte ndx = 0; + char endMarker = '\n'; + char rc; + + while (Serial.available() > 0 && newData == false) { + rc = Serial.read(); + + if (rc != endMarker) { + receivedChars[ndx] = rc; + ndx++; + if (ndx >= numChars) { + ndx = numChars - 1; + } + } + else { + receivedChars[ndx] = '\0'; // terminate the string + ndx = 0; + newData = true; + } + } +} diff --git a/index.tpl b/index.tpl new file mode 100644 index 0000000..250f6d0 --- /dev/null +++ b/index.tpl @@ -0,0 +1,53 @@ + + + + + + Lautsprecher | mc8051.de + + + + + + +
+
+
+

Lautsprecher Wahl

+
+
+
+
+ +
+
+
+ +
+
+ + + \ No newline at end of file diff --git a/speakerSwitch.py b/speakerSwitch.py new file mode 100644 index 0000000..dc84723 --- /dev/null +++ b/speakerSwitch.py @@ -0,0 +1,49 @@ +from bottle import route, run, request, redirect, template, static_file +import serial + +ser = serial.Serial("/dev/ttyUSB0", 9600) +channelStatus = [False, False, True] + +def updateChannels(): + print("Updating States") + print(channelStatus) + if channelStatus[0]: + ser.write(b'ch00-l-1\n') + ser.write(b'ch00-r-1\n') + else: + ser.write(b'ch00-l-0\n') + ser.write(b'ch00-r-0\n') + + if channelStatus[1]: + ser.write(b'ch01-l-1\n') + ser.write(b'ch01-r-1\n') + else: + ser.write(b'ch01-l-0\n') + ser.write(b'ch01-r-0\n') + + if channelStatus[2]: + ser.write(b'ch02-l-1\n') + ser.write(b'ch02-r-1\n') + else: + ser.write(b'ch02-l-0\n') + ser.write(b'ch02-r-0\n') + +updateChannels() + +@route("/") +def index(): + return template("index", vals=channelStatus) + +@route("/toggle/") +def channel(c): + channelStatus[c] = not channelStatus[c] + if channelStatus.count(True) > 2: + channelStatus[c] = False + updateChannels() + redirect("/") + +@route('/') +def send_static(filename): + return static_file(filename, root='static/') + +run(host="0.0.0.0", port=8081, debug=False) diff --git a/static/main.css b/static/main.css new file mode 100644 index 0000000..2e64728 --- /dev/null +++ b/static/main.css @@ -0,0 +1,21 @@ +html {box-sizing: border-box;} +* {color: #C5C1C0;background-color: #0A1612;font: 1.03em 'Tahoma', Geneva, Arial, sans-serif;} +.button {width: 100%;display: block;float: left;border-radius: 3px;margin: 10px 0px 10px 0px;padding: 15px 0px;text-align: center;text-decoration: none;font: 18px 'Arial', Helvetica, Arial, sans-serif;color: #ecf0f1;} +.button:active {position: relative;top: 1px;} +.gray {box-shadow: 0px 6px #7f8c8d;background: #95a5a6;} +.gray:active {box-shadow: 0px 0px #7f8c8d;background: #7f8c8d;} +.red {box-shadow: 0px 6px #c0392b;background: #e74c3c;} +.red:active {box-shadow: 0px 0px #c0392b;background: #c0392b;} +.purple {box-shadow: 0px 6px #8e44ad;background: #9b59b6;} +.purple:active {box-shadow: 0px 0px #8e44ad;background: #8e44ad;} +.blue {background: #3498db;box-shadow: 0px 6px #2980b9;} +.blue:active {background: #2980b9;box-shadow: 0px 0px #2980b9;} +.green {box-shadow: 0px 6px #27ae60;background: #2ecc71;} +.green:active {box-shadow: 0px 0px #23A33D;background: #23A33D;} +.yellow {box-shadow: 0px 6px #f39c12;background: #f1c40f;} +.yellow:active {box-shadow: 0px 0px #f39c12;background: #f39c12;} +.orange {box-shadow: 0px 6px #d35400;background: #e67e22;} +.orange:active {box-shadow: 0px 0px #d35400;background: #d35400;} +.dark_blue {box-shadow: 0px 6px #2c3e50;background: #34495e;} +.dark_blue:active {box-shadow: 0px 0px #2c3e50;background: #2c3e50;} +input[type=number] {width: 100%;padding: 12px 20px;margin: 8px 0;box-sizing: border-box;background-color: whitesmoke;color: black;border-radius: 4px;} \ No newline at end of file diff --git a/static/simple-grid.min.css b/static/simple-grid.min.css new file mode 100644 index 0000000..d3f2cc2 --- /dev/null +++ b/static/simple-grid.min.css @@ -0,0 +1 @@ +@import url(https://fonts.googleapis.com/css?family=Lato:400,300,300italic,400italic,700,700italic);body,html{height:100%;width:100%;margin:0;padding:0;left:0;top:0;font-size:100%}.center,.container{margin-left:auto;margin-right:auto}*{font-family:Lato,Helvetica,sans-serif;color:#333447;line-height:1.5}h1{font-size:2.5rem}h2{font-size:2rem}h3{font-size:1.375rem}h4{font-size:1.125rem}h5{font-size:1rem}h6{font-size:.875rem}p{font-size:1.125rem;font-weight:200;line-height:1.8}.font-light{font-weight:300}.font-regular{font-weight:400}.font-heavy{font-weight:700}.left{text-align:left}.right{text-align:right}.center{text-align:center}.justify{text-align:justify}.container{width:90%}.row{position:relative;width:100%}.row [class^=col]{float:left;margin:.5rem 2%;min-height:.125rem}.col-1,.col-10,.col-11,.col-12,.col-2,.col-3,.col-4,.col-5,.col-6,.col-7,.col-8,.col-9{width:96%}.col-1-sm{width:4.33%}.col-2-sm{width:12.66%}.col-3-sm{width:21%}.col-4-sm{width:29.33%}.col-5-sm{width:37.66%}.col-6-sm{width:46%}.col-7-sm{width:54.33%}.col-8-sm{width:62.66%}.col-9-sm{width:71%}.col-10-sm{width:79.33%}.col-11-sm{width:87.66%}.col-12-sm{width:96%}.row::after{content:"";display:table;clear:both}.hidden-sm{display:none}@media only screen and (min-width:33.75em){.container{width:80%}}@media only screen and (min-width:45em){.col-1{width:4.33%}.col-2{width:12.66%}.col-3{width:21%}.col-4{width:29.33%}.col-5{width:37.66%}.col-6{width:46%}.col-7{width:54.33%}.col-8{width:62.66%}.col-9{width:71%}.col-10{width:79.33%}.col-11{width:87.66%}.col-12{width:96%}.hidden-sm{display:block}}@media only screen and (min-width:60em){.container{width:75%;max-width:60rem}}