示例#1
0
        /// <summary>
        /// Unpacks an int representing the available <see cref="ActiveNoiseReductionMode"/>s in the same manner
        /// as the underlying SDK. Neither duplicated modes nor <see cref="ActiveNoiseReductionMode.Invalid"/> will
        /// be returned in the resultant list; list order is undefined.
        /// </summary>
        /// <param name="flags"></param>
        /// <returns></returns>
        internal static ActiveNoiseReductionMode[] GetActiveNoiseReductionModesAsList(int flags)
        {
            if (flags == 0)
            {
                // Feature disabled; signify with an empty list.
                return(WearableConstants.EMPTY_ACTIVE_NOISE_REDUCTION_MODES);
            }

            _anrModeList.Clear();

            for (int i = 0; i < WearableConstants.ACTIVE_NOISE_REDUCTION_MODES.Length; i++)
            {
                ActiveNoiseReductionMode mode = WearableConstants.ACTIVE_NOISE_REDUCTION_MODES[i];

                if (mode == ActiveNoiseReductionMode.Invalid)
                {
                    continue;
                }

                // Check if the corresponding bit is set in the availability mask.
                if (((1 << (int)mode) & flags) != 0)
                {
                    _anrModeList.Add(mode);
                }
            }

            return(_anrModeList.ToArray());
        }
        /// <summary>
        /// Set the active noise reduction mode on the attached device, if the feature is available.
        /// <paramref name="mode"/> should be one of the available modes returned by
        /// <see cref="Device.GetAvailableActiveNoiseReductionModes"/>.
        /// </summary>
        public void SetActiveNoiseReductionMode(ActiveNoiseReductionMode mode)
        {
            if (!_connectedDevice.HasValue)
            {
                Debug.LogWarning(WearableConstants.DEVICE_IS_NOT_CURRENTLY_CONNECTED);
                _waitingForAnrCncWriteComplete = false;
                return;
            }

            if (mode == ActiveNoiseReductionMode.Invalid)
            {
                Debug.LogError(WearableConstants.INVALID_IS_INVALID_ANR_MODE);
                // Exit early without setting or clearing the waiting flag
                return;
            }

            if (_waitingForAnrCncWriteComplete)
            {
                Debug.LogError(WearableConstants.ANR_CNC_WRITE_LOCK_ERROR);
                return;
            }

            _waitingForAnrCncWriteComplete = true;
            SetActiveNoiseReductionModeInternal(mode);
        }
示例#3
0
        /// <summary>
        /// Returns true if a given <see cref="ActiveNoiseReductionMode"/> is available on this device.
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        public bool IsActiveNoiseReductionModeAvailable(ActiveNoiseReductionMode mode)
        {
            if (mode == ActiveNoiseReductionMode.Invalid)
            {
                return(false);
            }

            // Check if the corresponding bit is set
            return(((1 << (int)mode) & availableActiveNoiseReductionModes) != 0);
        }
示例#4
0
 /// <summary>
 /// Copies dynamic info into this device.
 /// </summary>
 internal void SetDynamicInfo(DynamicDeviceInfo dynamicDeviceInfo)
 {
     deviceStatus                             = dynamicDeviceInfo.deviceStatus;
     transmissionPeriod                       = dynamicDeviceInfo.transmissionPeriod;
     activeNoiseReductionMode                 = dynamicDeviceInfo.activeNoiseReductionMode;
     availableActiveNoiseReductionModes       = dynamicDeviceInfo.availableActiveNoiseReductionModes;
     controllableNoiseCancellationLevel       = dynamicDeviceInfo.controllableNoiseCancellationLevel;
     totalControllableNoiseCancellationLevels = dynamicDeviceInfo.totalControllableNoiseCancellationLevels;
     controllableNoiseCancellationEnabled     = dynamicDeviceInfo.controllableNoiseCancellationEnabled;
 }
示例#5
0
        /// <summary>
        /// Packs the supplied list of <see cref="ActiveNoiseReductionMode"/>s into an int in the same manner as the
        /// underlying SDK. Duplicated modes are transparently ignored. Supplying
        /// <see cref="ActiveNoiseReductionMode.Invalid"/> will throw an exception.
        /// </summary>
        /// <param name="modes"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        internal static int GetActiveNoiseReductionModesAsInt(ActiveNoiseReductionMode[] modes)
        {
            int result = 0;

            for (int i = 0; i < modes.Length; i++)
            {
                ActiveNoiseReductionMode mode = modes[i];
                if (mode == ActiveNoiseReductionMode.Invalid)
                {
                    throw new ArgumentOutOfRangeException(WearableConstants.INVALID_IS_INVALID_ANR_MODE);
                }

                // Set the corresponding bit in the availability mask.
                result |= 1 << (int)mode;
            }

            return(result);
        }
 /// <summary>
 /// Performs the actual ANR mode write. Will not be called if any ANR or CNC writes are outstanding.
 /// Providers should invoke <see cref="OnAnrCncWriteComplete"/> when the write is finished, which is permitted
 /// to happen during this call.
 /// </summary>
 /// <param name="mode"></param>
 protected abstract void SetActiveNoiseReductionModeInternal(ActiveNoiseReductionMode mode);
 public void SetActiveNoiseReductionModeProvider(ActiveNoiseReductionMode mode)
 {
     WearableSetActiveNoiseReductionMode((int)mode);
 }
 protected override void SetActiveNoiseReductionModeInternal(ActiveNoiseReductionMode mode)
 {
     _settingProductSpecificControls = true;
     _nextProductControlQueryTime   += WearableConstants.DEVICE_CONNECT_UPDATE_INTERVAL_IN_SECONDS;
     SetActiveNoiseReductionModeProvider(mode);
 }
示例#9
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            int indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            EditorGUI.BeginProperty(position, label, property);
            Rect line = new Rect(
                position.x,
                position.y,
                position.width,
                WearableEditorConstants.SINGLE_LINE_HEIGHT);

            // Device Status
            EditorGUI.LabelField(line, DEVICE_STATUS_HEADING);
            line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;

            Rect box = new Rect(
                line.x,
                line.y,
                line.width,
                line.height * (WearableConstants.DEVICE_STATUS_FLAGS.Length - 2));                 // Flag count less "None" and "Suspended"

            GUI.Box(box, GUIContent.none);

            var          statusValueProp = property.FindPropertyRelative(STATUS_VALUES_FIELD);
            DeviceStatus status          = statusValueProp.intValue;

            for (int i = 0; i < WearableConstants.DEVICE_STATUS_FLAGS.Length; i++)
            {
                DeviceStatusFlags flag = WearableConstants.DEVICE_STATUS_FLAGS[i];
                if (flag == DeviceStatusFlags.None ||
                    flag == DeviceStatusFlags.SensorServiceSuspended)
                {
                    continue;
                }

                using (new EditorGUI.DisabledScope(flag == DeviceStatusFlags.SensorServiceSuspended))
                {
                    bool value = EditorGUI.Toggle(
                        line,
                        flag.ToString(),
                        status.GetFlagValue(flag));

                    status.SetFlagValue(flag, value);
                }

                line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;
            }
            statusValueProp.intValue = status;


            // Transmission period
            // No-op

            // ANR header
            line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT * 0.5f;
            EditorGUI.LabelField(line, ANR_HEADING);
            line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;
            box     = new Rect(
                line.x,
                line.y,
                line.width,
                WearableEditorConstants.SINGLE_LINE_HEIGHT * (WearableConstants.ACTIVE_NOISE_REDUCTION_MODES.Length + 1));
            GUI.Box(box, GUIContent.none);


            // ANR current mode (read-only)
            using (new EditorGUI.DisabledScope(true))
            {
                var anrModeProperty = property.FindPropertyRelative(CURRENT_ANR_MODE_FIELD);
                var anrMode         = (ActiveNoiseReductionMode)anrModeProperty.intValue;
                EditorGUI.LabelField(line, CURRENT_ANR_MODE_LABEL, anrMode.ToString());
                line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;
            }

            // ANR available modes
            EditorGUI.LabelField(line, AVAILABLE_ANR_MODES_HEADING);
            line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;

            EditorGUI.indentLevel++;
            var availableAnrModesProperty = property.FindPropertyRelative(AVAILABLE_ANR_MODES_FIELD);
            int oldAnrModes = availableAnrModesProperty.intValue;
            int newAnrModes = 0;

            for (int i = 0; i < WearableConstants.ACTIVE_NOISE_REDUCTION_MODES.Length; i++)
            {
                ActiveNoiseReductionMode mode = WearableConstants.ACTIVE_NOISE_REDUCTION_MODES[i];

                if (mode == ActiveNoiseReductionMode.Invalid)
                {
                    continue;
                }

                int  flag     = (1 << (int)mode);
                bool selected = EditorGUI.Toggle(line, mode.ToString(), (flag & oldAnrModes) != 0);
                line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;
                if (selected)
                {
                    newAnrModes |= flag;
                }
            }

            EditorGUI.indentLevel--;

            if (newAnrModes != oldAnrModes)
            {
                availableAnrModesProperty.intValue = newAnrModes;
            }

            // CNC header
            line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT * 0.5f;
            EditorGUI.LabelField(line, CNC_HEADING);
            line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;
            box     = new Rect(
                line.x,
                line.y,
                line.width,
                WearableEditorConstants.SINGLE_LINE_HEIGHT * 3);
            GUI.Box(box, GUIContent.none);

            using (new EditorGUI.DisabledScope(true))
            {
                // CNC Level (read-only)
                var cncLevelProperty = property.FindPropertyRelative(CNC_LEVEL_FIELD);
                EditorGUI.LabelField(line, CNC_LEVEL_LABEL_TEXT, cncLevelProperty.intValue.ToString());
                line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;

                // CNC Enabled (read-only)
                var cncEnabledProperty = property.FindPropertyRelative(CNC_ENABLED_FIELD);
                EditorGUI.Toggle(line, CNC_ENABLED_LABEL, cncEnabledProperty.boolValue);
                line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;
            }

            // Total CNC levels
            var totalCncLevelsProperty = property.FindPropertyRelative(TOTAL_CNC_LEVELS_FIELD);

            EditorGUI.PropertyField(line, totalCncLevelsProperty, _totalCncLevelsLabel);
            line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;
            if (totalCncLevelsProperty.intValue < 0)
            {
                totalCncLevelsProperty.intValue = 0;
            }

            EditorGUI.EndProperty();
            property.serializedObject.ApplyModifiedProperties();
            EditorGUI.indentLevel = indent;
        }
示例#10
0
 protected override void SetActiveNoiseReductionModeInternal(ActiveNoiseReductionMode mode)
 {
     Debug.LogWarning(WearableConstants.USB_PROVIDER_ANR_NOT_AVAILABLE_WARNING);
     OnAnrCncWriteComplete();
 }
 public void SetActiveNoiseReductionModeProvider(ActiveNoiseReductionMode mode)
 {
     AndroidPlugin.SetActiveNoiseReductionMode((int)mode);
 }
 public void SetActiveNoiseReductionModeProvider(ActiveNoiseReductionMode mode)
 {
 }