Esempio n. 1
0
        public void getAcceleration(string options)
        {
            try
            {
                if (this.accelerometer == null)
                {
                    this.accelerometer = new Microsoft.Devices.Sensors.Accelerometer();
                }

                this.accelerometer.CurrentValueChanged += new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(accelerometer_CurrentValueChanged);
                this.accelerometer.Start();
            }
            catch (UnauthorizedAccessException ex1)
            {
                //this.CallbackName = this.errorCallback;
                //this.CallbackArgs = new[] { unauthorizedAccessException.Message };
                //this.SendAsyncResponse();
            }
            catch (AccelerometerFailedException ex2)
            {
                //this.CallbackName = this.errorCallback;
                //this.CallbackArgs = new[] { accelerometerFailedException.Message };
                //this.SendAsyncResponse();
            }
        }
        private void Calibrate()
        {
            //Initialize the accelerometer
            accelerometer = new Microsoft.Devices.Sensors.Accelerometer();

            if (accelerometer.State == SensorState.Initializing ||
                accelerometer.State == SensorState.Ready)
            {
                accelerometer.ReadingChanged += (s, e) =>
                {
                    accelerometerState =
                        new Vector3((float)e.X, (float)e.Y, (float)e.Z);

                    samplesCount++;
                    accelerometerCalibrationData += accelerometerState;

                    if (DateTime.Now >= startTime.AddSeconds(5))
                    {
                        accelerometer.Stop();

                        accelerometerCalibrationData.X /= samplesCount;
                        accelerometerCalibrationData.Y /= samplesCount;
                        accelerometerCalibrationData.Z /= samplesCount;

                        isCalibrating = false;
                    }
                };
            }
            accelerometer.Start();
        }
Esempio n. 3
0
 public Accelerometer()
 {
     _meter = new Microsoft.Devices.Sensors.Accelerometer
              {
                  TimeBetweenUpdates = TimeSpan.FromMilliseconds(100)
              };
     _meter.CurrentValueChanged += CurrentValueChanged;
 }
 /// <summary>
 /// Stops this instance.
 /// </summary>
 partial void Stop()
 {
     if (this.accelerometer != null)
     {
         this.accelerometer.CurrentValueChanged -= AccelerometerOnCurrentValueChanged;
         this.accelerometer.Stop();
         this.accelerometer = null;
     }
 }
		/// <summary>
		/// Stops this instance.
		/// </summary>
		partial void Stop()
		{
			if (this.accelerometer != null)
			{
				this.accelerometer.CurrentValueChanged -= AccelerometerOnCurrentValueChanged;
				this.accelerometer.Stop();
				this.accelerometer = null;
			}
		}
Esempio n. 6
0
 public void Stop()
 {
     if (_accelerometer == null)
     {
         throw new MvxException("Accelerometer not started");
     }
     _accelerometer.Stop();
     _accelerometer = null;
 }
		/// <summary>
		/// Stops this instance.
		/// </summary>
		partial void Stop()
		{
			if (_accelerometer != null)
			{
				_accelerometer.CurrentValueChanged -= AccelerometerOnCurrentValueChanged;
				_accelerometer.Stop();
				_accelerometer = null;
			}
		}
 /// <summary>
 /// Stops this instance.
 /// </summary>
 partial void Stop()
 {
     if (_accelerometer != null)
     {
         _accelerometer.CurrentValueChanged -= AccelerometerOnCurrentValueChanged;
         _accelerometer.Stop();
         _accelerometer = null;
     }
 }
Esempio n. 9
0
 public void Stop()
 {
     if (_accelerometer == null)
     {
         throw new MvxException("Accelerometer not started");
     }
     _accelerometer.Stop();
     _accelerometer = null;
 }
Esempio n. 10
0
 public void Start()
 {
     if (_accelerometer != null)
     {
         throw new MvxException("Accelerometer already started");
     }
     _accelerometer = new Microsoft.Devices.Sensors.Accelerometer();
     _accelerometer.CurrentValueChanged += AccelerometerOnCurrentValueChanged;
     _accelerometer.Start();
 }
Esempio n. 11
0
 public void Start()
 {
     if (_accelerometer != null)
     {
         throw new MvxException("Accelerometer already started");
     }
     _accelerometer = new Microsoft.Devices.Sensors.Accelerometer();
     _accelerometer.CurrentValueChanged += AccelerometerOnCurrentValueChanged;
     _accelerometer.Start();
 }
Esempio n. 12
0
		/// <summary>
		/// Starts this instance.
		/// </summary>
		partial void Start()
		{
			this.accelerometer = new Microsoft.Devices.Sensors.Accelerometer
				                 {
					                 TimeBetweenUpdates =
						                 TimeSpan.FromMilliseconds((long)Interval)
				                 };

			this.accelerometer.CurrentValueChanged += AccelerometerOnCurrentValueChanged;
			this.accelerometer.Start();
		}
        /// <summary>
        /// Starts this instance.
        /// </summary>
        partial void Start()
        {
            this.accelerometer = new Microsoft.Devices.Sensors.Accelerometer
            {
                TimeBetweenUpdates =
                    TimeSpan.FromMilliseconds((long)Interval)
            };

            this.accelerometer.CurrentValueChanged += AccelerometerOnCurrentValueChanged;
            this.accelerometer.Start();
        }
Esempio n. 14
0
        /// <summary>
        /// Starts listening for acceleration sensor
        /// </summary>
        /// <returns>status of listener</returns>
        public void start(string parameters)
        {
            string[] args = WPCordovaClassLib.Cordova.JSON.JsonHelper.Deserialize <string[]>(parameters);

            string time = "1000";

            if (args.Length > 0)
            {
                time = args[0];
            }

            // account for the callback param
            if (args.Length > 2)
            {
                adjustForRotation = bool.Parse(args[1]);
            }

            // account for the callback param
            if (args.Length > 3)
            {
                orientation = args[2];
            }

            if (!this.isRunning)
            {
                if (this._accelerometer == null)
                {
                    _accelerometer = new Microsoft.Devices.Sensors.Accelerometer();
                }

                int tmpTime;
                int.TryParse(time, out tmpTime);

                this.time = tmpTime;
                try
                {
                    lock (_accelerometer)
                    {
                        _accelerometer = new Microsoft.Devices.Sensors.Accelerometer();
                        _accelerometer.TimeBetweenUpdates   = TimeSpan.FromMilliseconds(this.time);
                        _accelerometer.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <AccelerometerReading> >(accelerometer_CurrentValueChanged);

                        this.isRunning = true;
                        _accelerometer.Start();
                    }
                }
                catch (Exception)
                {
                }
            }
        }
Esempio n. 15
0
        public Accelerometer()
        {
            accelerometer = new Microsoft.Devices.Sensors.Accelerometer();

            if (Motion.IsSupported)
            {
                if (motion == null)
                {
                    motion = new Motion();
                    motion.TimeBetweenUpdates   = TimeSpan.FromMilliseconds(20);
                    motion.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <MotionReading> >(motion_CurrentValueChanged);
                }
            }
        }
Esempio n. 16
0
        void accelerometer_CurrentValueChanged(object sender, SensorReadingEventArgs<AccelerometerReading> e)
        {
            if (this.accelerometer != null)
            {
                SensorState state = this.accelerometer.State;

                // TODO: switch on sensor state
                if (state == SensorState.Ready)
                {

                    string messageResult = String.Format("\"x\":{0},\"y\":{1},\"z\":{2}",
                                                e.SensorReading.Acceleration.X.ToString("0.00000"),
                                                e.SensorReading.Acceleration.Y.ToString("0.00000"),
                                                e.SensorReading.Acceleration.Z.ToString("0.00000"));

                    messageResult = "{" + messageResult + "}";

                    DispatchCommandResult(new PluginResult(PluginResult.Status.OK, messageResult));
                }
                else
                {
                    //this.CallbackName = this.errorCallback;
                    //this.CallbackArgs = new[] { state.ToString() };
                    //this.SendAsyncResponse();
                }

                try
                {
                    this.accelerometer.Stop();
                    this.accelerometer.Dispose();
                    this.accelerometer = null;
                }
                catch
                {
                    // NOOP - We don't, currently, care if we can't stop the accelerometer
                }
            }
        }
 public AccelerometerWrapperWindowsPhone()
 {
     _accelerometer = new Accelerometer();
 }
Esempio n. 18
0
 public Accelerometer()
 {
     accelerometer = new Microsoft.Devices.Sensors.Accelerometer();
 }