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; }
private async void EnumerateSensors() { try { await Sensor.GetDefault(); int totalIndex = -1; for (int index = 0; index < Sensor.AccelerometerStandardList.Count; index++) { totalIndex++; SensorData AccelerometerData = new SensorData(Sensor.ACCELEROMETER, totalIndex, "Accelerometer (Standard)", Constants.AccelerometerPropertyTitles); SensorDisplay AccelerometerDisplay = new SensorDisplay(Sensor.ACCELEROMETER, index, totalIndex, "Accelerometer (Standard)", -2, 2, 2, Constants.AccelerometerColors); sensorDisplay.Add(AccelerometerDisplay); sensorData.Add(AccelerometerData); AddPivotItem(Sensor.ACCELEROMETER, index, totalIndex); } for (int index = 0; index < Sensor.AccelerometerLinearList.Count; index++) { totalIndex++; SensorData AccelerometerLinearData = new SensorData(Sensor.ACCELEROMETERLINEAR, totalIndex, "Accelerometer (Linear)", Constants.AccelerometerPropertyTitles); SensorDisplay AccelerometerLinearDisplay = new SensorDisplay(Sensor.ACCELEROMETERLINEAR, index, totalIndex, "Accelerometer (Linear)", -2, 2, 2, Constants.AccelerometerColors); sensorDisplay.Add(AccelerometerLinearDisplay); sensorData.Add(AccelerometerLinearData); AddPivotItem(Sensor.ACCELEROMETERLINEAR, index, totalIndex); } for (int index = 0; index < Sensor.AccelerometerGravityList.Count; index++) { totalIndex++; SensorData AccelerometerGravityData = new SensorData(Sensor.ACCELEROMETERGRAVITY, totalIndex, "Accelerometer (Gravity)", Constants.AccelerometerPropertyTitles); SensorDisplay AccelerometerGravityDisplay = new SensorDisplay(Sensor.ACCELEROMETERGRAVITY, index, totalIndex, "Accelerometer (Gravity)", -2, 2, 2, Constants.AccelerometerColors); sensorDisplay.Add(AccelerometerGravityDisplay); sensorData.Add(AccelerometerGravityData); AddPivotItem(Sensor.ACCELEROMETERGRAVITY, index, totalIndex); } for (int index = 0; index < Sensor.ActivitySensorList.Count; index++) { totalIndex++; SensorData ActivitySensorData = new SensorData(Sensor.ACTIVITYSENSOR, totalIndex, "ActivitySensor", Constants.ActivitySensorPropertyTitles); SensorDisplay ActivitySensorDisplay = new SensorDisplay(Sensor.ACTIVITYSENSOR, index, totalIndex, "ActivitySensor", 2, 0, 2, Constants.ActivitySensorColors); sensorDisplay.Add(ActivitySensorDisplay); sensorData.Add(ActivitySensorData); AddPivotItem(Sensor.ACTIVITYSENSOR, index, totalIndex); } if (Sensor.Altimeter != null) { totalIndex++; SensorData AltimeterData = new SensorData(Sensor.ALTIMETER, totalIndex, "Altimeter", Constants.AltimeterPropertyTitles); SensorDisplay AltimeterDisplay = new SensorDisplay(Sensor.ALTIMETER, 0, totalIndex, "Altimeter", -10, 10, 2, Constants.AltimeterColors); sensorDisplay.Add(AltimeterDisplay); sensorData.Add(AltimeterData); AddPivotItem(Sensor.ALTIMETER, 0, totalIndex); } for (int index = 0; index < Sensor.BarometerList.Count; index++) { totalIndex++; SensorData BarometerData = new SensorData(Sensor.BAROMETER, totalIndex, "Barometer", Constants.BarometerPropertyTitles); SensorDisplay BarometerDisplay = new SensorDisplay(Sensor.BAROMETER, index, totalIndex, "Barometer", 950, 1050, 2, Constants.BarometerColors); sensorDisplay.Add(BarometerDisplay); sensorData.Add(BarometerData); AddPivotItem(Sensor.BAROMETER, index, totalIndex); } for (int index = 0; index < Sensor.CompassList.Count; index++) { totalIndex++; SensorData CompassData = new SensorData(Sensor.COMPASS, totalIndex, "Compass", Constants.CompassPropertyTitles); SensorDisplay CompassDisplay = new SensorDisplay(Sensor.COMPASS, index, totalIndex, "Compass", 0, 360, 2, Constants.CompassColors); sensorDisplay.Add(CompassDisplay); sensorData.Add(CompassData); AddPivotItem(Sensor.COMPASS, index, totalIndex); } for (int index = 0; index < Sensor.GyrometerList.Count; index++) { totalIndex++; SensorData GyrometerData = new SensorData(Sensor.GYROMETER, totalIndex, "Gyrometer", Constants.GyrometerPropertyTitles); SensorDisplay GyrometerDisplay = new SensorDisplay(Sensor.GYROMETER, index, totalIndex, "Gyrometer", -200, 200, 2, Constants.GyrometerColors); sensorDisplay.Add(GyrometerDisplay); sensorData.Add(GyrometerData); AddPivotItem(Sensor.GYROMETER, index, totalIndex); } for (int index = 0; index < Sensor.InclinometerList.Count; index++) { totalIndex++; SensorData InclinometerData = new SensorData(Sensor.INCLINOMETER, totalIndex, "Inclinometer", Constants.InclinometerPropertyTitles); SensorDisplay InclinometerDisplay = new SensorDisplay(Sensor.INCLINOMETER, index, totalIndex, "Inclinometer", -180, 360, 3, Constants.InclinometerColors); sensorDisplay.Add(InclinometerDisplay); sensorData.Add(InclinometerData); AddPivotItem(Sensor.INCLINOMETER, index, totalIndex); } if (Sensor.LightSensor != null) { totalIndex++; SensorData LightSensorData = new SensorData(Sensor.LIGHTSENSOR, totalIndex, "LightSensor", Constants.LightSensorPropertyTitles); SensorDisplay LightSensorDisplay = new SensorDisplay(Sensor.LIGHTSENSOR, 0, totalIndex, "LightSensor", 0, 1000, 2, Constants.LightSensorColors); sensorDisplay.Add(LightSensorDisplay); sensorData.Add(LightSensorData); AddPivotItem(Sensor.LIGHTSENSOR, 0, totalIndex); } for (int index = 0; index < Sensor.MagnetometerList.Count; index++) { totalIndex++; SensorData MagnetometerData = new SensorData(Sensor.MAGNETOMETER, totalIndex, "Magnetometer", Constants.MagnetometerPropertyTitles); SensorDisplay MagnetometerDisplay = new SensorDisplay(Sensor.MAGNETOMETER, index, totalIndex, "Magnetometer", -500, 500, 2, Constants.MagnetometerColors); sensorDisplay.Add(MagnetometerDisplay); sensorData.Add(MagnetometerData); AddPivotItem(Sensor.MAGNETOMETER, index, totalIndex); } for (int index = 0; index < Sensor.OrientationAbsoluteList.Count; index++) { totalIndex++; SensorData OrientationAbsoluteData = new SensorData(Sensor.ORIENTATIONSENSOR, totalIndex, "Orientation (Absolute)", Constants.OrientationSensorPropertyTitles); SensorDisplay OrientationAbsoluteDisplay = new SensorDisplay(Sensor.ORIENTATIONSENSOR, index, totalIndex, "Orientation (Absolute)", -1, 1, 2, Constants.OrientationSensorColors); sensorDisplay.Add(OrientationAbsoluteDisplay); sensorData.Add(OrientationAbsoluteData); AddPivotItem(Sensor.ORIENTATIONSENSOR, index, totalIndex); } for (int index = 0; index < Sensor.OrientationRelativeList.Count; index++) { totalIndex++; SensorData OrientationRelativeData = new SensorData(Sensor.ORIENTATIONRELATIVE, totalIndex, "Orientation (Relative)", Constants.OrientationSensorPropertyTitles); SensorDisplay OrientationRelativeDisplay = new SensorDisplay(Sensor.ORIENTATIONRELATIVE, index, totalIndex, "Orientation (Relative)", -1, 1, 2, Constants.OrientationSensorColors); sensorDisplay.Add(OrientationRelativeDisplay); sensorData.Add(OrientationRelativeData); AddPivotItem(Sensor.ORIENTATIONRELATIVE, index, totalIndex); } for (int index = 0; index < Sensor.OrientationGeomagneticList.Count; index++) { totalIndex++; SensorData OrientationGeomagneticData = new SensorData(Sensor.ORIENTATIONGEOMAGNETIC, totalIndex, "Orientation (Geomagnetic)", Constants.OrientationSensorPropertyTitles); SensorDisplay OrientationGeomagneticDisplay = new SensorDisplay(Sensor.ORIENTATIONGEOMAGNETIC, index, totalIndex, "Orientation (Geomagnetic)", -1, 1, 2, Constants.OrientationSensorColors); sensorDisplay.Add(OrientationGeomagneticDisplay); sensorData.Add(OrientationGeomagneticData); AddPivotItem(Sensor.ORIENTATIONGEOMAGNETIC, index, totalIndex); } for (int index = 0; index < Sensor.PedometerList.Count; index++) { totalIndex++; SensorData PedometerData = new SensorData(Sensor.PEDOMETER, totalIndex, "Pedometer", Constants.PedometerPropertyTitles); SensorDisplay PedometerDisplay = new SensorDisplay(Sensor.PEDOMETER, index, totalIndex, "Pedometer", 0, 50, 2, Constants.PedometerColors); sensorDisplay.Add(PedometerDisplay); sensorData.Add(PedometerData); AddPivotItem(Sensor.PEDOMETER, index, totalIndex); } for (int index = 0; index < Sensor.ProximitySensorList.Count; index++) { totalIndex++; SensorData ProximitySensorData = new SensorData(Sensor.PROXIMITYSENSOR, totalIndex, "ProximitySensor", Constants.ProximitySensorPropertyTitles); SensorDisplay ProximitySensorDisplay = new SensorDisplay(Sensor.PROXIMITYSENSOR, index, totalIndex, "ProximitySensor", 0, 1, 1, Constants.ProximitySensorColors); sensorDisplay.Add(ProximitySensorDisplay); sensorData.Add(ProximitySensorData); AddPivotItem(Sensor.PROXIMITYSENSOR, index, totalIndex); } if (Sensor.SimpleOrientationSensor != null) { totalIndex++; SensorData simpleOrientationSensorData = new SensorData(Sensor.SIMPLEORIENTATIONSENSOR, totalIndex, "SimpleOrientationSensor", Constants.SimpleOrientationSensorPropertyTitles); SensorDisplay simpleOrientationSensorDisplay = new SensorDisplay(Sensor.SIMPLEORIENTATIONSENSOR, 0, totalIndex, "SimpleOrientationSensor", 0, 5, 5, Constants.SimpleOrientationSensorColors); sensorDisplay.Add(simpleOrientationSensorDisplay); sensorData.Add(simpleOrientationSensorData); AddPivotItem(Sensor.PROXIMITYSENSOR, 0, totalIndex); } AddSummaryPage(); var resourceLoader = ResourceLoader.GetForCurrentView(); rootPage.NotifyUser(resourceLoader.GetString("NumberOfSensors") + ": " + (PivotSensor.Items.Count - 1), NotifyType.StatusMessage); ProgressRingSensor.IsActive = false; if (PivotSensor.Items.Count > 0) { PivotSensor.SelectionChanged += PivotSensorSelectionChanged; PivotSensor.SelectedIndex = 0; PivotSensorSelectionChanged(null, null); } else { TextBlockNoSensor.Text = resourceLoader.GetString("CannotFindSensor"); return; } } catch (Exception ex) { rootPage.NotifyUser(ex.Message, NotifyType.ErrorMessage); } ProgressRingSensor.IsActive = false; }
public void UpdateText(SensorData sensorData) { try { int index = sensorData._reading.Count - 1; if (sensorData._count == Sensor.currentId) { UpdateProperty(sensorData._deviceId, sensorData._deviceName, sensorData._reportInterval, sensorData._minReportInterval, sensorData._reportLatency, sensorData._category, sensorData._persistentUniqueId, sensorData._manufacturer, sensorData._model, sensorData._connectionType); } 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._reading[index].value[0]); double y = Math.Min(1, sensorData._reading[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() { Left = margin * x, Bottom = margin * y }; break; case DisplayOrientations.Portrait: EllipseAccelerometer.Margin = new Thickness() { Left = margin * y, Bottom = -margin * x }; break; case DisplayOrientations.LandscapeFlipped: EllipseAccelerometer.Margin = new Thickness() { Left = -margin * x, Bottom = -margin * y }; break; case DisplayOrientations.PortraitFlipped: EllipseAccelerometer.Margin = new Thickness() { Left = -margin * y, Bottom = margin * x }; break; } } else if (displayInformation.NativeOrientation == DisplayOrientations.Portrait) { switch (displayInformation.CurrentOrientation) { case DisplayOrientations.Landscape: EllipseAccelerometer.Margin = new Thickness() { Left = -margin * y, Bottom = margin * x }; break; case DisplayOrientations.Portrait: EllipseAccelerometer.Margin = new Thickness() { Left = margin * x, Bottom = margin * y }; break; case DisplayOrientations.LandscapeFlipped: EllipseAccelerometer.Margin = new Thickness() { Left = margin * y, Bottom = -margin * x }; break; case DisplayOrientations.PortraitFlipped: EllipseAccelerometer.Margin = new Thickness() { Left = -margin * x, Bottom = -margin * y }; break; } } } for (int i = 0; i < sensorData._reading[index].value.Length; i++) { TextBlockProperty[i].Text = sensorData._property[i]; TextBlockValue[i].Text = String.Format(" {0,5:0.00}", sensorData._reading[index].value[i]); TextBlockMinValue[i].Text = String.Format(" {0,5:0.0}", sensorData._minValue[i]); TextBlockMaxValue[i].Text = String.Format(" {0,5:0.0}", sensorData._maxValue[i]); if (sensorData._property[i].StartsWith("MagneticNorth")) { RotateTransform rotateCompass = new RotateTransform(); ImageCompass.RenderTransform = rotateCompass; rotateCompass.Angle = (-1) * Convert.ToDouble(sensorData._reading[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._reading[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._reading[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._reading[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._reading[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._reading[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._reading[index].value[i]; } else if (sensorData._property[i] == "Illuminance (lux)") { TextBlockSensor.Text = "💡"; if (sensorData._reading[index].value[i] < 1) { TextBlockSensor.Opacity = 0.1; } else { TextBlockSensor.Opacity = Math.Min(0.1 + Math.Log(sensorData._reading[index].value[i], 2) / 10, 1); } } else if (sensorData._property[i] == "CumulativeSteps") { int value = Convert.ToInt32(sensorData._reading[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._reading[index].value[i]; TextBlockValue[i].Text = String.Format(" {0}", magnetometerAccuracy); } else if (sensorData._property[i] == "IsDetected") { TextBlockSensor.Text = (sensorData._reading[index].value[i] > 0.5 ? "📲" : "📱"); } else if (sensorData._property[i] == "StepKind") { PedometerStepKind pedometerStepKind = (PedometerStepKind)sensorData._reading[index].value[i]; TextBlockValue[i].Text = String.Format(" {0}", pedometerStepKind); TextBlockSensor.Text = DictionaryStepKind[pedometerStepKind]; } else if (sensorData._sensorType == Sensor.SIMPLEORIENTATIONSENSOR) { SimpleOrientation simpleOrientation = (SimpleOrientation)sensorData._reading[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._reading[index].value[i] == Sensor.ACTIVITYNONE) { TextBlockValue[i].Text = "None"; } else if (sensorData._reading[index].value[i] == Sensor.ACTIVITYNOTSUPPORTED) { TextBlockValue[i].Text = "Not Supported"; } else { ActivitySensorReadingConfidence activitySensorReadingConfidence = (ActivitySensorReadingConfidence)sensorData._reading[index].value[i]; TextBlockValue[i].Text = String.Format(" {0}", activitySensorReadingConfidence); TextBlockSensor.Text = DictionaryActivity[(ActivityType)i]; } } else if (sensorData._sensorType == Sensor.LIGHTSENSOR) { if (sensorData._reading[index].value[i] == -1) { TextBlockValue[i].Text = "N/A"; TextBlockMinValue[i].Text = "N/A"; TextBlockMaxValue[i].Text = "N/A"; } } } } } catch { } }
private async static void PeriodicTimerCallbackSensorDisplay(ThreadPoolTimer timer) { await cd.RunAsync(CoreDispatcherPriority.Normal, () => { for (int i = 0; i < Sensor.SensorDisplay.Count; i++) { SensorDisplay selectedDisplay = Sensor.SensorDisplay[i]; SensorData selectedData = Sensor.SensorData[i]; if (selectedDisplay.StackPanelSensor.Visibility == Visibility.Visible) { selectedDisplay.PlotCanvas.Plot(selectedData); selectedDisplay.UpdateText(selectedData); } if (selectedData.ReportIntervalChanged) { try { if (selectedData.SensorType == Sensor.ACCELEROMETER) { Sensor.AccelerometerStandardList[selectedDisplay.Index].ReportInterval = selectedData.ReportInterval; selectedData.ReportInterval = Sensor.AccelerometerStandardList[selectedDisplay.Index].ReportInterval; } else if (selectedData.SensorType == Sensor.ACCELEROMETERGRAVITY) { Sensor.AccelerometerGravityList[selectedDisplay.Index].ReportInterval = selectedData.ReportInterval; selectedData.ReportInterval = Sensor.AccelerometerGravityList[selectedDisplay.Index].ReportInterval; } else if (selectedData.SensorType == Sensor.ACCELEROMETERLINEAR) { Sensor.AccelerometerLinearList[selectedDisplay.Index].ReportInterval = selectedData.ReportInterval; selectedData.ReportInterval = Sensor.AccelerometerLinearList[selectedDisplay.Index].ReportInterval; } else if (selectedData.SensorType == Sensor.COMPASS) { Sensor.CompassList[selectedDisplay.Index].ReportInterval = selectedData.ReportInterval; selectedData.ReportInterval = Sensor.CompassList[selectedDisplay.Index].ReportInterval; } else if (selectedData.SensorType == Sensor.GYROMETER) { Sensor.GyrometerList[selectedDisplay.Index].ReportInterval = selectedData.ReportInterval; selectedData.ReportInterval = Sensor.GyrometerList[selectedDisplay.Index].ReportInterval; } else if (selectedData.SensorType == Sensor.INCLINOMETER) { Sensor.InclinometerList[selectedDisplay.Index].ReportInterval = selectedData.ReportInterval; selectedData.ReportInterval = Sensor.InclinometerList[selectedDisplay.Index].ReportInterval; } else if (selectedData.SensorType == Sensor.LIGHTSENSOR) { Sensor.LightSensorList[selectedDisplay.Index].ReportInterval = selectedData.ReportInterval; selectedData.ReportInterval = Sensor.LightSensorList[selectedDisplay.Index].ReportInterval; } else if (selectedData.SensorType == Sensor.ORIENTATIONSENSOR) { Sensor.OrientationAbsoluteList[selectedDisplay.Index].ReportInterval = selectedData.ReportInterval; selectedData.ReportInterval = Sensor.OrientationAbsoluteList[selectedDisplay.Index].ReportInterval; } else if (selectedData.SensorType == Sensor.ORIENTATIONGEOMAGNETIC) { Sensor.OrientationGeomagneticList[selectedDisplay.Index].ReportInterval = selectedData.ReportInterval; selectedData.ReportInterval = Sensor.OrientationGeomagneticList[selectedDisplay.Index].ReportInterval; } else if (selectedData.SensorType == Sensor.ORIENTATIONRELATIVE) { Sensor.OrientationRelativeList[selectedDisplay.Index].ReportInterval = selectedData.ReportInterval; selectedData.ReportInterval = Sensor.OrientationRelativeList[selectedDisplay.Index].ReportInterval; } selectedData.ReportIntervalChanged = false; } catch { } } } }); }
private async void EnumerateSensors() { try { await Sensor.GetDefault(); int totalIndex = -1; for (int index = 0; index < Sensor.AccelerometerStandardList.Count; index++) { totalIndex++; SensorData _accelerometerData = new SensorData(Sensor.ACCELEROMETER, totalIndex, "Accelerometer (Standard)", new string[] { "AccelerationX (g)", "AccelerationY (g)", "AccelerationZ (g)" }); SensorDisplay _accelerometerDisplay = new SensorDisplay(Sensor.ACCELEROMETER, index, totalIndex, "Accelerometer (Standard)", -2, 2, 2, new Color[] { Colors.DarkRed, Colors.DarkOrange, Colors.DarkCyan }); _sensorDisplay.Add(_accelerometerDisplay); _sensorData.Add(_accelerometerData); AddPivotItem(Sensor.ACCELEROMETER, index, totalIndex); } for (int index = 0; index < Sensor.AccelerometerLinearList.Count; index++) { totalIndex++; SensorData _accelerometerLinearData = new SensorData(Sensor.ACCELEROMETERLINEAR, totalIndex, "Accelerometer (Linear)", new string[] { "AccelerationX (g)", "AccelerationY (g)", "AccelerationZ (g)" }); SensorDisplay _accelerometerLinearDisplay = new SensorDisplay(Sensor.ACCELEROMETERLINEAR, index, totalIndex, "Accelerometer (Linear)", -2, 2, 2, new Color[] { Colors.DarkRed, Colors.DarkOrange, Colors.DarkCyan }); _sensorDisplay.Add(_accelerometerLinearDisplay); _sensorData.Add(_accelerometerLinearData); AddPivotItem(Sensor.ACCELEROMETERLINEAR, index, totalIndex); } for (int index = 0; index < Sensor.AccelerometerGravityList.Count; index++) { totalIndex++; SensorData _accelerometerGravityData = new SensorData(Sensor.ACCELEROMETERGRAVITY, totalIndex, "Accelerometer (Gravity)", new string[] { "AccelerationX (g)", "AccelerationY (g)", "AccelerationZ (g)" }); SensorDisplay _accelerometerGravityDisplay = new SensorDisplay(Sensor.ACCELEROMETERGRAVITY, index, totalIndex, "Accelerometer (Gravity)", -2, 2, 2, new Color[] { Colors.DarkRed, Colors.DarkOrange, Colors.DarkCyan }); _sensorDisplay.Add(_accelerometerGravityDisplay); _sensorData.Add(_accelerometerGravityData); AddPivotItem(Sensor.ACCELEROMETERGRAVITY, index, totalIndex); } for (int index = 0; index < Sensor.ActivitySensorList.Count; index++) { totalIndex++; SensorData _activitySensorData = new SensorData(Sensor.ACTIVITYSENSOR, totalIndex, "ActivitySensor", new string[] { "AccelerationX (g)", "AccelerationY (g)", "AccelerationZ (g)" }); SensorDisplay _activitySensorDisplay = new SensorDisplay(Sensor.ACTIVITYSENSOR, index, totalIndex, "ActivitySensor", 2, 0, 2, new Color[] { Colors.Gray, Colors.Brown, Colors.DarkRed, Colors.Orange, Colors.DarkOrange, Colors.Lime, Colors.DarkCyan, Colors.DarkViolet }); _sensorDisplay.Add(_activitySensorDisplay); _sensorData.Add(_activitySensorData); AddPivotItem(Sensor.ACTIVITYSENSOR, index, totalIndex); } if (Sensor.Altimeter != null) { totalIndex++; SensorData _altimeterData = new SensorData(Sensor.ALTIMETER, totalIndex, "Altimeter", new string[] { "AltitudeChange (m)" }); SensorDisplay _altimeterDisplay = new SensorDisplay(Sensor.ALTIMETER, 0, totalIndex, "Altimeter", -10, 10, 2, new Color[] { Colors.DarkRed }); _sensorDisplay.Add(_altimeterDisplay); _sensorData.Add(_altimeterData); AddPivotItem(Sensor.ALTIMETER, 0, totalIndex); } for (int index = 0; index < Sensor.BarometerList.Count; index++) { totalIndex++; SensorData _barometerData = new SensorData(Sensor.BAROMETER, totalIndex, "Barometer", new string[] { "Pressure (hPa)" }); SensorDisplay _barometerDisplay = new SensorDisplay(Sensor.BAROMETER, index, totalIndex, "Barometer", 950, 1050, 2, new Color[] { Colors.Lime }); _sensorDisplay.Add(_barometerDisplay); _sensorData.Add(_barometerData); AddPivotItem(Sensor.BAROMETER, index, totalIndex); } for (int index = 0; index < Sensor.CompassList.Count; index++) { totalIndex++; SensorData _compassData = new SensorData(Sensor.COMPASS, totalIndex, "Compass", new string[] { "MagneticNorth (°)", "TrueNorth (°)", "HeadingAccuracy" }); SensorDisplay _compassDisplay = new SensorDisplay(Sensor.COMPASS, index, totalIndex, "Compass", 0, 360, 2, new Color[] { Colors.DarkRed, Colors.DarkOrange, Colors.DarkCyan }); _sensorDisplay.Add(_compassDisplay); _sensorData.Add(_compassData); AddPivotItem(Sensor.COMPASS, index, totalIndex); } for (int index = 0; index < Sensor.GyrometerList.Count; index++) { totalIndex++; SensorData _gyrometerData = new SensorData(Sensor.GYROMETER, totalIndex, "Gyrometer", new string[] { "AngularVelocityX (°/s)", "AngularVelocityY (°/s)", "AngularVelocityZ (°/s)" }); SensorDisplay _gyrometerDisplay = new SensorDisplay(Sensor.GYROMETER, index, totalIndex, "Gyrometer", -200, 200, 2, new Color[] { Colors.DarkRed, Colors.DarkOrange, Colors.DarkCyan }); _sensorDisplay.Add(_gyrometerDisplay); _sensorData.Add(_gyrometerData); AddPivotItem(Sensor.GYROMETER, index, totalIndex); } for (int index = 0; index < Sensor.InclinometerList.Count; index++) { totalIndex++; SensorData _inclinometerData = new SensorData(Sensor.INCLINOMETER, totalIndex, "Inclinometer", new string[] { "Pitch (°)", "Roll (°)", "Yaw (°)", "YawAccuracy" }); SensorDisplay _inclinometerDisplay = new SensorDisplay(Sensor.INCLINOMETER, index, totalIndex, "Inclinometer", -180, 360, 3, new Color[] { Colors.DarkRed, Colors.DarkOrange, Colors.DarkCyan, Colors.Black }); _sensorDisplay.Add(_inclinometerDisplay); _sensorData.Add(_inclinometerData); AddPivotItem(Sensor.INCLINOMETER, index, totalIndex); } for (int index = 0; index < Sensor.LightSensorList.Count; index++) { totalIndex++; SensorData _lightSensorData = new SensorData(Sensor.LIGHTSENSOR, totalIndex, "LightSensor", new string[] { "Illuminance (lux)", "Chromaticity X", "Chromaticity Y" }); SensorDisplay _lightSensorDisplay = new SensorDisplay(Sensor.LIGHTSENSOR, index, totalIndex, "LightSensor", 0, 1000, 2, new Color[] { Colors.DarkRed, Colors.DarkOrange, Colors.DarkCyan }); _sensorDisplay.Add(_lightSensorDisplay); _sensorData.Add(_lightSensorData); AddPivotItem(Sensor.LIGHTSENSOR, index, totalIndex); } for (int index = 0; index < Sensor.MagnetometerList.Count; index++) { totalIndex++; SensorData _magnetometerData = new SensorData(Sensor.MAGNETOMETER, totalIndex, "Magnetometer", new string[] { "MagneticFieldX (µT)", "MagneticFieldY (µT)", "MagneticFieldZ (µT)" }); SensorDisplay _magnetometerDisplay = new SensorDisplay(Sensor.MAGNETOMETER, index, totalIndex, "Magnetometer", -500, 500, 2, new Color[] { Colors.DarkRed, Colors.DarkOrange, Colors.DarkCyan }); _sensorDisplay.Add(_magnetometerDisplay); _sensorData.Add(_magnetometerData); AddPivotItem(Sensor.MAGNETOMETER, index, totalIndex); } for (int index = 0; index < Sensor.OrientationAbsoluteList.Count; index++) { totalIndex++; SensorData _orientationAbsoluteData = new SensorData(Sensor.ORIENTATIONSENSOR, totalIndex, "Orientation (Absolute)", new string[] { "QuaternionX", "QuaternionY", "QuaternionZ", "QuaternionW", "RotationMatrixM11", "RotationMatrixM12", "RotationMatrixM13", "RotationMatrixM21", "RotationMatrixM22", "RotationMatrixM23", "RotationMatrixM31", "RotationMatrixM32", "RotationMatrixM33" }); SensorDisplay _orientationAbsoluteDisplay = new SensorDisplay(Sensor.ORIENTATIONSENSOR, index, totalIndex, "Orientation (Absolute)", -1, 1, 2, new Color[] { Colors.DarkRed, Colors.DarkOrange, Colors.DarkCyan, Colors.DarkViolet, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black }); _sensorDisplay.Add(_orientationAbsoluteDisplay); _sensorData.Add(_orientationAbsoluteData); AddPivotItem(Sensor.ORIENTATIONSENSOR, index, totalIndex); } for (int index = 0; index < Sensor.OrientationRelativeList.Count; index++) { totalIndex++; SensorData _orientationRelativeData = new SensorData(Sensor.ORIENTATIONRELATIVE, totalIndex, "Orientation (Relative)", new string[] { "QuaternionX", "QuaternionY", "QuaternionZ", "QuaternionW", "RotationMatrixM11", "RotationMatrixM12", "RotationMatrixM13", "RotationMatrixM21", "RotationMatrixM22", "RotationMatrixM23", "RotationMatrixM31", "RotationMatrixM32", "RotationMatrixM33" }); SensorDisplay _orientationRelativeDisplay = new SensorDisplay(Sensor.ORIENTATIONRELATIVE, index, totalIndex, "Orientation (Relative)", -1, 1, 2, new Color[] { Colors.DarkRed, Colors.DarkOrange, Colors.DarkCyan, Colors.DarkViolet, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black }); _sensorDisplay.Add(_orientationRelativeDisplay); _sensorData.Add(_orientationRelativeData); AddPivotItem(Sensor.ORIENTATIONRELATIVE, index, totalIndex); } for (int index = 0; index < Sensor.OrientationGeomagneticList.Count; index++) { totalIndex++; SensorData _orientationGeomagneticData = new SensorData(Sensor.ORIENTATIONGEOMAGNETIC, totalIndex, "Orientation (Geomagnetic)", new string[] { "QuaternionX", "QuaternionY", "QuaternionZ", "QuaternionW", "RotationMatrixM11", "RotationMatrixM12", "RotationMatrixM13", "RotationMatrixM21", "RotationMatrixM22", "RotationMatrixM23", "RotationMatrixM31", "RotationMatrixM32", "RotationMatrixM33" }); SensorDisplay _orientationGeomagneticDisplay = new SensorDisplay(Sensor.ORIENTATIONGEOMAGNETIC, index, totalIndex, "Orientation (Geomagnetic)", -1, 1, 2, new Color[] { Colors.DarkRed, Colors.DarkOrange, Colors.DarkCyan, Colors.DarkViolet, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black }); _sensorDisplay.Add(_orientationGeomagneticDisplay); _sensorData.Add(_orientationGeomagneticData); AddPivotItem(Sensor.ORIENTATIONGEOMAGNETIC, index, totalIndex); } for (int index = 0; index < Sensor.PedometerList.Count; index++) { totalIndex++; SensorData _pedometerData = new SensorData(Sensor.PEDOMETER, totalIndex, "Pedometer", new string[] { "CumulativeSteps", "CumulativeStepsDuration (s)", "StepKind" }); SensorDisplay _pedometerDisplay = new SensorDisplay(Sensor.PEDOMETER, index, totalIndex, "Pedometer", 0, 50, 2, new Color[] { Colors.DarkCyan, Colors.Black, Colors.Black }); _sensorDisplay.Add(_pedometerDisplay); _sensorData.Add(_pedometerData); AddPivotItem(Sensor.PEDOMETER, index, totalIndex); } for (int index = 0; index < Sensor.ProximitySensorList.Count; index++) { totalIndex++; SensorData _proximitySensorData = new SensorData(Sensor.PROXIMITYSENSOR, totalIndex, "ProximitySensor", new string[] { "IsDetected", "Distance (mm)" }); SensorDisplay _proximitySensorDisplay = new SensorDisplay(Sensor.PROXIMITYSENSOR, index, totalIndex, "ProximitySensor", 0, 1, 1, new Color[] { Colors.DarkOrange, Colors.Black }); _sensorDisplay.Add(_proximitySensorDisplay); _sensorData.Add(_proximitySensorData); AddPivotItem(Sensor.PROXIMITYSENSOR, index, totalIndex); } for (int index = 0; index < Sensor.SimpleOrientationSensorList.Count; index++) { totalIndex++; SensorData _simpleOrientationSensorData = new SensorData(Sensor.SIMPLEORIENTATIONSENSOR, totalIndex, "SimpleOrientationSensor", new string[] { "SimpleOrientation" }); SensorDisplay _simpleOrientationSensorDisplay = new SensorDisplay(Sensor.SIMPLEORIENTATIONSENSOR, index, totalIndex, "SimpleOrientationSensor", 0, 5, 5, new Color[] { Colors.Lime }); _sensorDisplay.Add(_simpleOrientationSensorDisplay); _sensorData.Add(_simpleOrientationSensorData); AddPivotItem(Sensor.PROXIMITYSENSOR, index, totalIndex); } AddSummaryPage(); var resourceLoader = ResourceLoader.GetForCurrentView(); rootPage.NotifyUser(resourceLoader.GetString("NumberOfSensors") + ": " + (PivotSensor.Items.Count - 1) + "\nNumber of sensors failed to enumerate: " + Sensor.NumFailedEnumerations, NotifyType.StatusMessage); ProgressRingSensor.IsActive = false; if (PivotSensor.Items.Count > 0) { PivotSensor.SelectionChanged += PivotSensorSelectionChanged; PivotSensor.SelectedIndex = 0; PivotSensorSelectionChanged(null, null); } else { TextBlockNoSensor.Text = resourceLoader.GetString("CannotFindSensor"); return; } } catch (Exception ex) { rootPage.NotifyUser(ex.Message, NotifyType.ErrorMessage); } ProgressRingSensor.IsActive = false; }
public void ReportIntervalButton(object sender, RoutedEventArgs e) { try { SensorDisplay selectedDisplay = Sensor.SensorDisplay[Sensor.CurrentId]; SensorData selectedData = Sensor.SensorData[Sensor.CurrentId]; uint newReportInterval = uint.Parse(selectedDisplay.TextboxReportInterval.Text); selectedData.UpdateReportInterval(newReportInterval); if (selectedDisplay.SensorType == Sensor.ACCELEROMETER) { Sensor.AccelerometerStandardList[selectedDisplay.Index].ReportInterval = newReportInterval; } else if (selectedDisplay.SensorType == Sensor.ACCELEROMETERGRAVITY) { Sensor.AccelerometerGravityList[selectedDisplay.Index].ReportInterval = newReportInterval; } else if (selectedDisplay.SensorType == Sensor.ACCELEROMETERLINEAR) { Sensor.AccelerometerLinearList[selectedDisplay.Index].ReportInterval = newReportInterval; } else if (selectedDisplay.SensorType == Sensor.ALTIMETER) { Sensor.Altimeter.ReportInterval = newReportInterval; } else if (selectedDisplay.SensorType == Sensor.BAROMETER) { Sensor.BarometerList[selectedDisplay.Index].ReportInterval = newReportInterval; } else if (selectedDisplay.SensorType == Sensor.COMPASS) { Sensor.CompassList[selectedDisplay.Index].ReportInterval = newReportInterval; } else if (selectedDisplay.SensorType == Sensor.CUSTOMSENSOR) { Sensor.CustomSensorList[selectedDisplay.Index].ReportInterval = newReportInterval; } else if (selectedDisplay.SensorType == Sensor.GYROMETER) { Sensor.GyrometerList[selectedDisplay.Index].ReportInterval = newReportInterval; } else if (selectedDisplay.SensorType == Sensor.INCLINOMETER) { Sensor.InclinometerList[selectedDisplay.Index].ReportInterval = newReportInterval; } else if (selectedDisplay.SensorType == Sensor.LIGHTSENSOR) { Sensor.LightSensorList[selectedDisplay.Index].ReportInterval = newReportInterval; } else if (selectedDisplay.SensorType == Sensor.MAGNETOMETER) { Sensor.MagnetometerList[selectedDisplay.Index].ReportInterval = newReportInterval; } else if (selectedDisplay.SensorType == Sensor.ORIENTATIONSENSOR) { Sensor.OrientationAbsoluteList[selectedDisplay.Index].ReportInterval = newReportInterval; } else if (selectedDisplay.SensorType == Sensor.ORIENTATIONGEOMAGNETIC) { Sensor.OrientationGeomagneticList[selectedDisplay.Index].ReportInterval = newReportInterval; } else if (selectedDisplay.SensorType == Sensor.ORIENTATIONRELATIVE) { Sensor.OrientationRelativeList[selectedDisplay.Index].ReportInterval = newReportInterval; } else if (selectedDisplay.SensorType == Sensor.PEDOMETER) { Sensor.PedometerList[selectedDisplay.Index].ReportInterval = newReportInterval; } } catch { } }
public void Plot(SensorData sensorData) { try { if (_replotGrid) { _canvas.Children.Clear(); _canvas.Height = _height; PlotGrid(_maxValue, _minValue, Colors.Black); _replotGrid = false; } else { int index = _canvas.Children.Count; for (int i = 0; i < _plotIndex.Count; i++) { index--; _canvas.Children.RemoveAt(index); } } PathFigure[] pathFigure = new PathFigure[_plotIndex.Count]; for (int i = 0; i < pathFigure.Length; i++) { pathFigure[i] = new PathFigure(); } DateTime now = DateTime.UtcNow; for (int i = sensorData._reading.Count - 1; i >= 0; i--) { if (sensorData._reading[i].timestamp < now) { if (i >= 0) { for (int j = 0; j < _plotIndex.Count; j++) { int index = _plotIndex[j]; AddLineSegmentToPathFigure(ref pathFigure[index], 0, sensorData._reading[i].value[index], (sensorData._reading[i].timestamp - now).TotalSeconds, sensorData._reading[i].value[index]); } } for (; i > 0 && sensorData._reading[i].timestamp > now.AddSeconds(-_frame); i--) { for (int j = 0; j < _plotIndex.Count; j++) { int index = _plotIndex[j]; AddLineSegmentToPathFigure(ref pathFigure[index], (sensorData._reading[i].timestamp - now).TotalSeconds, sensorData._reading[i - 1].value[index], (sensorData._reading[i - 1].timestamp - now).TotalSeconds, sensorData._reading[i - 1].value[index]); } } break; } } Path[] path = AddPathFigureToPath(pathFigure); for (int i = 0; i < path.Length; i++) { _canvas.Children.Add(path[i]); } } catch { } }