Ejemplo n.º 1
0
 /// <summary>
 /// Sets the data source used by the rotation sensor
 /// </summary>
 /// <param name="source"></param>
 public void SetRotationSource(RotationSensorSource source)
 {
     if (SetRotationSourceInternal(source))
     {
         LockDeviceStateUpdate();
     }
 }
Ejemplo n.º 2
0
 private void OnSetRotationSourcePacket(RotationSensorSource source)
 {
     _transmitIndex = 0;
     _deviceProvider.SetRotationSource(source);
     WearableProxyServerProtocol.EncodeRotationSourceValue(_transmitBuffer, ref _transmitIndex, source);
     SendTransmitBuffer();
 }
 public void SetRotationSource(RotationSensorSource source)
 {
     if (_wearablePlugin != null)
     {
         _wearablePlugin.Call(SetRotationSourceMethod, (int)source);
     }
 }
Ejemplo n.º 4
0
                #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);
            }
        }
Ejemplo n.º 5
0
        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>();
        }
Ejemplo n.º 6
0
        internal override void SetRotationSource(RotationSensorSource source)
        {
            if (_connectedDevice == null)
            {
                Debug.LogWarning(WearableConstants.SetRotationSourceWithoutDeviceWarning);
                return;
            }

            Debug.Log(WearableConstants.MobileProviderRotationSourceUnsupportedInfo);
            _rotationSource = source;
        }
        /// <summary>
        /// Sets the <see cref="RotationSensorSource"/> <paramref name="rotSource"/> value.
        /// </summary>
        /// <param name="rotSource"></param>
        public void SetRotationSensorSource(RotationSensorSource rotSource)
        {
            if (DeviceConfig.rotationSource == rotSource)
            {
                return;
            }

            DeviceConfig.rotationSource = rotSource;

            SetDirty();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Sets the <see cref="RotationSource"/> to <paramref name="newSource"/>
        /// </summary>
        /// <param name="newSource"></param>
        /// <returns></returns>
        private bool SetRotationSourceInternal(RotationSensorSource newSource)
        {
            bool hasDeviceStateChanged = false;

            if (_wearableDeviceConfig.rotationSource != newSource)
            {
                _wearableDeviceConfig.rotationSource = newSource;
                hasDeviceStateChanged = true;
            }

            return(hasDeviceStateChanged);
        }
Ejemplo n.º 9
0
        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;
        }
Ejemplo n.º 10
0
        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;
        }
Ejemplo n.º 11
0
        internal override void SetRotationSource(RotationSensorSource source)
        {
            if (_connectedDevice == null)
            {
                Debug.LogWarning(WearableConstants.SetRotationSourceWithoutDeviceWarning);
                return;
            }

            _rotationSource = source;

                        #if UNITY_EDITOR
            WearableUSBSetRotationSource((int)source);
                        #endif
        }
        public static void EncodeRotationSourceValue(byte[] buffer, ref int index, RotationSensorSource source)
        {
            // Encode header
            PacketHeader header = new PacketHeader(PacketTypeCode.RotationSourceValue);

            SerializePacket(buffer, ref index, header);

            // Encode payload
            RotationSourcePacket packet = EncodeRotationSource(source);

            SerializePacket(buffer, ref index, packet);

            // Encode footer
            SerializePacket(buffer, ref index, _footer);
        }
Ejemplo n.º 13
0
        internal override void SetRotationSource(RotationSensorSource source)
        {
            // N.B. This has no affect on the simulated data.

            if (_connectedDevice == null)
            {
                Debug.LogWarning(WearableConstants.SetRotationSourceWithoutDeviceWarning);
                return;
            }

            if (_verbose)
            {
                Debug.LogFormat(
                    WearableConstants.DebugProviderSetRotationSource,
                    Enum.GetName(typeof(RotationSensorSource), source));
            }

            Debug.Log(WearableConstants.DebugProviderRotationSourceUnsupportedInfo);
            _rotationSource = source;
        }
        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);
            }
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Returns true if <see cref="RotationSensorSource"/> <paramref name="self"/> is a lower priority
 /// value than <see cref="RotationSensorSource"/> <paramref name="other"/> based on lower rotation
 /// accuracy.
 /// </summary>
 /// <param name="self"></param>
 /// <param name="other"></param>
 /// <returns></returns>
 public static bool IsLowerPriority(this RotationSensorSource self, RotationSensorSource other)
 {
     return(self == RotationSensorSource.SixDof &&
            other == RotationSensorSource.NineDof);
 }
 /// <summary>
 /// Set the data source for the rotation sensor.
 /// </summary>
 /// <param name="source"></param>
 internal abstract void SetRotationSource(RotationSensorSource source);
Ejemplo n.º 17
0
 /// <summary>
 /// Create a <see cref="RotationSourcePacket"/> from a <see cref="RotationSensorSource"/>
 /// </summary>
 /// <param name="source"></param>
 /// <returns></returns>
 protected static RotationSourcePacket EncodeRotationSource(RotationSensorSource source)
 {
     return(new RotationSourcePacket {
         value = (int)source
     });
 }
Ejemplo n.º 18
0
 private void Reset()
 {
     _updateInterval = WearableConstants.DEFAULT_UPDATE_INTERVAL;
     _rotationSource = RotationSensorSource.SixDof;
 }
        /// <summary>
        /// Consume a packet from the buffer if possible, then advance the buffer index.
        /// </summary>
        /// <param name="buffer">Byte buffer to decode</param>
        /// <param name="index">(Ref) Index to read into buffer</param>
        /// <exception cref="WearableProxyProtocolException">Thrown when a packet cannot be decoded and the buffer
        /// must be discarded.</exception>
        /// <exception cref="IndexOutOfRangeException">Thrown when a packet was partially consumed but ran out of
        /// buffer contents.</exception>
        public override void ProcessPacket(byte[] buffer, ref int index)
        {
            PacketTypeCode packetType = DecodePacketType(buffer, ref index);

            switch (packetType)
            {
            case PacketTypeCode.KeepAlive:
            {
                CheckFooter(buffer, ref index);

                if (KeepAlive != null)
                {
                    KeepAlive.Invoke();
                }

                break;
            }

            case PacketTypeCode.PingQuery:
            {
                CheckFooter(buffer, ref index);

                if (PingQuery != null)
                {
                    PingQuery.Invoke();
                }

                break;
            }

            case PacketTypeCode.PingResponse:
            {
                CheckFooter(buffer, ref index);

                if (PingResponse != null)
                {
                    PingResponse.Invoke();
                }

                break;
            }

            case PacketTypeCode.SensorControl:
            {
                bool     enabled;
                SensorId sensor = DecodeSensorControl(buffer, ref index, out enabled);
                CheckFooter(buffer, ref index);

                if (SensorControl != null)
                {
                    SensorControl.Invoke(sensor, enabled);
                }

                break;
            }

            case PacketTypeCode.SetRssiFilter:
            {
                int value = DecodeRSSIFilterControlPacket(buffer, ref index);
                CheckFooter(buffer, ref index);

                if (RSSIFilterValueChange != null)
                {
                    RSSIFilterValueChange.Invoke(value);
                }

                break;
            }

            case PacketTypeCode.InitiateDeviceSearch:
            {
                CheckFooter(buffer, ref index);

                if (InitiateDeviceSearch != null)
                {
                    InitiateDeviceSearch.Invoke();
                }

                break;
            }

            case PacketTypeCode.StopDeviceSearch:
            {
                CheckFooter(buffer, ref index);

                if (StopDeviceSearch != null)
                {
                    StopDeviceSearch.Invoke();
                }

                break;
            }

            case PacketTypeCode.ConnectToDevice:
            {
                string uid = DecodeDeviceConnectPacket(buffer, ref index);
                CheckFooter(buffer, ref index);

                if (ConnectToDevice != null)
                {
                    ConnectToDevice.Invoke(uid);
                }

                break;
            }

            case PacketTypeCode.DisconnectFromDevice:
            {
                CheckFooter(buffer, ref index);

                if (DisconnectFromDevice != null)
                {
                    DisconnectFromDevice.Invoke();
                }

                break;
            }

            case PacketTypeCode.QueryConnectionStatus:
            {
                CheckFooter(buffer, ref index);

                if (QueryConnectionStatus != null)
                {
                    QueryConnectionStatus.Invoke();
                }

                break;
            }

            case PacketTypeCode.QueryUpdateInterval:
            {
                CheckFooter(buffer, ref index);

                if (QueryUpdateInterval != null)
                {
                    QueryUpdateInterval.Invoke();
                }

                break;
            }

            case PacketTypeCode.SetUpdateInterval:
            {
                SensorUpdateInterval interval = DecodeSetUpdateIntervalPacket(buffer, ref index);
                CheckFooter(buffer, ref index);

                if (SetUpdateInterval != null)
                {
                    SetUpdateInterval.Invoke(interval);
                }

                break;
            }

            case PacketTypeCode.QuerySensorStatus:
            {
                CheckFooter(buffer, ref index);

                if (QuerySensorStatus != null)
                {
                    QuerySensorStatus.Invoke();
                }

                break;
            }

            case PacketTypeCode.GestureControl:
            {
                bool      enabled;
                GestureId gestureId = DecodeGestureControl(buffer, ref index, out enabled);
                CheckFooter(buffer, ref index);

                if (GestureControl != null)
                {
                    GestureControl.Invoke(gestureId, enabled);
                }

                break;
            }

            case PacketTypeCode.QueryGestureStatus:
            {
                CheckFooter(buffer, ref index);

                if (QueryGestureStatus != null)
                {
                    QueryGestureStatus.Invoke();
                }

                break;
            }

            case PacketTypeCode.QueryRotationSource:
            {
                CheckFooter(buffer, ref index);

                if (QueryRotationSource != null)
                {
                    QueryRotationSource.Invoke();
                }

                break;
            }

            case PacketTypeCode.SetRotationSource:
            {
                RotationSensorSource source = DecodeRotationSource(buffer, ref index);
                CheckFooter(buffer, ref index);

                if (SetRotationSource != null)
                {
                    SetRotationSource.Invoke(source);
                }

                break;
            }

            case PacketTypeCode.SensorFrame:
            case PacketTypeCode.DeviceList:
            case PacketTypeCode.ConnectionStatus:
            case PacketTypeCode.SensorStatus:
            case PacketTypeCode.UpdateIntervalValue:
            case PacketTypeCode.GestureStatus:
            case PacketTypeCode.RotationSourceValue:
                // Known, but contextually-invalid packet
                throw new WearableProxyProtocolException(WearableConstants.ProxyProviderInvalidPacketError);

            default:
                // Unknown or corrupt packet
                throw new WearableProxyProtocolException(WearableConstants.ProxyProviderInvalidPacketError);
            }
        }
 internal override void SetRotationSource(RotationSensorSource source)
 {
     _transmitIndex = 0;
     WearableProxyClientProtocol.EncodeSetRotationSource(_transmitBuffer, ref _transmitIndex, source);
     SendTransmitBuffer();
 }
 private void OnRotationSourceValue(RotationSensorSource source)
 {
     _rotationSource = source;
 }
        /// <summary>
        /// Consume a packet from the buffer if possible, then advance the buffer index.
        /// </summary>
        /// <param name="buffer">Byte buffer to decode</param>
        /// <param name="index">(Ref) Index to read into buffer</param>
        /// <exception cref="WearableProxyProtocolException">Thrown when a packet cannot be decoded and the buffer
        /// must be discarded.</exception>
        /// <exception cref="IndexOutOfRangeException">Thrown when a packet was partially consumed but ran out of
        /// buffer contents.</exception>
        public override void ProcessPacket(byte[] buffer, ref int index)
        {
            PacketTypeCode packetType = DecodePacketType(buffer, ref index);

            switch (packetType)
            {
            case PacketTypeCode.KeepAlive:
            {
                CheckFooter(buffer, ref index);

                if (KeepAlive != null)
                {
                    KeepAlive.Invoke();
                }

                break;
            }

            case PacketTypeCode.PingQuery:
            {
                CheckFooter(buffer, ref index);

                if (PingQuery != null)
                {
                    PingQuery.Invoke();
                }

                break;
            }

            case PacketTypeCode.PingResponse:
            {
                CheckFooter(buffer, ref index);

                if (PingResponse != null)
                {
                    PingResponse.Invoke();
                }

                break;
            }

            case PacketTypeCode.SensorFrame:
            {
                SensorFrame frame = DecodeSensorFrame(buffer, ref index);
                CheckFooter(buffer, ref index);

                if (NewSensorFrame != null)
                {
                    NewSensorFrame.Invoke(frame);
                }

                break;
            }

            case PacketTypeCode.DeviceList:
            {
                Device[] devices = DecodeDeviceList(buffer, ref index);
                CheckFooter(buffer, ref index);

                if (DeviceList != null)
                {
                    DeviceList.Invoke(devices);
                }

                break;
            }

            case PacketTypeCode.ConnectionStatus:
            {
                Device?         device;
                ConnectionState status = DecodeConnectionStatus(buffer, ref index, out device);
                CheckFooter(buffer, ref index);

                if (ConnectionStatus != null)
                {
                    ConnectionStatus.Invoke(status, device);
                }

                break;
            }

            case PacketTypeCode.SensorStatus:
            {
                bool     enabled;
                SensorId sensor = DecodeSensorStatus(buffer, ref index, out enabled);
                CheckFooter(buffer, ref index);

                if (SensorStatus != null)
                {
                    SensorStatus.Invoke(sensor, enabled);
                }

                break;
            }

            case PacketTypeCode.UpdateIntervalValue:
            {
                SensorUpdateInterval rate = DecodeUpdateInterval(buffer, ref index);
                CheckFooter(buffer, ref index);

                if (SensorUpdateIntervalValue != null)
                {
                    SensorUpdateIntervalValue.Invoke(rate);
                }

                break;
            }

            case PacketTypeCode.GestureStatus:
            {
                bool      enabled;
                GestureId gesture = DecodeGestureStatus(buffer, ref index, out enabled);
                CheckFooter(buffer, ref index);

                if (GestureStatus != null)
                {
                    GestureStatus.Invoke(gesture, enabled);
                }

                break;
            }

            case PacketTypeCode.RotationSourceValue:
            {
                RotationSensorSource source = DecodeRotationSource(buffer, ref index);
                CheckFooter(buffer, ref index);

                if (RotationSourceValue != null)
                {
                    RotationSourceValue.Invoke(source);
                }

                break;
            }

            case PacketTypeCode.SensorControl:
            case PacketTypeCode.SetRssiFilter:
            case PacketTypeCode.InitiateDeviceSearch:
            case PacketTypeCode.StopDeviceSearch:
            case PacketTypeCode.ConnectToDevice:
            case PacketTypeCode.DisconnectFromDevice:
            case PacketTypeCode.QueryConnectionStatus:
            case PacketTypeCode.QueryUpdateInterval:
            case PacketTypeCode.SetUpdateInterval:
            case PacketTypeCode.QuerySensorStatus:
            case PacketTypeCode.GestureControl:
            case PacketTypeCode.QueryRotationSource:
            case PacketTypeCode.SetRotationSource:
                // This is a known, but contextually-invalid packet type
                throw new WearableProxyProtocolException(WearableConstants.ProxyProviderInvalidPacketError);

            default:
                // This is an unknown or invalid packet type
                throw new WearableProxyProtocolException(WearableConstants.ProxyProviderInvalidPacketError);
            }
        }