From 1abbe62c338cd16d44903968ed350c885b1c70f3 Mon Sep 17 00:00:00 2001 From: Kenneth Yang Date: Sun, 10 Mar 2024 12:01:50 -0700 Subject: [PATCH 1/2] Reset UI on no failed connection --- .../UI/EphysLinkSettings/EphysLinkSettings.cs | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/Assets/Scripts/Pinpoint/UI/EphysLinkSettings/EphysLinkSettings.cs b/Assets/Scripts/Pinpoint/UI/EphysLinkSettings/EphysLinkSettings.cs index 2dfbec9d..a883ad92 100644 --- a/Assets/Scripts/Pinpoint/UI/EphysLinkSettings/EphysLinkSettings.cs +++ b/Assets/Scripts/Pinpoint/UI/EphysLinkSettings/EphysLinkSettings.cs @@ -194,6 +194,7 @@ public void OnLaunchEphysLinkPressed() } }; _ephysLinkProcess.Start(); + _ephysLinkProcess.Exited += (_, _) => HandleDisconnectingFromServer(); // Configure UI (disable type dropdown and launch button, enable [dis]connect button). _manipulatorTypeDropdown.interactable = false; @@ -216,6 +217,9 @@ void ConnectToServer() { _connectionErrorText.text = err; _connectButtonText.text = "Connect"; + + _manipulatorTypeDropdown.interactable = !CommunicationManager.Instance.IsConnected; + _launchEphysLinkButton.interactable = !CommunicationManager.Instance.IsConnected; } else { @@ -260,24 +264,7 @@ public void OnConnectDisconnectPressed() else { // Disconnect from server - QuestionDialogue.Instance.YesCallback = () => - { - foreach (var probeManager in ProbeManager.Instances - .Where(probeManager => probeManager.IsEphysLinkControlled)) - { - probeManager.SetIsEphysLinkControlled(false, - probeManager.ManipulatorBehaviorController.ManipulatorID); - - // FIXME: This is done because of race condition with closing out server. Should be fixed with non-registration setup. - probeManager.ManipulatorBehaviorController.Deinitialize(); - } - - CommunicationManager.Instance.DisconnectFromServer(() => - { - KillEphysLinkProcess(); - UpdateConnectionPanel(); - }); - }; + QuestionDialogue.Instance.YesCallback = HandleDisconnectingFromServer; QuestionDialogue.Instance.NewQuestion( "Are you sure you want to disconnect?\nAll incomplete movements will be canceled."); @@ -325,6 +312,25 @@ private void HandleSuccessfulConnection() }); } + private void HandleDisconnectingFromServer() + { + foreach (var probeManager in ProbeManager.Instances + .Where(probeManager => probeManager.IsEphysLinkControlled)) + { + probeManager.SetIsEphysLinkControlled(false, + probeManager.ManipulatorBehaviorController.ManipulatorID); + + // FIXME: This is done because of race condition with closing out server. Should be fixed with non-registration setup. + probeManager.ManipulatorBehaviorController.Deinitialize(); + } + + CommunicationManager.Instance.DisconnectFromServer(() => + { + KillEphysLinkProcess(); + UpdateConnectionPanel(); + }); + } + /// /// Populate UI elements with current connection settings. /// From abf223f8642ca4ad12df77a86ffe80de54905934 Mon Sep 17 00:00:00 2001 From: Kenneth Yang Date: Sun, 10 Mar 2024 12:09:15 -0700 Subject: [PATCH 2/2] Ignore Ephys Link externally closing for now --- .../Scripts/Pinpoint/UI/EphysLinkSettings/EphysLinkSettings.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Assets/Scripts/Pinpoint/UI/EphysLinkSettings/EphysLinkSettings.cs b/Assets/Scripts/Pinpoint/UI/EphysLinkSettings/EphysLinkSettings.cs index a883ad92..ad773098 100644 --- a/Assets/Scripts/Pinpoint/UI/EphysLinkSettings/EphysLinkSettings.cs +++ b/Assets/Scripts/Pinpoint/UI/EphysLinkSettings/EphysLinkSettings.cs @@ -194,7 +194,6 @@ public void OnLaunchEphysLinkPressed() } }; _ephysLinkProcess.Start(); - _ephysLinkProcess.Exited += (_, _) => HandleDisconnectingFromServer(); // Configure UI (disable type dropdown and launch button, enable [dis]connect button). _manipulatorTypeDropdown.interactable = false;