gui: handle hard reset in _on_connection_changed()

- Ensure correct gui disconnection seq during Kirdy hard reset
This commit is contained in:
linuswck 2024-04-19 14:49:01 +08:00
parent 9524601cb6
commit 4a06a7579f
1 changed files with 10 additions and 5 deletions

View File

@ -70,6 +70,8 @@ class KirdyDataWatcher(QObject):
if task.done():
task = asyncio.create_task(self.signal_emitter())
await asyncio.sleep(self._update_s)
except asyncio.CancelledError:
pass
except Exception as e:
logging.error(f"Encountered an error: {e}. disconnecting.", exc_info=True)
self._kirdy.stop_report_mode()
@ -81,6 +83,7 @@ class KirdyDataWatcher(QObject):
async def stop_watching(self):
if self._watch_task is not None:
self._watch_task.cancel()
await self._watch_task
self._watch_task = None
await self.set_report_mode(False)
@ -89,9 +92,9 @@ class KirdyDataWatcher(QObject):
if enabled:
self._report_mode_task = asyncio.create_task(self.report_mode())
else:
self._kirdy.stop_report_mode()
if self._report_mode_task is not None:
self._report_mode_task.cancel()
self._kirdy.stop_report_mode()
await self._report_mode_task
self._report_mode_task = None
async def report_mode(self):
@ -610,7 +613,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
tree.setParameters(self.params[3], showTop=False)
self.params[3].sigTreeStateChanged.connect(self.send_command)
async def _on_connection_changed(self, result):
async def _on_connection_changed(self, result, hard_reset=False):
def ctrl_panel_setEnable(result):
self.ld_status.setEnabled(result)
self.ld_tree.setEnabled(result)
@ -659,8 +662,10 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.status_lbl.setText("Disconnected")
self.clear_graphs()
self.report_box.setChecked(False)
await self.kirdy_data_watcher.set_report_mode(False)
self.kirdy_data_watcher.stop_watching()
await self.kirdy_data_watcher.stop_watching()
if hard_reset:
await self.kirdy.device.hard_reset()
await self.kirdy.end_session()
self.status_lbl.setText("Disconnected")
def _status(self):