Skip to content

Commit

Permalink
add an optional button in the dashboard for remote mode switch
Browse files Browse the repository at this point in the history
  • Loading branch information
corruptbear committed Jun 22, 2024
1 parent cdd8ef4 commit fdada8b
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions software/management/dashboard/tottag.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
DEVICE_ID_UUID = '00002a23-0000-1000-8000-00805f9b34fb'
LOCATION_SERVICE_UUID = 'd68c3156-a23f-ee90-0c45-5231395e5d2e'
FIND_MY_TOTTAG_SERVICE_UUID = 'd68c3155-a23f-ee90-0c45-5231395e5d2e'
MODE_SWITCH_UUID = 'd68c3164-a23f-ee90-0c45-5231395e5d2e'
TIMESTAMP_SERVICE_UUID = 'd68c3154-a23f-ee90-0c45-5231395e5d2e'
VOLTAGE_SERVICE_UUID = 'd68c3153-a23f-ee90-0c45-5231395e5d2e'
EXPERIMENT_SERVICE_UUID = 'd68c3161-a23f-ee90-0c45-5231395e5d2e'
Expand Down Expand Up @@ -192,7 +193,9 @@ def __init__(self, command_queue, result_queue, event_loop):
'GET_EXPERIMENT': self.retrieve_experiment,
'DELETE_EXPERIMENT': self.delete_experiment,
'DOWNLOAD': self.download_logs,
'DOWNLOAD_DONE': self.download_logs_done }
'DOWNLOAD_DONE': self.download_logs_done,
'ENABLE_STORAGE_MAINTENANCE': self.enable_storage_maintenance,
}
self.storage_directory = get_download_directory()
self.subscribed_to_notifications = False
self.downloading_log_file = False
Expand Down Expand Up @@ -301,6 +304,15 @@ async def find_my_tottag(self):
except Exception:
self.result_queue.put_nowait(('ERROR', ('TotTag Error', 'Unable to activate FindMyTotTag')))

async def enable_storage_maintenance(self):
self.result_queue.put_nowait(('SWITCHING', True))
try:
await self.connected_device.write_gatt_char(MODE_SWITCH_UUID, struct.pack('<I', 1), True)
self.result_queue.put_nowait(('SWITCHING', False))
except Exception:
traceback.print_exc()
self.result_queue.put_nowait(('ERROR', ('TotTag Error', 'Unable to enable storage maintenance')))

async def retrieve_timestamp(self):
self.result_queue.put_nowait(('RETRIEVING', True))
try:
Expand Down Expand Up @@ -461,10 +473,9 @@ def __init__(self, mode_switch_visibility=False):
ttk.Button(self.operations_bar, text="Get Scheduled Deployment Details", command=partial(ble_issue_command, self.event_loop, self.ble_command_queue, 'GET_EXPERIMENT'), state=['disabled']).grid(row=6, sticky=tk.W+tk.E)
ttk.Button(self.operations_bar, text="Cancel Scheduled Pilot Deployment", command=self._delete_experiment, state=['disabled']).grid(row=7, sticky=tk.W+tk.E)
ttk.Button(self.operations_bar, text="Download Deployment Logs", command=self._download_logs, state=['disabled']).grid(row=8, sticky=tk.W+tk.E)
self.switch_button = ttk.Button(self.operations_bar, text="Mode Switch", command=self._download_logs, state=['disabled'])
self.switch_button.grid(row=9)
if not mode_switch_visibility:
self.switch_button.place_forget()
if mode_switch_visibility:
self.switch_button = ttk.Button(self.operations_bar, text="Mode Switch", command=partial(ble_issue_command, self.event_loop, self.ble_command_queue, 'ENABLE_STORAGE_MAINTENANCE'), state=['disabled'])
self.switch_button.grid(row=9)

# Create the workspace canvas
self.canvas = tk.Frame(self)
Expand Down Expand Up @@ -803,6 +814,12 @@ def _refresh_data(self):
tk.Label(self.canvas, text="Carrying out the selected operation. Please wait...").pack(fill=tk.BOTH, expand=True)
else:
tk.Label(self.canvas, text="Operation complete!").pack(fill=tk.BOTH, expand=True)
elif key == 'SWITCHING':
self._clear_canvas()
if data:
tk.Label(self.canvas, text="Carrying out the selected operation. Please wait...").pack(fill=tk.BOTH, expand=True)
else:
tk.Label(self.canvas, text="Operation complete!").pack(fill=tk.BOTH, expand=True)
elif key == 'TIMESTAMP':
self._clear_canvas()
date_string_utc, time_string_utc, _ = unpack_datetime('UTC', None, data)
Expand Down Expand Up @@ -874,7 +891,6 @@ def main(s):

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Parser for command line options")
parser.add_argument('-s', action='store_true', help='With the -s flag, the mode switch will show')
parser.add_argument('-s', action='store_true', help='With the -s flag, the mode switch will be visible')
args = parser.parse_args()
main(args.s)

main(args.s)

0 comments on commit fdada8b

Please sign in to comment.