Esempio n. 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;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Start a gesture with a given interval <see cref="GestureId"/>.
        /// </summary>
        /// <param name="gestureId"></param>
        private bool EnableGestureInternal(GestureId gestureId)
        {
            var gestureConfig = _wearableDeviceConfig.GetGestureConfig(gestureId);

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

            gestureConfig.isEnabled = true;

            return(true);
        }
Esempio n. 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);
                }
            }
Esempio n. 4
0
        /// <summary>
        /// Copy only the gesture configuration from another <see cref="WearableDeviceConfig"/>.
        /// </summary>
        /// <param name="config"></param>
        public void CopyGestureConfigFrom(WearableDeviceConfig config)
        {
            for (int i = 0; i < WearableConstants.GESTURE_IDS.Length; i++)
            {
                GestureId gestureId = WearableConstants.GESTURE_IDS[i];

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

                GetGestureConfig(gestureId).isEnabled = config.GetGestureConfig(gestureId).isEnabled;
            }
        }
Esempio n. 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);
        }
Esempio n. 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;
            }
        }
Esempio n. 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;
        }
Esempio n. 8
0
        /// <summary>
        /// Adds any gestures that were simulated during the last sensor frame to the current gesture data.
        /// Warns when unavailable or inactive gestures are simulated, and skips them.
        /// </summary>
        private void UpdateGestureData()
        {
            while (_pendingGestures.Count > 0)
            {
                GestureData gestureData = _pendingGestures.Dequeue();
                if (_config.GetGestureConfig(gestureData.gestureId).isEnabled&&
                    _virtualDevice.IsGestureAvailable(gestureData.gestureId))
                {
                    // If the gesture is enabled and available, go ahead and trigger it.
                    if (_verbose)
                    {
                        Debug.LogFormat(WearableConstants.DebugProviderTriggerGesture, Enum.GetName(typeof(GestureId), gestureData.gestureId));
                    }

                    _currentGestureData.Add(gestureData);
                }
                else
                {
                    // Otherwise, warn, and drop the gesture from the queue.
                    Debug.LogWarning(WearableConstants.DebugProviderTriggerDisabledGestureWarning);
                }
            }
        }
Esempio n. 9
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;
        }