void WiimoteUpdated(object sender, WiimoteUpdatedEventArgs e) { if (e.SignalSample.Source == currentWiimote) { SignalSample adjustedSample = AdjustSample(e.SignalSample); DrawGraph(adjustedSample, oldSample1, canvas1, Brushes.Blue, 1); oldSample1 = adjustedSample; sampleList1.Add(adjustedSample); if (sampleList1.Count > 3) { if (sampleList1.Count > 10) { int n = sampleList1.Count - 1; int check = 3; bool topChecks = true; bool bottomChecks = true; for (int i = 0; i <= check; i++) { if (sampleList1[n - check + i].Sample.X < sampleList1[n - check].Sample.X) { topChecks = false; } if (sampleList1[n - check - i].Sample.X < sampleList1[n - check].Sample.X) { topChecks = false; } if (sampleList1[n - check + i].Sample.X > sampleList1[n - check].Sample.X) { bottomChecks = false; } if (sampleList1[n - check - i].Sample.X > sampleList1[n - check].Sample.X) { bottomChecks = false; } } if (topChecks) { if (sampleList1[n - check].Sample.X - 125 < -25) { if ((sampleList1[n - check].TimeStamp - lastTop.TimeStamp).TotalMilliseconds > 300) { MarkTop(sampleList1[n - check], canvas1, Brushes.Brown, countTops.ToString()); variables.Code += "1"; countTops++; lastTop = sampleList1[n - check]; } } } if (bottomChecks) { if (sampleList1[n - check].Sample.X - 125 > 25) { if ((sampleList1[n - check].TimeStamp - lastBottom.TimeStamp).TotalMilliseconds > 300) { MarkTop(sampleList1[n - check], canvas1, Brushes.BlueViolet, countTops.ToString()); variables.Code += "0"; countTops++; lastBottom = sampleList1[n - check]; } } } } if (Math.Abs(e.SignalSample.Sample.X - 124) > 25 && !sendTimer.IsEnabled) { sendTimer.IsEnabled = true; } } if (sampleList1.Count > 1000) { canvas1.Children.Clear(); DrawStart = DateTime.Now; sampleList1.Clear(); receivedSampleList.Clear(); } } }
void OnWiimoteUpdated(object sender, WiimoteUpdatedEventArgs e) { Dispatcher.BeginInvoke(DispatcherPriority.Normal, new UpdateWiimoteStateDelegate(WiimoteUpdated), sender, e); }