Example #1
0
        protected override void OnAppearing()
        {
            base.OnAppearing();
            Analytics.TrackPage(Analytics.PAGE_RUN);

            isRunning        = true; // workaround for xamarin.com Bug 35407 - jobject muste not be IntPtr.Zero with Animation
            isLaunchDetected = false;
            isGpsOk          = false;
            isUnitKmh        = Settings.IsSpeedUnitKph();
            settleCounter    = SETTLE_COUNT_LIMIT;
            timeStampLastGps = DateTime.Now.Ticks;
            runAdjust        = new RunAdjust();
            runData          = new RunData(runModeProvider.Mode);

            Debug.LogToFile(runModeProvider.ToString());

            Device.StartTimer(TimeSpan.FromMilliseconds(SPEEDO_UPDATE_RATE_MS), OnTimer);

            gpsProvider.SetListener(this);
            accelerometerProvider.SetListener(this);
        }
        protected override void OnAppearing()
        {
            base.OnAppearing();
            Debug.LogToFileMethod();

            if (accelerometerProvider != null)
            {
                accelerometerProvider.SetListener(this);

                labelForceDetectLimit.Text = "ForceDetectLimit: " + sliderForceDetectLimit.Value;
                accelerometerProvider.SetForceDetectLimit((float)sliderForceDetectLimit.Value);

                sliderForceDetectLimit.ValueChanged += (object sender, ValueChangedEventArgs e) =>
                {
                    labelForceDetectLimit.Text = "ForceDetectLimit: " + e.NewValue;
                    accelerometerProvider.SetForceDetectLimit((float)sliderForceDetectLimit.Value);
                };

                labelTimeDetectLimit.Text = "TimeDetectLimit: " + sliderTimeDetectLimit.Value;
                accelerometerProvider.SetTimeDetectLimit((long)sliderTimeDetectLimit.Value);

                sliderTimeDetectLimit.ValueChanged += (object sender, ValueChangedEventArgs e) =>
                {
                    labelTimeDetectLimit.Text = "TimeDetectLimit: " + e.NewValue;
                    accelerometerProvider.SetTimeDetectLimit((long)sliderTimeDetectLimit.Value);
                };

                labelTimeUpdateInterval.Text = "UpdateInterval: " + sliderTimeUpdateInterval.Value;
                accelerometerProvider.SetTimeUpdateInterval((long)sliderTimeUpdateInterval.Value);

                sliderTimeUpdateInterval.ValueChanged += (object sender, ValueChangedEventArgs e) =>
                {
                    labelTimeUpdateInterval.Text = "UpdateInterval: " + e.NewValue;
                    accelerometerProvider.SetTimeUpdateInterval((long)sliderTimeUpdateInterval.Value);
                };

                labelLaunchDetected.Text = "";
            }
        }
        public void SetListener(IAcceleromterListener listener) // IDeviceAcceleromter
        {
            this.listener = listener;

            if (this.listener == null)
            {
                accelerometerProvider.SetListener(null);

                stopwatch.Stop();
                countdown.Stop();
                Debug.LogToFileMethod("accelerometer sensor off (demo mode)");
            }
            else
            {
                accelerometerProvider.SetListener(this);

                if (status.Equals("launchDetected"))
                {
                    stopwatch.Start();
                    Device.StartTimer(TimeSpan.FromMilliseconds(UPDATE_RATE_MS), OnTimer);
                    Debug.LogToFileMethod("accelerometer sensor on (demo mode)");
                }
            }
        }
Example #4
0
        protected override void OnAppearing()
        {
            base.OnAppearing();
            Debug.LogToFileMethod();
            Analytics.TrackPage(Analytics.PAGE_MAIN);

            InitState();
            ApplyCalibration(false); // but do not log details to file

            if (gpsProvider != null)
            {
                gpsProvider.SetListener(this);
            }

            if (accelerometerProvider != null)
            {
                // register for launch detection event
                accelerometerProvider.SetListener(this);
            }

            isRunning        = true;
            timeStampLastGps = DateTime.Now.Ticks;
            Device.StartTimer(TimeSpan.FromMilliseconds(CONDITION_UPDATE_RATE_MS), OnTimer);
        }
        bool OnTimer()
        {
            timeMilliSeconds += SAMPLE_INTERVAL_MS;

            if (timeMilliSeconds > SAMPLE_DURATION_MS)
            {
                btnOk.IsEnabled = true;
                state           = CalibrationState.End;

                if (GetCalibration() < CALIBRATION_SUCCESS_LIMIT)
                {
                    // not successful
                    lblText.Text      = Localization.pageCalibrationNotOk;
                    lblText.TextColor = Color.FromHex("FF0000");
                }
                else
                {
                    // successful
                    lblText.Text      = Localization.pageCalibrationOk;
                    lblText.TextColor = Color.FromHex("00FF00");
                }

                btnOk.Image = Localization.btn_calibration_done;
                return(false); // stop timer
            }

            var sensorXDelta = accelerometerProvider.GetXDelta();
            var sensorYDelta = accelerometerProvider.GetYDelta();
            var sensorZDelta = accelerometerProvider.GetZDelta();

            var noise = Math.Abs(sensorXDelta + sensorYDelta + sensorZDelta);

            calibration = calibrationFilter.Get(noise);

            if (Config.Calibration.LiveLabelEnabled)
            {
                lblText.Text = "" + GetCalibration().ToString("0.0") + " m/s²";
            }

            // animate, switch one image after another visible
            switch (timeMilliSeconds)
            {
            case 300:
                accelerometerProvider.SetListener(this);
                imgCalibAnim1.IsVisible = false;
                imgCalibAnim2.IsVisible = true;
                break;

            case 2200:
                imgCalibAnim2.IsVisible = false;
                imgCalibAnim3.IsVisible = true;
                break;

            case 3800:
                imgCalibAnim3.IsVisible = false;
                imgCalibAnim4.IsVisible = true;
                break;

            case 4500:
                accelerometerProvider.SetListener(null);
                break;
            }

            return(true); // restart timer
        }