コード例 #1
0
 public ActionHelper()
 {
     inclinometer = Inclinometer.GetDefault();
     inclinometer.ReadingChanged += inclinometer_ReadingChanged;
     InclinometerState = MagnetometerAccuracy.Unknown;
     offYaw = 0;offRoll = 0;offPitch = 0;
 }
コード例 #2
0
 private void _compass_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     try
     {
         od_kompasa = args.Reading.HeadingTrueNorth.Value - qibla_angle;
         accuracy   = args.Reading.HeadingAccuracy;
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Greška pri očitavanju kompasa uređaja " + "(" + ex.Message + ")");
     }
 }
コード例 #3
0
 /// <summary>
 /// Called when the application would like to show the calibration bar to the user
 /// to improve sensor accuracy.
 /// </summary>
 /// <param name="accuracy">Current accuracy of the sensor.</param>
 public void RequestCalibration(MagnetometerAccuracy accuracy)
 {
     // Only show the calibration bar if it is hidden and sufficient
     // time has passed since it was last hidden.
     if (!CalibrationPopup.IsOpen && CanShowCalibrationBar(accuracy))
     {
         InvalidateLayout();
         Window.Current.SizeChanged += OnWindowSizeChanged;
         HideGuidance(); // Calibration image hidden by default
         CalibrationPopup.IsOpen = true;
         _calibrationTimer.Start();
     }
 }
コード例 #4
0
ファイル: CalibrationBar.xaml.cs プロジェクト: ckc/WinApp
 /// <summary>
 /// Called when the application would like to show the calibration bar to the user 
 /// to improve sensor accuracy.
 /// </summary>
 /// <param name="accuracy">Current accuracy of the sensor.</param>
 public void RequestCalibration(MagnetometerAccuracy accuracy)
 {
     // Only show the calibration bar if it is hidden and sufficient
     // time has passed since it was last hidden.
     if (!CalibrationPopup.IsOpen && CanShowCalibrationBar(accuracy))
     {
         InvalidateLayout();
         Window.Current.SizeChanged += OnWindowSizeChanged;
         HideGuidance(); // Calibration image hidden by default
         CalibrationPopup.IsOpen = true;
         _calibrationTimer.Start();
     }
 }
コード例 #5
0
ファイル: MagnetometerReading.cs プロジェクト: zzyzy/uno
 public MagnetometerReading(
     float magneticFieldX,
     float magneticFieldY,
     float magneticFieldZ,
     MagnetometerAccuracy directionalAccuracy,
     DateTimeOffset timestamp)
 {
     MagneticFieldX      = magneticFieldX;
     MagneticFieldY      = magneticFieldY;
     MagneticFieldZ      = magneticFieldZ;
     DirectionalAccuracy = directionalAccuracy;
     Timestamp           = timestamp;
 }
コード例 #6
0
        /// <summary>
        /// Called to determine if sufficient time has passed since the calibration bar
        /// was hidden to show the calibration bar again. This suppression time is
        /// dependent on the current sensor accuracy.
        /// </summary>
        /// <param name="accuracy">Current accuracy of the sensor.</param>
        private bool CanShowCalibrationBar(MagnetometerAccuracy accuracy)
        {
            bool showBar = false;

            if (!_barDismissed)
            {
                if ((accuracy == MagnetometerAccuracy.Approximate) &&
                    (DateTime.Now.CompareTo(_lastCalibrationTime.AddMinutes(SUPPRESS_DURATION_APPROXIMATE_MIN)) >= 0))
                {
                    showBar = true;
                }
                else if ((accuracy == MagnetometerAccuracy.Unreliable) &&
                         (DateTime.Now.CompareTo(_lastCalibrationTime.AddMinutes(SUPPRESS_DURATION_UNRELIABLE_MIN)) >= 0))
                {
                    showBar = true;
                }
            }
            return(showBar);
        }
コード例 #7
0
        protected CompassAccuracy TranslateAccuracy(MagnetometerAccuracy accuracy)
        {
            var retVal = CompassAccuracy.Unknown;

            switch (accuracy)
            {
            case MagnetometerAccuracy.High:
                retVal = CompassAccuracy.High;
                break;

            case MagnetometerAccuracy.Unreliable:
                retVal = CompassAccuracy.Unreliable;
                break;

            case MagnetometerAccuracy.Approximate:
                retVal = CompassAccuracy.Approximate;
                break;
            }
            return(retVal);
        }
コード例 #8
0
        protected CompassAccuracy FromNative(MagnetometerAccuracy native)
        {
            switch (native)
            {
            case MagnetometerAccuracy.High:
                return(CompassAccuracy.High);

            case MagnetometerAccuracy.Unreliable:
                return(CompassAccuracy.Unreliable);

                ;

            case MagnetometerAccuracy.Approximate:
                return(CompassAccuracy.Approximate);

                ;

            default:
                return(CompassAccuracy.Unknown);

                ;
            }
        }
コード例 #9
0
        /// <summary>
        /// send sensor data to server ,depend on different mode.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void inclinometer_ReadingChanged(Inclinometer sender, InclinometerReadingChangedEventArgs args)
        {
            InclinometerReading reading = args.Reading;

            if (args.Reading.YawAccuracy != InclinometerState)
            {
                InclinometerState = args.Reading.YawAccuracy;
                if (InclinometerStateChanged != null)
                    InclinometerStateChanged(this, EventArgs.Empty);
            }

            if (connected && mode == SensorMode.TRACKER)
                App.comHelper.sendTrack(-(reading.YawDegrees-offYaw), -(reading.RollDegrees-offRoll), -(reading.PitchDegrees-offPitch));
            else if (connected && mode == SensorMode.JOYSTICK)
                App.comHelper.sendAxis((reading.PitchDegrees-offPitch) / 120 + 0.5, -(reading.RollDegrees-offRoll) / 100 + 0.5);
            else if (mode == SensorMode.CALIBRATION)
            {
                offYaw = reading.YawDegrees;
                offRoll = reading.RollDegrees;
                offPitch = reading.PitchDegrees;
            }
        }
コード例 #10
0
ファイル: CalibrationBar.xaml.cs プロジェクト: ckc/WinApp
 /// <summary>
 /// Called to determine if sufficient time has passed since the calibration bar
 /// was hidden to show the calibration bar again. This suppression time is
 /// dependent on the current sensor accuracy.
 /// </summary>
 /// <param name="accuracy">Current accuracy of the sensor.</param>
 private bool CanShowCalibrationBar(MagnetometerAccuracy accuracy)
 {
     bool showBar = false;
     if (!_barDismissed)
     {
         if ((accuracy == MagnetometerAccuracy.Approximate) &&
             (DateTime.Now.CompareTo(_lastCalibrationTime.AddMinutes(SUPPRESS_DURATION_APPROXIMATE_MIN)) >= 0))
         {
             showBar = true;
         }
         else if ((accuracy == MagnetometerAccuracy.Unreliable) &&
             (DateTime.Now.CompareTo(_lastCalibrationTime.AddMinutes(SUPPRESS_DURATION_UNRELIABLE_MIN)) >= 0))
         {
             showBar = true;
         }
     }
     return showBar;
 }
コード例 #11
0
ファイル: SensorDisplay.cs プロジェクト: aschoorl/busiotools
        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 { }
        }
コード例 #12
0
 private void _compass_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     od_kompasa = args.Reading.HeadingTrueNorth.Value - qibla_angle;
     accuracy   = args.Reading.HeadingAccuracy;
 }