/// <summary>
 /// Invokes the <see cref="SensorsOrGestureUpdated"/> event.
 /// </summary>
 /// <param name="frame"></param>
 protected void OnSensorsOrGestureUpdated(SensorFrame frame)
 {
     if (SensorsOrGestureUpdated != null)
     {
         SensorsOrGestureUpdated.Invoke(frame);
     }
 }
        protected WearableProviderBase()
        {
            _currentSensorFrames = new List <SensorFrame>();
            _lastSensorFrame     = WearableConstants.EMPTY_FRAME;

            _currentGestureData = new List <GestureData>();
        }
Ejemplo n.º 3
0
        private void Update()
        {
            if (_wearableControl.ConnectedDevice == null)
            {
                return;
            }

            // Get a frame of sensor data. Since no integration is being performed, we can safely ignore all
            // intermediate frames and just grab the most recent.

            SensorFrame frame           = _wearableControl.LastSensorFrame;
            Vector3     newAcceleration = frame.acceleration;

            if (lastFrameAcceleration != new Vector3(0, 0, 0))
            {
                Vector3 diff = lastFrameAcceleration - newAcceleration;
                lastFrameAcceleration = newAcceleration;


                if (interpolation)
                {
                    transform.position = Vector3.Lerp(transform.position, diff, Time.deltaTime * relativeSpeed);
                }
                else
                {
                    transform.position = diff * relativeSpeed;
                }
            }
            else
            {
                lastFrameAcceleration = newAcceleration;
            }
        }
Ejemplo n.º 4
0
        static WearableConstants()
        {
            // Ensure that empty frame has a valid rotation quaternion
            EMPTY_FRAME = new SensorFrame
            {
                rotationNineDof = new SensorQuaternion {
                    value = Quaternion.identity
                },
                rotationSixDof = new SensorQuaternion {
                    value = Quaternion.identity
                }
            };

            CONNECTING_STATES = new List <ConnectionStatus>
            {
                ConnectionStatus.FirmwareUpdateRequired,
                ConnectionStatus.FirmwareUpdateAvailable,
                ConnectionStatus.Connecting,
                ConnectionStatus.AutoReconnect,
                ConnectionStatus.SecurePairingRequired
            };

            EMPTY_DEVICE_LIST = new Device[0];

            GESTURE_IDS                        = (GestureId[])Enum.GetValues(typeof(GestureId));
            SENSOR_IDS                         = (SensorId[])Enum.GetValues(typeof(SensorId));
            UPDATE_INTERVALS                   = (SensorUpdateInterval[])Enum.GetValues(typeof(SensorUpdateInterval));
            SIGNAL_STRENGTHS                   = (SignalStrength[])Enum.GetValues(typeof(SignalStrength));
            ACTIVE_NOISE_REDUCTION_MODES       = (ActiveNoiseReductionMode[])Enum.GetValues(typeof(ActiveNoiseReductionMode));
            EMPTY_ACTIVE_NOISE_REDUCTION_MODES = new ActiveNoiseReductionMode[0];
            DEVICE_STATUS_FLAGS                = (DeviceStatusFlags[])Enum.GetValues(typeof(DeviceStatusFlags));
            OS_PERMISSIONS                     = (OSPermission[])Enum.GetValues(typeof(OSPermission));
            OS_SERVICES                        = (OSService[])Enum.GetValues(typeof(OSService));

            DISABLED_DEVICE_CONFIG = new WearableDeviceConfig();
            DISABLED_DEVICE_CONFIG.DisableAllSensors();
            DISABLED_DEVICE_CONFIG.DisableAllGestures();

                        #pragma warning disable 618
            DISALLOWED_EDITOR_PROVIDERS  = new[] { ProviderId.BluetoothProvider };
            DISALLOWED_RUNTIME_PROVIDERS = new[] { ProviderId.USBProvider };
                        #pragma warning restore 618

            DEBUG_PROVIDER_DEFAULT_AVAILABLE_ANR_MODES = new[] {
                ActiveNoiseReductionMode.Off,
                ActiveNoiseReductionMode.Low,
                ActiveNoiseReductionMode.High
            };

            EMPTY_DEVICE_STATUS       = new DeviceStatus();
            EMPTY_DYNAMIC_DEVICE_INFO = new DynamicDeviceInfo
            {
                transmissionPeriod                       = -1,
                activeNoiseReductionMode                 = ActiveNoiseReductionMode.Invalid,
                availableActiveNoiseReductionModes       = WearableTools.GetActiveNoiseReductionModesAsInt(EMPTY_ACTIVE_NOISE_REDUCTION_MODES),
                controllableNoiseCancellationLevel       = 0,
                controllableNoiseCancellationEnabled     = false,
                totalControllableNoiseCancellationLevels = 0
            };
        }
Ejemplo n.º 5
0
        private void Update()
        {
            if (_wearableControl.ConnectedDevice == null)
            {
                return;
            }

            // Get a frame of sensor data. Since no integration is being performed, we can safely ignore all
            // intermediate frames and just grab the most recent.
            SensorFrame frame = _wearableControl.LastSensorFrame;

            if (_mode == RotationReference.Absolute)
            {
                // In absolute mode, match the rotation exactly.
                transform.rotation =
                    (_rotationSource == RotationSensorSource.NineDof ?
                     frame.rotationNineDof :
                     frame.rotationSixDof);
            }
            else if (_mode == RotationReference.Relative)
            {
                // In relative mode, left-apply the inverse of the reference rotation to compute the relative change
                transform.rotation = _inverseReference *
                                     (_rotationSource == RotationSensorSource.NineDof ?
                                      frame.rotationNineDof :
                                      frame.rotationSixDof);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Invokes the <see cref="SensorsUpdated"/> event.
        /// If the frame contains a gesture, also invokes the <see cref="GestureDetected"/> event.
        /// </summary>
        /// <param name="frame"></param>
        private void OnSensorsUpdated(SensorFrame frame)
        {
            if (SensorsUpdated != null)
            {
                SensorsUpdated.Invoke(frame);
            }

            if (frame.gestureId != GestureId.None)
            {
                if (GestureDetected != null)
                {
                    GestureDetected.Invoke(frame.gestureId);
                }

                switch (frame.gestureId)
                {
                case GestureId.DoubleTap:
                    if (DoubleTapDetected != null)
                    {
                        DoubleTapDetected.Invoke();
                    }
                    break;

                case GestureId.None:
                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Ejemplo n.º 7
0
        private void Update()
        {
            if (_wearableControl.ConnectedDevice == null)
            {
                return;
            }

            // Get a frame of sensor data. Since no integration is being performed, we can safely ignore all
            // intermediate frames and just grab the most recent.
            SensorFrame frame = _wearableControl.LastSensorFrame;

            Quaternion rotation =
                (_rotationSource == RotationSensorSource.NineDof ?
                 frame.rotationNineDof :
                 frame.rotationSixDof);

            transform.eulerAngles = new Vector3(0, rotation.eulerAngles.y, 0);
            Debug.Log(rotation.eulerAngles.x);
            if (10 < rotation.eulerAngles.x && rotation.eulerAngles.x < 90)
            {
                if (_rigidBody.velocity.magnitude > 10)
                {
                    _rigidBody.AddForce(transform.forward * -6);
                }
                else
                {
                    _rigidBody.AddForce(transform.forward * 6);
                }
            }
        }
Ejemplo n.º 8
0
        static WearableConstants()
        {
            // Ensure that empty frame has a valid rotation quaternion
            EmptyFrame = new SensorFrame
            {
                rotation = new SensorQuaternion {
                    value = Quaternion.identity
                }
            };

            EmptyDeviceList = new Device[0];

            EmptyLayoutOptions = new GUILayoutOption[0];

            GestureIds = (GestureId[])Enum.GetValues(typeof(GestureId));
        }
Ejemplo n.º 9
0
        static WearableConstants()
        {
            // Ensure that empty frame has a valid rotation quaternion
            EmptyFrame = new SensorFrame
            {
                rotationNineDof = new SensorQuaternion {
                    value = Quaternion.identity
                },
                rotationSixDof = new SensorQuaternion {
                    value = Quaternion.identity
                }
            };

            ConnectingStates = new List <ConnectionStatus>
            {
                ConnectionStatus.FirmwareUpdateRequired,
                ConnectionStatus.FirmwareUpdateAvailable,
                ConnectionStatus.Connecting,
                ConnectionStatus.AutoReconnect,
                ConnectionStatus.SecurePairingRequired
            };

            EmptyDeviceList = new Device[0];

            EmptyLayoutOptions = new GUILayoutOption[0];

            GestureIds      = (GestureId[])Enum.GetValues(typeof(GestureId));
            SensorIds       = (SensorId[])Enum.GetValues(typeof(SensorId));
            UpdateIntervals = (SensorUpdateInterval[])Enum.GetValues(typeof(SensorUpdateInterval));
            SignalStrengths = (SignalStrength[])Enum.GetValues(typeof(SignalStrength));

            DisabledDeviceConfig = new WearableDeviceConfig();
            DisabledDeviceConfig.DisableAllSensors();
            DisabledDeviceConfig.DisableAllGestures();

                        #pragma warning disable 618
            DisallowedEditorProviders  = new[] { ProviderId.MobileProvider, ProviderId.WearableDevice };
            DisallowedRuntimeProviders = new[] { ProviderId.MobileProvider, ProviderId.USBProvider };
                        #pragma warning restore 618

            EmptyDeviceStatus      = new DeviceStatus();
            EmptyDynamicDeviceInfo = new DynamicDeviceInfo {
                transmissionPeriod = -1
            };
        }
Ejemplo n.º 10
0
        private void UpdateUI(SensorFrame frame)
        {
            var currentDeviceConfig = _wearableControl.CurrentDeviceConfig;
            var style = _colorPalette.GetCustomizedActiveStyle();

            // Update Accelerometer
            var isAccelerometerEnabled = currentDeviceConfig.GetSensorConfig(SensorId.Accelerometer).isEnabled;
            var accelChildElementColor = isAccelerometerEnabled
                                ? _colorPalette.ActiveDataTextColor
                                : _colorPalette.InactiveDataTextColor;

            Color accelTitleTextColor;
            Color accelTitleElementColor;

            if (isAccelerometerEnabled)
            {
                accelTitleTextColor    = style.textColor;
                accelTitleElementColor = style.elementColor;
            }
            else
            {
                accelTitleTextColor    = _colorPalette.InactiveTitleElementStyle.textColor;
                accelTitleElementColor = _colorPalette.InactiveTitleElementStyle.elementColor;
            }

            _accelerometerTitleImage.color  = accelTitleElementColor;
            _accelerometerTitleText.color   = accelTitleTextColor;
            _accelerometerAccuracyText.text = Enum.GetName(typeof(SensorAccuracy), frame.acceleration.accuracy).ToUpper();

            _accelerometerX.color = accelChildElementColor;
            _accelerometerX.text  = string.Format(
                frame.acceleration.value.x >= 0
                                        ? DebuggingConstants.DataComponentFormatPositive
                                        : DebuggingConstants.DataComponentFormatNegative,
                DebuggingConstants.XField,
                Mathf.Abs(frame.acceleration.value.x));

            _accelerometerY.color = accelChildElementColor;
            _accelerometerY.text  = string.Format(
                frame.acceleration.value.y >= 0
                                        ? DebuggingConstants.DataComponentFormatPositive
                                        : DebuggingConstants.DataComponentFormatNegative,
                DebuggingConstants.YField,
                Mathf.Abs(frame.acceleration.value.y));

            _accelerometerZ.color = accelChildElementColor;
            _accelerometerZ.text  = string.Format(
                frame.acceleration.value.z >= 0
                                        ? DebuggingConstants.DataComponentFormatPositive
                                        : DebuggingConstants.DataComponentFormatNegative,
                DebuggingConstants.ZField,
                Mathf.Abs(frame.acceleration.value.z));

            // Update Gyroscope
            var isGyroscopeEnabled    = currentDeviceConfig.GetSensorConfig(SensorId.Gyroscope).isEnabled;
            var gyroChildElementColor = isGyroscopeEnabled
                                ? _colorPalette.ActiveDataTextColor
                                : _colorPalette.InactiveDataTextColor;

            Color gyroTitleTextColor;
            Color gyroTitleElementColor;

            if (isGyroscopeEnabled)
            {
                gyroTitleTextColor    = style.textColor;
                gyroTitleElementColor = style.elementColor;
            }
            else
            {
                gyroTitleTextColor    = _colorPalette.InactiveTitleElementStyle.textColor;
                gyroTitleElementColor = _colorPalette.InactiveTitleElementStyle.elementColor;
            }

            _gyroscopeTitleImage.color  = gyroTitleElementColor;
            _gyroscopeTitleText.color   = gyroTitleTextColor;
            _gyroscopeAccuracyText.text = Enum.GetName(typeof(SensorAccuracy), frame.angularVelocity.accuracy).ToUpper();

            _gyroscopeX.color = gyroChildElementColor;
            _gyroscopeX.text  = string.Format(
                frame.angularVelocity.value.x >= 0
                                        ? DebuggingConstants.DataComponentFormatPositive
                                        : DebuggingConstants.DataComponentFormatNegative,
                DebuggingConstants.XField,
                Mathf.Abs(frame.angularVelocity.value.x));

            _gyroscopeY.color = gyroChildElementColor;
            _gyroscopeY.text  = string.Format(
                frame.angularVelocity.value.y >= 0
                                        ? DebuggingConstants.DataComponentFormatPositive
                                        : DebuggingConstants.DataComponentFormatNegative,
                DebuggingConstants.YField,
                Mathf.Abs(frame.angularVelocity.value.y));

            _gyroscopeZ.color = gyroChildElementColor;
            _gyroscopeZ.text  = string.Format(
                frame.angularVelocity.value.z >= 0
                                        ? DebuggingConstants.DataComponentFormatPositive
                                        : DebuggingConstants.DataComponentFormatNegative,
                DebuggingConstants.ZField,
                Mathf.Abs(frame.angularVelocity.value.z));

            _rotationControlNineDof.UpdateUI(frame.rotationNineDof);
            _rotationControlSixDof.UpdateUI(frame.rotationSixDof);
        }
 protected WearableProviderBase()
 {
     _currentSensorFrames = new List <SensorFrame>();
     _lastSensorFrame     = WearableConstants.EmptyFrame;
 }
Ejemplo n.º 12
0
        private void Update()
        {
            if (_wearableControl.ConnectedDevice == null)
            {
                return;
            }

            // Get a frame of sensor data. Since no integration is being performed, we can safely ignore all
            // intermediate frames and just grab the most recent.
            SensorFrame frame = _wearableControl.LastSensorFrame;

            //if (_mode == RotationReference.Absolute)
            //{
            //    xValueText.text = frame.rotation.value.x.ToString();

            //    yValueText.text = frame.rotation.value.y.ToString();

            //    zValueText.text = frame.rotation.value.z.ToString();

            //    xAccel.text = frame.acceleration.value.normalized.x.ToString();
            //    yAccel.text = frame.acceleration.value.y.ToString();
            //    zAccel.text = frame.acceleration.value.z.ToString();



            //}

            //else if (_mode == RotationReference.Relative)

            //{

            //    xValueText.text = frame.rotation.value.x.ToString();

            //    yValueText.text = frame.rotation.value.y.ToString();

            //    zValueText.text = frame.rotation.value.z.ToString();
            //}

            if (frame.acceleration.value.x > 4.0f)
            {
                left.Play();
            }
            if (frame.acceleration.value.x < -4.0f)
            {
                right.Play();
            }

            if (frame.acceleration.value.y > 13.0f)
            {
                jump.Play();
            }
            if (frame.acceleration.value.y < 5.0f)
            {
                duck.Play();
            }
            if (frame.acceleration.value.z > 4.0f)
            {
                headbutt.Play();
            }
            if (frame.acceleration.value.z < -4.0f)
            {
                back.Play();
            }
        }
Ejemplo n.º 13
0
        private void Update()
        {
            if (_wearableControl.ConnectedDevice == null)
            {
                return;
            }

            // Get a frame of sensor data. Since no integration is being performed, we can safely ignore all
            // intermediate frames and just grab the most recent.
            SensorFrame frame = _wearableControl.LastSensorFrame;

            if (_mode == RotationReference.Absolute)
            {
                xValueText.text = frame.rotation.value.x.ToString();

                yValueText.text = frame.rotation.value.y.ToString();

                zValueText.text = frame.rotation.value.z.ToString();

                xAccel.text = frame.acceleration.value.x.ToString();
                yAccel.text = frame.acceleration.value.y.ToString();
                zAccel.text = frame.acceleration.value.z.ToString();

                //xAccelNorm.text = frame.acceleration.value.x.ToString();
                //yAccelNorm.text = frame.acceleration.value.y.ToString();
                //zAccelNorm.text = frame.acceleration.value.z.ToString();
            }

            else if (_mode == RotationReference.Relative)

            {
                xValueText.text = frame.rotation.value.x.ToString();

                yValueText.text = frame.rotation.value.y.ToString();

                zValueText.text = frame.rotation.value.z.ToString();
            }


            if (frame.acceleration.value.x > 4.0f)
            {
                Action.text = "X is positive";
            }
            if (frame.acceleration.value.x < -4.0f)
            {
                Action.text = "X is negative";
            }

            if (frame.acceleration.value.y > 13.0f)
            {
                Action.text = "Y is positive";
            }
            if (frame.acceleration.value.y < 5.0f)
            {
                Action.text = "Y is negative";
            }
            if (frame.acceleration.value.z > 4.0f)
            {
                Action.text = "Z is positive";
            }
            if (frame.acceleration.value.z < -4.0f)
            {
                Action.text = "Z is negative";
            }
        }
Ejemplo n.º 14
0
        // Update is called once per frame
        void Update()
        {
            if (_wearableControl.ConnectedDevice == null)
            {
                return;
            }

            // Get a frame of sensor data. Since no integration is being performed, we can safely ignore all
            // intermediate frames and just grab the most recent.
            SensorFrame frame = _wearableControl.LastSensorFrame;

            curAcc = frame.acceleration.value.magnitude;

            if (!songPlayer.isPlaying)
            {
                Globals.score    += finalPoints;
                songPlayer.volume = 0;
                audioDone.Play();
                //GAME IS OVER
                return;
            }
            timeleft -= Time.deltaTime;
            if (timeleft < changeVolTime)
            {
                songPlayer.volume = 0;

                if (timeleft > changeVolTime - .8) //allow a sec for person to react
                {
                    FreezePosition();
                }
                else
                {
                    //check that person isn't moving
                    if (CheckMove() == true)
                    {
                        FreezePosition(); //reset position to give them another chance
                        if (!audioFreeze.isPlaying)
                        {
                            audioFreeze.clip = freezeAudioClips[Random.Range(0, freezeAudioClips.Length)];
                            audioFreeze.Play(); //play buzz if they move
                            Globals.score -= 1;
                        }
                    }

                    if (timeleft < changeVolTime - 5)
                    {
                        songPlayer.volume = .4f;
                        updateMoveCheck   = Mathf.FloorToInt(Time.time) + 0.8f; //give react time to dance
                        RandomTime();
                        //if person successfully didn't move, play point audioRight.Play();
                        //else play buzz audioFreeze.Play();
                    }
                }
            }
            else //check that person is actually moving
            {
                //TODO make this nicer
                // TODO make sure event isn't near the freeze time
                if (timeleft < changeSpinTime)  //do a spin
                {
                    if (task == 0 || task == 1) //slide to right or left
                    {
                        if (!inATask)
                        {
                            audioInstructions.Play();
                            inATask = true;
                            return;
                        }
                        if ((task == 0 && frame.acceleration.value.x > 3.0f) ||
                            (task == 1 && frame.acceleration.value.x < -3.0f))   //tothe right or left
                        {
                            //you did it!
                            audioRight.Play();
                            Globals.score += 1;
                            RandomSpinTime();
                        }

                        if (timeleft < changeSpinTime - 5) //5 seconds to do a task
                        {
                            audioFeedback.clip = boo;
                            audioFeedback.Play();
                            RandomSpinTime();
                        }
                    }
                    else // spin
                    {
                        if (!inASpin)
                        {
                            curXangle = 0;
                            audioInstructions.clip = spin;
                            audioInstructions.Play();
                            lastFwd = transform.forward;
                            inASpin = true;
                            return;
                        }

                        DoASpin(); //calc angles


                        if (Mathf.Abs(curXangle) >= 120) //congrats you did a spin
                        {
                            //you did it!
                            audioRight.Play();
                            Globals.score += 1;
                            RandomSpinTime();
                        }

                        if (timeleft < changeSpinTime - 5) //5 seconds to do a spin
                        {
                            audioFeedback.clip = boo;
                            audioFeedback.Play();
                            RandomSpinTime();
                        }
                    }
                }
                else if (Time.time >= updateMoveCheck)
                {
                    inASpin         = false;
                    inATask         = false;
                    updateMoveCheck = Mathf.FloorToInt(Time.time) + 3f;
                    //allow them a sec to react
                    if (frame.acceleration.value.magnitude > min && frame.acceleration.value.magnitude < max)
                    {
                        if (!audioFeedback.isPlaying)
                        {
                            audioFeedback.clip = danceHarderAudioClips[Random.Range(0, danceHarderAudioClips.Length)];
                            audioFeedback.Play();
                            Globals.score -= 1;
                        }
                    }
                }
                else
                {
                    FreezePosition();
                }
            }
        }
Ejemplo n.º 15
0
        private void Update()
        {
            if (_wearableControl.ConnectedDevice == null)
            {
                return;
            }

            // Get a frame of sensor data. Since no integration is being performed, we can safely ignore all
            // intermediate frames and just grab the most recent.
            SensorFrame frame = _wearableControl.LastSensorFrame;

            if (turnStart)
            {
                //Pick audio clip
                direction = Random.Range(0, audioSources.Length);
                //Play direction
                audioSources[direction].Play();
                //Start turn timer
                turnTimer = turnSpeed;
                if (hurt)
                {
                    oof.Play();
                    hurt = false;
                    if (Globals.score > 0)
                    {
                        Globals.score--;
                    }
                }
                actionTaken = false;
            }
            turnStart = false;


            if (turnTimer <= 0.0f)
            {
                //Start next turn
                turnStart = true;
            }

            if (turnTimer > 0.0f && !actionTaken)
            {
                if (frame.acceleration.value.x > 4.0f)
                {
                    //right
                    grunt.Play();
                    if (direction == 1)
                    {
                        delayedPoint.Play();
                        Globals.score++;
                    }
                    else
                    {
                        hurt = true;
                    }
                    actionTaken = true;
                }
                else if (frame.acceleration.value.x < -4.0f)
                {
                    //left
                    grunt.Play();
                    if (direction == 0)
                    {
                        delayedPoint.Play();
                        Globals.score++;
                    }
                    else
                    {
                        hurt = true;
                    }
                    actionTaken = true;
                }

                if (frame.acceleration.value.y > 13.0f)
                {
                    //down
                    grunt.Play();
                    if (direction == 4)
                    {
                        delayedPoint.Play();
                        Globals.score++;
                    }
                    else
                    {
                        hurt = true;
                    }
                    actionTaken = true;
                }
                else if (frame.acceleration.value.y < 5.0f)
                {
                    //up
                    grunt.Play();
                    if (direction == 2)
                    {
                        delayedPoint.Play();
                        Globals.score++;
                    }
                    else
                    {
                        hurt = true;
                    }
                    actionTaken = true;
                }
                if (frame.acceleration.value.z > 4.0f)
                {
                    //forward
                    headbutt.Play();
                    if (direction == 5)
                    {
                        delayedPoint.Play();
                        Globals.score++;
                    }
                    else
                    {
                        hurt = true;
                    }
                    actionTaken = true;
                }
                else if (frame.acceleration.value.z < -4.0f)
                {
                    //back
                    grunt.Play();
                    if (direction == 3)
                    {
                        delayedPoint.Play();
                        Globals.score++;
                    }
                    else
                    {
                        hurt = true;
                    }
                    actionTaken = true;
                }
            }

            float subTime = Time.deltaTime;

            turnTimer -= subTime;
        }