init repo
This commit is contained in:
commit
b7de3e97ad
81
Arduino/speakerSwitch.ino
Normal file
81
Arduino/speakerSwitch.ino
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
53
index.tpl
Normal file
53
index.tpl
Normal file
@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<title>Lautsprecher | mc8051.de</title>
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1'>
|
||||
<link rel='stylesheet' type='text/css' href='/simple-grid.min.css' />
|
||||
<link rel='stylesheet' type='text/css' href='/main.css' />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class='container'>
|
||||
<div class='row'>
|
||||
<div class='col-12 center'>
|
||||
<h1 style='margin-top: 0px;'>Lautsprecher Wahl</h1>
|
||||
</div>
|
||||
</div>
|
||||
<hr/>
|
||||
<div class='row' style='margin-bottom: 35px'>
|
||||
<div class='col-12'>
|
||||
</br>
|
||||
<a class='button
|
||||
%if vals[0] == True:
|
||||
green
|
||||
%else:
|
||||
dark_blue
|
||||
%end
|
||||
' href='/toggle/0'>Küche</a>
|
||||
<a class='button
|
||||
%if vals[1] == True:
|
||||
green
|
||||
%else:
|
||||
dark_blue
|
||||
%end
|
||||
' href='/toggle/1'>Badezimmer</a>
|
||||
<a class='button
|
||||
%if vals[2] == True:
|
||||
green
|
||||
%else:
|
||||
dark_blue
|
||||
%end
|
||||
' href='/toggle/2'>Niklas</a>
|
||||
</div>
|
||||
</div>
|
||||
<hr/>
|
||||
<div class='row'>
|
||||
<div class='col-12'><i>Twitter: <a target='_blank' href='https://twitter.com/Gurkengewuerz' title='Twitter: @Gurkengewuerz'>@Gurkengewuerz</a> | <a target='_blank' href='http://mc8051.de' title='Website'>mc8051.de</a></i></div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
49
speakerSwitch.py
Normal file
49
speakerSwitch.py
Normal file
@ -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/<c:int>")
|
||||
def channel(c):
|
||||
channelStatus[c] = not channelStatus[c]
|
||||
if channelStatus.count(True) > 2:
|
||||
channelStatus[c] = False
|
||||
updateChannels()
|
||||
redirect("/")
|
||||
|
||||
@route('/<filename:path>')
|
||||
def send_static(filename):
|
||||
return static_file(filename, root='static/')
|
||||
|
||||
run(host="0.0.0.0", port=8081, debug=False)
|
21
static/main.css
Normal file
21
static/main.css
Normal file
@ -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;}
|
1
static/simple-grid.min.css
vendored
Normal file
1
static/simple-grid.min.css
vendored
Normal file
@ -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}}
|
Loading…
Reference in New Issue
Block a user