internal WearableMobileProvider() { _virtualDevice = new Device { isConnected = false, name = WearableConstants.MobileProviderDeviceName, productId = WearableConstants.MobileProviderProductId, variantId = WearableConstants.MobileProviderVariantId, rssi = 0, uid = WearableConstants.EmptyUID }; _sensorStatus = new Dictionary <SensorId, bool>(); _sensorUpdateInterval = WearableConstants.DefaultUpdateInterval; _nextSensorUpdateTime = 0.0f; _sensorStatus.Add(SensorId.Accelerometer, false); _sensorStatus.Add(SensorId.Gyroscope, false); _sensorStatus.Add(SensorId.Rotation, false); _sensorStatus.Add(SensorId.GameRotation, false); // All gestures start disabled. _gestureStatus = new Dictionary <GestureId, bool>(); GestureId[] gestures = WearableConstants.GestureIds; for (int i = 0; i < gestures.Length; ++i) { if (gestures[i] != GestureId.None) { _gestureStatus.Add(gestures[i], false); } } }
internal override void SetSensorUpdateInterval(SensorUpdateInterval updateInterval) { if (_connectedDevice == null) { Debug.LogWarning(WearableConstants.SetUpdateRateWithoutDeviceWarning); return; } _sensorUpdateInterval = updateInterval; // n.b. currently, the only way to set the global update interval is along with a call to EnableSensor. // Until a method is added for this, a suitable workaround is to call EnableSensor on a sensor that is // already enabled. If no sensors are enabled, the cached value will of _sensorUpdateInterval will be // used the next time a sensor is enabled. #if UNITY_EDITOR var enumerator = _sensorStatus.GetEnumerator(); try { while (enumerator.MoveNext()) { KeyValuePair <SensorId, bool> element = enumerator.Current; if (element.Value) { int milliseconds = (int)WearableTools.SensorUpdateIntervalToMilliseconds(_sensorUpdateInterval); WearableUSBEnableSensor((int)element.Key, milliseconds); } } } finally { enumerator.Dispose(); } #endif // UNITY_EDITOR }
#pragma warning restore CS0414 internal WearableUSBProvider() { _statusMessageSeparators = new char[] { '\n' }; _sessionStatus = SessionStatus.Closed; _statusMessage = new StringBuilder(8192); _uidBuilder = new StringBuilder(256); _nameBuilder = new StringBuilder(256); _sensorStatus = new Dictionary <SensorId, bool>(); _sensorUpdateInterval = WearableConstants.DefaultUpdateInterval; _rotationSource = WearableConstants.DefaultRotationSource; _sensorStatus.Add(SensorId.Accelerometer, false); _sensorStatus.Add(SensorId.Gyroscope, false); _sensorStatus.Add(SensorId.Rotation, false); _gestureStatus = new Dictionary <GestureId, bool>(); for (var i = 0; i < WearableConstants.GestureIds.Length; i++) { if (WearableConstants.GestureIds[i] == GestureId.None) { continue; } _gestureStatus.Add(WearableConstants.GestureIds[i], false); } }
private void OnSetUpdateIntervalPacket(SensorUpdateInterval interval) { _transmitIndex = 0; _deviceProvider.SetSensorUpdateInterval(interval); WearableProxyServerProtocol.EncodeUpdateIntervalValue(_transmitBuffer, ref _transmitIndex, interval); SendTransmitBuffer(); }
/// <summary> /// Returns true if <see cref="SensorUpdateInterval"/> <paramref name="interval"/> is slower than /// <see cref="SensorUpdateInterval"/> <paramref name="otherInterval"/>. /// </summary> /// <param name="interval"></param> /// <param name="otherInterval"></param> /// <returns></returns> public static bool IsSlowerThan(this SensorUpdateInterval interval, SensorUpdateInterval otherInterval) { var intervalSeconds = WearableTools.SensorUpdateIntervalToSeconds(interval); var otherIntervalSeconds = WearableTools.SensorUpdateIntervalToSeconds(otherInterval); return(intervalSeconds > otherIntervalSeconds); }
internal WearableMobileProvider() { _virtualDevice = new Device { isConnected = false, name = WearableConstants.MobileProviderDeviceName, productId = WearableConstants.MobileProviderProductId, variantId = WearableConstants.MobileProviderVariantId, rssi = 0, uid = WearableConstants.EmptyUID }; _sensorStatus = new Dictionary <SensorId, bool>(); _sensorUpdateInterval = WearableConstants.DefaultUpdateInterval; _nextSensorUpdateTime = 0.0f; _rotationSource = WearableConstants.DefaultRotationSource; _sensorStatus.Add(SensorId.Accelerometer, false); _sensorStatus.Add(SensorId.Gyroscope, false); _sensorStatus.Add(SensorId.Rotation, false); // All gestures start disabled. _gestureStatus = new Dictionary <GestureId, bool>(); for (var i = 0; i < WearableConstants.GestureIds.Length; i++) { if (WearableConstants.GestureIds[i] == GestureId.None) { continue; } _gestureStatus.Add(WearableConstants.GestureIds[i], false); } _pendingGestures = new Queue <GestureId>(); }
/// <summary> /// Get the Bose SDK bit for a SensorUpdateInterval. /// </summary> /// <param name="interval"></param> /// <returns></returns> public static int SensorUpdateIntervalToBit(SensorUpdateInterval interval) { int bit = 0; switch (interval) { case SensorUpdateInterval.ThreeHundredTwentyMs: bit = 1; break; case SensorUpdateInterval.OneHundredSixtyMs: bit = 2; break; case SensorUpdateInterval.EightyMs: bit = 4; break; case SensorUpdateInterval.FortyMs: bit = 8; break; case SensorUpdateInterval.TwentyMs: bit = 16; break; default: throw new ArgumentOutOfRangeException("interval", interval, null); } return(bit); }
/// <summary> /// Get the number of seconds between samples for a given <see cref="SensorUpdateInterval"/>. /// </summary> /// <param name="interval"></param> /// <returns></returns> public static float SensorUpdateIntervalToSeconds(SensorUpdateInterval interval) { // This is needed because the update interval enum doesn't reflect the actual sampling interval, // but the values of the underlying SDK enum. switch (interval) { case SensorUpdateInterval.TwentyMs: return(0.020f); case SensorUpdateInterval.FortyMs: return(0.040f); case SensorUpdateInterval.EightyMs: return(0.080f); case SensorUpdateInterval.OneHundredSixtyMs: return(0.160f); case SensorUpdateInterval.ThreeHundredTwentyMs: return(0.320f); default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Adds an interval to the profile. /// </summary> /// <param name="interval"></param> public void AddInterval(SensorUpdateInterval interval) { if (!GetIntervalInProfile(interval)) { _intervals.Add(interval); _dirty = true; } }
public static byte[] EncodeUpdateIntervalValueAlloc(SensorUpdateInterval interval) { byte[] buffer = new byte[_headerSize + Marshal.SizeOf(typeof(UpdateIntervalPacket)) + _footerSize]; int index = 0; EncodeUpdateIntervalValue(buffer, ref index, interval); return(buffer); }
/// <summary> /// Sets the update interval for the WearableDevice. /// </summary> public void SetSensorUpdateInterval(SensorUpdateInterval interval) { // If we've made a change that would result in the device's state changing, // mark the device config as dirty. if (SetSensorUpdateIntervalInternal(interval)) { LockDeviceStateUpdate(); } }
/// <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; }
internal override void SetSensorUpdateInterval(SensorUpdateInterval updateInterval) { if (_connectedDevice == null) { Debug.LogWarning(WearableConstants.SetUpdateRateWithoutDeviceWarning); return; } _sensorUpdateInterval = updateInterval; }
/// <summary> /// Sets the <see cref="SensorUpdateInterval"/> <paramref name="updateInterval"/> value. /// </summary> /// <param name="updateInterval"></param> public void SetSensorUpdateInterval(SensorUpdateInterval updateInterval) { if (DeviceConfig.updateInterval == updateInterval) { return; } DeviceConfig.updateInterval = updateInterval; SetDirty(); }
public WearableDeviceConfig() { accelerometer = new WearableSensorConfig(); gyroscope = new WearableSensorConfig(); rotation = new WearableSensorConfig(); doubleTap = new WearableGestureConfig(); headNod = new WearableGestureConfig(); headShake = new WearableGestureConfig(); updateInterval = WearableConstants.DefaultUpdateInterval; rotationSource = WearableConstants.DefaultRotationSource; }
/// <summary> /// Sets the <see cref="SensorUpdateInterval"/> <paramref name="newInterval"/>. /// </summary> private bool SetSensorUpdateIntervalInternal(SensorUpdateInterval newInterval) { var hasDeviceStateChanged = false; if (_wearableDeviceConfig.updateInterval != newInterval) { _wearableDeviceConfig.updateInterval = newInterval; hasDeviceStateChanged = true; } return(hasDeviceStateChanged); }
internal WearableDebugProvider() { _virtualDevice = new Device { name = _name, firmwareVersion = _firmwareVersion, rssi = _rssi, uid = _uid, productId = _productId, variantId = _variantId }; _name = WearableConstants.DebugProviderDefaultDeviceName; _firmwareVersion = WearableConstants.DefaultFirmwareVersion; _rssi = WearableConstants.DebugProviderDefaultRSSI; _uid = WearableConstants.DebugProviderDefaultUID; _productId = WearableConstants.DebugProviderDefaultProductId; _variantId = WearableConstants.DebugProviderDefaultVariantId; _verbose = true; _eulerSpinRate = Vector3.zero; _axisAngleSpinRate = Vector3.up; _sensorStatus = new Dictionary <SensorId, bool>(); _sensorUpdateInterval = WearableConstants.DefaultUpdateInterval; _rotationSource = WearableConstants.DefaultRotationSource; _sensorStatus.Add(SensorId.Accelerometer, false); _sensorStatus.Add(SensorId.Gyroscope, false); _sensorStatus.Add(SensorId.Rotation, false); // All gestures start disabled. _gestureStatus = new Dictionary <GestureId, bool>(); for (var i = 0; i < WearableConstants.GestureIds.Length; i++) { if (WearableConstants.GestureIds[i] == GestureId.None) { continue; } _gestureStatus.Add(WearableConstants.GestureIds[i], false); } _pendingGestures = new Queue <GestureId>(); _nextSensorUpdateTime = 0.0f; _rotation = Quaternion.identity; }
private USBAppIntentProfile MakeUSBProfile(AppIntentProfile appIntentProfile) { USBAppIntentProfile usbProfile = new USBAppIntentProfile(); if (appIntentProfile != null) { // Sensors usbProfile.sensorBitmask = 0; for (int i = 0; i < WearableConstants.SensorIds.Length; i++) { SensorId sensor = WearableConstants.SensorIds[i]; // Does this profile require this sensor? if (appIntentProfile.GetSensorInProfile(sensor)) { SensorFlags sensorBit = WearableTools.GetSensorFlag(sensor); usbProfile.sensorBitmask |= (int)sensorBit; } } // Gestures usbProfile.gestureBitmask = 0; for (int i = 0; i < WearableConstants.GestureIds.Length; i++) { GestureId gesture = WearableConstants.GestureIds[i]; // Does this profile require this gesture? if (appIntentProfile.GetGestureInProfile(gesture)) { GestureFlags gestureBit = WearableTools.GetGestureFlag(gesture); usbProfile.gestureBitmask |= (int)gestureBit; } } usbProfile.updateIntervalBitmask = 0; for (int i = 0; i < WearableConstants.UpdateIntervals.Length; i++) { SensorUpdateInterval interval = WearableConstants.UpdateIntervals[i]; // Does this profile require this update interval? if (appIntentProfile.GetIntervalInProfile(interval)) { int intervalBit = WearableTools.SensorUpdateIntervalToBit(interval); usbProfile.updateIntervalBitmask |= intervalBit; } } } return(usbProfile); }
/// <summary> /// Returns a label for the passed <see cref="SensorUpdateInterval"/> <paramref name="updateInterval"/>. /// </summary> /// <param name="updateInterval"></param> /// <returns></returns> public string GetLabel(SensorUpdateInterval updateInterval) { for (var i = 0; i < _updateIntervalToLabels.Length; i++) { if (_updateIntervalToLabels[i].updateInterval != updateInterval) { continue; } return(_updateIntervalToLabels[i].label); } return(string.Empty); }
/// <summary> /// Encode an update interval value packet into the buffer /// </summary> /// <param name="buffer"></param> /// <param name="index"></param> /// <param name="interval"></param> public static void EncodeUpdateIntervalValue(byte[] buffer, ref int index, SensorUpdateInterval interval) { // Encode header PacketHeader header = new PacketHeader(PacketTypeCode.UpdateIntervalValue); SerializePacket(buffer, ref index, header); // Encode payload UpdateIntervalPacket packet = EncodeUpdateInterval(interval); SerializePacket(buffer, ref index, packet); // Encode footer SerializePacket(buffer, ref index, _footer); }
internal override void SetSensorUpdateInterval(SensorUpdateInterval updateInterval) { if (_connectedDevice == null) { Debug.LogWarning(WearableConstants.SetUpdateRateWithoutDeviceWarning); return; } if (_verbose) { Debug.LogFormat( WearableConstants.DebugProviderSetUpdateInterval, Enum.GetName(typeof(SensorUpdateInterval), updateInterval)); } _sensorUpdateInterval = updateInterval; }
public WearableDeviceConfig() { accelerometer = new WearableSensorConfig(); gyroscope = new WearableSensorConfig(); rotationNineDof = new WearableSensorConfig(); rotationSixDof = new WearableSensorConfig(); doubleTapGesture = new WearableGestureConfig(); headNodGesture = new WearableGestureConfig(); headShakeGesture = new WearableGestureConfig(); touchAndHoldGesture = new WearableGestureConfig(); inputGesture = new WearableGestureConfig(); affirmativeGesture = new WearableGestureConfig(); negativeGesture = new WearableGestureConfig(); updateInterval = WearableConstants.DefaultUpdateInterval; }
internal override void SetSensorUpdateInterval(SensorUpdateInterval updateInterval) { if (_connectedDevice == null) { Debug.LogWarning(WearableConstants.SetUpdateRateWithoutDeviceWarning); return; } _sensorUpdateInterval = updateInterval; // n.b. currently, the only way to set the global update interval is along with a call to EnableSensor. // Until a method is added for this, a suitable workaround is to call EnableSensor on a sensor that is // already enabled. If no sensors are enabled, the cached value will of _sensorUpdateInterval will be // used the next time a sensor is enabled. #if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR Dictionary <SensorId, bool> .Enumerator enumerator = _sensorStatus.GetEnumerator(); try { while (enumerator.MoveNext()) { KeyValuePair <SensorId, bool> element = enumerator.Current; if (element.Value) { #if UNITY_IOS WearableEnableSensor((int)element.Key, (int)_sensorUpdateInterval); #elif UNITY_ANDROID AndroidPlugin.EnableSensor(element.Key, (int)_sensorUpdateInterval); #endif // Only one call is needed since the interval is global break; } } } finally { enumerator.Dispose(); } #endif }
/// <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; }
internal WearableDebugProvider() { _virtualDevice = new Device { name = _name, rssi = _rssi, uid = _uid, productId = _productId, variantId = _variantId }; _name = WearableConstants.DebugProviderDefaultDeviceName; _rssi = WearableConstants.DebugProviderDefaultRSSI; _uid = WearableConstants.DebugProviderDefaultUID; _productId = WearableConstants.DebugProviderDefaultProductId; _variantId = WearableConstants.DebugProviderDefaultVariantId; _verbose = true; _sensorStatus = new Dictionary <SensorId, bool>(); _sensorUpdateInterval = WearableConstants.DefaultUpdateInterval; _sensorStatus.Add(SensorId.Accelerometer, false); _sensorStatus.Add(SensorId.Gyroscope, false); _sensorStatus.Add(SensorId.Rotation, false); _sensorStatus.Add(SensorId.GameRotation, false); // All gestures start disabled. _gestureStatus = new Dictionary <GestureId, bool>(); GestureId[] gestures = WearableConstants.GestureIds; for (int i = 0; i < gestures.Length; ++i) { if (gestures[i] != GestureId.None) { _gestureStatus.Add(gestures[i], false); } } }
internal WearableDeviceProvider() { _rotationMode = RotationMode.NineDof; _sensorStatus = new Dictionary <SensorId, bool>(); _sensorUpdateInterval = WearableConstants.DefaultUpdateInterval; _sensorStatus.Add(SensorId.Accelerometer, false); _sensorStatus.Add(SensorId.Gyroscope, false); _sensorStatus.Add(SensorId.Rotation, false); _sensorStatus.Add(SensorId.GameRotation, false); // All gestures start disabled. _gestureStatus = new Dictionary <GestureId, bool>(); GestureId[] gestureValues = WearableConstants.GestureIds; for (int i = 0; i < gestureValues.Length; ++i) { if (gestureValues[i] != GestureId.None) { _gestureStatus.Add(gestureValues[i], false); } } }
internal WearableDeviceProvider() { _rotationSource = WearableConstants.DefaultRotationSource; _sensorStatus = new Dictionary <SensorId, bool>(); _sensorUpdateInterval = WearableConstants.DefaultUpdateInterval; _sensorStatus.Add(SensorId.Accelerometer, false); _sensorStatus.Add(SensorId.Gyroscope, false); _sensorStatus.Add(SensorId.Rotation, false); // All gestures start disabled. _gestureStatus = new Dictionary <GestureId, bool>(); for (var i = 0; i < WearableConstants.GestureIds.Length; i++) { if (WearableConstants.GestureIds[i] == GestureId.None) { continue; } _gestureStatus.Add(WearableConstants.GestureIds[i], false); } }
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; }
/// <summary> /// Set the update interval of all sensors on the provider. /// </summary> /// <param name="updateInterval"></param> internal abstract void SetSensorUpdateInterval(SensorUpdateInterval updateInterval);
/// <summary> /// Create an <see cref="UpdateIntervalPacket"/> from a <see cref="SensorUpdateInterval"/>. /// </summary> /// <param name="interval"></param> /// <returns></returns> protected static UpdateIntervalPacket EncodeUpdateInterval(SensorUpdateInterval interval) { return(new UpdateIntervalPacket { value = (int)interval }); }