Esempio n. 1
0
        internal static void PlatformStart(SensorSpeed sensorSpeed)
        {
            var delay = SensorDelay.Normal;

            switch (sensorSpeed)
            {
            case SensorSpeed.Normal:
                delay = SensorDelay.Normal;
                break;

            case SensorSpeed.Fastest:
                delay = SensorDelay.Fastest;
                break;

            case SensorSpeed.Game:
                delay = SensorDelay.Game;
                break;

            case SensorSpeed.Ui:
                delay = SensorDelay.Ui;
                break;
            }

            accelerometer = Platform.SensorManager.GetDefaultSensor(SensorType.Accelerometer);
            magnetometer  = Platform.SensorManager.GetDefaultSensor(SensorType.MagneticField);
            listener      = new SensorListener(accelerometer, magnetometer, delay);
            Platform.SensorManager.RegisterListener(listener, accelerometer, delay);
            Platform.SensorManager.RegisterListener(listener, magnetometer, delay);
        }
Esempio n. 2
0
        internal static void PlatformStop()
        {
            if (listener == null)
            {
                return;
            }

            Platform.SensorManager.UnregisterListener(listener, accelerometer);
            Platform.SensorManager.UnregisterListener(listener, magnetometer);
            listener.Dispose();
            listener = null;
            magnetometer?.Dispose();
            magnetometer = null;
            accelerometer?.Dispose();
            accelerometer = null;
        }
Esempio n. 3
0
        internal static void PlatformStart(SensorSpeed sensorSpeed, Action <CompassData> handler)
        {
            var delay          = SensorDelay.Normal;
            var useSyncContext = false;

            switch (sensorSpeed)
            {
            case SensorSpeed.Normal:
                delay = SensorDelay.Normal;
                break;

            case SensorSpeed.Fastest:
                delay = SensorDelay.Fastest;
                break;

            case SensorSpeed.Game:
                delay          = SensorDelay.Game;
                useSyncContext = true;
                break;

            case SensorSpeed.Ui:
                delay          = SensorDelay.Ui;
                useSyncContext = true;
                break;
            }

            var sensorListener = new SensorListener(useSyncContext, handler, delay);

            MonitorCTS.Token.Register(CancelledToken, useSyncContext);

            void CancelledToken()
            {
                sensorListener.Dispose();
                sensorListener = null;
                DisposeToken();
            }
        }