Skip to content

Commit

Permalink
Add setting enable/disble auto reconnect arduino
Browse files Browse the repository at this point in the history
Default True but allows the user to disable auto reconnect if they so
choose.

- Add support for Boolean type settings
- Will not add separator lines under Headers

Signed-off-by: Rune Haugaard <[email protected]>
  • Loading branch information
Noloxs committed May 30, 2024
1 parent 920c410 commit 1e1d677
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

## EXECUTORS
SETTINGS_VALUE_TYPE_INT = "Integer"
SETTINGS_VALUE_TYPE_BOOL = "Boolean"
SETTINGS_VALUE_TYPE_HEADER = "Header"

MENU_TYPE_MENU = "Menu"
Expand Down
9 changes: 7 additions & 2 deletions src/executer_arduino.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
KEY_DELAY_JITTER_DEFAULT = 20
KEY_LAST_CONNECTED = "arduino_lastConnectedDevice"
KEY_LAST_CONNECTED_DEFAULT = None
KEY_AUTO_RECONNECT = "arduino_autoReconnect"
KEY_AUTO_RECONNECT_DEFAULT = True


START_HEX = "fb"
TERMINATION_HEX = "f7"
Expand All @@ -25,7 +28,8 @@ def __init__(self, controller):
self.controller = controller

def initialize(self):
self.attempt_auto_connect()
if getattr(self.settings, KEY_AUTO_RECONNECT, KEY_AUTO_RECONNECT_DEFAULT):
self.attempt_auto_connect()
self.prepare()

def attempt_auto_connect(self):
Expand Down Expand Up @@ -80,7 +84,8 @@ def get_settings_items(self):
#settings.append(SettingsItem("Trigger delay jitter", "arduino_triggerDelayJitter", constants.SETTINGS_VALUE_TYPE_INT))
settings.append(SettingsItem("Stratagem key delay", KEY_DELAY_DEFAULT, KEY_DELAY, constants.SETTINGS_VALUE_TYPE_INT))
settings.append(SettingsItem("Stratagem key delay jitter", KEY_DELAY_JITTER_DEFAULT, KEY_DELAY_JITTER, constants.SETTINGS_VALUE_TYPE_INT))
settings.append(SettingsItem("Header", None, None, constants.SETTINGS_VALUE_TYPE_HEADER))
settings.append(SettingsItem("Hardware Connection", None, None, constants.SETTINGS_VALUE_TYPE_HEADER))
settings.append(SettingsItem("Auto re-connect to latest device", KEY_AUTO_RECONNECT_DEFAULT, KEY_AUTO_RECONNECT, constants.SETTINGS_VALUE_TYPE_BOOL))

return settings

Expand Down
32 changes: 25 additions & 7 deletions src/view/pyqt5/edit_config_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,30 @@ def update_executor_settings(self):
self.add_settings_headline(self.executor_grid_layout, "XDPTool settings")

settings_items = self.controller.executer.get_settings_items()
previous_item = None

for i, item in enumerate(settings_items):
if item.value_type == constants.SETTINGS_VALUE_TYPE_INT:
value = getattr(self.settings, item.key, item.default_value)
self.add_key_binding(self.executor_grid_layout, item.title, str(value), i > 0, lambda checked, default_value=value, key=item.key: self.show_number_input_dialog(default_value, SettingsBindingHandler(self, key, self.update_executor_settings).on_next_value))
elif item.value_type == constants.SETTINGS_VALUE_TYPE_HEADER:
if item.value_type == constants.SETTINGS_VALUE_TYPE_HEADER:
self.add_settings_headline(self.executor_grid_layout, item.title)
else:
value = getattr(self.settings, item.key, item.default_value)
if i == 0 or previous_item.value_type == constants.SETTINGS_VALUE_TYPE_HEADER:
show_separator = False
else:
show_separator = True

if item.value_type == constants.SETTINGS_VALUE_TYPE_INT:
value_desc = str(value)
callback = lambda checked, default_value=value, key=item.key: self.show_number_input_dialog(default_value, SettingsBindingHandler(key, self.update_executor_settings).on_next_value)
elif item.value_type == constants.SETTINGS_VALUE_TYPE_BOOL:
if value:
value_desc = "Yes"
else:
value_desc = "No"
callback = lambda checked, current_value=value, key=item.key: SettingsBindingHandler(key, self.update_executor_settings).on_next_value(not current_value)

self.add_key_binding(self.executor_grid_layout, item.title, value_desc, show_separator, callback)
previous_item = item

def open_executor_selector_dialog(self):
items = {
Expand Down Expand Up @@ -191,13 +209,13 @@ def create_button(self, callback):
return button

class SettingsBindingHandler:
def __init__ (self, edit_config_dialog, settings_key, callback):
def __init__ (self, settings_key, callback):
self.settings_key = settings_key
self.edit_config_dialog = edit_config_dialog
self.callback = callback

def on_next_value(self, value):
setattr(self.edit_config_dialog.settings, self.settings_key, value)
settings = Settings.getInstance()
setattr(settings, self.settings_key, value)
self.callback()

class StratagemKeyBindingHandler:
Expand Down

0 comments on commit 1e1d677

Please sign in to comment.