Example #1
0
        void _accelerometer_ReadingChanged(object sender, SensorReadingEventArgs <AccelerometerReading> e)
        {
            //Does the currenet acceleration vector meet the minimum magnitude that we
            //care about?
            if ((e.SensorReading.Acceleration.X * e.SensorReading.Acceleration.X + e.SensorReading.Acceleration.Y * e.SensorReading.Acceleration.Y) > MinimumAccelerationMagnitudeSquared)
            {
                //I prefer to work in radians. For the sake of those reading this code
                //I will work in degrees. In the following direction will contain the direction
                // in which the device was accelerating in degrees.
                double    degrees   = 180.0 * Math.Atan2(e.SensorReading.Acceleration.Y, e.SensorReading.Acceleration.X) / Math.PI;
                Direction direction = DegreesToDirection(degrees);
                //
                D   = direction;
                deg = degrees;
                //
                //If the shake detected is in the same direction as the last one then ignore it
                if ((direction & _shakeRecordList[_shakeRecordIndex].ShakeDirection) != Direction.None)
                {
                    return;
                }
                ShakeRecord record = new ShakeRecord();
                record.EventTime      = DateTime.Now;
                record.ShakeDirection = direction;
                _shakeRecordIndex     = (_shakeRecordIndex + 1) % _minimumShakes;
                _shakeRecordList[_shakeRecordIndex] = record;

                CheckForShakes();
            }
        }
Example #2
0
        public override void addValues(GVector gv)
        {
            //use new GVector 16 segmented direction
            GVector.Direction direction = gv.direction;

            double accel = gv.Length;// Math.Sqrt(e.X * e.X + e.Y * e.Y);// + e.Z*e.Z);

            //Does the currenet acceleration vector meet the minimum magnitude that we
            //care about?
            if (accel > MinimumAccelerationMagnitudeSquared)
            {
                //If the shake detected is in the same direction as the last one then ignore it
                //if ((direction & _shakeRecordList[_shakeRecordIndex].ShakeDirection) != GVector.Direction.None)// Direction.None)
                if ((direction == _shakeRecordList[_shakeRecordIndex].ShakeDirection))
                {
                    return;
                }
                ShakeRecord record = new ShakeRecord();
                record.EventTime      = DateTime.Now;
                record.ShakeDirection = direction;
                _shakeRecordIndex     = (_shakeRecordIndex + 1) % _minimumShakes;
                _shakeRecordList[_shakeRecordIndex] = record;

                CheckForShakes(gv);
            }
        }
        public override void addValues(GVector gv)
		{
            //use new GVector 16 segmented direction
            GVector.Direction direction = gv.direction;

            double accel = gv.Length;// Math.Sqrt(e.X * e.X + e.Y * e.Y);// + e.Z*e.Z);
            //Does the currenet acceleration vector meet the minimum magnitude that we
            //care about?
            if (accel > MinimumAccelerationMagnitudeSquared)
            {
                //If the shake detected is in the same direction as the last one then ignore it
                //if ((direction & _shakeRecordList[_shakeRecordIndex].ShakeDirection) != GVector.Direction.None)// Direction.None)
                if((direction == _shakeRecordList[_shakeRecordIndex].ShakeDirection))
                    return;
                ShakeRecord record = new ShakeRecord();
                record.EventTime = DateTime.Now;
                record.ShakeDirection = direction;
                _shakeRecordIndex = (_shakeRecordIndex + 1)%_minimumShakes;
                _shakeRecordList[_shakeRecordIndex] = record;

                 CheckForShakes(gv);

            }
        }
Example #4
0
 public ShakeClass7(string s, int minShakes)
 {
     _minimumShakes   = minShakes;
     _shakeRecordList = new ShakeRecord[minShakes];
 }
Example #5
0
 /// <summary>
 /// shake detection using a list of directions
 /// if  acceleration is > treshold and current direction is != actual direction and
 /// number of detected shakes is > min number of shakes then
 /// the ShakeDetected event will be fired
 /// </summary>
 /// <param name="s"></param>
 public ShakeClass7(string s)
 {
     _minimumShakes   = 1;
     _shakeRecordList = new ShakeRecord[_minimumShakes];
     base.name        = s;
 }
 public ShakeClass7(string s, int minShakes)
 {
     _minimumShakes = minShakes;
     _shakeRecordList = new ShakeRecord[minShakes];
 }
 /// <summary>
 /// shake detection using a list of directions
 /// if  acceleration is > treshold and current direction is != actual direction and
 /// number of detected shakes is > min number of shakes then 
 /// the ShakeDetected event will be fired
 /// </summary>
 /// <param name="s"></param>
 public ShakeClass7(string s) 
 {
     _minimumShakes=1;
     _shakeRecordList = new ShakeRecord[_minimumShakes];
     base.name = s;
 }