예제 #1
0
 private void thinkGear_ThinkGearChanged(object sender, ThinkGearChangedEventArgs e)
 {
     int signal = 100 - (int)e.ThinkGearState.PoorSignal;
     if (signal != lastSignal)
     {
         SignalChangedEventArgs signalArgs = new SignalChangedEventArgs();
         signalArgs.NewSignal = signal;
         signalArgs.OldSignal = lastSignal;
         lastSignal = signal;
         OnSignalChanged(signalArgs);
     }
     ThinkGearStateEventArgs args = new ThinkGearStateEventArgs();
     args.Data = new EEGState(e.ThinkGearState);
     args.Timestamp = sw.ElapsedMilliseconds;
     OnDataReceived(args);
     if (IsLogging && logWriter != null)
     {
         string line = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12}",
             sw.ElapsedMilliseconds, e.ThinkGearState.Alpha1, e.ThinkGearState.Alpha2, e.ThinkGearState.Beta1, e.ThinkGearState.Beta2,
             e.ThinkGearState.Delta, e.ThinkGearState.Gamma1, e.ThinkGearState.Gamma2, e.ThinkGearState.Theta, e.ThinkGearState.Meditation,
             e.ThinkGearState.Attention, e.ThinkGearState.Raw, 100 - e.ThinkGearState.PoorSignal);
         logWriter.WriteLine(line);
     }
     Thread.Sleep(sleepTime);
 }
예제 #2
0
 private void ReplayLogAsync(object obj)
 {
     SortedDictionary<int, EEGState> log = ((Tuple<SortedDictionary<int, EEGState>,int>)obj).Item1;
     int interval = ((Tuple<SortedDictionary<int, EEGState>, int>)obj).Item2;
     foreach (KeyValuePair<int, EEGState> item in log)
     {
         if (!IsReplaying)
             break;
         ThinkGearStateEventArgs args = new ThinkGearStateEventArgs();
         args.Data = item.Value;
         args.Timestamp = item.Key;
         OnDataReceived(args);
         if (!string.IsNullOrWhiteSpace(args.Data.Comment))
             OnLogCommentFound(new CommentEventArgs(item.Key, args.Data.Comment));
         if ((int)item.Value.Signal != lastSignal)
         {
             SignalChangedEventArgs signalArgs = new SignalChangedEventArgs();
             signalArgs.NewSignal = (int)item.Value.Signal;
             signalArgs.OldSignal = lastSignal;
             lastSignal = (int)item.Value.Signal;
             OnSignalChanged(signalArgs);
         }
         lastSignal = (int)item.Value.Signal;
         Thread.Sleep(interval);
     }
     OnLogReplayFinished(null);
 }
예제 #3
0
 // --------------------------------------------------------------------------------------------------------------------
 void core_DataReceived(object sender, ThinkGearStateEventArgs e)
 {
     try
     {
         Invoke(updateUI, e);
     }
     catch (Exception)
     {
         // can happen when object is disposed
     }
 }
예제 #4
0
 protected virtual void OnDataReceived(ThinkGearStateEventArgs e)
 {
     EventHandler<ThinkGearStateEventArgs> handler = DataReceived;
     if (handler != null)
     {
         handler(this, e);
     }
 }
예제 #5
0
        // --------------------------------------------------------------------------------------------------------------------
        private void _updateUi(ThinkGearStateEventArgs e)
        {
            txtRaw.Text = e.Data.Raw.ToString();
            txtSignal.Text = e.Data.Signal.ToString();

            labelElapsedTime.Text = watch.Elapsed.Minutes.ToString("00") + ":" + watch.Elapsed.Seconds.ToString("00");

            // update channel values. this also updates all measures like avg5, avg15, avg60
            float timeInSec = (float)(watch.Elapsed.TotalSeconds + watch.Elapsed.Milliseconds * 1.0f / 1000);

            channelsRaw.alpha1.addSample(timeInSec, e.Data.Alpha1);
            channelsRaw.alpha2.addSample(timeInSec, e.Data.Alpha2);
            channelsRaw.beta1.addSample(timeInSec, e.Data.Beta1);
            channelsRaw.beta2.addSample(timeInSec, e.Data.Beta2);
            channelsRaw.gamma1.addSample(timeInSec, e.Data.Gamma1);
            channelsRaw.gamma2.addSample(timeInSec, e.Data.Gamma2);
            channelsRaw.delta.addSample(timeInSec, e.Data.Delta);
            channelsRaw.theta.addSample(timeInSec, e.Data.Theta);
            channelsRaw.meditation.addSample(timeInSec, e.Data.Meditation);
            channelsRaw.attention.addSample(timeInSec, e.Data.Attention);

            List<EEGChannelBuffer> lst = channelsRaw.ToList();
            foreach (EEGChannelBuffer ch in lst)
            {
                dataRows[ch.Name].Cells[1].Value = ch.CurrentValue.ToString("0");
                dataRows[ch.Name].Cells[2].Value = ch.Average15.ToString("0.00");
            }

            // update normalized channel values.
            channelsNormalized.alpha1.addSample(timeInSec,  channelsRaw.alpha1.CurrentValueNormalized);
            channelsNormalized.alpha2.addSample(timeInSec,  channelsRaw.alpha2.CurrentValueNormalized);
            channelsNormalized.beta1.addSample(timeInSec,   channelsRaw.beta1.CurrentValueNormalized);
            channelsNormalized.beta2.addSample(timeInSec,   channelsRaw.beta2.CurrentValueNormalized);
            channelsNormalized.gamma1.addSample(timeInSec,  channelsRaw.gamma1.CurrentValueNormalized);
            channelsNormalized.gamma2.addSample(timeInSec,  channelsRaw.gamma2.CurrentValueNormalized);
            channelsNormalized.delta.addSample(timeInSec,   channelsRaw.delta.CurrentValueNormalized);
            channelsNormalized.theta.addSample(timeInSec,   channelsRaw.theta.CurrentValueNormalized);
            channelsNormalized.meditation.addSample(timeInSec, channelsRaw.meditation.CurrentValueNormalized);
            channelsNormalized.attention.addSample(timeInSec, channelsRaw.attention.CurrentValueNormalized);

            lst = channelsNormalized.ToList();
            foreach (EEGChannelBuffer ch in lst)
            {
                dataRows[ch.Name].Cells[3].Value = ch.CurrentValue.ToString("0.00");
                dataRows[ch.Name].Cells[4].Value = ch.Average15.ToString("0.00");
            }

            _refreshUIAndSendOsc();
        }