public void OnSensorChanged(SensorEvent e) { try { if (e != null && e.Sensor.Type == SensorType.Accelerometer && accelerometer != null) { var values = e.Values; try { AccelerometerReading reading = new AccelerometerReading(); accelerometer.IsDataValid = (values != null && values.Count == 3); if (accelerometer.IsDataValid) { reading.Acceleration = new Vector3(values[0], values[1], values[2]); reading.Timestamp = DateTime.Now; } accelerometer.FireOnCurrentValueChanged(this, new SensorReadingEventArgs<AccelerometerReading>(reading)); } finally { IDisposable d = values as IDisposable; if (d != null) d.Dispose(); } } } catch (NullReferenceException) { //Occassionally an NullReferenceException is thrown when accessing e.Values?? // mono : Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object // mono : at Android.Runtime.JNIEnv.GetObjectField (IntPtr jobject, IntPtr jfieldID) [0x00000] in <filename unknown>:0 // mono : at Android.Hardware.SensorEvent.get_Values () [0x00000] in <filename unknown>:0 } }
private void UpdateUI(AccelerometerReading accreading) { Vector3 acc = accreading.Acceleration; X.Text = acc.X.ToString("0.00"); Y.Text = acc.Y.ToString("0.00"); Z.Text = acc.Z.ToString("0.00"); //send w,a,s or d according to accelerometer readings to server if (acc.Z < -0.55) { websoc.Send("w"); } else if (acc.Z > 0.25) { websoc.Send("s"); } else if (acc.Y > 0.30) { websoc.Send("a"); } else if (acc.Y < -0.30) { websoc.Send("d"); } else websoc.Send("p"); }
public void OnSensorChanged(SensorEvent e) { try { if (e != null && e.Sensor.Type == SensorType.Accelerometer && accelerometer != null) { var values = e.Values; try { var reading = default(AccelerometerReading); accelerometer.IsDataValid = (values != null && values.Count == 3); if (accelerometer.IsDataValid) { const float gravity = SensorManager.GravityEarth; reading = new AccelerometerReading( acceleration: new Vector3(values[0], values[1], values[2]) / gravity, timestamp: DateTime.UtcNow); } accelerometer.CurrentValue = reading; } finally { (values as IDisposable)?.Dispose(); } } } catch (NullReferenceException) { //Occassionally an NullReferenceException is thrown when accessing e.Values?? // mono : Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object // mono : at Android.Runtime.JNIEnv.GetObjectField (IntPtr jobject, IntPtr jfieldID) [0x00000] in <filename unknown>:0 // mono : at Android.Hardware.SensorEvent.get_Values () [0x00000] in <filename unknown>:0 } }
private static Reading ToReading(AccelerometerReading sensorReading) { var reading = new Reading { X = sensorReading.Acceleration.X, Y = sensorReading.Acceleration.Y, Z = sensorReading.Acceleration.Z, }; return reading; }
void updateMyScreen(AccelerometerReading e) { Microsoft.Xna.Framework.Vector3 v = e.Acceleration; darkImageRotation = (darkImageRotation * 0.7) + v.X * 0.3; leftImageRotation = (leftImageRotation * 0.7) + (v.Y - darkImageRotation) * 0.3; rightImageRotation = (rightImageRotation * 0.7) + (v.Z - leftImageRotation) * 0.3; DarkImageProjection.RotationZ = darkImageRotation * rad2degree; RightImageProjection.RotationZ = rightImageRotation * rad2degree; LeftImageProjection.RotationZ = leftImageRotation * rad2degree; }
private void actualizadatos(AccelerometerReading accelerometerReading) { Vector3 aceleracion = accelerometerReading.Acceleration; if (aceleracion.Y >= -0.5) { completa = false; } if(aceleracion.Y <=-0.5 && completa == false) { lagartijas++; Numero.Text = lagartijas.ToString(); completa = true; } }
public void UpdateUI(AccelerometerReading accelerometerReading) { Vector3 accelerator = accelerometerReading.Acceleration; points = points + (accelerator.Z+accelerator.X) + 1; readings.Text = "Speed: " + points + "\nTimer: " + i++.ToString(); Brush brushRed = new SolidColorBrush(Colors.Red); Brush brushAmber = new SolidColorBrush(Colors.Yellow); Brush brushGreen = new SolidColorBrush(Colors.Green); Brush brushGray = new SolidColorBrush(Colors.Gray); //Start Red if (i == 1){ amberLight.Fill = brushGray; redLight.Fill = brushRed; greenLight.Fill = brushGray;} //In 2 seconds Go Green if (i == 2){ amberLight.Fill = brushGray; redLight.Fill = brushGray; greenLight.Fill = brushGreen;} //In 4 seconds Go Amber if (i == 3){ amberLight.Fill = brushAmber; redLight.Fill = brushGray; greenLight.Fill = brushGray;} //In 6 seconds Go Red again if(i==4){ redLight.Fill = brushRed; greenLight.Fill = brushGray; amberLight.Fill = brushGray;} //Wait 1 second and give the score if (i == 6){ accelerometer.Stop(); if (Math.Round(points) > 0) { MessageBox.Show("You made " + Math.Round(points) + " points!"); NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); //points = Math.Round(points); App ppoints = Application.Current as App; ppoints.PPoints = Math.Round(points); } else{ MessageBox.Show("Oh No, you didn't cross the street correctly. Player disclassified, (" + points + " points!)"); NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); } } }
private void UpdateUI(AccelerometerReading accelerometerReading) { statusTextBlock.Text = "getting data"; Vector3 acceleration = accelerometerReading.Acceleration; //show numeric value xTextBlock.Text = "X: " + acceleration.X.ToString("0.00"); yTextBlock.Text = "Y: " + acceleration.Y.ToString("0.00"); zTextBlock.Text = "Z: " + acceleration.Z.ToString("0.00"); //show value graphically xLine.X2 = xLine.X1 + acceleration.X * 200; yLine.Y2 = yLine.Y1 + acceleration.Y * 200; zLine.X2 = zLine.X1 + acceleration.Z * 100; zLine.X2 = zLine.Y1 + acceleration.Z * 100; }
private void DoUpdate(AccelerometerReading accelerometerReading) { currentReading.X = accelerometerReading.Acceleration.X; currentReading.Y = accelerometerReading.Acceleration.Y; currentReading.Z = accelerometerReading.Acceleration.Z; float xScale = NormalizeScaleFactor(currentReading.X); float yScale = NormalizeScaleFactor(currentReading.Y) * -1.0f; double xCoord = (double)((ContentPanel.Width / 2.0) * xScale + (offset.X - 20.0f)); double yCoord = (double)((ContentPanel.Height / 2.0) * yScale + (offset.Y - 20.0f)); Square.SetValue(Canvas.TopProperty, yCoord); Square.SetValue(Canvas.LeftProperty, xCoord); text_sensor.Text = String.Format("X: {0}, Y: {1}", Math.Round(currentReading.X, 2).ToString(), Math.Round(currentReading.Y, 2).ToString()); }
private void undo(AccelerometerReading acceleromterReading) { //MessageBox.Show("I shook the phone?"); Vector3 acceleration = acceleromterReading.Acceleration; if ((acceleration.X > thresh || acceleration.Y > thresh || acceleration.Z > thresh) && !undone) { BitmapImage bi = new BitmapImage(); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream fileStream = store.OpenFile("undoJPEG", System.IO.FileMode.Open, System.IO.FileAccess.Read)) { bi.SetSource(fileStream); image2.Source = bi; store.CopyFile("undoJPEG", "tempJPEG2", true); fileStream.Close(); } } undone = true; //MessageBox.Show("I shook the phone?"); } }
private void UpdateUI(AccelerometerReading reading) { AccXLabel.Text = reading.Acceleration.X.ToString(); AccYLabel.Text = reading.Acceleration.Y.ToString(); AccZLabel.Text = reading.Acceleration.Z.ToString(); }
void ProcessReading(AccelerometerReading accelerometerReading) { ThreeDimensionalVector lowPassFilteredAcceleration; ThreeDimensionalVector optimalFilteredAcceleration; ThreeDimensionalVector averagedAcceleration; Vector3 acceleration = accelerometerReading.Acceleration; ThreeDimensionalVector rawAcceleration = new ThreeDimensionalVector( acceleration.X, acceleration.Y, acceleration.Z); lock (sampleBuffer) { if (!initialized) { /* Initialize buffer with first value. */ sampleSumVector = rawAcceleration * SamplesCount; averageAcceleration = rawAcceleration; for (int i = 0; i < SamplesCount; i++) { sampleBuffer[i] = averageAcceleration; } previousLowPassOutput = averageAcceleration; previousOptimalFilterOutput = averageAcceleration; initialized = true; } lowPassFilteredAcceleration = new ThreeDimensionalVector( ApplyLowPassFilter(rawAcceleration.X, previousLowPassOutput.X), ApplyLowPassFilter(rawAcceleration.Y, previousLowPassOutput.Y), ApplyLowPassFilter(rawAcceleration.Z, previousLowPassOutput.Z)); previousLowPassOutput = lowPassFilteredAcceleration; optimalFilteredAcceleration = new ThreeDimensionalVector( ApplyLowPassFilterWithNoiseThreshold(rawAcceleration.X, previousOptimalFilterOutput.X), ApplyLowPassFilterWithNoiseThreshold(rawAcceleration.Y, previousOptimalFilterOutput.Y), ApplyLowPassFilterWithNoiseThreshold(rawAcceleration.Z, previousOptimalFilterOutput.Z)); previousOptimalFilterOutput = optimalFilteredAcceleration; /* Increment circular buffer insertion index. */ if (++sampleIndex >= SamplesCount) { /* If at max length then wrap samples back * to the beginning position in the list. */ sampleIndex = 0; } /* Add new and remove old at sampleIndex. */ ThreeDimensionalVector vector = optimalFilteredAcceleration; sampleSumVector += vector; sampleSumVector -= sampleBuffer[sampleIndex]; sampleBuffer[sampleIndex] = vector; averagedAcceleration = sampleSumVector / SamplesCount; averageAcceleration = averagedAcceleration; /* Stablity check * If current low-pass filtered sample is deviating * for more than 1/100 g from average * (max of 0.5 deg inclination noise if device steady), * then reset the stability counter. * The calibration will be prevented until the counter is reaching * the sample count size. * Calibration enabled only if entire sampling buffer is "stable" */ ThreeDimensionalVector deltaAcceleration = averagedAcceleration - optimalFilteredAcceleration; if ((Math.Abs(deltaAcceleration.X) > maximumStabilityDeltaOffset) || (Math.Abs(deltaAcceleration.Y) > maximumStabilityDeltaOffset) || (Math.Abs(deltaAcceleration.Z) > maximumStabilityDeltaOffset)) { /* Unstable */ deviceStableCount = 0; } else { if (deviceStableCount < SamplesCount) { ++deviceStableCount; } } /* Adjust with calibration value. */ rawAcceleration += CalibrationOffset; lowPassFilteredAcceleration += CalibrationOffset; optimalFilteredAcceleration += CalibrationOffset; averagedAcceleration += CalibrationOffset; } Reading = new EnhancedAccelerometerReading(accelerometerReading.Timestamp, rawAcceleration, optimalFilteredAcceleration, lowPassFilteredAcceleration, averagedAcceleration); DetectShake(acceleration); previousAcceleration = acceleration; }
public AccelerometerSensorReading(AccelerometerReading accelerometerReading) { Acceleration = accelerometerReading.Acceleration; Timestamp = accelerometerReading.Timestamp; }
private void UpdateUI(AccelerometerReading accReading) { Vector3 acceleration = accReading.Acceleration; // AccTxt.Text = "[x:" + acceleration.X.ToString() + ",y:" + acceleration.Y.ToString() + ",z:" + acceleration.Z.ToString() + "]"; }
/// <summary> /// Initializes a new instance of the <see cref="AccelerometerValue"/> class. /// </summary> /// <param name="reading">The accelerometer reading.</param> public AccelerometerValue(AccelerometerReading reading) : this(reading.Timestamp, reading.Acceleration.X, reading.Acceleration.Y, reading.Acceleration.Z) { }
private void updateUi(AccelerometerReading sensorReading) { statusTextBlock.Text = "getting data"; Vector3 acceleration = sensorReading.Acceleration; // Show the numeric values. xTextBlock.Text = "X: " + acceleration.X.ToString("0.00"); yTextBlock.Text = "Y: " + acceleration.Y.ToString("0.00"); zTextBlock.Text = "Z: " + acceleration.Z.ToString("0.00"); var buffer = new List<byte> { (byte) ServerCommands.AccelerometerData }; buffer.AddRange(BitConverter.GetBytes(acceleration.X)); buffer.AddRange(BitConverter.GetBytes(acceleration.Y)); buffer.AddRange(BitConverter.GetBytes(acceleration.Z)); _socketClient.Send(buffer.ToArray()); }
//void accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingEventArgs e) //{ // // Call UpdateUI on the UI thread and pass the AccelerometerReading. // //Dispatcher.BeginInvoke(() => UpdateUI(e.SensorReading)); //} private void UpdateUI(AccelerometerReading accelerometerReading) { Vector3 acceleration = accelerometerReading.Acceleration; //if (acceleration.X <= -0.35) //{ // if (pivot.SelectedIndex != 4) // { // pivot.SelectedIndex += 1; // } // else // pivot.SelectedIndex = 0; //} //if (acceleration.X >= 0.35) //{ // if (pivot.SelectedIndex != 0) // pivot.SelectedIndex -= 1; // else // pivot.SelectedIndex = 5; //} barraX.Value = acceleration.X*100; barraY.Value = acceleration.Y*100; barraZ.Value = acceleration.Z*100; }
private async void WriteData(AccelerometerReading reading) { if (storageFile == null) { return; } String x = reading.Acceleration.X.ToString(); String y = reading.Acceleration.Y.ToString(); String z = reading.Acceleration.Z.ToString(); String line = x + ";" + y + ";" + z + "\n"; try { using (IRandomAccessStream stream = await storageFile.OpenAsync(FileAccessMode.ReadWrite)) { IOutputStream outStream = stream.GetOutputStreamAt(seekLocation); using (DataWriter writer = new DataWriter(outStream)) { writer.WriteString(line); await writer.StoreAsync(); seekLocation += (ulong)System.Text.Encoding.UTF8.GetByteCount(line); } } } catch (Exception) { } }
private void UpdateAccelerometerUI(AccelerometerReading accelerometerReading) { // have to use Vector3 class object Microsoft.Xna.Framework.Vector3 acceleration = accelerometerReading.Acceleration; StringBuilder sb = new StringBuilder(); sb.Append("Accelerometer sensor, raw data X: " + acceleration.X.ToString("0.00")); sb.Append("\nAccelerometer sensor, raw data Y: " + acceleration.Y.ToString("0.00")); sb.Append("\nAccelerometer sensor, raw data Z: " + acceleration.Y.ToString("0.00")); System.Diagnostics.Debug.WriteLine(sb.ToString()); DataValue.Text = sb.ToString(); }
private void UpdateUI(AccelerometerReading accelerometerReading) { Vector3 aceleracion = accelerometerReading.Acceleration; //Comparo los milisegundos si es igual a 50 es igual a 1 segundo if (miliseg == 50) { miliseg = 0; segundos++; txtBlockTime.Text = segundos + "." + miliseg + " s"; } else { //Agrego 1 a los milisegundos txtBlockTime.Text = segundos + "." + miliseg + " s"; miliseg++; } //obtengo los valores de aceleromero txtBlockY.Text = "Y: " + aceleracion.Y.ToString("0.00"); txtBlockZ.Text = "Z: " + aceleracion.Z.ToString("0.00"); //Reviso para que si Y == 1 Agrege una abdominal :D if (aceleracion.Y >= -0.38) { completa = false; } if (aceleracion.Y <= -0.38 && completa == false) { AgregaAbdominal(1); completa = true; } }