|
@@ -1,10 +1,7 @@
|
|
|
|
|
|
|
|
|
from serial import Serial
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+from serial.tools.list_ports import comports as port_list
|
|
|
|
|
|
from remotes import tv
|
|
|
|
|
@@ -14,6 +11,28 @@ ser = Serial(timeout=1)
|
|
|
ser.baudrate = 9600
|
|
|
ser.port = '/dev/ttyACM0'
|
|
|
|
|
|
+
|
|
|
+ports_open = port_list(False)
|
|
|
+found = False
|
|
|
+for p in ports_open:
|
|
|
+
|
|
|
+ if ser.port == None:
|
|
|
+ if p.manufacturer == "Arduino (www.arduino.cc)":
|
|
|
+ found = True
|
|
|
+ ser.port = "/dev/{0}".format(p.name)
|
|
|
+ print("Automagically found an Arduino on port '/dev/{0}'!".format(p.name))
|
|
|
+ break
|
|
|
+ else:
|
|
|
+ if '/dev/{0}'.format(p.name) == ser.port:
|
|
|
+ found = True
|
|
|
+ print("Found your Arduino!")
|
|
|
+ break
|
|
|
+
|
|
|
+
|
|
|
+if not found:
|
|
|
+ raise TypeError("Device not found!")
|
|
|
+
|
|
|
+
|
|
|
def send_code(ky):
|
|
|
if ky in tv:
|
|
|
msg = "0x{0},{1},1\n".format(tv[ky], tv["_config"]["size"])
|
|
@@ -22,18 +41,20 @@ def send_code(ky):
|
|
|
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 != "":
|
|
|
+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:
|
|
|
+ elif connect_t == 30:
|
|
|
ser.close()
|
|
|
print("Closed!")
|
|
|
- connect_t += 1
|
|
|
+ connect_t += 1
|