Ejemplo n.º 1
0
    private void UpdateTransform(int serialListPosition, NotificationCallback.EventArgs e)
    {
        // ignore magnetic field, heratrate and temperature
        float x, y, z;

        if (e.Subscriptionpath == SubscriptionPath.MagneticField || e.Subscriptionpath == SubscriptionPath.HeartRate || e.Subscriptionpath == SubscriptionPath.Temperature)
        {
            return;
        }

        var notificationFieldArgs = (NotificationCallback.FieldArgs)e;

        if (e.Subscriptionpath == SubscriptionPath.AngularVelocity)
        {
            z = (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].z * angularCorrection;
            y = (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].y * angularCorrection;
            x = (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].x * angularCorrection;
            angularVelocity = new Vector3(x, y, z);
        }
        else if (e.Subscriptionpath == SubscriptionPath.LinearAcceleration)
        {
            z = (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].z;
            y = (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].y;
            x = (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].x;
            linearAcceleration = new Vector3(x, y, z);
        }
    }
Ejemplo n.º 2
0
    void RefreshHeartrate(NotificationCallback.EventArgs e)
    {
        if (e == null)
        {
            return;
        }

        if (e.Subscriptionpath == SubscriptionPath.HeartRate)
        {
            var notificationHeartRateArgs = (NotificationCallback.HeartRateArgs)e;
            heartRate = (int)notificationHeartRateArgs.Pulse;
        }
    }
Ejemplo n.º 3
0
 void OnNotificationCallbackEvent(object sender, NotificationCallback.EventArgs e)
 {
             #pragma warning disable CS0162
     if (isLogging)
     {
         Debug.Log(TAG + "OnNotificationCallbackEvent: " + e.Data);
     }
             #pragma warning restore CS0162
     notificationLock.EnterWriteLock();
     try {
         notificationCallbackEventArgs.Add(e);
     } finally {
         notificationLock.ExitWriteLock();
     }
 }
Ejemplo n.º 4
0
    void RefreshPanelSubscription(int connectedElementIndex, NotificationCallback.EventArgs e)
    {
                #pragma warning disable CS0162
        if (isLogging)
        {
            Debug.Log(TAG + "RefreshPanelSubscription, connectedElementIndex: " + connectedElementIndex + ", e.Data: " + (e == null?"e == null!":e.Data));
        }
                #pragma warning restore CS0162
        if (e == null)           // @Start or on DisconnectEvent or if another Sensor is selected
        {
                        #pragma warning disable CS0162
            if (isLogging)
            {
                Debug.Log(TAG + "RefreshPanelSubscription, refreshing Sensorlist");
            }
                        #pragma warning restore CS0162
            // check subscriptionTypes per serial in MovesenseDevice
            if (MovesenseDevice.Devices.Count == 0)
            {
                Debug.LogError(TAG + "RefreshPanelSubscription, MovesenseDevice.Devices.Count == 0");
                return;
            }

            Dictionary <string, int?> subscriptionTypes = new Dictionary <string, int?>();
            if (MovesenseDevice.GetAllSubscriptionPaths(MovesenseDevice.Devices[connectedElementIndex].Serial) != null)
            {
                subscriptionTypes = new Dictionary <string, int?>(MovesenseDevice.GetAllSubscriptionPaths(MovesenseDevice.Devices[connectedElementIndex].Serial));
            }

            if (subscriptionTypes.ContainsKey(SubscriptionPath.LinearAcceleration))
            {
                buttonsSubscription[0].image.sprite = buttonOn;
                // Example for getting samplerate:
                // Debug.Log("SampleRate: " + subscriptionTypes[SubscriptionPath.LinearAcceleration]);
                TextLinAcc[0].text = "...";
                TextLinAcc[1].text = "...";
                TextLinAcc[2].text = "...";
            }
            else
            {
                buttonsSubscription[0].image.sprite = buttonOff;
                TextLinAcc[0].text = "--";
                TextLinAcc[1].text = "--";
                TextLinAcc[2].text = "--";
            }
            if (subscriptionTypes.ContainsKey(SubscriptionPath.AngularVelocity))
            {
                buttonsSubscription[1].image.sprite = buttonOn;
                TextGyro[0].text = "...";
                TextGyro[1].text = "...";
                TextGyro[2].text = "...";
            }
            else
            {
                buttonsSubscription[1].image.sprite = buttonOff;
                TextGyro[0].text = "--";
                TextGyro[1].text = "--";
                TextGyro[2].text = "--";
            }
            if (subscriptionTypes.ContainsKey(SubscriptionPath.MagneticField))
            {
                buttonsSubscription[2].image.sprite = buttonOn;
                TextMagnField[0].text = "...";
                TextMagnField[1].text = "...";
                TextMagnField[2].text = "...";
            }
            else
            {
                buttonsSubscription[2].image.sprite = buttonOff;
                TextMagnField[0].text = "--";
                TextMagnField[1].text = "--";
                TextMagnField[2].text = "--";
            }
            if (subscriptionTypes.ContainsKey(SubscriptionPath.HeartRate))
            {
                buttonsSubscription[3].image.sprite = buttonOn;
                TextHeartrate.text = "...";
                TextRrData.text    = "...";
            }
            else
            {
                buttonsSubscription[3].image.sprite = buttonOff;
                TextHeartrate.text = "--";
                TextRrData.text    = "--";
            }
            Pulsing.ObjectTransform.IsPulsing = false;
            if (subscriptionTypes.ContainsKey(SubscriptionPath.Temperature))
            {
                buttonsSubscription[4].image.sprite = buttonOn;
                TextTemp.text = "...";
            }
            else
            {
                buttonsSubscription[4].image.sprite = buttonOff;
                TextTemp.text = "--";
            }
        }
        else
        {
                        #pragma warning disable CS0162
            if (isLogging)
            {
                Debug.Log(TAG + "RefreshPanelSubscription, refreshing Subscriptionlist");
            }
                        #pragma warning restore CS0162
            // only highlighted Sensordata will be updated
            if (connectedElementIndex != connectedElementHighlitedIndex)
            {
                                #pragma warning disable CS0162
                if (isLogging)
                {
                    Debug.Log(TAG + "Values for " + MovesenseDevice.Devices[connectedElementIndex].Serial + " do not match displayed " + MovesenseDevice.Devices[connectedElementHighlitedIndex].Serial);
                }
                                #pragma warning restore CS0162
                return;
            }

            if (e.Subscriptionpath == SubscriptionPath.LinearAcceleration)
            {
                var notificationFieldArgs = (NotificationCallback.FieldArgs)e;
                                #pragma warning disable CS0162
                if (isLogging)
                {
                    Debug.Log(TAG + "updating LinearAcceleration texts");
                }
                                #pragma warning restore CS0162
                TextLinAcc[0].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].x.ToString("F6");
                TextLinAcc[1].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].y.ToString("F6");
                TextLinAcc[2].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].z.ToString("F6");
            }
            else if (e.Subscriptionpath == SubscriptionPath.AngularVelocity)
            {
                var notificationFieldArgs = (NotificationCallback.FieldArgs)e;
                                #pragma warning disable CS0162
                if (isLogging)
                {
                    Debug.Log(TAG + "updating Gyroscope texts");
                }
                                #pragma warning restore CS0162
                TextGyro[0].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].x.ToString("F6");
                TextGyro[1].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].y.ToString("F6");
                TextGyro[2].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].z.ToString("F6");
            }
            else if (e.Subscriptionpath == SubscriptionPath.MagneticField)
            {
                var notificationFieldArgs = (NotificationCallback.FieldArgs)e;
                                #pragma warning disable CS0162
                if (isLogging)
                {
                    Debug.Log(TAG + "updating Magnetic texts");
                }
                                #pragma warning restore CS0162
                TextMagnField[0].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].x.ToString("F6");
                TextMagnField[1].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].y.ToString("F6");
                TextMagnField[2].text = notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].z.ToString("F6");
            }
            else if (e.Subscriptionpath == SubscriptionPath.HeartRate)
            {
                var notificationHeartRateArgs = (NotificationCallback.HeartRateArgs)e;
                TextHeartrate.text                = notificationHeartRateArgs.Pulse.ToString("F0");
                TextRrData.text                   = notificationHeartRateArgs.RrData[notificationHeartRateArgs.RrData.Length - 1].ToString("F0");
                Pulsing.ObjectTransform.BPM       = (int)notificationHeartRateArgs.Pulse;
                Pulsing.ObjectTransform.IsPulsing = true;
            }
            else if (e.Subscriptionpath == SubscriptionPath.Temperature)
            {
                var notificationTemperatureArgs = (NotificationCallback.TemperatureArgs)e;
                TextTemp.text = (notificationTemperatureArgs.Temperature - 273.15).ToString("F1");
            }
        }
    }
Ejemplo n.º 5
0
    private void UpdateTransform(int serialListPosition, NotificationCallback.EventArgs e)
    {
        // ignore magnetic field, heratrate and temperature
        if (e.Subscriptionpath == SubscriptionPath.MagneticField || e.Subscriptionpath == SubscriptionPath.HeartRate || e.Subscriptionpath == SubscriptionPath.Temperature)
        {
            return;
        }

        var notificationFieldArgs = (NotificationCallback.FieldArgs)e;

        Transform transform = visualizationDevices[serialListPosition].MovesenseSensorTransform;

        if (e.Subscriptionpath == SubscriptionPath.AngularVelocity)
        {
            float z = (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].z * angularCorrection;
            if (z < -threshold || z > threshold)
            {
                transform.RotateAround(transform.position, -transform.up, z);                 // spin around Z-axis
            }
            float y = (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].y * angularCorrection;
            if (y < -threshold || y > threshold)
            {
                transform.RotateAround(transform.position, -transform.forward, y);
            }
            float x = (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].x * angularCorrection;
            if (x < -threshold || x > threshold)
            {
                transform.RotateAround(transform.position, -transform.right, x);                // spin around Movesense-axis
            }
        }
        else if (e.Subscriptionpath == SubscriptionPath.LinearAcceleration)
        {
            Transform CylinderUpDown    = visualizationDevices[serialListPosition].CylinderUpDown;
            Transform ConeUpDown        = visualizationDevices[serialListPosition].ConeUpDown;
            Transform CylinderForthBack = visualizationDevices[serialListPosition].CylinderForthBack;
            Transform ConeForthBack     = visualizationDevices[serialListPosition].ConeForthBack;
            Transform CylinderLeftRight = visualizationDevices[serialListPosition].CylinderLeftRight;
            Transform ConeLeftRight     = visualizationDevices[serialListPosition].ConeLeftRight;

            // Up/Down
            float cylUpDown        = 0;
            float coneUpDownDegree = 0;
            float coneUpDown       = 0;
            if (notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].z < 0)             // up
            {
                cylUpDown        = 26.5F * transform.localScale.y - (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].z;
                coneUpDownDegree = 270;
                coneUpDown       = 51.6F * transform.localScale.y - 2 * (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].z;
            }
            else
            {
                cylUpDown        = -51.3F * transform.localScale.y - (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].z;
                coneUpDownDegree = 90;
                coneUpDown       = -76.4F * transform.localScale.y - 2 * (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].z;
            }
            CylinderUpDown.localPosition = new Vector3(CylinderUpDown.localPosition.x, cylUpDown, CylinderUpDown.localPosition.z);
            CylinderUpDown.localScale    = new Vector3(CylinderUpDown.localScale.x, (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].z, CylinderUpDown.localScale.z);
            ConeUpDown.localRotation     = Quaternion.Euler(coneUpDownDegree, 0, 0);
            ConeUpDown.localPosition     = new Vector3(ConeUpDown.localPosition.x, coneUpDown, ConeUpDown.localPosition.z);

            // Forth/Back
            float cylForthBack        = 0;
            float coneForthBackDegree = 0;
            float coneForthBack       = 0;
            if (notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].y < 0)             // forth
            {
                cylForthBack        = 178.1F * transform.localScale.z - (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].y;
                coneForthBackDegree = 0;
                coneForthBack       = 203.2F * transform.localScale.y - 2 * (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].y;
            }
            else
            {
                cylForthBack        = -178.1F * transform.localScale.z - (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].y;
                coneForthBackDegree = 180;
                coneForthBack       = -203.2F * transform.localScale.y - 2 * (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].y;
            }
            CylinderForthBack.localPosition = new Vector3(CylinderForthBack.localPosition.x, CylinderForthBack.localPosition.y, cylForthBack);
            CylinderForthBack.localScale    = new Vector3(CylinderForthBack.localScale.x, (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].y, CylinderForthBack.localScale.z);
            ConeForthBack.localRotation     = Quaternion.Euler(coneForthBackDegree, 0, 0);
            ConeForthBack.localPosition     = new Vector3(ConeForthBack.localPosition.x, ConeForthBack.localPosition.y, coneForthBack);

            // Left/Right
            float cylLeftRight        = 0;
            float coneLeftRightDegree = 0;
            float coneLeftRight       = 0;
            if (notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].x < 0)             // right
            {
                cylLeftRight        = 178.1F * transform.localScale.x - (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].x;
                coneLeftRightDegree = 90;
                coneLeftRight       = 203.2F * transform.localScale.x - 2 * (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].x;
            }
            else
            {
                cylLeftRight        = -178.1F * transform.localScale.x - (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].x;
                coneLeftRightDegree = 270;
                coneLeftRight       = -203.2F * transform.localScale.x - 2 * (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].x;
            }
            CylinderLeftRight.localPosition = new Vector3(cylLeftRight, CylinderLeftRight.localPosition.y, CylinderLeftRight.localPosition.z);
            CylinderLeftRight.localScale    = new Vector3(CylinderLeftRight.localScale.x, (float)notificationFieldArgs.Values[notificationFieldArgs.Values.Length - 1].x, CylinderLeftRight.localScale.z);
            ConeLeftRight.localRotation     = Quaternion.Euler(0, coneLeftRightDegree, 0);
            ConeLeftRight.localPosition     = new Vector3(coneLeftRight, ConeLeftRight.localPosition.y, ConeLeftRight.localPosition.z);
        }
    }