diff --git a/empkins_sync_board_gui/constants/board_constants.py b/empkins_sync_board_gui/constants/board_constants.py index 0f9e3c3..c9d8a4d 100644 --- a/empkins_sync_board_gui/constants/board_constants.py +++ b/empkins_sync_board_gui/constants/board_constants.py @@ -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" diff --git a/empkins_sync_board_gui/dialogs/connection_config_dialog.py b/empkins_sync_board_gui/dialogs/connection_config_dialog.py index a983bd6..8d6c1b4 100644 --- a/empkins_sync_board_gui/dialogs/connection_config_dialog.py +++ b/empkins_sync_board_gui/dialogs/connection_config_dialog.py @@ -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) @@ -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): @@ -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, @@ -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, @@ -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 diff --git a/empkins_sync_board_gui/utils/board_configuration.py b/empkins_sync_board_gui/utils/board_configuration.py index 5f64212..0a92a25 100644 --- a/empkins_sync_board_gui/utils/board_configuration.py +++ b/empkins_sync_board_gui/utils/board_configuration.py @@ -16,6 +16,7 @@ DEFAULT_SOURCE, DEFAULT_SYNC_SIGNAL, INPUT_CONNECTION, + IS_ACTIVE, MAX_DEGREE, MAX_DELAY, MAX_FREQ, @@ -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.""" @@ -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, @@ -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.""" diff --git a/empkins_sync_board_gui/windows/main_window.py b/empkins_sync_board_gui/windows/main_window.py index 46fc482..4b31814 100644 --- a/empkins_sync_board_gui/windows/main_window.py +++ b/empkins_sync_board_gui/windows/main_window.py @@ -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) @@ -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() @@ -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?")