123456789101112131415161718192021222324252627282930313233343536373839 |
- #!/usr/bin/env python3
- from serial import Serial
- # Use port_listing to print out the avalible ports
- # from serial.tools.list_ports import main as port_listing
- # port_listing()
- from remotes import tv
- from pprint import pprint
- ser = Serial(timeout=1)
- ser.baudrate = 9600
- ser.port = '/dev/ttyACM0'
- def send_code(ky):
- if ky in tv:
- msg = "0x{0},{1},1\n".format(tv[ky], tv["_config"]["size"])
- ser.write(msg.encode())
- print("Sent {0}".format(msg.encode()))
- else:
- print("Invalid key")
- ser.open()
- print("Opened!")
- connect_t = 0
- while ser.is_open:
- line = ser.readline().decode().strip("\n").strip("\r")
- if line != "":
- pprint(line)
- if connect_t == 6:
- send_code('power')
- elif connect_t == 18:
- send_code('power')
- elif connect_t == 30:
- ser.close()
- print("Closed!")
- connect_t += 1 # About 1 every second
|