public void OnSensorChanged(SensorEvent e) { if (SensorValueChanged == null) return; float[] values = new float[3]; values[0] = e.Values[0]; values[1] = e.Values[1]; values[2] = e.Values[2]; switch (e.Sensor.Type) { case SensorType.Gravity: gravity = values; filterLowPass(values, gravity, 0.8f); //Console.WriteLine("Gravity {0}, {1}, {2}", values[0], values[1], values[2]); break; case SensorType.MagneticField: magnetic = values; //Console.WriteLine("Magnetometer" + values[0]); if (gravity != null && magnetic != null) { float[] R1 = new float[9]; float[] R = new float[9]; float[] I = new float[9]; if (SensorManager.GetRotationMatrix(R1, I, gravity, magnetic)) { SensorManager.RemapCoordinateSystem(R1, Axis.X, Axis.Z, R); float[] orientation = new float[3]; SensorManager.GetOrientation(R, orientation); SensorValueChanged(this, orientation, "Orientation"); } } break; } }
/// <summary> /// Raises the sensor changed event. /// </summary> /// <param name="e">E.</param> public void OnSensorChanged(SensorEvent e) { if (SensorValueChanged == null) return; switch (e.Sensor.Type) { case SensorType.Accelerometer: SensorValueChanged(this, new SensorValueChangedEventArgs() { ValueType = MotionSensorValueType.Vector, SensorType = MotionSensorType.Accelerometer, Value = new MotionVector() { X = e.Values[0], Y = e.Values[1], Z = e.Values[2] } }); break; case SensorType.Gyroscope: SensorValueChanged(this, new SensorValueChangedEventArgs() { ValueType=MotionSensorValueType.Vector,SensorType = MotionSensorType.Gyroscope, Value = new MotionVector() { X = e.Values[0], Y = e.Values[1], Z = e.Values[2] } }); break; case SensorType.MagneticField: SensorValueChanged(this, new SensorValueChangedEventArgs() { ValueType=MotionSensorValueType.Vector,SensorType = MotionSensorType.Magnetometer, Value = new MotionVector() { X = e.Values[0], Y = e.Values[1], Z = e.Values[2] } }); break; case SensorType.Orientation: SensorValueChanged(this, new SensorValueChangedEventArgs() { ValueType=MotionSensorValueType.Single,SensorType = MotionSensorType.Compass, Value = new MotionValue(){Value =e.Values[0]} }); break; } }
public void OnSensorChanged(SensorEvent e) { lock (_syncLock) { _sensorTextView.Text = string.Format("x={0:f}, y={1:f}, y={2:f}", e.Values[0], e.Values[1], e.Values[2]); } }
public void OnSensorChanged(SensorEvent e) { if (SensorValueChanged == null) return; DeviceSensorValues sensorValues = new DeviceSensorValues(); sensorValues.Values[0] = e.Values[0]; sensorValues.Values[1] = e.Values[1]; sensorValues.Values[2] = e.Values[2]; //float[] temp = new float[3]; //SensorManager.RemapCoordinateSystem(sensorValues.Values, Axis.X, Axis.Z, temp); //sensorValues.Values = temp; switch (e.Sensor.Type) { case SensorType.Accelerometer: SensorValueChanged(this, new SensorValueChangedEventArgs(sensorValues, DeviceSensorType.Accelerometer)); break; case SensorType.Gravity: SensorValueChanged(this, new SensorValueChangedEventArgs(sensorValues, DeviceSensorType.Gravimeter)); break; case SensorType.Gyroscope: SensorValueChanged(this, new SensorValueChangedEventArgs(sensorValues, DeviceSensorType.Gyroscope)); break; case SensorType.MagneticField: SensorValueChanged(this, new SensorValueChangedEventArgs(sensorValues, DeviceSensorType.Magnetometer)); break; case SensorType.Orientation: SensorValueChanged(this, new SensorValueChangedEventArgs(sensorValues, DeviceSensorType.Orientation)); break; } }
public void OnSensorChanged(SensorEvent e) { //lock (_syncLock) //{ e.Values.CopyTo(Accl, 0); //} }
public void OnSensorChanged(SensorEvent e) { if (SensorValueChanged == null) return; float[] values = new float[3]; values[0] = e.Values[0]; values[1] = e.Values[1]; values[2] = e.Values[2]; switch (e.Sensor.Type) { case SensorType.Gravity: gravity = values; filterLowPass(values, gravity, 0.8f); Console.WriteLine("Accelerometer"+values[0]); break; case SensorType.MagneticField: magnetic = values; Console.WriteLine("Magnetometer" + values[0]); if (gravity != null && magnetic != null) { float[] R = new float[9]; float[] I = new float[9]; if (SensorManager.GetRotationMatrix(R, I, gravity, magnetic)) { float[] orientation = new float[3]; SensorManager.GetOrientation(R, orientation); SensorValueChanged(this, orientation, "Orientation"); } } break; } }
public void OnSensorChanged(SensorEvent se) { if (this._shakeHelper.IsShake(se.Values[0], se.Values[1], se.Values[2])) { MakeDecision (); } }
public void OnSensorChanged(SensorEvent e) { var values = e.Values; int valueBg = (int)Math.Round(values[0], 0); //_layout.SetBackgroundColor(valueBg); }
public void OnSensorChanged(SensorEvent e) { lock (syncLock) { stepDetector++; //RunOnUiThread(() => numSteps.Text = stepDetector.ToString()); numSteps.Text = stepDetector.ToString(); } }
public void OnSensorChanged(SensorEvent e) { if (e.Sensor.Type != SensorType.Gyroscope) { return; } this.onSensor(e); }
public void OnSensorChanged(SensorEvent e) { lock (_syncLock) { if(e.Sensor.Type == SensorType.LinearAcceleration) { accelX.Text = e.Values[0].ToString(); accelY.Text = e.Values[1].ToString(); accelZ.Text = e.Values[2].ToString(); } //Test for changing Material Dark theme for Night Time mode else if(e.Sensor.Type == SensorType.Light) { ambientLight.Text = e.Values[0].ToString(); if(e.Values[0] > 50.0) { title1.SetTextColor(Android.Graphics.Color.ParseColor("#000000")); title2.SetTextColor(Android.Graphics.Color.ParseColor("#000000")); title3.SetTextColor(Android.Graphics.Color.ParseColor("#000000")); overallLayout.SetBackgroundColor(Android.Graphics.Color.ParseColor("#FFFFFF")); subLayout1.SetBackgroundColor(Android.Graphics.Color.ParseColor("#EEEEEE")); subLayout2.SetBackgroundColor(Android.Graphics.Color.ParseColor("#EEEEEE")); subLayout3.SetBackgroundColor(Android.Graphics.Color.ParseColor("#EEEEEE")); } else { title1.SetTextColor(Android.Graphics.Color.ParseColor("#EEEEEE")); title2.SetTextColor(Android.Graphics.Color.ParseColor("#EEEEEE")); title3.SetTextColor(Android.Graphics.Color.ParseColor("#EEEEEE")); overallLayout.SetBackgroundColor(Android.Graphics.Color.ParseColor("#212121")); subLayout1.SetBackgroundColor(Android.Graphics.Color.ParseColor("#607D8B")); subLayout2.SetBackgroundColor(Android.Graphics.Color.ParseColor("#607D8B")); subLayout3.SetBackgroundColor(Android.Graphics.Color.ParseColor("#607D8B")); } } //Try purely based on GPS for now /* if(e.Values[1] > 0.5) { thresholdReached(); threshold.Text = "Reached"; blackout.Visibility = ViewStates.Visible; } else { threshold.Text = "Not Reached"; blackout.Visibility = ViewStates.Gone; } * */ } }
public void OnSensorChanged(SensorEvent e) { var values = new double[] { e.Values[0], e.Values[1], e.Values[2] }; if (listener != null) { listener.OnDataReceived(values); } }
// When the sensor tells us we have moved, update public void OnSensorChanged(SensorEvent e) { lock (lock_obj) { var values = e.Values; if (Math.Abs (heading - values[0]) > ROTATE_TOLERANCE) { heading = values[0]; Invalidate (); } } }
public void OnSensorChanged(SensorEvent sensorEvent) { if (sensorEvent.Sensor.GetType() == Sensor.TYPE_GRAVITY) { double x = sensorEvent.Values[0]; double y = sensorEvent.Values[1]; //double z = sensorEvent.Values[2]; panel.setOrientation(y, x); } }
public void OnSensorChanged(SensorEvent e) { if (e.Sensor.Type == SensorType.Proximity) { lock (_locker) { location = e.ToString(); Monitor.Pulse(_locker); } } }
public void OnSensorChanged (SensorEvent e) { lock (sensorSyncLock) { var text = new StringBuilder ("Acelerometro: x = ") .Append (e.Values [0]) .Append (", y=") .Append (e.Values [1]) .Append (", z=") .Append (e.Values [2]); usa_acelerometro.Text = text.ToString (); } }
public void OnSensorChanged (SensorEvent e) { if (e.Sensor == _compass) { double degrees = e.Values [0]; var newHeading = new Traq.Heading { Degrees = degrees }; HeadingUpdated (this, new HeadingUpdateEvent { NewHeading = newHeading }); } }
public void OnSensorChanged(SensorEvent e) { lock (_syncLock) { var text = new StringBuilder("x = ") .Append(e.Values[0]) .Append(", y=") .Append(e.Values[1]) .Append(", z=") .Append(e.Values[2]); _sensorTextView.Text = text.ToString(); } }
public void OnSensorChanged(SensorEvent e) { if (e.Sensor.Type != SensorType.Accelerometer) return; var reading = ToReading(e.Values[0], e.Values[1], e.Values[2]); LastReading = reading.Clone(); var handler = ReadingAvailable; handler?.Invoke(this, new MvxValueEventArgs<MvxAccelerometerReading>(reading)); }
public void OnSensorChanged (SensorEvent e) { if (e.Sensor.Type != SensorType.Accelerometer) { return; } var reading = new AccelometerStatus(e.Values[0], e.Values[1], e.Values[2]); Accelometer.LatestStatus = new AccelometerStatus (reading); Accelometer.readingAvailable.Invoke (this, reading); }
public void OnSensorChanged(SensorEvent e) { var values = e.Values; double cumulatedValues = values.Aggregate<float, float>(0, (current, value) => Math.Abs(current) + Math.Abs(value)); this._cumulatedValues = this._cumulatedValues + cumulatedValues; var roundedValues = this.RoundValues(values); //string valueString = roundedValues.Aggregate(string.Empty, (current, value) => string.Format("{0}; {1}", current, value)); //_label.Text = string.Format("Cumulated: '{0}' -> Current: {1}", this._cumulatedValues, valueString); //_label.Text = string.Format("Cumulated: '{0}' For Sensor: '{1}'", Math.Round(this._cumulatedValues, 0), this._sensorType); }
public void OnSensorChanged(SensorEvent e) { try { if (e.Sensor.Type == SensorType.Accelerometer) { var x = e.Values[0]; var y = e.Values[1]; var z = e.Values[2]; if (_prevZ.HasValue && (Math.Abs(x) < 3 && Math.Abs(y) < 3)) { var diffZ = (Math.Abs(z - _prevZ.Value) / z) * 100; if (diffZ > 15 && diffZ < 30) { var timeDiff = (JavaSystem.NanoTime() - _lastKnockTime) / 1000000; if (timeDiff > 100 && timeDiff < 800) { TurnOnScreen(); Log.Debug("ScreenWaker", $"Screen Opened !, {z} || {diffZ}"); } _lastKnockTime = JavaSystem.NanoTime(); //Log.Debug("ScreenWaker", $"Knocked !, {diffZ}"); } } _prevZ = z; } //if (e.Sensor.Type == SensorType.Proximity) //{ // var dist = e.Values[0]; // if (dist < 5) // { // var timeDiff = (Java.Lang.JavaSystem.NanoTime() - _lastDistTime) / 1000000; // if ((timeDiff > 500 && timeDiff < 1500)) // { // TurnOnScreen(); // Log.Debug("ScreenWaker", $"Proximity Turned On Screen !"); // } // _lastDistTime = Java.Lang.JavaSystem.NanoTime(); // } // //Log.Debug("ScreenWaker", $"Proximity !, {e.Values[0]}"); //} } catch (Exception ex) { Log.Error("OnSensorChanged", ex.ToString()); } }
public void OnSensorChanged(SensorEvent e) { switch (e.Sensor.Type) { case SensorType.Accelerometer: e.Values.CopyTo(m_lastAccels, 0); break; case SensorType.MagneticField: e.Values.CopyTo(m_lastMagFields, 0); break; default: return; } computeOrientation(); }
/// <summary> /// Detects sensor changes and is set up to listen for shakes. /// </summary> public async void OnSensorChanged(Android.Hardware.SensorEvent e) { //System.Diagnostics.Debug.WriteLine("OnSensorChanged - START"); //if (handleSensorChanged) // return; //handleSensorChanged = true; if (e.Sensor.Type == Android.Hardware.SensorType.Accelerometer) { var x = e.Values[0]; var y = e.Values[1]; var z = e.Values[2]; // use to check against last time it was called so we don't register every delta var currentTime = DateTime.Now; if (hasUpdated == false) { hasUpdated = true; lastUpdate = currentTime; lastX = x; lastY = y; lastZ = z; } else { if ((currentTime - lastUpdate).TotalMilliseconds > ShakeDetectionTimeLapse) { var diffTime = (float)(currentTime - lastUpdate).TotalMilliseconds; lastUpdate = currentTime; var total = x + y + z - lastX - lastY - lastZ; var speed = Math.Abs(total) / diffTime * 10000; if (speed > ShakeThreshold) { // We have a shake folks! await HandleShaking(); } lastX = x; lastY = y; lastZ = z; } } } }
public void OnSensorChanged(SensorEvent e) { lock (syncLock) { sensorText.Text = string.Format("X = {0:N4}\nY = {1:N4}", e.Values[0], e.Values[1]); // 現在の位置を取得 nowX = sensorText.GetX(); nowY = sensorText.GetY(); Log.Debug("Info", string.Format("nowX: {0}, nowY: {1}", nowX, nowY)); // Viewをはみ出さないようにAccelerometerの値によってTextViewを移動 if (nowX - e.Values[0] * 10 > 0 && nowX - e.Values[0] * 10 < layoutW - textW) sensorText.SetX(nowX - e.Values[0] * 10); if (nowY + e.Values[1] * 10 > 0 && nowY + e.Values[1] * 10 < layoutH - textH) sensorText.SetY(nowY + e.Values[1] * 10); } }
public void OnSensorChanged(SensorEvent e) { //Get sensor degree float degree = (float)Math.Round(e.Values[0]); //values[0]: Angle between the magnetic north direction and the y-axis around the z-axis (0 to 359), where 0=North, 90=East, 180=South, 270=West. //values[1]: Rotation around x-axis (-180 to 180), with positive values when the z-axis moves towards the y-axis. //values[2]: Rotation around x-axis, (-90 to 90), increasing as the device moves clockwise. //calculate direction coordinal headingDirection.Text = CalculateDirection(degree); // Set text for degree headingDegree.Text = Convert.ToString(degree) + "\u00B0"; outerDialImage.Rotation = degree; //currentDegree is updated with the value of -degree so that the next animation will start from the new position. currentDegree = -degree; }
public void OnSensorChanged(Android.Hardware.SensorEvent e) { if (e.Sensor.Type == SensorType.Accelerometer) { float x = e.Values[0]; float y = e.Values[1]; float z = e.Values[2]; var previous = this.gravity; this.gravity = Math.Sqrt(x * x + y * y + z * z); var delta = gravity - previous; this.acceleration = this.acceleration * LowPassFilter + delta; if ((acceleration > ShakeThreshold) && (lastUpdate + ShakeDetectionTimeLapse < DateTime.Now)) { lastUpdate = DateTime.Now; this.Shaked?.Invoke(this, EventArgs.Empty); } } }
//===============================================ACCELEROMETER INTERFACE METHODS=================== public void OnSensorChanged(SensorEvent e) { lock(_syncLock) { if(e.Sensor == mSensor) { accelStrength.Text = e.Accuracy.ToString(); accelX.Text = e.Values[0].ToString(); accelY.Text = e.Values[1].ToString(); accelZ.Text = e.Values[2].ToString(); } else if(e.Sensor == mLinearSensor) { linearStrength.Text = e.Accuracy.ToString(); linearX.Text = e.Values[0].ToString(); linearY.Text = e.Values[1].ToString(); linearZ.Text = e.Values[2].ToString(); } } }
public void OnSensorChanged(Android.Hardware.SensorEvent e) { if (e.Sensor.Type == Android.Hardware.SensorType.Accelerometer) { float x = e.Values[0]; float y = e.Values[1]; float z = e.Values[2]; DateTime curTime = System.DateTime.Now; if (hasUpdated == false) { hasUpdated = true; lastUpdate = curTime; last_x = x; last_y = y; last_z = z; } else { if ((curTime - lastUpdate).TotalMilliseconds > ShakeDetectionTimeLapse) { float diffTime = (float)(curTime - lastUpdate).TotalMilliseconds; lastUpdate = curTime; float total = x + y + z - last_x - last_y - last_z; float speed = Math.Abs(total) / diffTime * 10000; if (speed > ShakeThreshold) { Toast.MakeText(this, "shake detected w/ speed: " + speed, ToastLength.Short).Show(); SingleViewBacgroundview.RemoveAllViews(); } last_x = x; last_y = y; last_z = z; } } } }
public void OnSensorChanged(SensorEvent @event) { if (@event.Sensor.Type != Sensor.TYPE_ACCELEROMETER) { return; } /* * record the accelerometer data, the event's timestamp as well as * the current time. The latter is needed so we can calculate the * "present" time during rendering. In this application, we need to * take into account how the screen is rotated with respect to the * sensors (which always return data in a coordinate space aligned * to with the screen in its native orientation). */ //JAVA TO C# CONVERTER TODO TASK: C# doesn't allow accessing outer class instance members within a nested class: switch (activity.mDisplay.Rotation) { case Surface.ROTATION_0: mSensorX = @event.Values[0]; mSensorY = @event.Values[1]; break; case Surface.ROTATION_90: mSensorX = [email protected][1]; mSensorY = @event.Values[0]; break; case Surface.ROTATION_180: mSensorX = [email protected][0]; mSensorY = [email protected][1]; break; case Surface.ROTATION_270: mSensorX = @event.Values[1]; mSensorY = [email protected][0]; break; } mSensorTimeStamp = @event.Timestamp; mCpuTimeStamp = Java.Lang.System.NanoTime(); }
public void OnSensorChanged(SensorEvent args) { if (args.Sensor.Type == SensorType.Accelerometer) gravity = args.Values.ToArray(); if (args.Sensor.Type == SensorType.MagneticField) geomagnetic = args.Values.ToArray(); if (gravity != null && geomagnetic != null) { float[] R = new float[9]; float[] I = new float[9]; bool success = SensorManager.GetRotationMatrix(R, I, gravity, geomagnetic); if (success) { float[] orientation = new float[3]; SensorManager.GetOrientation(R, orientation); // double azimuth = Math.toDegrees(matrixValues[0]); // double pitch = Math.toDegrees(matrixValues[1]); // double roll = Math.toDegrees(matrixValues[2]); var newHeading = orientation[0] < 0 ? 360.0 + orientation[0] * 180.0 / Math.PI : orientation[0] * 180.0 / Math.PI; // orientation contains: azimut, pitch and roll if (Math.Abs(heading - newHeading) >= 5.0) { heading = newHeading; if (HeadingChanged != null) HeadingChanged(this, new HeadingEventArgs(heading)); } } } }
public void OnSensorChanged(SensorEvent e) { compass.mValues = e.Values.ToArray (); Invalidate (); }
public virtual void OnSensorChanged(Android.Hardware.SensorEvent e) { // Store reading lastValues = e.Values; updated = true; }
public void OnSensorChanged(Android.Hardware.SensorEvent e) { if (!m_shakeEnabled) { return; } if (e.Sensor.Type == Android.Hardware.SensorType.Accelerometer) { float x = e.Values[0]; float y = e.Values[1]; float z = e.Values[2]; float gX = x / SensorManager.GravityEarth; float gY = y / SensorManager.GravityEarth; float gZ = z / SensorManager.GravityEarth; // gForce will be close to 1 when there is no movement. double gForce = Math.Sqrt(gX * gX + gY * gY + gZ * gZ); if (gForce > SHAKE_NOMOVEMENT_GRAVITY) { // Log.Debug(LogTag, "*** (" + x + "," + y + "," + z + ") (" + gX + "," + gY + "," + gZ + ") " + gForce); MovingDateTime = DateTime.Now; } if (gForce <= SHAKE_THRESHOLD_GRAVITY) { return; } // Log.Debug(LogTag, "(" + x + "," + y + "," + z + ") (" + gX + "," + gY + "," + gZ + ") " + gForce); DateTime curTime = System.DateTime.Now; if (hasUpdated == false) { hasUpdated = true; lastUpdate = curTime; firstUpdate = curTime; last_x = x; last_y = y; last_z = z; } else { float dTime = (float)(curTime - firstUpdate).TotalMilliseconds; if (Convert.ToInt32(dTime) > ShakeDuration) { currentCount = 0; } float diffTime = (float)(curTime - lastUpdate).TotalMilliseconds; if (Convert.ToInt32(diffTime) > ShakeDetectionTimeLapse) { lastUpdate = curTime; float dX = Math.Abs(x - last_x); float dY = Math.Abs(y - last_y); float dZ = Math.Abs(z - last_z); float total = dX + dY + dZ; float speed = total / diffTime * 10000; if (speed > ShakeSpeedThreshold) { Log.Debug(LogTag, "" + currentCount + " speed=" + speed + "/" + ShakeSpeedThreshold + " (" + dX + "," + dY + "," + dZ + ") " + firstUpdate.ToString("HH:mm:ss.fff") + "/" + curTime.ToString("HH:mm:ss.fff")); // shake deteced if (currentCount == 0) { firstUpdate = curTime; } else { if (dTime < ShakeDuration) { if (currentCount >= ShakeCounter) { this.ShakeDetected(this, new EventArgs()); currentCount = 0; hasUpdated = false; } } } currentCount++; } last_x = x; last_y = y; last_z = z; } } } }
public void OnSensorChanged(SensorEvent e) { lock (_syncLock) { /*var text = new StringBuilder("x = ") .Append(e.Values[0]) .Append(", y=") .Append(e.Values[1]) .Append(", z=") .Append(e.Values[2]); _sensorTextView.Text = text.ToString();*/ double x = e.Values [0]; double y = e.Values [1]; if (Math.Abs (x) < 1 && Math.Abs (y) < 1) { mainLayout.SetBackgroundColor (Android.Graphics.Color.Green); green = true; } else { mainLayout.SetBackgroundColor (Android.Graphics.Color.Red); green = false; } } }