OOP full overhaul

This commit is contained in:
2022-06-05 15:31:17 +02:00
parent 76e227ae9e
commit 8f9b7501ae
7 changed files with 406 additions and 102 deletions

View File

@@ -1,90 +1,11 @@
#! /usr/bin/env python3
from serial import Serial
from argparse import ArgumentParser
from time import sleep
# w == escape
# | == carriage return
POWER_SAVE_ON = "w1PSAV|"
POWER_SAVE_OFF = "w0PSAV|"
POWER_SAVE = "wpsav|"
INPUT = lambda x: f"{x}!"
EDIDS = {
"automatic": 0,
"1280x800": 14,
"720p60": 34,
"1080p60": 45,
}
ERRORS = {
"E01": "Invalid input number",
"E06": "Invalid switch attempt in this mode",
"E10": "Invalid command",
"E11": "Invalid preset number",
"E12": "Invalid port number",
"E13": "Invalid parameter",
"E14": "Not valid for this configuration",
"E17": "Invalid command for signal type",
"E22": "Busy",
}
from projector import ProjectorSerial
from extron import ExtronSerial
verbose = False
def send_command(command: str) -> str:
with Serial("/dev/serial/by-id/usb-Extron_Product-if00", 9600, timeout=1) as ser:
if verbose:
print("Send:", command)
ser.write(command.encode())
# response = ser.readline().decode().strip()
response = None
while not (response := ser.readline()):
pass
response = response.decode().strip()
if verbose:
print("Resp:", response)
if not response:
print("no reponse")
exit(1)
if response[0] == "E":
print(response, ERRORS.get(response, "Unknown"))
exit(1)
return response
def send_command_projector(command: str) -> str:
with Serial("/dev/serial0", 9600, timeout=1) as ser:
ser.write(command.encode())
response = ser.readline()
if response:
print(response.decode())
def check_power_save():
resp = send_command(POWER_SAVE)
return int(resp)
def sleep_extron():
send_command(POWER_SAVE_ON)
def wake():
send_command(POWER_SAVE_OFF)
def change_input(input: int):
send_command(INPUT(input))
if __name__ == "__main__":
parser = ArgumentParser()
@@ -105,16 +26,14 @@ if __name__ == "__main__":
verbose = args.verbose
if args.input:
send_command_projector("\x02ADZZ;PON\x03")
wake()
change_input(args.input)
proj = ProjectorSerial()
extr = ExtronSerial()
if verbose:
print("Waking projector")
#send_command_projector("\x02ADZZ;PON\x03")
if args.input:
proj.power_on()
extr.wake()
extr.change_input(args.input)
elif args.sleep:
send_command_projector("\x02ADZZ;POF\x03")
sleep_extron()
proj.power_off()
extr.sleep()