Skip to content

Commit

Permalink
bitcraze#473 Block connection when cold booting
Browse files Browse the repository at this point in the history
  • Loading branch information
krichardsson committed Mar 4, 2021
1 parent 7386a8a commit 4ed2180
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
28 changes: 15 additions & 13 deletions src/cfclient/ui/connectivity_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,23 @@ def register_ui_elements(self, ui_elements):
self._interface_combo_current_index_changed_handler)

def set_state(self, state):
self._state = state
self._update_ui()

if self._state == self.UIState.DISCONNECTED:
self.connection_state_changed.emit(self.UIState.DISCONNECTED)
elif self._state == self.UIState.CONNECTED:
self.connection_state_changed.emit(self.UIState.CONNECTED)
elif self._state == self.UIState.CONNECTING:
self.connection_state_changed.emit(self.UIState.CONNECTING)
elif self._state == self.UIState.SCANNING:
self.connection_state_changed.emit(self.UIState.SCANNING)
if self._state != state:
self._state = state
self._update_ui()

if self._state == self.UIState.DISCONNECTED:
self.connection_state_changed.emit(self.UIState.DISCONNECTED)
elif self._state == self.UIState.CONNECTED:
self.connection_state_changed.emit(self.UIState.CONNECTED)
elif self._state == self.UIState.CONNECTING:
self.connection_state_changed.emit(self.UIState.CONNECTING)
elif self._state == self.UIState.SCANNING:
self.connection_state_changed.emit(self.UIState.SCANNING)

def set_enable(self, enable):
self._is_enabled = enable
self._update_ui()
if self._is_enabled != enable:
self._is_enabled = enable
self._update_ui()

def set_address(self, address):
for ui_elements in self._ui_elements:
Expand Down
13 changes: 10 additions & 3 deletions src/cfclient/ui/dialogs/bootloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def __init__(self, helper, *args):
self.clt.disconnectedSignal.connect(
lambda: self.setUiState(UIState.DISCONNECTED))

self._cold_boot_error_message = ''

self._releases = {}
self._release_firmwares_found.connect(self._populate_firmware_dropdown)
self._release_downloaded.connect(self.release_zip_downloaded)
Expand All @@ -129,8 +131,8 @@ def __init__(self, helper, *args):
self.clt.start()

def _ui_connection_fail(self, message):
self.setStatusLabel(message)
self.coldBootButton.setEnabled(True)
self._cold_boot_error_message = message
self.setUiState(UIState.CONNECT_FAILED)

def setUiState(self, state):
if (state == UIState.DISCONNECTED):
Expand All @@ -141,25 +143,30 @@ def setUiState(self, state):
self.progressBar.setTextVisible(False)
self.progressBar.setValue(0)
self.statusLabel.setText('Status: <b>IDLE</b>')
self.helper.connectivity_manager.set_enable(True)
elif (state == UIState.CONNECTING):
self.resetButton.setEnabled(False)
self.programButton.setEnabled(False)
self.setStatusLabel("Trying to connect cold bootloader, restart "
"the Crazyflie to connect")
self.coldBootButton.setEnabled(False)
self.helper.connectivity_manager.set_enable(False)
elif (state == UIState.CONNECT_FAILED):
self.setStatusLabel("Connecting to bootloader failed")
self.setStatusLabel(self._cold_boot_error_message)
self.coldBootButton.setEnabled(True)
self.helper.connectivity_manager.set_enable(True)
elif (state == UIState.COLD_CONNECT):
self.resetButton.setEnabled(True)
self.programButton.setEnabled(True)
self.setStatusLabel("Connected to bootloader")
self.coldBootButton.setEnabled(False)
self.helper.connectivity_manager.set_enable(False)
elif (state == UIState.RESET):
self.setStatusLabel("Resetting to firmware, disconnected")
self.resetButton.setEnabled(False)
self.programButton.setEnabled(False)
self.coldBootButton.setEnabled(False)
self.helper.connectivity_manager.set_enable(False)

def setStatusLabel(self, text):
self.connectionStatus.setText("Status: <b>%s</b>" % text)
Expand Down

0 comments on commit 4ed2180

Please sign in to comment.