From 0cab61370b0a6914aa2521f82719f7ed7d11fba3 Mon Sep 17 00:00:00 2001 From: telegnom Date: Thu, 5 Oct 2017 11:56:36 +0200 Subject: [PATCH] moved serial commands to module --- .gitignore | 7 +++++++ beamer/__init__.py | 1 + beamer/acer.py | 11 +++++++++++ beamerctl.py | 21 +++++++++++---------- 4 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 .gitignore create mode 100644 beamer/__init__.py create mode 100644 beamer/acer.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f279f78 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# ide +.idea/ diff --git a/beamer/__init__.py b/beamer/__init__.py new file mode 100644 index 0000000..a2a25d9 --- /dev/null +++ b/beamer/__init__.py @@ -0,0 +1 @@ +from . import acer \ No newline at end of file diff --git a/beamer/acer.py b/beamer/acer.py new file mode 100644 index 0000000..67f8c09 --- /dev/null +++ b/beamer/acer.py @@ -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.*'] + } diff --git a/beamerctl.py b/beamerctl.py index de602ad..a7c0e99 100755 --- a/beamerctl.py +++ b/beamerctl.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.4 +#!/usr/bin/env python3 import argparse import re @@ -9,7 +9,8 @@ import logging import sys import schedule import paho.mqtt.client as mqtt - +from beamer import acer as beamercodes +code = beamercodes.clubbeamer() def on_connect(client, userdata, flags, rc): global beamer_state @@ -34,25 +35,25 @@ def on_message(client, userdata, message): msg = message.payload.decode("utf-8") log.debug('received message: {}'.format(msg)) if (msg == "on"): - ser.write(b"* 0 IR 001\r") + ser.write(code.set['on']) if (msg == "off"): - ser.write(b"* 0 IR 002\r") + ser.write(code.set['off']) if (msg == "vga"): - ser.write(b"* 0 IR 015\r") + ser.write(code.set['vga']) if (msg == "hdmi1"): - ser.write(b"* 0 IR 015\r") + ser.write(code.set['hdmi1'][0]) time.sleep(1) - ser.write(b"* 0 IR 050\r") + ser.write(code.set['hdmi1'][1]) if (msg == "hdmi2"): - ser.write(b"* 0 IR 015\r") + ser.write(code.set['hdmi2'][0]) time.sleep(0.5) - ser.write(b"* 0 IR 050\r") + ser.write(code.set['hdmi2'][1]) time.sleep(0.5) - ser.write(b"* 0 IR 050\r") + ser.write(code.set['hdmi2'][2]) def readBeamerState():