// Function invoked during the onClick event of "StartBySrcButton". public void StartBySrcButtonFunction() { try { // Get Device Configuration input values. SamplingRate = Int32.Parse(SamplingRateInput.text); int resolution = Int32.Parse(ResolutionDropDownOptions[ResolutionDropdown.value]); // Update graphical window size variable (the plotting zone should contain 10 seconds of data). GraphWindSize = SamplingRate * 10; WindowInMemorySize = Convert.ToInt32(1.1 * GraphWindSize); // Number of Active Channels. int nbrChannels = 0; Toggle[] toggleArray = new Toggle[] { CH1Toggle, CH2Toggle, CH3Toggle, CH4Toggle, CH5Toggle, CH6Toggle, CH7Toggle, CH8Toggle }; MultiThreadList.Add(new List <int>(Enumerable.Repeat(0, GraphWindSize).ToList())); List <PluxDeviceManager.PluxSource> pluxSources = new List <PluxDeviceManager.PluxSource>(); for (int i = 0; i < toggleArray.Length; i++) { if (toggleArray[i].isOn == true || PluxDevManager.GetProductIdUnity() == 542) { // Preparation of a string that will be communicated to our .dll // This string will be formed by "1" or "0" characters, identifying sequentially which channels are active or not. ActiveChannels.Add(i + 1); // Definition of the first active channel. if (VisualizationChannel == -1) { VisualizationChannel = i + 1; // Update the label with the Current Channel Number. CurrentChannel.text = "CH" + VisualizationChannel; } nbrChannels++; // Add a new Plux::Source. if (PluxDevManager.GetProductIdUnity() != 542) // Clause applicable only for non fNIRS Explorer systems. { pluxSources.Add(new PluxDeviceManager.PluxSource(i + 1, 1, resolution, 0x01)); } else if (PluxDevManager.GetProductIdUnity() == 542 && i == toggleArray.Length - 1) // Configuring sources if we are dealing with a fNIRS Explorer system. { // >>> fNIRS Explorer [Full set of SpO2 and Accelerometer channels] // [SpO2 Port (4 channels - 0x0F > 0000 1111)] pluxSources.Add(new PluxDeviceManager.PluxSource(9, 1, resolution, 0x0F)); // [ACC Port (3 channels - 0x07 > 0000 0111)] pluxSources.Add(new PluxDeviceManager.PluxSource(11, 1, resolution, 0x07)); } } // Dictionary that stores all the data received from .dll API. MultiThreadList.Add(new List <int>(Enumerable.Repeat(0, GraphWindSize).ToList())); } // Check if at least one channel is active. if (ActiveChannels.Count != 0) { // Start of Acquisition. PluxDevManager.StartAcquisitionBySourcesUnity(SamplingRate, pluxSources.ToArray()); // Enable StopButton. StopButton.interactable = true; // Disable ConnectButton. ConnectButton.interactable = false; // Disable Start Button. StartBySrcButton.interactable = false; StartButton.interactable = false; // Hide PlotIcon and show AcquiringIcon. PlotIcon.SetActive(false); TransparencyLevel.SetActive(false); //AcquiringIcon.SetActive(true); // Hide panel with the "Change Channel" button. SelectedChannelPanel.SetActive(true); if (ActiveChannels.Count == 1) { ChangeChannel.interactable = false; } else { ChangeChannel.interactable = true; } // Disable About Button to avoid entering a new scene during the acquisition. AboutButton.interactable = false; } else { // Show Info Message. ChannelSelectioInfoPanel.SetActive(true); // Hide object after 5 seconds. StartCoroutine(RemoveAfterSeconds(5, ChannelSelectioInfoPanel)); } } catch (Exception exc) { // Exception info. Debug.Log("Exception: " + exc.Message + "\n" + exc.StackTrace); // Show info message. ConnectInfoPanel.SetActive(true); // Hide object after 5 seconds. StartCoroutine(RemoveAfterSeconds(5, ConnectInfoPanel)); // Reboot interface. ConnectButtonFunction(true); } }
// Function invoked during the onClick event of "StartBySrcButton". public void StartBySrcButtonFunction() { try { // Update the value of the flag that identifies when the started acquisition was done by defining sources (true) or not (false). startBySrc = true; // Get Device Configuration input values. SamplingRate = Int32.Parse(SamplingRateInput.text); int resolution = Int32.Parse(ResolutionDropDownOptions[ResolutionDropdown.value]); // Update graphical window size variable (the plotting zone should contain 10 seconds of data). GraphWindSize = SamplingRate * 10; WindowInMemorySize = Convert.ToInt32(1.1 * GraphWindSize); // Number of Active Channels. int nbrChannels = 0; Toggle[] toggleArray = new Toggle[] { CH1Toggle, CH2Toggle, CH3Toggle, CH4Toggle, CH5Toggle, CH6Toggle, CH7Toggle, CH8Toggle }; List <PluxDeviceManager.PluxSource> pluxSources = new List <PluxDeviceManager.PluxSource>(); MultiThreadList.Add(new List <int>(Enumerable.Repeat(0, GraphWindSize).ToList())); for (int i = 0; i < toggleArray.Length; i++) { if (toggleArray[i].isOn == true || PluxDevManager.GetProductIdUnity() == 542) { // Adding an extra channel if dealing with the biosignalsplux Hybrid-8 scenario. int chnNbr = i + 1; if (PluxDevManager.GetProductIdUnity() == 517) // Divergence of the port into two separate channels. { chnNbr = (2 * i) + 1; ActiveChannels.Add(chnNbr); ActiveChannels.Add(chnNbr + 1); } else { ActiveChannels.Add(chnNbr); } // Definition of the first active channel. if (VisualizationChannel == -1) { VisualizationChannel = chnNbr; // Update the label with the Current Channel Number. if (PluxDevManager.GetProductIdUnity() == 517) // biosignalsplux Hybrid-8 scenario where all channels are considered digital ones. { // Update the label with the Current Channel Number. CurrentChannel.text = "CH" + ((int)Math.Ceiling(chnNbr / 2.0)) + "A"; } else { CurrentChannel.text = "CH" + VisualizationChannel; } } nbrChannels++; // Add a new Plux::Source. if (PluxDevManager.GetProductIdUnity() != 542) // Clause applicable only for non fNIRS Explorer systems. { // Set LED intensities if the current device is a biosignalsplux Hybrid-8. if (PluxDevManager.GetProductIdUnity() == 517) { // Add new source. pluxSources.Add(new PluxDeviceManager.PluxSource(i + 1, 1, resolution, 0x03)); // Led Intensities. int[] ledIntensities = new int[2] { (int)((redLedIntensities[i] / 100f) * 255), (int)((infraredLedIntensities[i] / 100f) * 255) }; PluxDevManager.SetParameter(i + 1, 0x03, ledIntensities); } else { // Add new source. pluxSources.Add(new PluxDeviceManager.PluxSource(i + 1, 1, resolution, 0x01)); } } else if (PluxDevManager.GetProductIdUnity() == 542 && i == toggleArray.Length - 1) // Configuring sources if we are dealing with a fNIRS Explorer system. { // >>> fNIRS Explorer [Full set of SpO2 and Accelerometer channels] // [SpO2 Port (4 channels - 0x0F > 0000 1111)] pluxSources.Add(new PluxDeviceManager.PluxSource(9, 1, resolution, 0x0F)); // [ACC Port (3 channels - 0x07 > 0000 0111)] pluxSources.Add(new PluxDeviceManager.PluxSource(11, 1, resolution, 0x07)); } } // Dictionary that stores all the data received from .dll API. MultiThreadList.Add(new List <int>(Enumerable.Repeat(0, GraphWindSize).ToList())); // Add an extra channel if we are dealing with a Hybrid-8 system. if (PluxDevManager.GetProductIdUnity() == 517) { MultiThreadList.Add(new List <int>(Enumerable.Repeat(0, GraphWindSize).ToList())); } } // Check if at least one channel is active. if (ActiveChannels.Count != 0) { // Start of Acquisition. PluxDevManager.StartAcquisitionBySourcesUnity(SamplingRate, pluxSources.ToArray()); // Enable StopButton. StopButton.interactable = true; // Disable ConnectButton. ConnectButton.interactable = false; // Disable Start Button. StartBySrcButton.interactable = false; StartButton.interactable = false; // Hide PlotIcon and show AcquiringIcon. PlotIcon.SetActive(false); TransparencyLevel.SetActive(false); //AcquiringIcon.SetActive(true); // Hide panel with the "Change Channel" button. SelectedChannelPanel.SetActive(true); if (ActiveChannels.Count == 1) { ChangeChannel.interactable = false; } else { ChangeChannel.interactable = true; } // Disable About Button to avoid entering a new scene during the acquisition. AboutButton.interactable = false; } else { // Show Info Message. ChannelSelectioInfoPanel.SetActive(true); // Hide object after 5 seconds. StartCoroutine(RemoveAfterSeconds(5, ChannelSelectioInfoPanel)); } } catch (Exception exc) { // Exception info. Debug.Log("Exception: " + exc.Message + "\n" + exc.StackTrace); // Show info message. ConnectInfoPanel.SetActive(true); // Hide object after 5 seconds. StartCoroutine(RemoveAfterSeconds(5, ConnectInfoPanel)); // Reboot interface. ConnectButtonFunction(true); } }