Example #1
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");
            }
        }
    }
Example #2
0
    private void RefreshVisualizationDevices()
    {
        // get subcribed sensors
        int subscriptedDevices = 0;

        foreach (var item in MovesenseDevice.Devices)
        {
            if (MovesenseDevice.GetAllSubscriptionPaths(item.Serial) != null)
            {
                subscriptedDevices++;
            }
        }
        int visualizationDevicesCount = visualizationDevices.Count;

        if (visualizationDevicesCount < subscriptedDevices)
        {
                        #pragma warning disable CS0162
            if (isLogging)
            {
                Debug.Log(TAG + "RefreshVisualizationDevices, add clones");
            }
                        #pragma warning restore CS0162
            for (int i = visualizationDevicesCount; i < MovesenseDevice.Devices.Count; i++)
            {
                // needed to keep index consistent with connected Devices (unconnected have been removed)
                if (MovesenseDevice.GetAllSubscriptionPaths(MovesenseDevice.Devices[i].Serial) == null)
                {
                    visualizationDevices.Add(new VisualizationDevice(null, false, null, null, null, null, null, null, null));
                    Debug.LogWarning(TAG + "RefreshVisualizationDevices, no Subscriptions available for " + MovesenseDevice.Devices[i].Serial);
                    continue;
                }
                GameObject movesenseSensorClone = Instantiate(MovesenseSensor) as GameObject;

                // DeviceSerial
                TMP_Text serial = movesenseSensorClone.GetComponentInChildren <TMP_Text>();
                serial.text = MovesenseDevice.Devices[i].Serial;

                Transform cylinderUpDown    = null;
                Transform coneUpDown        = null;
                Transform cylinderForthBack = null;
                Transform coneForthBack     = null;
                Transform cylinderLeftRight = null;
                Transform coneLeftRight     = null;
                for (int j = 0; j < movesenseSensorClone.transform.childCount; j++)
                {
                    if (movesenseSensorClone.transform.GetChild(j).name == "CylinderUpDown")
                    {
                        cylinderUpDown = movesenseSensorClone.transform.GetChild(j);
                    }
                    else if (movesenseSensorClone.transform.GetChild(j).name == "ConeUpDown")
                    {
                        coneUpDown = movesenseSensorClone.transform.GetChild(j);
                    }
                    else if (movesenseSensorClone.transform.GetChild(j).name == "CylinderForthBack")
                    {
                        cylinderForthBack = movesenseSensorClone.transform.GetChild(j);
                    }
                    else if (movesenseSensorClone.transform.GetChild(j).name == "ConeForthBack")
                    {
                        coneForthBack = movesenseSensorClone.transform.GetChild(j);
                    }
                    else if (movesenseSensorClone.transform.GetChild(j).name == "CylinderLeftRight")
                    {
                        cylinderLeftRight = movesenseSensorClone.transform.GetChild(j);
                    }
                    else if (movesenseSensorClone.transform.GetChild(j).name == "ConeLeftRight")
                    {
                        coneLeftRight = movesenseSensorClone.transform.GetChild(j);
                    }
                }

                Transform movesenseSensorTransform = movesenseSensorClone.GetComponent <Transform>();

                visualizationDevices.Add(new VisualizationDevice(movesenseSensorClone, true, movesenseSensorTransform, cylinderUpDown, coneUpDown, cylinderForthBack, coneForthBack, cylinderLeftRight, coneLeftRight));
            }
        }
        else if (visualizationDevicesCount > subscriptedDevices)
        {
                        #pragma warning disable CS0162
            if (isLogging)
            {
                Debug.Log(TAG + "RefreshVisualizationDevices, destroy clones");
            }
                        #pragma warning restore CS0162
            for (int i = visualizationDevicesCount - 1; i > subscriptedDevices - 1; i--)
            {
                Destroy(visualizationDevices[i].Clone);
                visualizationDevices.RemoveAt(i);
            }
        }

        // Positioning
        int devicesWithSubscription = 0;
        for (int i = 0; i < MovesenseDevice.Devices.Count; i++)
        {
            if (MovesenseDevice.GetAllSubscriptionPaths(MovesenseDevice.Devices[i].Serial) != null)
            {
                visualizationDevices[i].MovesenseSensorTransform.localPosition = devicePositions[subscriptedDevices - 1][devicesWithSubscription];
                devicesWithSubscription++;
            }
        }
    }