Skip to content

Commit

Permalink
Cleaning up resources when session window closed
Browse files Browse the repository at this point in the history
- Woodway treadmill gets closed
- Vibrotactors get disconnected
  • Loading branch information
wsarce committed Jun 27, 2022
1 parent 40e21b7 commit 4b1eb38
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
34 changes: 22 additions & 12 deletions output_view_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,16 @@ def close(self):
if self.e4_view:
self.e4_view.stop_plot()
self.e4_view.disconnect_e4()
if self.video_view.player:
self.video_view.player.loading = False
if self.video_view.recorder:
self.video_view.recorder.stop_recording()
self.video_view.recorder.stop_playback()
if self.video_view:
if self.video_view.player:
self.video_view.player.loading = False
if self.video_view.recorder:
self.video_view.recorder.stop_recording()
self.video_view.recorder.stop_playback()
if self.ble_view:
self.ble_view.disconnect_ble()
if self.woodway_view:
self.woodway_view.disconnect_woodway()

def start_session(self, recording_path=None):
if self.e4_view:
Expand Down Expand Up @@ -405,6 +410,9 @@ def disable_ui_elements(self):
self.prot_load_button.config(state='disabled')
self.calibrate_button.config(state='disabled')

def __enable_connect_button(self):
self.woodway_connect_button.config(state='active')

def __disable_ui_elements(self):
self.belt_incline_l.config(state='disabled')
self.belt_speed_l.config(state='disabled')
Expand Down Expand Up @@ -432,10 +440,12 @@ def start_session(self):
self.__save_protocol_to_file()

def stop_session(self):
self.session_started = False
self.woodway.belt_a.set_speed(0.0)
self.woodway.belt_b.set_speed(0.0)
self.woodway.set_elevations(0.0)
if self.woodway:
self.session_started = False
self.woodway.belt_a.set_speed(0.0)
self.woodway.belt_b.set_speed(0.0)
self.woodway.set_elevations(0.0)
self.woodway.close()

def next_protocol_step(self, current_time):
if current_time == 1:
Expand Down Expand Up @@ -591,12 +601,11 @@ def __connect_to_woodway(self):
def disconnect_woodway(self):
if self.woodway:
self.woodway.stop_belts()
self.woodway.set_elevations(0)
self.woodway.set_elevations(float(0.0))
self.woodway.close()
self.woodway = None
self.__disable_ui_elements()
else:
messagebox.showwarning("Warning", "Connect to Woodway first!")
self.__enable_connect_button()

def __write_speed(self):
if self.session_started:
Expand Down Expand Up @@ -818,6 +827,7 @@ def stop_session(self):
self.session_started = False
self.right_vta.stop_imu()
self.left_vta.stop_imu()
self.disconnect_ble()

def is_calibrated(self):
return self.calibrated
Expand Down
2 changes: 1 addition & 1 deletion ui_params.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cometrics_version = "1.1.1"
cometrics_version = "1.1.3"
ui_title = f"cometrics v{cometrics_version}"

cometrics_data_root = fr'C:\cometrics'
Expand Down

0 comments on commit 4b1eb38

Please sign in to comment.