Example #1
0
 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();
                 }
                 last_x = x;
                 last_y = y;
                 last_z = z;
             }
         }
     }
 }
Example #2
0
            public void OnSensorChanged(Android.Hardware.SensorEvent e)
            {
                if (e.Sensor.Type != Android.Hardware.SensorType.LinearAcceleration)
                {
                    return;
                }
                processData(e.Values.ToArray <float>());

                if ((DateTime.Now - _LatestUpdatedDataDateTime).TotalMilliseconds >= UpdateTimestep)
                {
                    _LatestUpdatedDataDateTime = DateTime.Now;
                    OnSensorDataUpdated?.Invoke(this, velocity.Array);
                }
            }
Example #3
0
        public void OnSensorChanged(Android.Hardware.SensorEvent e)
        {
            //Trigger of the Accelerometer Sensor
            audioPlayer = new AudioPlayer();
            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 = DateTime.Now;
                if (hasUpdated == false)
                {
                    hasUpdated = true;
                    lastUpdate = curTime;
                    last_x     = x;
                    last_y     = y;
                    last_z     = z;
                }
                else
                {
                    if ((curTime - lastUpdate).TotalMilliseconds > ShakeDetectionTimeLapse)
                    {
                        //ccalculation for the speed of the Shake
                        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)
                        {
                            //Detect if Smartphone shaked
                            Toast.MakeText(this, "shake detected w/ speed: " + speed, ToastLength.Short).Show();
                            audioPlayer.StartPlayer();
                        }
                        else
                        {
                            audioPlayer.StopPlayer();
                        }

                        last_x = x;
                        last_y = y;
                        last_z = z;
                    }
                }
            }
        }
Example #4
0
            public void OnSensorChanged(Android.Hardware.SensorEvent e)
            {
                if (e.Sensor.Type != DroidSensorType)
                {
                    return;
                }
                if ((DateTime.Now - _LatestUpdatedDataDateTime).TotalMilliseconds >= UpdateTimestep)
                {
                    _LatestUpdatedDataDateTime = DateTime.Now;

                    if (DroidSensorType == Android.Hardware.SensorType.GameRotationVector)
                    {
                        float[] quaternion = new float[4];
                        Android.Hardware.SensorManager.GetQuaternionFromVector(quaternion, e.Values.ToArray <float>());
                        OnSensorDataUpdated?.Invoke(this, quaternion);
                    }
                    else
                    {
                        OnSensorDataUpdated?.Invoke(this, e.Values.ToArray <float>());
                    }
                }
            }
Example #5
0
 public int AccelerometerValueChanaged(Android.Hardware.SensorEvent e)
 {
     AccelerometerValue = e.Values [1];
     return(0);
 }