public void OnSensorChanged(SensorEvent e) { if (e.Sensor.Type == SensorType.MagneticField) { magnet.Clear(); magnet.AddRange(e.Values); } if (e.Sensor.Type == SensorType.Accelerometer) { gravity.Clear(); gravity.AddRange(e.Values); } if (magnet.Count > 0 && gravity.Count > 0) { float[] R = new float[9]; float[] I = new float[9]; bool worked = SensorManager.GetRotationMatrix(R, I, gravity.ToArray(), magnet.ToArray()); if (worked) { float[] orientation = new float[3]; SensorManager.GetOrientation(R, orientation); ImageView arrowImageView = FindViewById <ImageView>(Resource.Id.arrowImageView); float azimuth = orientation[0] * 180 / (float)Math.PI; //convert to degrees arrowImageView.Rotation = azimuth; } } }
public void OnSensorChanged(SensorEvent e) { if (_sensorValueChangedCallback != null && e != null && e.Values != null && e.Values.Count > 0) { _sensorValueChangedCallback(e); } }
public void OnSensorChanged(SensorEvent e) { lock (_syncLock) { if (e.Sensor.Type == SensorType.Accelerometer) { _sensorTextView.Text = string.Format("x={0:f}, y={1:f}, z={2:f}", e.Values[0], e.Values[1], e.Values[2]); accelerometer += string.Format("{0:f};{1:f};{2:f}", e.Values[0], e.Values[1], e.Values[2]); } if (e.Sensor.Type == SensorType.MagneticField) { _sensorMagnetoMeterTextView.Text = string.Format("x={0:f}, y={1:f}, z={2:f}", e.Values[0], e.Values[1], e.Values[2]); magnetometer += string.Format("{0:f};{1:f};{2:f}", e.Values[0], e.Values[1], e.Values[2]); } if (e.Sensor.Type == SensorType.Gyroscope) { _sensorGyroscopeTextView.Text = string.Format("x={0:f}, y={1:f}, z={2:f}", e.Values[0], e.Values[1], e.Values[2]); gyroscope += string.Format("{0:f};{1:f};{2:f}", e.Values[0], e.Values[1], e.Values[2]); } if (e.Sensor.Type == SensorType.GeomagneticRotationVector) { _sensorGeomagneticRotationVectorTextView.Text = string.Format("x={0:f}, y={1:f}, z={2:f}", e.Values[0], e.Values[1], e.Values[2]); gyroscope += string.Format("{0:f};{1:f};{2:f}", e.Values[0], e.Values[1], e.Values[2]); } } }
private void HandleLinAccelEvent(SensorEvent sensorEvent) { if (0 == this.lastLinAccelTimestamp) { this.lastLinAccelTimestamp = sensorEvent.Timestamp; return; } // double deltaT = (sensorEvent.Timestamp - this.lastLinAccelTimestamp) * AbstractTrackSolver.ns2s; /* * this.lastPosition[0] += -sensorEvent.Y * deltaT * deltaT * 0.5 * 100; * this.lastPosition[1] += sensorEvent.Z * deltaT * deltaT * 0.5 * 100; * this.lastPosition[2] += -sensorEvent.X * deltaT * deltaT * 0.5 * 100; */ ulong nsDeltaT = sensorEvent.Timestamp - this.lastLinAccelTimestamp; double sqDeltaT = nsDeltaT * nsDeltaT * this.accumulatedPositionFactor; this.lastPosition[0] += -sensorEvent.Y * sqDeltaT; this.lastPosition[1] += sensorEvent.Z * sqDeltaT; this.lastPosition[2] += -sensorEvent.X * sqDeltaT; this.lastLinAccelTimestamp = sensorEvent.Timestamp; this.PushSolverFrame(sensorEvent); }
public void OnSensorChanged(SensorEvent e) { if (e.Sensor.Type != SensorType.Accelerometer) { return; } var curTime = TimeSpan.FromTicks(DateTime.UtcNow.Ticks).TotalMilliseconds; var diffTime = curTime - _lastUpdate; if (diffTime < 100 || curTime - _lastShake < RateLimitMilliseconds) { return; } _lastUpdate = curTime; var speed = Math.Abs(e.Values.Sum() - _lastValues.Sum()) / diffTime * 10000; _lastValues = e.Values.ToList(); if (speed < 2000) { return; } _lastShake = curTime; ShakeOccurred?.Invoke(this, EventArgs.Empty); }
public void OnSensorChanged(SensorEvent e) { // The light sensor returns a single value. // Many sensors return 3 values, one for each axis. txtInfo.Text = Sensors.ShowProperlyInfo(e); // https://www.codespeedy.com/simple-compass-code-with-android-studio/ if (sensor.Type == SensorType.Orientation) { // get angle around the z-axis rotated float degree = (float)Math.Round(e.Values[0], 0); // rotation animation - reverse turn degree degrees RotateAnimation animation = new RotateAnimation( degreeStart, -degree, Dimension.RelativeToSelf, 0.5f, Dimension.RelativeToSelf, 0.5f) { // set the compass animation after the end of the reservation status FillAfter = true, // set how long the animation for the compass image will take place Duration = 210 }; // Start animation of compass image imgVisualization.StartAnimation(animation); degreeStart = -degree; } }
public void OnSensorChanged(SensorEvent e) { for (int i = 0; i < lastValues.Length; i++) { lastValues[i] = e.Values[i]; } }
private void HandleFusion(SensorEvent sensorEvent) { if (null == this.accelMagnetRotation) { return; } this.fusionCounter += sensorEvent.Timestamp - this.fusionLastTimestamp; this.fusionLastTimestamp = sensorEvent.Timestamp; if (this.fusionCounter >= 10000000) { this.fusionCounter = 0; // do fusion double t = 0.008; double invt = 1.0 - t; ulong timestamp = sensorEvent.Timestamp - this.firstTimestamp; this.gyroRotation[0] = invt * this.gyroRotation[0] + t * this.accelMagnetRotation[0]; this.gyroRotation[1] = invt * this.gyroRotation[1] + t * this.accelMagnetRotation[1]; this.gyroRotation[2] = invt * this.gyroRotation[2] + t * this.accelMagnetRotation[2]; if (this.solverData.ContainsKey(timestamp)) { this.solverData.Remove(timestamp); } this.solverData.Add(timestamp, new SolverFrame(timestamp, ref this.accelMagnetPosition, ref this.gyroRotation)); } }
public void OnSensorChanged(SensorEvent e) { lock (syncLock) { plotModel.Series.Clear(); var barSeries = new BarSeries { ItemsSource = new List <BarItem>(new[] { new BarItem { Value = (e.Values[2]), Color = OxyColors.Red }, new BarItem { Value = (e.Values[1]), Color = OxyColors.Green }, new BarItem { Value = (e.Values[0]), Color = OxyColors.Blue } }), LabelPlacement = LabelPlacement.Inside, LabelFormatString = "{0:.00} m/s^-2" }; plotModel.Series.Add(barSeries); view.InvalidatePlot(true); } }
public void OnSensorChanged(SensorEvent e) { if (DateTime.Now > lastMessageSend.AddMilliseconds(50) && manager != null && manager.Initialized) { lastMessageSend = DateTime.Now; float x = e.Values[0], y = e.Values[1], z = e.Values[2]; if (x > 5) { manager.Send(Model.Directions.Left); } else if (x < -5) { manager.Send(Model.Directions.Right); } else if (y < -5) { manager.Send(Model.Directions.Up); } else { manager.Send(Model.Directions.None); } } }
public void OnSensorChanged(SensorEvent e) { if (e.Sensor.Type == SensorType.Light) { lux = e.Values[0]; } }
public void OnSensorChanged(SensorEvent evento) { //Arreglame: Ejecutame en un Backgroudn thread Sensor sensor = evento.Sensor; if (sensor.Type == SensorType.Proximity) { //Mientras el sensor de proximidad esté cubierto haga: while (evento.Values[0] > 1) { //Si el wakelock no está sostenido, entonces adquirir el Wakelock que apaga la pantalla. if (!wakeLock.IsHeld) { wakeLock.Acquire(); } } //Si el wakelock está adquirido, entonces soltarlo cuando el sensor no esté cubierto. if (wakeLock.IsHeld) { wakeLock.Release(); } } else if (sensor.Type == SensorType.Accelerometer) { //values 1 es el eje Y, values 2 es el eje Z while (evento.Values[1] > 3 && evento.Values[2] < 9) { Toast.MakeText(Application.Context, "El dispositivo se levantó", ToastLength.Short).Show(); } } }
public void OnSensorChanged(SensorEvent e) { if (e.Values == null) { throw new InvalidOperationException(); } var vector = new Vector3(); if (e.Values.Count > 0) { vector.X = e.Values[0]; } if (e.Values.Count > 1) { vector.Y = e.Values[1]; } if (e.Values.Count > 2) { vector.Z = e.Values[2]; } // Translate into iOS accelerometer units: g-forces instead of m/s^2 var a = -vector / 9.81f; input.Acceleration = a; }
public void OnSensorChanged(SensorEvent e) { //lock (_syncLock) //{ e.Values.CopyTo(Accl, 0); //} }
public void OnSensorChanged(SensorEvent e) { var gNorm = (float)Sqrt(Pow(e.Values[0], 2) + Pow(e.Values[1], 2) + Pow(e.Values[2], 2)); // Normalize the accelerometer vector. float g0 = e.Values[0] / gNorm; float g1 = e.Values[1] / gNorm; float g2 = e.Values[2] / gNorm; // Roll is the Z-Rot. Counter-clockwise (+) and clockwise (-), moving the device like a steering wheel. // 0° when the screen is perpendicular to the floor, -90º when the screen is fully tilted to the right, 90º when the screen is fully tilted to the left. // Range from 180° to -180°. var roll = (float)Atan2(g0, g1); // Pitch is the X-Rot. Forward (+) and backwards (-). // 0º when the screen is facing the ceiling, 180º when the screen is facing the floor, 90º when the screen is facing the person. var pitch = (float)Atan2(g1, g2); // This avoids over-sensitivity of the accelerometer. if ((Abs(this.lastRoll - roll) > angleSensitivity) && (Abs(this.lastPitch - pitch) > angleSensitivity)) { this.lastRoll = roll; this.lastPitch = pitch; SetIridescentEffect(roll, pitch); } }
public void OnSensorChanged(SensorEvent e) { if (e.Sensor.Type == SensorType.Accelerometer) { _accelerometer.OnValuesUpdated(new AccelerometerData(e.Values[0], e.Values[1], e.Values[2])); } }
public void OnSensorChanged(SensorEvent evt) { if (evt.Sensor.Type == SensorType.Accelerometer) { mGravity = evt.Values.ToArray(); } if (evt.Sensor.Type == SensorType.MagneticField) { mGeomagnetic = evt.Values.ToArray(); } if (mGravity != null && mGeomagnetic != null) { var R = new float[9]; var I = new float[9]; var success = SensorManager.GetRotationMatrix(R, I, mGravity, mGeomagnetic); if (success) { var orientation = new float[3]; SensorManager.GetOrientation(R, orientation); if (Interlocked.CompareExchange(ref Updating, 1, 0) == 1) { return; } RunOnUiThread(() => { UpdateElementsOnScreen(orientation[2], orientation[1], orientation[0]); Interlocked.Exchange(ref Updating, 0); }); } } }
public void OnSensorChanged(SensorEvent s) { s.Sensor = sensorManager.GetDefaultSensor(SensorType.Light); lightSensorValue = s.Values[0]; app.LightValue = lightSensorValue; }
public void OnSensorChanged(SensorEvent e) { if (!Settings.AutomaticDayNightMode) { return; } m_fLastSensorIlluminanceValue = -1; try { m_fLastSensorIlluminanceValue = e.Values[0]; } catch (Exception) { } if (m_fLastSensorIlluminanceValue == -1) { return; } try { m_handler.RemoveCallbacks(m_workRunnable); m_handler.PostDelayed(m_workRunnable, Settings.NbMillisecondBeforeSwitchDayNightMode); } catch (Exception) { } }
protected override void PushSolverFrame(SensorEvent sensorEvent) { ulong timestamp = sensorEvent.Timestamp - this.firstTimestamp; SolverFrame solverFrame; SolverFrame existingSolverFrame; double[] existingData; if (this.solverData.TryGetValue(timestamp, out existingSolverFrame)) { switch (sensorEvent.Type) { case SensorEvent.SensorType.ACCEL: existingData = existingSolverFrame.Rotation; solverFrame = new SolverFrame(timestamp, ref this.accelMagnetPosition, ref existingData); break; case SensorEvent.SensorType.GYRO: existingData = existingSolverFrame.Position; solverFrame = new SolverFrame(timestamp, ref existingData, ref this.gyroRotation); break; default: return; } this.solverData.Remove(timestamp); } else { solverFrame = new SolverFrame(timestamp, ref this.accelMagnetPosition, ref this.gyroRotation); } this.solverData.Add(solverFrame.Timestamp, solverFrame); }
public void OnSensorChanged(SensorEvent e) { lock (_syncLock) { lightTextView.Text = string.Format("Brightness={0:f}", e.Values[0]); lightLayout.Alpha = (float)0.001 * e.Values[0]; float value = (float)e.Values[0]; if (value < lowLimit || value > highLimit) { if (!player.IsPlaying) { player.Start(); } } else { if (player.IsPlaying) { player.Pause(); } } } Invalidate(); }
void ISensorEventListener.OnSensorChanged(SensorEvent e) { var count = e?.Values?.Count ?? 0; if (count < 3) { return; } OrientationSensorData?data; // Docs: https://developer.android.com/reference/android/hardware/SensorEvent#sensor.type_rotation_vector-: // values[3], originally optional, will always be present from SDK Level 18 onwards. values[4] is a new value that has been added in SDK Level 18. if (count < 4) { data = new OrientationSensorData(e.Values[0], e.Values[1], e.Values[2], -1); } else { data = new OrientationSensorData(e.Values[0], e.Values[1], e.Values[2], e.Values[3]); } OrientationSensor.OnChanged(data.Value); }
public void OnSensorChanged(SensorEvent e) { lock (_syncLock) // Ensure single modification at any one time { _lastAccelerometerValue = new Microsoft.Xna.Framework.Vector3(e.Values[0], e.Values[1], e.Values[2]); } }
public void OnSensorChanged(SensorEvent e) { if (e.Sensor.Name == accelerometer && !lastAccelerometerSet) { CopyValues(e.Values, lastAccelerometer); lastAccelerometerSet = true; } else if (e.Sensor.Name == magnetometer && !lastMagnetometerSet) { CopyValues(e.Values, lastMagnetometer); lastMagnetometerSet = true; } if (lastAccelerometerSet && lastMagnetometerSet) { SensorManager.GetRotationMatrix(r, null, lastAccelerometer, lastMagnetometer); SensorManager.GetOrientation(r, orientation); var azimuthInRadians = orientation[0]; var azimuthInDegress = (Java.Lang.Math.ToDegrees(azimuthInRadians) + 360.0) % 360.0; var data = new CompassData(azimuthInDegress); Compass.OnChanged(data); lastMagnetometerSet = false; lastAccelerometerSet = false; } }
void SensorEvent(SensorEvent type, IActor actor) { if (type == CraftingLegends.Framework.SensorEvent.ActorDetected) { _actor.SetTarget(actor as Actor); } }
public void OnSensorChanged(SensorEvent e) { steps++; StepCountChanged(this, new StepCountChangedEventArgs { Value = Steps }); }
public void OnSensorChanged(SensorEvent e) { if (utilities.UpdateRotation(gameActivity.playerPosition, e)) { Log.Info("OnSensorChanged", "Sensor changed"); } }
public async void setOffsetFromSensorMeasurement(SensorEvent sensorEvent) { await Task.Delay(TimeSpan.FromMilliseconds(5)); if (sensorEvent.sensor is GaugeDeviceSensor) { if (sensorEvent.sensor.type == ESensorType.Pressure) { if (sensorEvent.sensor.measurement.amount >= ptView.minPressure && sensorEvent.sensor.measurement.amount <= ptView.maxPressure.amount) { if (ptView.lookup != sensorEvent.sensor.unit) { ptView.resetData(sensorEvent.sensor.unit, ptView.tempLookup); await Task.Delay(TimeSpan.FromMilliseconds(2)); } var convertedTemperature = AppState.context.fluidManager.lastUsedFluid.GetSaturatedTemperature(sensorEvent.sensor.fluidState, new Scalar(sensorEvent.sensor.unit, sensorEvent.sensor.measurement.amount), AppState.context.locationManager.lastKnownLocation.altitude).ConvertTo(ptView.tempLookup); var tempOffset = (convertedTemperature.amount - ptView.minTemperature.amount) * ptView.tempTicks; ptScroller.SetContentOffset(new CGPoint(tempOffset, 0), true); } } else if (sensorEvent.sensor.type == ESensorType.Temperature) { if (sensorEvent.sensor.measurement.amount >= ptView.minTemperature.amount && sensorEvent.sensor.measurement.amount <= ptView.maxTemperature) { if (ptView.tempLookup != sensorEvent.sensor.unit) { ptView.resetData(ptView.lookup, sensorEvent.sensor.unit); await Task.Delay(TimeSpan.FromMilliseconds(2)); } var tempOffset = (sensorEvent.sensor.measurement.amount - ptView.minTemperature.amount) * ptView.tempTicks + ptView.startGap; ptScroller.SetContentOffset(new CGPoint(tempOffset, 0), true); } } } }
protected override DeviceOrientation ToReading(SensorEvent e) { var degrees = e.Values[0]; if (degrees >= 0 && degrees < 90) { return(DeviceOrientation.Portrait); } if (degrees >= 90 && degrees < 180) { return(DeviceOrientation.LandscapeLeft); } if (degrees >= 180 && degrees < 270) { return(DeviceOrientation.PortraitUpsideDown); } if (degrees >= 270 && degrees < 360) { return(DeviceOrientation.LandscapeRight); } throw new ArgumentException("Invalid rotational degrees - " + degrees); }
public void OnSensorChanged(SensorEvent e) { for (int i = 0; i < 3; i++) { data[i] += e.Values[i]; } if (mCount++ <= 10) { return; } mCount = 0; ((SensorManager)DroidFactory.MainActivity.GetSystemService(Context.SensorService)). UnregisterListener(this); if (locationGetter != null) { locationGetter.Dismiss(); locationGetter = null; } if (_accel.CallbackUrl != null) { DroidFactory.Navigate(_accel, new Dictionary <string, string> { { "X", (data[0] / 10).ToString(CultureInfo.InvariantCulture) }, { "Y", (data[1] / 10).ToString(CultureInfo.InvariantCulture) }, { "Z", (data[2] / 10).ToString(CultureInfo.InvariantCulture) }, }); } _accel = null; }
public void Send(SensorEvent sensorEvent) { var eventHubClient = EventHubClient.CreateFromConnectionString(ConnectionString); var serializedString = JsonConvert.SerializeObject(sensorEvent); eventHubClient.Send(new EventData(Encoding.UTF8.GetBytes(serializedString))); }
/// <summary> /// Called when sensor values have changed. /// </summary> /// <param name="e">the <c><see cref="T:Android.Hardware.SensorEvent" /></c>.</param> public void OnSensorChanged(SensorEvent e) { if (e.Sensor.Type != SensorType.Accelerometer) { return; } var dateTimeOffset = new DateTimeOffset().AddMilliseconds(e.Timestamp); var value = new AccelerometerValue(dateTimeOffset, e.Values[0], e.Values[1], e.Values[2]); var eventArgs = new AccelerometerValueChangedEventArgs(value); SensorChanged.SafeInvoke(this, eventArgs); }
public void onSensorChanged(SensorEvent e) { var TYPE_ACCELEROMETER = 1; // check sensor type if (e.sensor.getType() == TYPE_ACCELEROMETER) { // assign directions float x = e.values[0]; float y = e.values[1]; float z = e.values[2]; if (onaccelerometer != null) onaccelerometer(x, y, z); } }