Add receiver support

pull/5/head
viido 6 years ago
parent e5a0eb685a
commit cb951a9559
  1. 2
      nginx/default
  2. 5
      projektor/projektor.py
  3. 45
      projektor/server.py
  4. 1
      systemd/projektor.service
  5. 61
      www/index.html

@ -32,6 +32,8 @@ server {
} }
location /mopidy { location /mopidy {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:6680/mopidy; proxy_pass http://127.0.0.1:6680/mopidy;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;

@ -58,7 +58,7 @@ def off():
class Projektor: class Projektor:
def __init__(self, device): def __init__(self, device):
self.ser = serial.Serial(device, 115200, timeout=1) self.ser = serial.Serial(device, timeout=1)
def close(self): def close(self):
self.ser.close() self.ser.close()
@ -99,7 +99,9 @@ class Projektor:
self.ser.write(b"\r*pow=?#\r") self.ser.write(b"\r*pow=?#\r")
while True: while True:
#print (self.ser.read(999))
c = self.ser.read(1) c = self.ser.read(1)
#print(c);
if c == b">": if c == b">":
self.ser.read(15) self.ser.read(15)
status = self.ser.read(3) status = self.ser.read(3)
@ -121,6 +123,7 @@ if __name__ == "__main__":
while True: while True:
if p.get_power() != "ON": if p.get_power() != "ON":
print("POWER ON") print("POWER ON")
print(p.get_power())
p.on() p.on()
elif p.get_source() != "HDMI": elif p.get_source() != "HDMI":

@ -1,22 +1,55 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from bottle import get, post, request, run from bottle import get, post, request, run
import projektor import serial
import termios
def send(cmd):
ser = serial.Serial()
ser.rts = False
ser.dtr = False
ser.port = "/dev/ttyS0"
ser.open()
ser.write(cmd)
ser.close()
def send1(cmd):
port="/dev/ttyUSB0"
ser = serial.Serial()
ser.rts = False
ser.dtr = False
ser.port = port
ser.open()
ser.write(cmd)
ser.close()
@get("/status") @get("/status")
def status(): def status():
print("asking status") print("asking status")
return projektor.get_status() return "hdmi"
@post("/status") @post("/status")
def set_status(): def set_status():
mode = request.forms.get("mode") mode = request.forms.get("mode")
print("SETTING STATUS TO", mode) print("SETTING STATUS TO", mode)
if mode == "off": if mode == "off":
projektor.off() send(b"\r*pow=off#\r")
elif mode == "on":
send(b"\r*pow=on#\r")
elif mode == "viido":
send1(b"t")
elif mode == "hdmi": elif mode == "hdmi":
projektor.on_hdmi() send1(b"m")
elif mode == "vga": elif mode == "steam":
projektor.on_vga() send1(b"l")
elif mode == "aux":
send1(b"a")
elif mode == "volumeup":
send1(b"q")
elif mode == "volumedown":
send1(b"w")
return "OK" return "OK"

@ -2,6 +2,7 @@
Description=Projektori server Description=Projektori server
[Service] [Service]
Environment=PYTHONUNBUFFERED=1
ExecStart=/opt/projektor/server.py ExecStart=/opt/projektor/server.py
[Install] [Install]

@ -52,12 +52,22 @@
display: flex; display: flex;
flex-direction: row; flex-direction: row;
width: 100%; width: 100%;
flex-wrap: wrap;
user-select: none;
-webkit-user-select: none; /* Chrome all / Safari all */
-moz-user-select: none; /* Firefox all */
-ms-user-select: none; /* IE 10+ */
user-select: none; /* Likely future */
} }
.radio-toolbar input[type="radio"] { .radio-toolbar input[type="radio"] {
display: none; display: none;
} }
.radio-toolbar input[type="button"] {
display: none;
}
.radio-toolbar label { .radio-toolbar label {
background-color: white; /* RED */ background-color: white; /* RED */
border: none; border: none;
@ -73,9 +83,18 @@
cursor: pointer; cursor: pointer;
flex: 1 0 auto; flex: 1 0 auto;
border: 2px solid #4CAF50; border: 2px solid #4CAF50;
user-select: none;
}
.rbnt{
width: 30%;
transition-duration: 0s;
} }
.rbnt:active{
background-color: #4CAF50;
color: white;
}
.radio-toolbar lable.red { .radio-toolbar lable.red {
border: 2px solid #af4c4c; border: 2px solid #af4c4c;
} }
@ -120,11 +139,6 @@
<script> <script>
$(function() $(function()
{ {
$.get("/projektor/status", function(data)
{
$(".radio-toolbar input[type=radio][value=" + data + "]").prop("checked", true);
$(".radio-toolbar input[type=radio]").prop("disabled", false);
});
$(".radio-toolbar input[type=radio]").change(function() $(".radio-toolbar input[type=radio]").change(function()
{ {
@ -135,6 +149,12 @@
$("#loading").css("visibility", "hidden"); $("#loading").css("visibility", "hidden");
}); });
}); });
$(".radio-toolbar input[type=button]").click(function()
{
$.post("/projektor/status", {mode: $(this).val()}, function(data)
{
});
});
}); });
</script> </script>
</head> </head>
@ -148,15 +168,38 @@
<h2 class="title">Projektori juhtimine</h2> <h2 class="title">Projektori juhtimine</h2>
<div class="radio-toolbar"> <div class="radio-toolbar">
<input type="radio" id="radio1" name="radios" value="off" class="red" disabled> <input type="radio" id="radio1" name="radios" value="off" class="red">
<label for="radio1" class="red">OFF</label> <label for="radio1" class="red">OFF</label>
<input type="radio" id="radio2" name="radios" value="hdmi" disabled> <input type="radio" id="radio2" name="radios" value="on">
<label for="radio2">HDMI</label> <label for="radio2">ON</label>
</div> </div>
<h2 class="title">Sisendi juhtimine</h2>
<h2 class="title">Linux audio tunnel</h2> <div class="radio-toolbar">
<input type="radio" id="r2" name="receiver" value="viido">
<label class="rbnt" for="r2">Viido</label>
<input type="radio" id="r3" name="receiver" value="steam">
<label class="rbnt" for="r3">Steam</label>
<input type="button" id="v1" name="receiver" value="volumeup">
<label class="rbnt" for="v1">Vol +</label>
</div>
<br>
<div class="radio-toolbar">
<input type="radio" id="r4" name="receiver" value="hdmi">
<label class="rbnt" for="r4">HDMI</label>
<input type="radio" id="r5" name="receiver" value="aux">
<label class="rbnt" for="r5">AUX</label>
<input type="button" id="v2" name="receiver" value="volumedown">
<label class="rbnt" for="v2">Vol -</label>
</div>
<h2 class="title">Linux audio tunnel</h2>
<pre> <pre>
pacmd load-module module-tunnel-sink-new server=viido pacmd load-module module-tunnel-sink-new server=viido
PULSE_SERVER=viido pavucontrol & PULSE_SERVER=viido pavucontrol &

Loading…
Cancel
Save