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 MarkTop(SignalSample sample, Canvas camvas1, Brush b, string text) { Line ln = new Line(); ln.X1 = (sample.TimeStamp - DrawStart).TotalSeconds * variables.TimeZoom - 2; ln.X2 = (sample.TimeStamp - DrawStart).TotalSeconds * variables.TimeZoom + 2; ln.Y1 = ln.Y2 = (sample.Sample.X * variables.SignalZoom - 110 * variables.SignalZoom + 120); ln.Stroke = b; ln.StrokeThickness = 1; TextBlock tb = new TextBlock(); tb.Text = text; Canvas.SetLeft(tb, ln.X1 + 10); Canvas.SetTop(tb, ln.Y1 + 10); canvas1.Children.Add(tb); canvas1.Children.Add(ln); }
SignalSample AdjustSample(SignalSample sample) { SignalSample adjustedSample = sample; adjustedSample.Sample = new Point3() { X = Convert.ToInt32(adjustedSample.Sample.X * variables.ScaleAdjustment + variables.SignalAdjustment), Y = adjustedSample.Sample.Y, Z = adjustedSample.Sample.Z }; adjustedSample.TimeStamp += dateDifference; return adjustedSample; }
void DrawGraph(SignalSample newRecord, SignalSample oldRecord, Canvas canvas, Brush brush, double thickness) { Line ln = new Line(); ln.X1 = (newRecord.TimeStamp - DrawStart).TotalSeconds * variables.TimeZoom; ln.Y1 = newRecord.Sample.X * variables.SignalZoom - 110 * variables.SignalZoom + 120; //ln.X2 = (newRecord.TimeStamp - DrawStart).TotalSeconds * variables.TimeZoom+1; //ln.Y2 = newRecord.Sample.X * variables.SignalZoom - 110 * variables.SignalZoom + 120+1; ln.X2 = (oldRecord.TimeStamp - DrawStart).TotalSeconds * variables.TimeZoom; ln.Y2 = oldRecord.Sample.X * variables.SignalZoom - 110 * variables.SignalZoom + 120; ln.Stroke = brush; ln.StrokeThickness = 1; canvas.Children.Add(ln); }
void AddMarker(SignalSample record, Canvas canvas, string label) { Line ln = new Line(); TextBlock text = new TextBlock(); ln.X1 = ln.X2 = (record.TimeStamp - DrawStart).TotalSeconds * variables.TimeZoom; Canvas.SetLeft(text, ln.X1 - 40); Canvas.SetTop(text, 20); ln.Y1 = 0; ln.Y2 = 100; ln.Stroke = Brushes.Firebrick; ln.StrokeThickness = 1; text.Text = label; canvas.Children.Add(ln); canvas.Children.Add(text); }