/// <summary>
 /// Calculates the value of the different gyroscope axis and scales it.
 /// </summary>
 /// <param name="data">Complete array of data retrieved from the sensor</param>
 /// <param name="axis">Specifies the axis the gyroscope was configured to read</param>
 /// <returns>Array of float with values in order of the GyroscopeAxis enum</returns>
 public static float[] CalculateAxisValue(byte[] data, GyroscopeAxis axis)
 {
     switch(axis)
     {
         case GyroscopeAxis.X:
         case GyroscopeAxis.Y:
         case GyroscopeAxis.Z:
             return new float[] { BitConverter.ToInt16(data, 0) * (500f / 65536f) };
         case GyroscopeAxis.XY:
         case GyroscopeAxis.XZ:
         case GyroscopeAxis.YZ:
             return new float[] { BitConverter.ToInt16(data, 0) * (500f / 65536f), 
                 BitConverter.ToInt16(data, 2) * (500f / 65536f) };
         case GyroscopeAxis.XYZ:
             return new float[] { BitConverter.ToInt16(data, 0) * (500f / 65536f), 
                 BitConverter.ToInt16(data, 2) * (500f / 65536f), 
                 BitConverter.ToInt16(data, 4) * (500f / 65536f) };
         default:
             return new float[] { 0, 0, 0 };
     }
 }
Example #2
0
        /// <summary>
        /// Calculates the value of the different gyroscope axis and scales it.
        /// </summary>
        /// <param name="data">Complete array of data retrieved from the sensor</param>
        /// <param name="axis">Specifies the axis the gyroscope was configured to read</param>
        /// <returns>Array of float with values in order of the GyroscopeAxis enum</returns>
        public static float[] CalculateAxisValue(byte[] data, GyroscopeAxis axis)
        {
            switch (axis)
            {
            case GyroscopeAxis.X:
            case GyroscopeAxis.Y:
            case GyroscopeAxis.Z:
                return(new float[] { BitConverter.ToInt16(data, 0) * (500f / 65536f) });

            case GyroscopeAxis.XY:
            case GyroscopeAxis.XZ:
            case GyroscopeAxis.YZ:
                return(new float[] { BitConverter.ToInt16(data, 0) * (500f / 65536f),
                                     BitConverter.ToInt16(data, 2) * (500f / 65536f) });

            case GyroscopeAxis.XYZ:
                return(new float[] { BitConverter.ToInt16(data, 0) * (500f / 65536f),
                                     BitConverter.ToInt16(data, 2) * (500f / 65536f),
                                     BitConverter.ToInt16(data, 4) * (500f / 65536f) });

            default:
                return(new float[] { 0, 0, 0 });
            }
        }
Example #3
0
 /// <summary>
 /// Enables the sensor with the specified axis
 /// </summary>
 /// <param name="gyroscopeAxis">axis you want to record</param>
 /// <returns></returns>
 /// <exception cref="DeviceUnreachableException">Thrown if it wasn't possible to communicate with the device.</exception>
 /// <exception cref="DeviceNotInitializedException">Thrown if sensor has not been initialized successfully.</exception>
 public async Task EnableSensor(GyroscopeAxis gyroscopeAxis)
 {
     Validator.Requires <DeviceNotInitializedException>(deviceService != null);
     this.gyroscopeAxis = gyroscopeAxis;
     await base.EnableSensor(new byte[] { (byte)gyroscopeAxis });
 }
 /// <summary>
 /// Enables the sensor with the specified axis
 /// </summary>
 /// <param name="gyroscopeAxis">axis you want to record</param>
 /// <returns></returns>
 /// <exception cref="DeviceUnreachableException">Thrown if it wasn't possible to communicate with the device.</exception>
 /// <exception cref="DeviceNotInitializedException">Thrown if sensor has not been initialized successfully.</exception>
 public async Task EnableSensor(GyroscopeAxis gyroscopeAxis)
 {
     Validator.Requires<DeviceNotInitializedException>(deviceService != null);
     this.gyroscopeAxis = gyroscopeAxis;
     await base.EnableSensor(new byte[] { (byte)gyroscopeAxis });
 }