Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect incomplete comms + fix RTB beeps #181

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/wificom/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions lib/wificom/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
'''
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Loading