/// <summary> /// Check an arbitrary intent for validity against the configurable sensor and gesture availability. /// </summary> /// <param name="profile"></param> /// <returns></returns> private bool CheckIntentValidity(AppIntentProfile profile) { // Sensors for (int i = 0; i < WearableConstants.SensorIds.Length; i++) { SensorId id = WearableConstants.SensorIds[i]; if (profile.GetSensorInProfile(id) && !_virtualDevice.IsSensorAvailable(id)) { return(false); } } // Check gestures for (int i = 0; i < WearableConstants.GestureIds.Length; i++) { GestureId id = WearableConstants.GestureIds[i]; if (id == GestureId.None) { continue; } if (profile.GetGestureInProfile(id) && !_virtualDevice.IsGestureAvailable(id)) { return(false); } } // NB All intervals are supported by the debug provider, so this part of the intent profile is not validated. return(true); }
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); }
private int GetSensorsFromAppIntentProfile(AppIntentProfile profile) { int sensors = 0; if (profile != null) { for (int i = 0; i < WearableConstants.SensorIds.Length; i++) { if (profile.GetSensorInProfile(WearableConstants.SensorIds[i])) { sensors |= (1 << i); } } } return(sensors); }
/// <summary> /// Helper function to convert our AppIntentProfile to something more easily consumable /// by the bridge layer. /// </summary> private static BridgeAppIntentProfile CreateBridgeAppIntentProfile(AppIntentProfile appIntentProfile) { BridgeAppIntentProfile bridgeAppIntentProfile = new BridgeAppIntentProfile(); int sensors = 0; int samplePeriods = 0; int gestures = 0; if (appIntentProfile != null) { for (int i = 0; i < WearableConstants.SENSOR_IDS.Length; i++) { if (appIntentProfile.GetSensorInProfile(WearableConstants.SENSOR_IDS[i])) { sensors |= (1 << i); } } for (int i = 0; i < WearableConstants.UPDATE_INTERVALS.Length; i++) { if (appIntentProfile.GetIntervalInProfile(WearableConstants.UPDATE_INTERVALS[i])) { samplePeriods |= (1 << i); } } for (int i = 0; i < WearableConstants.GESTURE_IDS.Length; i++) { if (WearableConstants.GESTURE_IDS[i] == GestureId.None) { continue; } if (appIntentProfile.GetGestureInProfile(WearableConstants.GESTURE_IDS[i])) { gestures |= (1 << (i - 1)); } } } bridgeAppIntentProfile.sensors = sensors; bridgeAppIntentProfile.samplePeriods = samplePeriods; bridgeAppIntentProfile.gestures = gestures; return(bridgeAppIntentProfile); }