From 191a580469d792dfcf9abac706ee7fa8ecce1d1d Mon Sep 17 00:00:00 2001 From: Andrew Andrianov Date: Sun, 8 Oct 2017 23:20:17 +0300 Subject: [PATCH] protocols: Move device reset logic to a separate method Signed-off-by: Andrew Andrianov --- stcgal/protocols.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/stcgal/protocols.py b/stcgal/protocols.py index 8f0672b..31b88f9 100644 --- a/stcgal/protocols.py +++ b/stcgal/protocols.py @@ -241,6 +241,21 @@ class StcBaseProtocol: def set_option(self, name, value): self.options.set_option(name, value) + def reset_device(self, resetcmd=False): + if not resetcmd: + print("Cycling power: ", end="") + sys.stdout.flush() + self.ser.setDTR(True) + time.sleep(0.5) + self.ser.setDTR(False) + print("done") + else: + print("Cycling power via shell cmd: " + resetcmd) + os.system(resetcmd) + + print("Waiting for MCU: ", end="") + sys.stdout.flush() + def connect(self, autoreset=False, resetcmd=False): """Connect to MCU and initialize communication. @@ -260,18 +275,7 @@ class StcBaseProtocol: self.ser.flushInput() if autoreset: - if not resetcmd: - print("Cycling power: ", end="") - sys.stdout.flush() - self.ser.setDTR(True) - time.sleep(0.5) - self.ser.setDTR(False) - print("done") - print("Waiting for MCU: ", end="") - sys.stdout.flush() - else: - print("Cycling power via shell cmd: " + resetcmd) - os.system(resetcmd) + self.reset_device(resetcmd) else: print("Waiting for MCU, please cycle power: ", end="") sys.stdout.flush()