public void GetAndSendAccelero(Windows.Devices.Sensors.Accelerometer accel)
        {
            var read = accel.GetCurrentReading();
            var str  = "IMU: " + read.Timestamp.TimeOfDay.ToString() + " " /*+ "X "*/ + read.AccelerationX.ToString("0.0") + " " + /* "Y " +*/ read.AccelerationY.ToString("0.0") + " " /* + "Z " */ + read.AccelerationZ.ToString("0.0") + "\n";

            Send(str);
        }
        private static Vector3 GetAcceleration(WindowsAccelerometer accelerometer)
        {
            var currentReading = accelerometer.GetCurrentReading();

            if (currentReading == null)
            {
                return(Vector3.Zero);
            }

            return(G * new Vector3((float)currentReading.AccelerationX, (float)currentReading.AccelerationZ, -(float)currentReading.AccelerationY));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the current accelerometer reading.
        /// </summary>
        /// <returns></returns>
        public AccelerometerReading GetCurrentReading()
        {
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP
            return(_accelerometer.GetCurrentReading());
#elif __IOS__
            return(_manager.AccelerometerData);
#elif TIZEN
            return(new AccelerometerReading(_accelerometer.X, _accelerometer.Y, _accelerometer.Z, DateTimeOffset.Now));
#else
            throw new PlatformNotSupportedException();
#endif
        }
Exemplo n.º 4
0
        /// <summary>
        /// Formats current coordinates into JSON format
        /// </summary>
        /// <returns>Coordinates in JSON format</returns>
        private string GetCurrentAccelerationFormatted()
        {
            try
            {
                var currentReading     = accelerometer.GetCurrentReading();
                var currentCoordinates = String.Format("\"x\":{0},\"y\":{1},\"z\":{2}",
                                                       (currentReading.AccelerationX * gConstant).ToString("0.00000", CultureInfo.InvariantCulture),
                                                       (currentReading.AccelerationY * gConstant).ToString("0.00000", CultureInfo.InvariantCulture),
                                                       (currentReading.AccelerationZ * gConstant).ToString("0.00000", CultureInfo.InvariantCulture));

                return("{" + currentCoordinates + "}");
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        private static Vector3 GetAcceleration(WindowsAccelerometer accelerometer)
        {
            var currentReading = accelerometer.GetCurrentReading();
            if(currentReading == null)
                return Vector3.Zero;

            return G * new Vector3((float)currentReading.AccelerationX, (float)currentReading.AccelerationZ, -(float)currentReading.AccelerationY);
        }