private void LoadGyros(Object sender, RoutedEventArgs e) { Gyr = new Gyroscope(); Gyr.TimeBetweenUpdates = TimeSpan.FromMilliseconds(5); Gyr.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <GyroscopeReading> >(GyroHandler); Gyr.Start(); }
public void ToggleGyroscope() { try { if (Gyroscope.IsMonitoring) { Gyroscope.Stop(); this.Started = false; Console.WriteLine("Gyroscope is stoped"); } else { Gyroscope.Start(Speed); this.Started = true; Console.WriteLine("Gyroscope is started"); } } catch (FeatureNotSupportedException fnsEx) { Console.WriteLine("Non Pris en charge" + fnsEx); } catch (Exception ex) { Console.WriteLine("Une Exception s'est produite" + ex); } }
public void ToggleGyroscope() { // The Main Thread - To start the code on Main Thread MainThread.BeginInvokeOnMainThread(() => { try { if (Gyroscope.IsMonitoring) { Console.WriteLine("Gyroscope Stoped"); Gyroscope.Stop(); Console.WriteLine("Gyroscope Stoped - isStarted : " + isStarted); } else { Console.WriteLine("Gyroscope Started"); Gyroscope.Start(speed); this.isStarted = true; Console.WriteLine("Gyroscope Started - isStarted : " + isStarted); } } catch (FeatureNotSupportedException fnsEx) { // Feature not supported on device } catch (Exception ex) { // Other error has occurred. } }); }
public void ToggleGyroscope() { try { if (Gyroscope.IsMonitoring) { Gyroscope.Stop(); isStarted = false; } else { Gyroscope.Start(speed); isStarted = true; } } catch (FeatureNotSupportedException fnsEx) { // Feature not supported on device throw fnsEx.InnerException; } catch (Exception ex) { // Other error has occurred. throw ex.InnerException; } }
public void GyroscopeSwitch_Toggled(object sender, ToggledEventArgs e) { try { if (e.Value && !Gyroscope.IsMonitoring) { Gyroscope.ReadingChanged += Gyroscope_ReadingChanged; Gyroscope.Start(speed); } else if (!e.Value && Gyroscope.IsMonitoring) { Gyroscope.Stop(); Gyroscope.ReadingChanged -= Gyroscope_ReadingChanged; GyroscopeMin = null; GyroscopeMax = null; } } catch (FeatureNotSupportedException) { // Feature not supported on device } catch (Exception) { // Other error has occurred. } }
public async Task Stop_Monitor(SensorSpeed sensorSpeed) { // TODO: the test runner app (UI version) should do this, until then... if (!HardwareSupport.HasGyroscope) { return; } var tcs = new TaskCompletionSource <GyroscopeData>(); Gyroscope.ReadingChanged += Gyroscope_ReadingChanged; Gyroscope.Start(sensorSpeed); void Gyroscope_ReadingChanged(object sender, GyroscopeChangedEventArgs e) { tcs.TrySetResult(e.Reading); } var d = await tcs.Task; Gyroscope.Stop(); Gyroscope.ReadingChanged -= Gyroscope_ReadingChanged; Assert.False(Gyroscope.IsMonitoring); }
public IObservable <MotionReading> WhenReadingTaken() { this.observable = this.observable ?? Observable.Create <MotionReading>(ob => { var handler = new EventHandler <GyroscopeDataUpdatedEventArgs>((sender, args) => ob.OnNext(new MotionReading(args.X, args.Y, args.Z)) ); var sensor = new Gyroscope { Interval = 250 }; sensor.DataUpdated += handler; sensor.Start(); return(() => { sensor.Stop(); sensor.DataUpdated -= handler; sensor.Dispose(); }); }) .Publish() .RefCount(); return(this.observable); }
public override void OnAppearing() { try { Magnetometer.ReadingChanged += OnMagnetometerReadingChanged; if (!Magnetometer.IsMonitoring) { Magnetometer.Start(SensorSpeed.UI); } Accelerometer.ShakeDetected += OnShakeDetected; Accelerometer.ReadingChanged += OnAccelerometerReadingChanged; if (!Accelerometer.IsMonitoring) { Accelerometer.Start(SensorSpeed.UI); } Gyroscope.ReadingChanged += OnGyroscopeReadingChanged; if (!Gyroscope.IsMonitoring) { Gyroscope.Start(SensorSpeed.UI); } } catch (FeatureNotSupportedException ex) { Logger.Debug("Feature not supported: " + ex.Message); } }
public void ToggleGyroscope() { try { if (Gyroscope.IsMonitoring) { Gyroscope.Stop(); this.lblResult.Text += "Stop!!!" + Environment.NewLine; } else { Gyroscope.Start(speed); this.lblResult.Text = ""; } } catch (FeatureNotSupportedException fnsEx) { // Feature not supported on device this.lblResult.Text = fnsEx.ToString(); } catch (Exception ex) { // Other error has occurred. this.lblResult.Text = ex.ToString(); } }
public void ToggleMetrics(bool isToogled) { try { if (isToogled) { Accelerometer.Start(speed); //Barometer.Start(speed); Compass.Start(speed); Gyroscope.Start(speed); Magnetometer.Start(speed); OrientationSensor.Start(speed); } else { Accelerometer.Stop(); //Barometer.Stop(); Compass.Stop(); Gyroscope.Stop(); Magnetometer.Stop(); OrientationSensor.Stop(); } } catch (FeatureNotSupportedException) { ShowNotSupportedError(); } catch (Exception ex) { ShowError(ex.Message); } }
private void start_Click(object sender, EventArgs e) { if (!timer.IsEnabled) { string runningMessage = "Reading: "; if (Accelerometer.IsSupported) { accelSensor.Start(); runningMessage += "Accelerometer "; } if (Compass.IsSupported) { compassSensor.Start(); runningMessage += "Compass "; } if (Gyroscope.IsSupported) { gyroSensor.Start(); runningMessage += "Gyroscope "; } timer.Start(); messageBlock.Text = runningMessage; } }
public void ControlSunscribe(bool flag) { try { if (Gyroscope.IsMonitoring && !flag) { Gyroscope.Stop(); GyroWatch.Reset(); } else if (!Gyroscope.IsMonitoring && flag) { GyroWatch.Start(); Gyroscope.Start(Config.sensorSpeed); } else { //Dont think anything is needed here } } catch (FeatureNotEnabledException ex) { } catch (Exception ex) { } }
protected override void OnAppearing() { Accelerometer.Start(SensorSpeed.UI); Gyroscope.Start(SensorSpeed.UI); Magnetometer.Start(SensorSpeed.UI); Compass.Start(SensorSpeed.UI); base.OnAppearing(); }
public void StartReading(int reportInterval = -1) { if (reportInterval >= 0) { _gyroscope.Interval = (uint)reportInterval; } _gyroscope.DataUpdated += GyrosocopeReadingChanged; _gyroscope.Start(); }
private void PositionChanged(object sender, PositionEventArgs e) { Gyroscope.Stop(); if (updatePosition != null && lastPosition.Latitude != e.Position.Latitude && lastPosition.Longitude != e.Position.Longitude) { updatePosition(e.Position); } Gyroscope.Start(SensorSpeed.UI); }
public DeviceStatus start() { if (_gyroscope != null) { _gyroscope.Start(); _timer.Start(); return(DeviceStatus.DEVICE_OK); } else { return(DeviceStatus.DEVICE_ERROR); } }
public GyroscopeSamplePage() { InitializeComponent(); Loaded += (s, e) => { if (Gyroscope.IsSupported) { _g = new Gyroscope(); _g.CurrentValueChanged += GyroscopeCurrentValueChanged; _g.Start(); } }; }
/// <summary> /// Starts sensor and registers listener to a sensor /// </summary> /// <param name="listener">Event handler to listen sensor events</param> public void Start(EventHandler <SensorEventArgs> listener) { handler = (sender, e) => { listener?.Invoke(this, new SensorEventArgs(new List <float>() { e.X, e.Y, e.Z })); }; sensor.DataUpdated += handler; sensor.Start(); }
public async Task StartTracking(Action <Position> actionPosition) { updatePosition = actionPosition; if (CrossGeolocator.Current.IsListening) { return; } CrossGeolocator.Current.PositionChanged += PositionChanged; await CrossGeolocator.Current.StartListeningAsync(TimeSpan.FromSeconds(5), 2, true); Gyroscope.Start(SensorSpeed.UI); }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); if (!Gyroscope.IsSupported) { MessageBox.Show("Ihr Gerät verfügt über keinem Gyroskope!"); return; } lastTimestamp = DateTimeOffset.MinValue; gyro = new Gyroscope(); gyro.CurrentValueChanged += gyro_CurrentValueChanged; gyro.TimeBetweenUpdates = TimeSpan.FromMilliseconds(100); gyro.Start(); }
public void StartSensors() { try { Accelerometer.Start(SensorSpeed.Default); Magnetometer.Start(SensorSpeed.Default); Gyroscope.Start(SensorSpeed.Default); OrientationSensor.Start(SensorSpeed.Default); Accelerometer.ReadingChanged += Accelerometer_ReadingChanged; Magnetometer.ReadingChanged += Magnetometer_ReadingChanged; Gyroscope.ReadingChanged += Gyrotometer_ReadingChanged; OrientationSensor.ReadingChanged += OrientationSensor_ReadingChanged; } catch (Exception EX) { //Log.Error(TAG, EX.GetBaseException().ToString()); } }
private void button1_Click(object sender, RoutedEventArgs e) { if (!timer.IsEnabled) { string runningMessage = "Reading Acelerometro: "; textBlock2.Text = "Reading Magnetic: "; textBlock3.Text = "Reading Gyroscope: "; textBlock4.Text = "Reading Gravity: "; textBlock5.Text = "Reading Attitude: "; timer.Start(); textBlock1.Text = runningMessage; } if (Accelerometer.IsSupported) { accelSensor.Start(); runningMessage += "Accelerometer "; } if (Compass.IsSupported) { compassSensor.Start(); } else { compassX.Text = "Magnetic no soportada"; } if (Gyroscope.IsSupported) { gyroSensor.Start(); } else { gyroX.Text = "Gyroscope no soportada"; } if (Motion.IsSupported) { sensor.Start(); } else { attitudeX.Text = "Attude no soportada"; gravityX.Text = "Gravity no soportada"; } }
public ApplicationPage() { stopPressed = false; InitializeComponent(); MessagingCenter.Subscribe <SettingsPage, string>(this, "telefon", (sender, arg) => { telephone.Text = arg; }); //MessagingCenter.Subscribe<SettingsPage, string>(this, "lab", (sender, arg) => //{ // LOWER_ACCEL_BOUNDRY = Convert.ToDouble(arg); //}); //MessagingCenter.Subscribe<SettingsPage, string>(this, "uab", (sender, arg) => //{ // UPPER_ACCEL_BOUNDRY = Convert.ToDouble(arg); //}); //MessagingCenter.Subscribe<SettingsPage, string>(this, "mra", (sender, arg) => //{ // MAX_RESTING_AMPLITUDE = Convert.ToDouble(arg); //}); //MessagingCenter.Subscribe<SettingsPage, string>(this, "mav", (sender, arg) => //{ // MAX_ANGULAR_VELOCITY = Convert.ToDouble(arg); //}); if (!Accelerometer.IsMonitoring) { Accelerometer.ReadingChanged += Accelerometer_ReadingChanged; Accelerometer.Start(SensorSpeed.UI); } if (!Gyroscope.IsMonitoring) { Gyroscope.ReadingChanged += Gyroscope_ReadingChanged; Gyroscope.Start(SensorSpeed.UI); } FallTest(); }
private void Abilities_Appearing(object sender, EventArgs e) { try { if (!Accelerometer.IsMonitoring) { Accelerometer.ShakeDetected += Accelerometer_ShakeDetected; Accelerometer.Start(SensorSpeed.Game); } } catch { } try { if (!Gyroscope.IsMonitoring) { Gyroscope.ReadingChanged += Gyroscope_ReadingChanged; Gyroscope.Start(SensorSpeed.Game); } } catch { } }
private void ApplicationBarIconButton_Click(object sender, EventArgs e) { if (gyroscope != null && gyroscope.IsDataValid) { // Stop data acquisition from the gyroscope. gyroscope.Stop(); timer.Stop(); statusTextBlock.Text = "gyroscope stopped."; } else { if (gyroscope == null) { // Instantiate the Gyroscope. gyroscope = new Gyroscope(); // Specify the desired time between updates. The sensor accepts // intervals in multiples of 20 ms. gyroscope.TimeBetweenUpdates = TimeSpan.FromMilliseconds(20); // The sensor may not support the requested time between updates. // The TimeBetweenUpdates property reflects the actual rate. timeBetweenUpdatesTextBlock.Text = "time between updates: " + gyroscope.TimeBetweenUpdates.TotalMilliseconds + " ms"; gyroscope.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <GyroscopeReading> >(gyroscope_CurrentValueChanged); } try { statusTextBlock.Text = "starting gyroscope."; gyroscope.Start(); timer.Start(); } catch (InvalidOperationException) { statusTextBlock.Text = "unable to start gyroscope."; } } }
private void Button_OnClicked(object sender, EventArgs e) { try { if (Gyroscope.IsMonitoring) { Gyroscope.Stop(); } else { Gyroscope.Start(speed); } } catch (FeatureNotSupportedException fnsEx) { // Feature not supported on device } catch (Exception ex) { // Other error has occurred. } }
public async Task Monitor(SensorSpeed sensorSpeed) { if (!TestSupported) { return; } var tcs = new TaskCompletionSource <GyroscopeData>(); Gyroscope.ReadingChanged += Gyroscope_ReadingChanged; Gyroscope.Start(sensorSpeed); void Gyroscope_ReadingChanged(GyroscopeChangedEventArgs e) { tcs.TrySetResult(e.Reading); } var d = await tcs.Task; Gyroscope.Stop(); Gyroscope.ReadingChanged -= Gyroscope_ReadingChanged; }
public void ToggleGyroscope() { try { if (Gyroscope.IsMonitoring) { Gyroscope.Stop(); } else { Gyroscope.Start(speed); } } catch (FeatureNotSupportedException fnsEx) { // Feature not supported on device } catch (Exception ex) { // Other error has occurred. } }
void Start() { this._sensingData.ID = "charlie"; this._sensingData.DeviceName = DeviceInfo.Name; if (!Compass.IsMonitoring) { Compass.ReadingChanged += Compass_ReadingChanged; Compass.Start(SensorSpeed.Fastest); } if (!Accelerometer.IsMonitoring) { Accelerometer.ReadingChanged += Accelerometer_Essentials_ReadingChanged; Accelerometer.Start(SensorSpeed.Fastest); } if (!Gyroscope.IsMonitoring) { Gyroscope.ReadingChanged += Gyroscope_ReadingChanged; Gyroscope.Start(SensorSpeed.Fastest); } if (!Magnetometer.IsMonitoring) { Magnetometer.ReadingChanged += Magnetometer_ReadingChanged; Magnetometer.Start(SensorSpeed.Fastest); } // device-specific sensor readings if (Device.RuntimePlatform.Equals((Device.Android))) { MessagingCenter.Subscribe <Sensors.Android.LinearAcceleration>(this, Sensors.Android.SubscriberMessage.LinearAcceleration, (linear_acceleration) => { this.LinearAccelerometer_Android_ReadingChanged(linear_acceleration); }); } }
private void startButton_Click(object sender, RoutedEventArgs e) { if (accelerometer == null) { // Instantiate the Accelerometer. accelerometer = new Accelerometer(); //accelerometer.TimeBetweenUpdates = TimeSpan.FromMilliseconds(200); accelerometer.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <AccelerometerReading> >(accelerometer_CurrentValueChanged); } if (gyroscope == null) { // Instantiate the Accelerometer. gyroscope = new Gyroscope(); // gyroscope.TimeBetweenUpdates = TimeSpan.FromMilliseconds(200); gyroscope.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <GyroscopeReading> >(gyroscope_CurrentValueChanged); } try { accOutput.Text = "starting accelerometer."; accelerometer.Start(); } catch (InvalidOperationException ex) { accOutput.Text = "unable to start accelerometer."; } try { gyrOutput.Text = "starting gyroscope."; gyroscope.Start(); } catch (InvalidOperationException ex) { gyrOutput.Text = "unable to start gyroscope."; } }
private void Btn_Iniciar_Click(object sender, RoutedEventArgs e) { if(Gyroscope.IsSupported){ if(!vEstado) { giroscopio = new Gyroscope(); giroscopio.TimeBetweenUpdates = TimeSpan.FromMilliseconds(2); giroscopio.CurrentValueChanged += giroscopio_CurrentValueChanged; giroscopio.Start(); Btn_Iniciar.Content = "Apagar Giroscopio"; vEstado = true; } else { Btn_Iniciar.Content = "Iniciar Giroscopio"; vEstado = false; giroscopio.Stop(); } } else { MessageBox.Show("El dispositivo no cuenta con Giroscopio", "Giroscopio", MessageBoxButton.OK); } }
public void Init(Ioctls ioctls, Core core, Runtime runtime) { ioctls.maSensorStart = delegate(int _sensor, int _interval) { _interval = GetSensorIntervalDefaults(_interval); TimeSpan time = TimeSpan.FromMilliseconds((double)_interval); if (_sensor == MoSync.Constants.SENSOR_TYPE_ACCELEROMETER && Accelerometer.IsSupported) { mAccelerometer = new Accelerometer(); mAccelerometer.TimeBetweenUpdates = time; mAccelerometer.CurrentValueChanged += delegate(object sender, SensorReadingEventArgs<AccelerometerReading> args) { Vector3 acc = args.SensorReading.Acceleration; SendSensorEventVector(runtime, MoSync.Constants.SENSOR_TYPE_ACCELEROMETER, acc); }; mAccelerometer.Start(); } else if (_sensor == MoSync.Constants.SENSOR_TYPE_GYROSCOPE && Gyroscope.IsSupported) { mGyroscope = new Gyroscope(); mGyroscope.TimeBetweenUpdates = time; mGyroscope.CurrentValueChanged += delegate(object sender, SensorReadingEventArgs<GyroscopeReading> args) { Vector3 rot = args.SensorReading.RotationRate; SendSensorEventVector(runtime, MoSync.Constants.SENSOR_TYPE_GYROSCOPE, rot); }; mGyroscope.Start(); } else if (_sensor == MoSync.Constants.SENSOR_TYPE_MAGNETIC_FIELD && Compass.IsSupported) { mCompass = new Compass(); mCompass.TimeBetweenUpdates = time; mCompass.CurrentValueChanged += delegate(object sender, SensorReadingEventArgs<CompassReading> args) { Vector3 rot = args.SensorReading.MagnetometerReading; SendSensorEventVector(runtime, MoSync.Constants.SENSOR_TYPE_MAGNETIC_FIELD, rot); }; mCompass.Start(); } #if false else if (_sensor == MoSync.Constants.SENSOR_TYPE_ORIENTATION && Motion.IsSupported) { mMotion = new Motion(); mMotion.TimeBetweenUpdates = new TimeSpan(intervalIn100Nanoseconds); mMotion.CurrentValueChanged += delegate(object sender, SensorReadingEventArgs<MotionReading> args) { }; } #endif else return MoSync.Constants.SENSOR_ERROR_NOT_AVAILABLE; return MoSync.Constants.SENSOR_ERROR_NONE; }; ioctls.maSensorStop = delegate(int _sensor) { switch (_sensor) { case MoSync.Constants.SENSOR_TYPE_ACCELEROMETER: if (mAccelerometer != null) { mAccelerometer.Stop(); mAccelerometer = null; } break; case MoSync.Constants.SENSOR_TYPE_GYROSCOPE: if (mGyroscope != null) { mGyroscope.Stop(); mGyroscope = null; } break; case MoSync.Constants.SENSOR_TYPE_MAGNETIC_FIELD: if (mCompass != null) { mCompass.Stop(); mCompass = null; } break; case MoSync.Constants.SENSOR_TYPE_ORIENTATION: if (mMotion != null) { mMotion.Stop(); mMotion = null; } break; } return MoSync.Constants.SENSOR_ERROR_NONE; }; ioctls.maLocationStart = delegate() { if (mGeoWatcher == null) { mGeoWatcher = new GeoCoordinateWatcher(); mGeoWatcher.MovementThreshold = 20; mGeoWatcher.StatusChanged += delegate(object sender, GeoPositionStatusChangedEventArgs args) { }; mGeoWatcher.PositionChanged += delegate(object sender, GeoPositionChangedEventArgs<GeoCoordinate> args) { }; mGeoWatcher.Start(); } return 0; }; ioctls.maLocationStop = delegate() { if (mGeoWatcher != null) { mGeoWatcher.Stop(); mGeoWatcher = null; } return 0; }; }
public void Init(Ioctls ioctls, Core core, Runtime runtime) { ioctls.maSensorStart = delegate(int _sensor, int _interval) { _interval = GetSensorIntervalDefaults(_interval); TimeSpan time = TimeSpan.FromMilliseconds((double)_interval); if (_sensor == MoSync.Constants.SENSOR_TYPE_ACCELEROMETER && Accelerometer.IsSupported) { if (mAccelerometer != null) return MoSync.Constants.SENSOR_ERROR_ALREADY_ENABLED; mAccelerometer = new Accelerometer(); mAccelerometer.TimeBetweenUpdates = time; mAccelerometer.CurrentValueChanged += delegate(object sender, SensorReadingEventArgs<AccelerometerReading> args) { Vector3 acc = args.SensorReading.Acceleration; SendSensorEventVector(runtime, MoSync.Constants.SENSOR_TYPE_ACCELEROMETER, acc); }; mAccelerometer.Start(); } else if (_sensor == MoSync.Constants.SENSOR_TYPE_GYROSCOPE && Gyroscope.IsSupported) { if (mGyroscope != null) return MoSync.Constants.SENSOR_ERROR_ALREADY_ENABLED; mGyroscope = new Gyroscope(); mGyroscope.TimeBetweenUpdates = time; mGyroscope.CurrentValueChanged += delegate(object sender, SensorReadingEventArgs<GyroscopeReading> args) { Vector3 rot = args.SensorReading.RotationRate; SendSensorEventVector(runtime, MoSync.Constants.SENSOR_TYPE_GYROSCOPE, rot); }; mGyroscope.Start(); } else if ((_sensor == MoSync.Constants.SENSOR_TYPE_MAGNETIC_FIELD || _sensor == MoSync.Constants.SENSOR_TYPE_COMPASS) && Compass.IsSupported) { if (_sensor == MoSync.Constants.SENSOR_TYPE_MAGNETIC_FIELD && mMagneticFieldEnabled == true) return MoSync.Constants.SENSOR_ERROR_ALREADY_ENABLED; if (_sensor == MoSync.Constants.SENSOR_TYPE_COMPASS && mCompassEnabled == true) return MoSync.Constants.SENSOR_ERROR_ALREADY_ENABLED; if (mCompass == null) { mCompass = new Compass(); mCompass.TimeBetweenUpdates = time; } else { if(time < mCompass.TimeBetweenUpdates) mCompass.TimeBetweenUpdates = time; } if (mCompassEnabled == false && mMagneticFieldEnabled == false) { mCompass.CurrentValueChanged += delegate(object sender, SensorReadingEventArgs<CompassReading> args) { if (mMagneticFieldEnabled) { Vector3 rot = args.SensorReading.MagnetometerReading; SendSensorEventVector(runtime, MoSync.Constants.SENSOR_TYPE_MAGNETIC_FIELD, rot); } if (mCompassEnabled) { Vector3 heading = new Vector3(); heading.X = (float)args.SensorReading.MagneticHeading; SendSensorEventVector(runtime, MoSync.Constants.SENSOR_TYPE_COMPASS, heading); } }; mCompass.Start(); } if (_sensor == MoSync.Constants.SENSOR_TYPE_MAGNETIC_FIELD) mMagneticFieldEnabled = true; else if (_sensor == MoSync.Constants.SENSOR_TYPE_COMPASS) mCompassEnabled = true; } #if false else if (_sensor == MoSync.Constants.SENSOR_TYPE_ORIENTATION && Motion.IsSupported) { mMotion = new Motion(); mMotion.TimeBetweenUpdates = new TimeSpan(intervalIn100Nanoseconds); mMotion.CurrentValueChanged += delegate(object sender, SensorReadingEventArgs<MotionReading> args) { }; } #endif else return MoSync.Constants.SENSOR_ERROR_NOT_AVAILABLE; return MoSync.Constants.SENSOR_ERROR_NONE; }; ioctls.maSensorStop = delegate(int _sensor) { switch (_sensor) { case MoSync.Constants.SENSOR_TYPE_ACCELEROMETER: if (mAccelerometer != null) { mAccelerometer.Stop(); mAccelerometer = null; } else { return MoSync.Constants.SENSOR_ERROR_NOT_ENABLED; } break; case MoSync.Constants.SENSOR_TYPE_GYROSCOPE: if (mGyroscope != null) { mGyroscope.Stop(); mGyroscope = null; } else { return MoSync.Constants.SENSOR_ERROR_NOT_ENABLED; } break; case MoSync.Constants.SENSOR_TYPE_MAGNETIC_FIELD: if(!mMagneticFieldEnabled) return MoSync.Constants.SENSOR_ERROR_NOT_ENABLED; if (mCompass != null && !mCompassEnabled) { mCompass.Stop(); mCompass = null; } mMagneticFieldEnabled = false; break; case MoSync.Constants.SENSOR_TYPE_COMPASS: if (!mCompassEnabled) return MoSync.Constants.SENSOR_ERROR_NOT_ENABLED; if (mCompass != null && !mMagneticFieldEnabled) { mCompass.Stop(); mCompass = null; } mCompassEnabled = false; break; case MoSync.Constants.SENSOR_TYPE_ORIENTATION: if (mMotion != null) { mMotion.Stop(); mMotion = null; } else { return MoSync.Constants.SENSOR_ERROR_NOT_ENABLED; } break; } return MoSync.Constants.SENSOR_ERROR_NONE; }; ioctls.maLocationStart = delegate() { if (mGeoWatcher == null) { mGeoWatcher = new GeoCoordinateWatcher(); //mGeoWatcher.MovementThreshold = 20; mGeoWatcher.StatusChanged += delegate(object sender, GeoPositionStatusChangedEventArgs args) { int maState; switch (args.Status) { case GeoPositionStatus.Disabled: maState = MoSync.Constants.MA_LPS_OUT_OF_SERVICE; break; case GeoPositionStatus.NoData: case GeoPositionStatus.Initializing: maState = MoSync.Constants.MA_LPS_TEMPORARILY_UNAVAILABLE; break; case GeoPositionStatus.Ready: maState = MoSync.Constants.MA_LPS_AVAILABLE; break; default: throw new Exception("invalid GeoPositionStatus"); } Memory evt = new Memory(2 * 4); evt.WriteInt32(MoSync.Struct.MAEvent.type, MoSync.Constants.EVENT_TYPE_LOCATION_PROVIDER); evt.WriteInt32(MoSync.Struct.MAEvent.state, maState); runtime.PostEvent(new Event(evt)); }; mGeoWatcher.PositionChanged += delegate(object sender, GeoPositionChangedEventArgs<GeoCoordinate> args) { int maValidity = args.Position.Location.IsUnknown ? MoSync.Constants.MA_LOC_INVALID : MoSync.Constants.MA_LOC_QUALIFIED; Memory evt = new Memory(4 + 4 * 8 + 4); GeoCoordinate l = args.Position.Location; evt.WriteInt32(MoSync.Struct.MALocation.state, maValidity); evt.WriteDouble(MoSync.Struct.MALocation.lat, l.Latitude); evt.WriteDouble(MoSync.Struct.MALocation.lon, l.Longitude); evt.WriteDouble(MoSync.Struct.MALocation.horzAcc, l.HorizontalAccuracy); evt.WriteDouble(MoSync.Struct.MALocation.vertAcc, l.VerticalAccuracy); evt.WriteFloat(MoSync.Struct.MALocation.alt, (float)l.Altitude); runtime.PostCustomEvent(MoSync.Constants.EVENT_TYPE_LOCATION, evt); }; mGeoWatcher.Start(); } return 0; }; ioctls.maLocationStop = delegate() { if (mGeoWatcher != null) { mGeoWatcher.Stop(); mGeoWatcher = null; } return 0; }; }