diff --git a/lib/wificom/main.py b/lib/wificom/main.py index f7f5979..ff8b274 100644 --- a/lib/wificom/main.py +++ b/lib/wificom/main.py @@ -74,10 +74,11 @@ def serial_readline(): return None return serial_str -def execute_digirom(rom, do_led=True): +def execute_digirom(rom, do_led=True, do_beep=True): ''' Execute the digirom and report results. ''' + #pylint: disable=too-many-branches try: controller.execute(rom) result = str(rom.result) @@ -92,12 +93,18 @@ def execute_digirom(rom, do_led=True): print(result) else: mqtt.handle_result(result) - if do_led: + if do_beep: if "Error" in result: ui.beep_error() - time.sleep(0.2) elif "r:" in result: - ui.beep_ready() + if len(rom.result) < 2 * len(rom): + ui.beep_error() + elif rom.turn == 1 and " t" in result: + ui.beep_error() + else: + ui.beep_ready() + if do_led: + if "r:" in result or "Error" in result: time.sleep(0.2) else: time.sleep(0.05) diff --git a/lib/wificom/realtime.py b/lib/wificom/realtime.py index 3868e5d..b4a2763 100644 --- a/lib/wificom/realtime.py +++ b/lib/wificom/realtime.py @@ -34,11 +34,11 @@ def __init__(self, execute_callback, send_callback, receive_callback, status_cal self.received_message = None self.received_digirom = None self.comm_attempts = 0 # for host only - def execute(self, digirom, do_led=False): + def execute(self, digirom, do_led, do_beep): ''' Execute digirom using the execute callback, and store result. ''' - self._execute_callback(digirom, do_led) + self._execute_callback(digirom, do_led, do_beep) self.result = digirom.result def modify_received_digirom(self): ''' @@ -123,7 +123,7 @@ def loop(self): elif self.time_start is None: self.update_status(STATUS_PUSH) digirom = dmcomm.protocol.parse_command(self.scan_str) - self.execute(digirom) + self.execute(digirom, do_led=False, do_beep=False) if self.scan_successful(): self.send_message() self.time_start = time.monotonic() @@ -139,7 +139,7 @@ def loop(self): self.comm_attempts = 0 self._attempt_second_comm() def _attempt_second_comm(self): - self.execute(self.received_digirom, True) + self.execute(self.received_digirom, do_led=True, do_beep=True) if self.comm_successful(): self.received_digirom = None self.time_start = None @@ -167,7 +167,7 @@ def loop(self): self.receive_digirom() if self.received_digirom is not None: self.update_status(STATUS_PUSH) - self.execute(self.received_digirom) + self.execute(self.received_digirom, do_led=False, do_beep=True) self.update_status(STATUS_WAIT) if self.comm_successful(): self.send_message()