moved serial commands to module

This commit is contained in:
telegnom 2017-10-05 11:56:36 +02:00
parent 5bf28aafd9
commit 0cab61370b
4 changed files with 30 additions and 10 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# ide
.idea/

1
beamer/__init__.py Normal file
View File

@ -0,0 +1 @@
from . import acer

11
beamer/acer.py Normal file
View File

@ -0,0 +1,11 @@
class clubbeamer():
set = {
'on': b'* 0 IR 001\r',
'off': b'* 0 IR 002\r',
'vga': b'* 0 IR 015\r',
'hdmi1': [b'* 0 IR 015\r', b'* 0 IR 050\r'],
'hdmi2': [b'* 0 IR 015\r', b'* 0 IR 050\r', b'* 0 IR 050\r']
}
get = {
'state': [b'* 0 Lamp ?\r', r'.*Lamp.1.*']
}

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3.4 #!/usr/bin/env python3
import argparse import argparse
import re import re
@ -9,7 +9,8 @@ import logging
import sys import sys
import schedule import schedule
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
from beamer import acer as beamercodes
code = beamercodes.clubbeamer()
def on_connect(client, userdata, flags, rc): def on_connect(client, userdata, flags, rc):
global beamer_state global beamer_state
@ -34,25 +35,25 @@ def on_message(client, userdata, message):
msg = message.payload.decode("utf-8") msg = message.payload.decode("utf-8")
log.debug('received message: {}'.format(msg)) log.debug('received message: {}'.format(msg))
if (msg == "on"): if (msg == "on"):
ser.write(b"* 0 IR 001\r") ser.write(code.set['on'])
if (msg == "off"): if (msg == "off"):
ser.write(b"* 0 IR 002\r") ser.write(code.set['off'])
if (msg == "vga"): if (msg == "vga"):
ser.write(b"* 0 IR 015\r") ser.write(code.set['vga'])
if (msg == "hdmi1"): if (msg == "hdmi1"):
ser.write(b"* 0 IR 015\r") ser.write(code.set['hdmi1'][0])
time.sleep(1) time.sleep(1)
ser.write(b"* 0 IR 050\r") ser.write(code.set['hdmi1'][1])
if (msg == "hdmi2"): if (msg == "hdmi2"):
ser.write(b"* 0 IR 015\r") ser.write(code.set['hdmi2'][0])
time.sleep(0.5) time.sleep(0.5)
ser.write(b"* 0 IR 050\r") ser.write(code.set['hdmi2'][1])
time.sleep(0.5) time.sleep(0.5)
ser.write(b"* 0 IR 050\r") ser.write(code.set['hdmi2'][2])
def readBeamerState(): def readBeamerState():