Skip to content

Commit

Permalink
Merge pull request #13 from empkins/12-buttons-are-not-activated-as-e…
Browse files Browse the repository at this point in the history
…vent-input-sources

12 buttons are not activated as event input sources
  • Loading branch information
a-mosquito authored Jan 15, 2024
2 parents 299656c + 87e7043 commit 59ff899
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 32 deletions.
2 changes: 2 additions & 0 deletions empkins_sync_board_gui/constants/board_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# connection information
INPUT_CONNECTION = 0
OUTPUT_CONNECTION = 1
IS_INACTIVE = "00"
IS_ACTIVE = "01"
CONNECTION_MAPPING = "mapping"
CONNECTION_CONFIG = "connections"
CONNECTION_NAMES = "names"
Expand Down
17 changes: 5 additions & 12 deletions empkins_sync_board_gui/dialogs/connection_config_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, main_window: QWidget, conn: Connection, conn_idx: int):

def get_data(self):
"""Return the data entered by the user after dialog closes."""
return self.connection_update_command, self.optional_update_command, self.user_hint
return self.connection_update_command, self.user_hint

def _setup_ui(self):
self.ui.setupUi(self)
Expand Down Expand Up @@ -275,8 +275,7 @@ class InputOutputConnectionConfigDialog(OutputConnectionConfigDialog):

def __init__(self, main_window: QWidget, conn: Connection, conn_idx: int):
super().__init__(main_window, conn, conn_idx, init_ui=Ui_InOutConnectionConfigDialog())
self.input_connection_update_command = ""
self.output_connection_update_command = ""
self.connection_update_command = ""
self._set_configuration_option()

def _setup_ui(self):
Expand Down Expand Up @@ -354,10 +353,7 @@ def update_connection(self):
conn_type = INPUT_CONNECTION if self.ui.event_config_radio.isChecked() else OUTPUT_CONNECTION
self.connection.conn_type = conn_type
if conn_type == OUTPUT_CONNECTION:
(
self.output_connection_update_command,
self.input_connection_update_command,
) = self.connection.update_bidirectional_connection(
self.connection_update_command = self.connection.update_bidirectional_connection(
self.main_window.board_config.command_dict,
self.connection_index,
delay=delay,
Expand All @@ -369,10 +365,7 @@ def update_connection(self):
self.user_hint = "Please make sure one little plastic jumper is at the position marked with `OUT`!\n"

else:
(
self.input_connection_update_command,
self.output_connection_update_command,
) = self.connection.update_bidirectional_connection(
self.connection_update_command = self.connection.update_bidirectional_connection(
self.main_window.board_config.command_dict,
self.connection_index,
delay=delay,
Expand All @@ -387,4 +380,4 @@ def update_connection(self):

def get_data(self):
"""Access connection update commands and user hint after dialog was closed."""
return self.input_connection_update_command, self.output_connection_update_command, self.user_hint
return self.connection_update_command, self.user_hint
36 changes: 21 additions & 15 deletions empkins_sync_board_gui/utils/board_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
DEFAULT_SOURCE,
DEFAULT_SYNC_SIGNAL,
INPUT_CONNECTION,
IS_ACTIVE,
MAX_DEGREE,
MAX_DELAY,
MAX_FREQ,
Expand Down Expand Up @@ -131,6 +132,25 @@ def get_event_command(self, event_id: int) -> bytes:
cmd = bytes.fromhex(cmd) + event_id
return cmd

def activate_buttons(self) -> Tuple[bytes, bytes]:
"""Create command to activate buttons."""
print(self.command_dict["trigger"])
button_1_cmd = (
self.command_dict["hello"]
+ self.command_dict["event"]
+ self.command_dict["trigger"][1]["Button1"]
+ IS_ACTIVE
+ self.command_dict["event_sync_signal"][2]["Any Edge"]
)
button_2_cmd = (
self.command_dict["hello"]
+ self.command_dict["event"]
+ self.command_dict["trigger"][2]["Button2"]
+ IS_ACTIVE
+ self.command_dict["event_sync_signal"][2]["Any Edge"]
)
return bytes.fromhex(button_1_cmd), bytes.fromhex(button_2_cmd)

@property
def start_source(self):
"""Return start source."""
Expand Down Expand Up @@ -366,9 +386,6 @@ def update_bidirectional_connection(
):
"""Update bidirectional connection properties."""
if self.conn_type == OUTPUT_CONNECTION:
inactive_update_command = self._build_event_command(
command_dict, conn_idx=INPUT_CONNECTION, is_active=False, sync_signal=DEFAULT_SYNC_SIGNAL
)
active_update_command = self.update_connection(
command_dict,
conn_idx,
Expand All @@ -384,23 +401,12 @@ def update_bidirectional_connection(
else:
# manipulate connection type to set output connection inactive first
self.conn_type = OUTPUT_CONNECTION
inactive_update_command = self.update_connection(
command_dict,
conn_idx,
is_active=False,
delay=delay,
sync_signal=sync_signal,
freq=freq,
stop_trigger=stop_trigger,
degree=degree,
pulse_length=pulse_length,
)
# reset connection type
self.conn_type = INPUT_CONNECTION
active_update_command = self._build_event_command(
command_dict, conn_idx, is_active=True, sync_signal=sync_signal
)
return active_update_command, inactive_update_command
return active_update_command

def _toggle_bidirectional_connection(self, command_dict: Dict[str, str], conn_idx: int, is_visible) -> bytes:
"""Toggle bidirectional connection."""
Expand Down
15 changes: 10 additions & 5 deletions empkins_sync_board_gui/windows/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, mock_mode=True, version=BOARD_VERSION_V3):
self.connector_setup()
# after successful connector setup, send first commands
self.init_start_stop_source()
# setup start and stop source afterward as they might be using the connector already
self.activate_buttons()
self.ui.start_source.currentIndexChanged.connect(self.change_start_source)
self._set_source_button_activation(self.ui.start_source, mode=START_MODE)
self.ui.stop_source.currentIndexChanged.connect(self.change_stop_source)
Expand Down Expand Up @@ -181,6 +181,14 @@ def init_start_stop_source(self):
self.change_start_source()
self.change_stop_source()

def activate_buttons(self):
"""Activate buttons as possible event input sources.
They are activated directly after startup and remain active during the entire measurement.
"""
for cmd in self.board_config.activate_buttons():
self.connector.send_command(cmd)

def toggle_connection(self):
"""Toggle connection active/inactive."""
button = self.sender()
Expand Down Expand Up @@ -246,12 +254,9 @@ def open_config_dialog(self):
raise ValueError(f"Invalid connection type {conn.conn_type}!")
d.exec_()
d.show()
connection_update_command, optional_update_command, user_hint = d.get_data()
# only send if it's not empty
connection_update_command, user_hint = d.get_data()
if connection_update_command:
self.connector.send_command(connection_update_command)
if optional_update_command:
self.connector.send_command(optional_update_command)
if user_hint:
msg = QMessageBox()
msg.setWindowTitle("Device selected! What's next?")
Expand Down

0 comments on commit 59ff899

Please sign in to comment.