public void PullQuality() { if (sendTCP.monitoring) { liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "Quality"); liblsl.StreamInlet inlet2 = new liblsl.StreamInlet(results[0]); float[] sample = new float[num_channels]; inlet2.pull_sample(sample); Debug.Log ("Quality: "); for (int i = 0; i < sample.Length; ++i) Debug.Log("# Ch" + (i+1) + ": " + sample[i]); if (sample.Length > 0) { if (sample[0] <= 0.5F) b_quality.GetComponent<Image>().color = Color.red; else if (sample[0] <= 0.8F) b_quality.GetComponent<Image>().color = new Color(1.0F, 0.5F, 0.0F); else b_quality.GetComponent<Image>().color = Color.green; //button_quality.GetComponent<UIButton>().isEnabled = true; } } else { Debug.Log("Need to start monitoring EEG"); //button_quality.GetComponent<UIWidget>().color = Color.gray; } }
static void Main(string[] args) { // wait until an EEG stream shows up liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "Markers"); // open an inlet and print meta-data liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0]); System.Console.Write(inlet.info().as_xml()); // read samples string[] sample = new string[1]; while (true) { inlet.pull_sample(sample); System.Console.WriteLine(sample[0]); } }
static void Main(string[] args) { // wait until an EEG stream shows up liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "EEG"); // open an inlet and print some interesting info about the stream (meta-data, etc.) liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0]); System.Console.Write(inlet.info().as_xml()); // read samples float[] sample = new float[8]; while (true) { inlet.pull_sample(sample); foreach (float f in sample) System.Console.Write("\t{0}",f); System.Console.WriteLine(); } System.Console.ReadKey(); }
void GetData() { while(!finished) { if (inlet != null) { inlet.pull_sample(sample, 0.5f); if (listMax.Count < maxWindowSize) { if (listMax.Count < (realTime - lastTime)) { listMax.Add(float.MinValue); } if (listMin.Count < (realTime - lastTime)) { listMin.Add(float.MaxValue); } } else { if (lastTime < (realTime - 1.0f)) { lastTime = realTime; listMax.RemoveAt(0); listMin.RemoveAt(0); listMax.Add(float.MinValue); listMin.Add(float.MaxValue); } } int currentItem = listMax.Count; Debug.Log(currentItem); if (sample[0] > listMax[currentItem-1]) { listMax[currentItem-1] = sample[0]; } if (sample[0] < listMin[currentItem-1]) { listMin[currentItem-1] = sample[0]; } float min = float.MaxValue; float max = float.MinValue; foreach(float element in listMin) { if (element < min) { min = element; } } foreach(float element in listMax) { if (element > max) { max = element; } } Breathe = (sample[0]-min) / (max-min); //Debug.Log (Breathe); } else { // wait until an EEG stream shows up liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "breath", 1, 0.5f); // open an inlet and print some interesting info about the stream (meta-data, etc.) inlet = new liblsl.StreamInlet(results[0]); Debug.Log(inlet.info().as_xml()); inlet.pull_sample(sample, 0.5f); listMax[0] = sample[0]; listMin[0] = sample[0]; } } }