public void UpdateProperty()

in sensors/Tools/SensorExplorer/SensorDisplay.cs [478:702]


        public void UpdateProperty(SensorData sensorData)
        {
            textBlockPropertyValue[0].Text = string.Format("\r\n  {0}", sensorData.ReportInterval != 0 ? sensorData.ReportInterval.ToString() : "-");
            textBlockPropertyValue[1].Text = string.Format("  {0}", sensorData.MinReportInterval != 0 ? sensorData.MinReportInterval.ToString() : "-");
            textBlockPropertyValue[2].Text = "  " + sensorData.Category;
            textBlockPropertyValue[3].Text = "  " + sensorData.PersistentUniqueId;
            textBlockPropertyValue[4].Text = "  " + sensorData.ObjectHierarchy;
            textBlockPropertyValue[5].Text = "  " + sensorData.SensorName;
            textBlockPropertyValue[6].Text = "  " + sensorData.Manufacturer;
            textBlockPropertyValue[7].Text = "  " + sensorData.Model;
            textBlockPropertyValue[8].Text = "  " + sensorData.ConnectionType;
            textBlockPropertyValue[9].Text = "  " + sensorData.IsPrimary;
            textBlockPropertyValue[10].Text = "  " + sensorData.VendorDefinedSubType;
            textBlockPropertyValue[11].Text = "  " + sensorData.State;
            if (sensorData.HumanPresenceDetectionType != null)
            {
                textBlockPropertyValue[12].Text = "  " + sensorData.HumanPresenceDetectionType;
            }
            if (sensorData.DeviceId != null)
            {
                textBlockPropertyValue[13].Text = $"{sensorData.DeviceId.Replace("{", "\r\n  {")}";
            }
        }

        public void UpdatePLDProperty(SensorData sensorData)
        {
            textBlockPLDValue[0].Text = (sensorData.PanelId == null) ? "null" : sensorData.PanelId;
            textBlockPLDValue[1].Text = (sensorData.PanelGroup == null) ? "null" : sensorData.PanelGroup;
            textBlockPLDValue[2].Text = (sensorData.PanelSide == null) ? "null" : Constants.PanelSide[sensorData.PanelSide];
            textBlockPLDValue[3].Text = (sensorData.PanelWidth == null) ? "null" : sensorData.PanelWidth;
            textBlockPLDValue[4].Text = (sensorData.PanelHeight == null) ? "null" : sensorData.PanelHeight;
            textBlockPLDValue[5].Text = (sensorData.PanelLength == null) ? "null" : sensorData.PanelLength;
            textBlockPLDValue[6].Text = (sensorData.PanelPositionX == null) ? "null" : sensorData.PanelPositionX;
            textBlockPLDValue[7].Text = (sensorData.PanelPositionY == null) ? "null" : sensorData.PanelPositionY;
            textBlockPLDValue[8].Text = (sensorData.PanelPositionZ == null) ? "null" : sensorData.PanelPositionZ;
            textBlockPLDValue[9].Text = (sensorData.PanelRotationX == null) ? "null" : Constants.PanelRotation[sensorData.PanelRotationX];
            textBlockPLDValue[10].Text = (sensorData.PanelRotationY == null) ? "null" : Constants.PanelRotation[sensorData.PanelRotationY];
            textBlockPLDValue[11].Text = (sensorData.PanelRotationZ == null) ? "null" : Constants.PanelRotation[sensorData.PanelRotationZ];

            try
            {
                textBlockPLDValue[12].Text = (sensorData.PanelColor == null) ? "null" : "0x" + long.Parse(sensorData.PanelColor).ToString("X");    // convert to hex
            }
            catch { }

            textBlockPLDValue[13].Text = (sensorData.PanelShape == null) ? "null" : Constants.PanelShape[sensorData.PanelShape];
            textBlockPLDValue[14].Text = (sensorData.PanelVisible == null) ? "null" : sensorData.PanelVisible;
        }

        public void UpdateText(SensorData sensorData)
        {
            try
            {
                int index = sensorData.Readings.Count - 1;
                if (sensorData.TotalIndex == Sensor.CurrentId)
                {
                    UpdateProperty(sensorData);
                    UpdatePLDProperty(sensorData);
                }

                if (StackPanelSensor.Visibility == Visibility.Visible)
                {
                    if (sensorData.SensorType == Sensor.ACCELEROMETER || sensorData.SensorType == Sensor.ACCELEROMETERLINEAR || sensorData.SensorType == Sensor.ACCELEROMETERGRAVITY)
                    {
                        double margin = 80;
                        double x = Math.Min(1, sensorData.Readings[index].Value[0]);
                        double y = Math.Min(1, sensorData.Readings[index].Value[1]);
                        double square = x * x + y * y;

                        if (square > 1)
                        {
                            x /= Math.Sqrt(square);
                            y /= Math.Sqrt(square);
                        }

                        DisplayInformation displayInformation = DisplayInformation.GetForCurrentView();
                        if (displayInformation.NativeOrientation == DisplayOrientations.Landscape)
                        {
                            switch (displayInformation.CurrentOrientation)
                            {
                                case DisplayOrientations.Landscape: ellipseAccelerometer.Margin = new Thickness(margin * x, 0, 0, margin * y); break;
                                case DisplayOrientations.Portrait: ellipseAccelerometer.Margin = new Thickness(margin * y, 0, 0, -margin * x); break;
                                case DisplayOrientations.LandscapeFlipped: ellipseAccelerometer.Margin = new Thickness(-margin * x, 0, 0, -margin * y); break;
                                case DisplayOrientations.PortraitFlipped: ellipseAccelerometer.Margin = new Thickness(-margin * y, 0, 0, margin * x); break;
                            }
                        }
                        else if (displayInformation.NativeOrientation == DisplayOrientations.Portrait)
                        {
                            switch (displayInformation.CurrentOrientation)
                            {
                                case DisplayOrientations.Landscape: ellipseAccelerometer.Margin = new Thickness(-margin * y, 0, 0, margin * x); break;
                                case DisplayOrientations.Portrait: ellipseAccelerometer.Margin = new Thickness(margin * x, 0, 0, margin * y); break;
                                case DisplayOrientations.LandscapeFlipped: ellipseAccelerometer.Margin = new Thickness(margin * y, 0, 0, -margin * x); break;
                                case DisplayOrientations.PortraitFlipped: ellipseAccelerometer.Margin = new Thickness(-margin * x, 0, 0, -margin * y); break;
                            }
                        }
                    }

                    for (int i = 0; i < sensorData.Readings[index].Value.Length; i++)
                    {
                        textBlockProperty[i].Text = sensorData.Property[i];
                        textBlockValue[i].Text = string.Format("        {0,5:0.0000}", sensorData.Readings[index].Value[i]);
                        textBlockMinValue[i].Text = string.Format("        {0,5:0.0000}", sensorData.MinValue[i]);
                        textBlockMaxValue[i].Text = string.Format("        {0,5:0.0000}", sensorData.MaxValue[i]);

                        if (sensorData.Property[i].StartsWith("MagneticNorth"))
                        {
                            RotateTransform rotateCompass = new RotateTransform();
                            imageCompass.RenderTransform = rotateCompass;
                            rotateCompass.Angle = (-1) * Convert.ToDouble(sensorData.Readings[index].Value[i]);
                            rotateCompass.CenterX = imageCompass.ActualWidth / 2;
                            rotateCompass.CenterY = imageCompass.ActualHeight / 2;
                        }
                        else if (sensorData.Property[i].StartsWith("AngularVelocityX"))
                        {
                            RotateTransform rotateGyrometerX = new RotateTransform() { CenterX = imageGyrometerX.ActualWidth / 2, CenterY = imageGyrometerX.ActualHeight / 2 };
                            imageGyrometerX.RenderTransform = rotateGyrometerX;
                            rotateGyrometerX.Angle = Math.Max(-135, Math.Min(135, Convert.ToDouble(sensorData.Readings[index].Value[i])));
                        }
                        else if (sensorData.Property[i].StartsWith("AngularVelocityY"))
                        {
                            RotateTransform rotateGyrometerY = new RotateTransform();
                            imageGyrometerY.RenderTransform = rotateGyrometerY;
                            rotateGyrometerY.Angle = Math.Max(-135, Math.Min(135, Convert.ToDouble(sensorData.Readings[index].Value[i])));
                            rotateGyrometerY.CenterX = imageGyrometerY.ActualWidth / 2;
                            rotateGyrometerY.CenterY = imageGyrometerY.ActualHeight / 2;
                        }
                        else if (sensorData.Property[i].StartsWith("AngularVelocityZ"))
                        {
                            RotateTransform rotateGyrometerZ = new RotateTransform();
                            imageGyrometerZ.RenderTransform = rotateGyrometerZ;
                            rotateGyrometerZ.Angle = Math.Max(-135, Math.Min(135, Convert.ToDouble(sensorData.Readings[index].Value[i])));
                            rotateGyrometerZ.CenterX = imageGyrometerZ.ActualWidth / 2;
                            rotateGyrometerZ.CenterY = imageGyrometerZ.ActualHeight / 2;
                        }
                        else if (sensorData.Property[i].StartsWith("Pitch"))
                        {
                            RotateTransform rotate = new RotateTransform() { CenterX = imageInclinometerPitch.ActualWidth / 2, CenterY = imageInclinometerPitch.ActualHeight / 2 };
                            imageInclinometerPitch.RenderTransform = rotate;
                            rotate.Angle = sensorData.Readings[index].Value[i];
                        }
                        else if (sensorData.Property[i].StartsWith("Roll"))
                        {
                            RotateTransform rotate = new RotateTransform() { CenterX = imageInclinometerRoll.ActualWidth / 2, CenterY = imageInclinometerRoll.ActualHeight / 2 };
                            imageInclinometerRoll.RenderTransform = rotate;
                            rotate.Angle = sensorData.Readings[index].Value[i];
                        }
                        else if (sensorData.Property[i] == "Yaw (°)")
                        {
                            RotateTransform rotate = new RotateTransform() { CenterX = imageInclinometerYaw.ActualWidth / 2, CenterY = imageInclinometerYaw.ActualHeight / 2 };
                            imageInclinometerYaw.RenderTransform = rotate;
                            rotate.Angle = -sensorData.Readings[index].Value[i];
                        }
                        else if (sensorData.Property[i] == "Illuminance (lux)")
                        {
                            textBlockSensor.Text = "💡";
                            if (sensorData.Readings[index].Value[i] < 1)
                            {
                                textBlockSensor.Opacity = 0.1;
                            }
                            else
                            {
                                textBlockSensor.Opacity = Math.Min(0.1 + Math.Log(sensorData.Readings[index].Value[i], 2) / 10, 1);
                            }
                        }
                        else if (sensorData.Property[i] == "CumulativeSteps")
                        {
                            int value = Convert.ToInt32(sensorData.Readings[index].Value[i]) / 100;
                            PlotCanvas.SetRange((value + 1) * 100, value * 100);
                        }
                        else if (sensorData.Property[i] == "HeadingAccuracy" || sensorData.Property[i] == "YawAccuracy")
                        {
                            MagnetometerAccuracy magnetometerAccuracy = (MagnetometerAccuracy)sensorData.Readings[index].Value[i];
                            textBlockValue[i].Text = string.Format("        {0}", magnetometerAccuracy);
                        }
                        else if (sensorData.Property[i] == "IsDetected")
                        {
                            textBlockSensor.Text = (sensorData.Readings[index].Value[i] > 0.5 ? "📲" : "📱");
                        }
                        else if (sensorData.Property[i] == "StepKind")
                        {
                            PedometerStepKind pedometerStepKind = (PedometerStepKind)sensorData.Readings[index].Value[i];
                            textBlockValue[i].Text = string.Format("        {0}", pedometerStepKind);
                            textBlockSensor.Text = DictionaryStepKind[pedometerStepKind];
                        }
                        else if (sensorData.SensorType == Sensor.SIMPLEORIENTATIONSENSOR)
                        {
                            SimpleOrientation simpleOrientation = (SimpleOrientation)sensorData.Readings[index].Value[i];
                            textBlockValue[i].Text = string.Format("        {0}", simpleOrientation).Replace("DegreesCounterclockwise", "°â†º");
                            textBlockMinValue[i].Text = "";
                            textBlockMaxValue[i].Text = "";
                        }
                        else if (sensorData.SensorType == Sensor.ACTIVITYSENSOR)
                        {
                            if (sensorData.Readings[index].Value[i] == Sensor.ACTIVITYNONE)
                            {
                                textBlockValue[i].Text = "None";
                            }
                            else if (sensorData.Readings[index].Value[i] == Sensor.ACTIVITYNOTSUPPORTED)
                            {
                                textBlockValue[i].Text = "Not Supported";
                            }
                            else
                            {
                                ActivitySensorReadingConfidence activitySensorReadingConfidence = (ActivitySensorReadingConfidence)sensorData.Readings[index].Value[i];
                                textBlockValue[i].Text = string.Format("        {0}", activitySensorReadingConfidence);
                                textBlockSensor.Text = DictionaryActivity[(ActivityType)i];
                            }
                        }
                        else if (sensorData.SensorType == Sensor.LIGHTSENSOR)
                        {
                            if (sensorData.Readings[index].Value[i] == -1)
                            {
                                textBlockValue[i].Text = "N/A";
                                textBlockMinValue[i].Text = "N/A";
                                textBlockMaxValue[i].Text = "N/A";
                            }
                        }
                    }
                }
            }
            catch { }
        }
    }
}