Example #1
0
        /// <summary>
        /// Resets all sensors/gestures on the final device config to be false and sets the sensor update
        /// interval to the slowest speeds.
        /// </summary>
        private void ResetFinalDeviceConfig()
        {
            _finalWearableDeviceConfig.updateInterval = SensorUpdateInterval.ThreeHundredTwentyMs;

            // Set all sensor state and update intervals
            for (var i = 0; i < WearableConstants.SensorIds.Length; i++)
            {
                var finalSensorConfig = _finalWearableDeviceConfig.GetSensorConfig(WearableConstants.SensorIds[i]);
                finalSensorConfig.isEnabled = false;
            }

            // Set rotation source
            _finalWearableDeviceConfig.rotationSource = WearableConstants.DefaultRotationSource;

            // Set all gesture state
            for (var i = 0; i < WearableConstants.GestureIds.Length; i++)
            {
                if (WearableConstants.GestureIds[i] == GestureId.None)
                {
                    continue;
                }

                var finalGestureConfig = _finalWearableDeviceConfig.GetGestureConfig(WearableConstants.GestureIds[i]);
                finalGestureConfig.isEnabled = false;
            }
        }
Example #2
0
        /// <summary>
        /// Start a sensor with a given interval <see cref="SensorId"/>. Returns true if the sensor was started,
        /// otherwise false.
        /// </summary>
        /// <param name="sensorId"></param>
        private bool StartSensorInternal(SensorId sensorId)
        {
            var sensorConfig = _wearableDeviceConfig.GetSensorConfig(sensorId);

            if (sensorConfig.isEnabled)
            {
                return(false);
            }

            sensorConfig.isEnabled = true;

            return(true);
        }
Example #3
0
            public void SetDeviceConfiguration(WearableDeviceConfig config)
            {
                if (_wearablePlugin != null)
                {
                    bool[] sensors = new bool[WearableConstants.SensorIds.Length];
                    for (int i = 0; i < WearableConstants.SensorIds.Length; i++)
                    {
                        sensors[i] = config.GetSensorConfig(WearableConstants.SensorIds[i]).isEnabled;
                    }
                    IntPtr sensorsJava = AndroidJNIHelper.ConvertToJNIArray(sensors);

                    bool[] gestures = new bool[WearableConstants.GestureIds.Length - 1];                   // -1 to Exclude .None
                    for (int i = 1; i < WearableConstants.GestureIds.Length; i++)
                    {
                        gestures[i - 1] = config.GetGestureConfig(WearableConstants.GestureIds[i]).isEnabled;
                    }
                    IntPtr gesturesJava = AndroidJNIHelper.ConvertToJNIArray(gestures);

                    // The AndroidJavaObject.Call method doesn't support arrays, so we have to convert & pass them more deliberately.
                    jvalue[] args = new jvalue[4];
                    args[0].l = sensorsJava;
                    args[1].l = gesturesJava;
                    args[2].i = (int)config.updateInterval;
                    IntPtr setMethod = AndroidJNIHelper.GetMethodID(_wearablePlugin.GetRawClass(), SetDeviceConfigurationMethod);
                    AndroidJNI.CallVoidMethod(_wearablePlugin.GetRawObject(), setMethod, args);
                }
            }
Example #4
0
 /// <summary>
 /// Copy only the sensor configuration from another <see cref="WearableDeviceConfig"/>. Includes the sensor
 /// update interval.
 /// </summary>
 /// <param name="config"></param>
 public void CopySensorConfigFrom(WearableDeviceConfig config)
 {
     for (int i = 0; i < WearableConstants.SENSOR_IDS.Length; i++)
     {
         SensorId sensorId = WearableConstants.SENSOR_IDS[i];
         GetSensorConfig(sensorId).isEnabled = config.GetSensorConfig(sensorId).isEnabled;
     }
     updateInterval = config.updateInterval;
 }
Example #5
0
        /// <summary>
        /// True if the device state needs to be updated because it differs from our the
        /// <see cref="WearableDeviceConfig"/> <paramref name="config"/>, otherwise false.
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        private bool ShouldUpdateDeviceState(WearableDeviceConfig config)
        {
            // Check all sensors to see if we need to update the device.
            var deviceShouldBeUpdated = false;

            for (var i = 0; i < WearableConstants.SensorIds.Length; i++)
            {
                var sensorId     = WearableConstants.SensorIds[i];
                var sensorConfig = config.GetSensorConfig(sensorId);

                if (sensorConfig.isEnabled != GetSensorActive(sensorId))
                {
                    deviceShouldBeUpdated = true;
                }
            }

            // Check the sensor update interval to see if we need to update the device.
            if (config.updateInterval != UpdateInterval)
            {
                deviceShouldBeUpdated = true;
            }

            // Check the rotation source to see if we need to update the device.
            if (config.rotationSource != RotationSource)
            {
                deviceShouldBeUpdated = true;
            }

            // Check all gestures to see if we need to update the device state.
            if (!deviceShouldBeUpdated)
            {
                for (var i = 0; i < WearableConstants.GestureIds.Length; i++)
                {
                    if (WearableConstants.GestureIds[i] == GestureId.None)
                    {
                        continue;
                    }

                    var gestureConfig = config.GetGestureConfig(WearableConstants.GestureIds[i]);
                    if (gestureConfig.isEnabled != GetGestureEnabled(WearableConstants.GestureIds[i]))
                    {
                        deviceShouldBeUpdated = true;
                        break;
                    }
                }
            }

            return(deviceShouldBeUpdated);
        }
Example #6
0
        /// <summary>
        /// Additively updates the final device config with <see cref="WearableDeviceConfig"/> <paramref name="config"/>
        /// </summary>
        /// <param name="config"></param>
        private void UpdateFinalDeviceConfig(WearableDeviceConfig config)
        {
            // Set all sensor state and update intervals
            for (var i = 0; i < WearableConstants.SensorIds.Length; i++)
            {
                var sensorId          = WearableConstants.SensorIds[i];
                var finalSensorConfig = _finalWearableDeviceConfig.GetSensorConfig(sensorId);
                var reqSensorConfig   = config.GetSensorConfig(sensorId);

                finalSensorConfig.isEnabled |= reqSensorConfig.isEnabled;
            }

            // Set all gesture state.
            for (var i = 0; i < WearableConstants.GestureIds.Length; i++)
            {
                if (WearableConstants.GestureIds[i] == GestureId.None)
                {
                    continue;
                }

                var finalGestureConfig = _finalWearableDeviceConfig.GetGestureConfig(WearableConstants.GestureIds[i]);
                var reqGestureConfig   = config.GetGestureConfig(WearableConstants.GestureIds[i]);

                finalGestureConfig.isEnabled |= reqGestureConfig.isEnabled;
            }

            if (config.HasAnySensorsEnabled())
            {
                if (_finalWearableDeviceConfig.updateInterval.IsSlowerThan(config.updateInterval))
                {
                    _finalWearableDeviceConfig.updateInterval = config.updateInterval;
                }
            }

            // If the config rotation sensor is enabled and the final config has a lower priority rotation
            // source, override it
            if (config.rotation.isEnabled &&
                _finalWearableDeviceConfig.rotationSource.IsLowerPriority(config.rotationSource))
            {
                _finalWearableDeviceConfig.rotationSource = config.rotationSource;
            }
        }
Example #7
0
        /// <summary>
        /// Copy all the configuration values from the specified configuration.
        /// </summary>
        /// <param name="config"></param>
        public void CopyValuesFrom(WearableDeviceConfig config)
        {
            for (int i = 0; i < WearableConstants.SensorIds.Length; i++)
            {
                SensorId sensorId = WearableConstants.SensorIds[i];
                GetSensorConfig(sensorId).isEnabled = config.GetSensorConfig(sensorId).isEnabled;
            }

            for (int i = 0; i < WearableConstants.GestureIds.Length; i++)
            {
                GestureId gestureId = WearableConstants.GestureIds[i];

                if (gestureId == GestureId.None)
                {
                    continue;
                }

                GetGestureConfig(gestureId).isEnabled = config.GetGestureConfig(gestureId).isEnabled;
            }

            updateInterval = config.updateInterval;
        }
Example #8
0
        internal override void SetDeviceConfiguration(WearableDeviceConfig config)
        {
            if (_dynamicDeviceInfo.deviceStatus.ServiceSuspended)
            {
                Debug.LogWarning(WearableConstants.DebugProviderSetConfigWhileSuspendedWarning);
                _waitingToSendConfigFailure = true;
                _sendConfigFailureTime      = Time.unscaledTime + _simulatedDelayTime;
                return;
            }

            if (_verbose)
            {
                // Sensor info
                for (int i = 0; i < WearableConstants.SensorIds.Length; i++)
                {
                    SensorId sensorId  = WearableConstants.SensorIds[i];
                    bool     oldSensor = _config.GetSensorConfig(sensorId).isEnabled;
                    bool     newSensor = config.GetSensorConfig(sensorId).isEnabled;

                    if (newSensor == oldSensor)
                    {
                        continue;
                    }

                    Debug.LogFormat(
                        newSensor ? WearableConstants.DebugProviderStartSensor : WearableConstants.DebugProviderStopSensor,
                        Enum.GetName(typeof(SensorId), sensorId));
                }

                // Gesture info
                for (int i = 0; i < WearableConstants.GestureIds.Length; i++)
                {
                    GestureId gestureId = WearableConstants.GestureIds[i];

                    if (gestureId == GestureId.None)
                    {
                        continue;
                    }

                    bool oldGesture = _config.GetGestureConfig(gestureId).isEnabled;
                    bool newGesture = config.GetGestureConfig(gestureId).isEnabled;
                    if (newGesture == oldGesture)
                    {
                        continue;
                    }

                    Debug.LogFormat(
                        newGesture ? WearableConstants.DebugProviderEnableGesture : WearableConstants.DebugProviderDisableGesture,
                        Enum.GetName(typeof(GestureId), gestureId));
                }


                // Update interval
                SensorUpdateInterval oldInterval = _config.updateInterval;
                SensorUpdateInterval newInterval = config.updateInterval;
                if (oldInterval != newInterval)
                {
                    Debug.LogFormat(
                        WearableConstants.DebugProviderSetUpdateInterval,
                        Enum.GetName(typeof(SensorUpdateInterval), newInterval));
                }
            }

            _config.CopyValuesFrom(config);
            _waitingToSendConfigSuccess = true;
            _sendConfigSuccessTime      = Time.unscaledTime + _simulatedDelayTime;
        }