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 }
internal override void SetDeviceConfiguration(WearableDeviceConfig config) { #if UNITY_EDITOR USBDeviceConfiguration deviceConfig = new USBDeviceConfiguration { intervalMilliseconds = (int)WearableTools.SensorUpdateIntervalToMilliseconds(config.updateInterval), sensorRotationNineDof = config.rotationNineDof.isEnabled ? 1 : 0, sensorRotationSixDof = config.rotationSixDof.isEnabled ? 1 : 0, sensorGyroscope = config.gyroscope.isEnabled ? 1 : 0, sensorAccelerometer = config.accelerometer.isEnabled ? 1 : 0, gestureHeadNod = config.headNodGesture.isEnabled ? 1 : 0, gestureHeadShake = config.headShakeGesture.isEnabled ? 1 : 0, gestureDoubleTap = config.doubleTapGesture.isEnabled ? 1 : 0, gestureTouchAndHold = config.touchAndHoldGesture.isEnabled ? 1 : 0, gestureInput = config.inputGesture.isEnabled ? 1 : 0, gestureAffirmative = config.affirmativeGesture.isEnabled ? 1 : 0, gestureNegative = config.negativeGesture.isEnabled ? 1 : 0 }; WearableUSBSetDeviceConfiguration(deviceConfig); #endif // Assume the configuration succeeded, because it generally will. Failed configs will show up when we poll // for status flags, and adjust the internal config as necessary. _config = config.Clone(); }
internal override void StartSensor(SensorId sensorId) { if (_connectedDevice == null) { _sensorStatus[sensorId] = false; Debug.LogWarning(WearableConstants.StartSensorWithoutDeviceWarning); return; } if (_sensorStatus[sensorId]) { return; } #if UNITY_EDITOR int milliseconds = (int)WearableTools.SensorUpdateIntervalToMilliseconds(_sensorUpdateInterval); WearableUSBEnableSensor((int)sensorId, milliseconds); #endif // UNITY_EDITOR _sensorStatus[sensorId] = true; }
public override string ToString() { const string ItemSeparator = ", "; const string NoneLabel = "None"; const string SensorsLabel = "Sensors: "; const string GesturesLabel = "Gestures: "; const string IntervalsLabel = "Intervals: "; const string IntervalFormat = "{0}ms"; if (_stringBuilder == null) { _stringBuilder = new StringBuilder(); } else { _stringBuilder.Length = 0; } _stringBuilder.Append(SensorsLabel); for (int i = 0; i < _sensors.Count; i++) { SensorId id = _sensors[i]; _stringBuilder.Append(_sensors[i].ToString()); if (i != _sensors.Count - 1) { _stringBuilder.Append(ItemSeparator); } } if (_sensors.Count == 0) { _stringBuilder.Append(NoneLabel); } _stringBuilder.AppendLine(); _stringBuilder.Append(IntervalsLabel); for (int i = 0; i < _intervals.Count; i++) { _stringBuilder.AppendFormat( IntervalFormat, ((int)WearableTools.SensorUpdateIntervalToMilliseconds(_intervals[i])).ToString()); if (i != _intervals.Count - 1) { _stringBuilder.Append(ItemSeparator); } } if (_intervals.Count == 0) { _stringBuilder.Append(NoneLabel); } _stringBuilder.AppendLine(); _stringBuilder.Append(GesturesLabel); for (int i = 0; i < _gestures.Count; i++) { _stringBuilder.Append(_gestures[i].ToString()); if (i != _gestures.Count - 1) { _stringBuilder.Append(ItemSeparator); } } if (_gestures.Count == 0) { _stringBuilder.Append(NoneLabel); } return(_stringBuilder.ToString()); }
public override string ToString() { const string ITEM_SEPARATOR = ", "; const string NONE_LABEL = "None"; const string SENSORS_LABEL = "Sensors: "; const string GESTURES_LABEL = "Gestures: "; const string INTERVALS_LABEL = "Intervals: "; const string INTERVAL_FORMAT = "{0}ms"; if (_stringBuilder == null) { _stringBuilder = new StringBuilder(); } else { _stringBuilder.Length = 0; } _stringBuilder.Append(SENSORS_LABEL); for (int i = 0; i < _sensors.Count; i++) { SensorId id = _sensors[i]; _stringBuilder.Append(_sensors[i].ToString()); if (i != _sensors.Count - 1) { _stringBuilder.Append(ITEM_SEPARATOR); } } if (_sensors.Count == 0) { _stringBuilder.Append(NONE_LABEL); } _stringBuilder.AppendLine(); _stringBuilder.Append(INTERVALS_LABEL); for (int i = 0; i < _intervals.Count; i++) { _stringBuilder.AppendFormat( INTERVAL_FORMAT, ((int)WearableTools.SensorUpdateIntervalToMilliseconds(_intervals[i])).ToString()); if (i != _intervals.Count - 1) { _stringBuilder.Append(ITEM_SEPARATOR); } } if (_intervals.Count == 0) { _stringBuilder.Append(NONE_LABEL); } _stringBuilder.AppendLine(); _stringBuilder.Append(GESTURES_LABEL); for (int i = 0; i < _gestures.Count; i++) { _stringBuilder.Append(_gestures[i].ToString()); if (i != _gestures.Count - 1) { _stringBuilder.Append(ITEM_SEPARATOR); } } if (_gestures.Count == 0) { _stringBuilder.Append(NONE_LABEL); } return(_stringBuilder.ToString()); }