Allows disconnecting and reconnecting serial
This commit is contained in:
parent
647edcc2ed
commit
69a231bd69
18
main.py
18
main.py
@ -19,11 +19,23 @@ class SerialWriter(threading.Thread):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
ser = serial.Serial(config.Serial)
|
||||
should_connect = True
|
||||
ser = None
|
||||
while True:
|
||||
try:
|
||||
if should_connect:
|
||||
ser = serial.Serial(config.Serial)
|
||||
should_connect = False
|
||||
with self.lock:
|
||||
ser.write(b"\01")
|
||||
ser.write(self.data)
|
||||
time.sleep(1/120)
|
||||
except:
|
||||
if ser != None:
|
||||
ser.close()
|
||||
ser = None
|
||||
should_connect = True
|
||||
time.sleep(0.1)
|
||||
|
||||
|
||||
|
||||
@ -51,7 +63,6 @@ class AppRunner(threading.Thread):
|
||||
self.app = subprocess.Popen(args, stdout=subprocess.PIPE)
|
||||
|
||||
def run(self):
|
||||
ser = serial.Serial("/dev/ttyACM0")
|
||||
while True:
|
||||
with self.lock:
|
||||
if self.app == None or self.app.poll() != None:
|
||||
@ -62,9 +73,6 @@ class AppRunner(threading.Thread):
|
||||
d = self.app.stdout
|
||||
oshandle = d.fileno()
|
||||
data = os.read(oshandle, config.ScreenX*config.ScreenY*3)
|
||||
# data = d.raw.read(config.ScreenX*config.ScreenY*3)
|
||||
#ser.write(b"\01")
|
||||
#ser.write(data)
|
||||
self.serial.setData(data)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user