Esempio n. 1
0
        void ApplyCalibration(bool logDetailsToFile)
        {
            // apply calibration of given profile to acceleration sensor launch detection
            DataItemVehicle vehicle   = Database.GetInstance().GetActiveProfile();
            RunStartStop    startStop = new RunStartStop(vehicle);

            if (logDetailsToFile == true)
            {
                string latitude  = gpsProvider.GetLatitude().ToString().Replace(',', '.');
                string longitute = gpsProvider.GetLongitude().ToString().Replace(',', '.');

                Debug.LogToFile("location [latitude, longitude]: " + latitude + ", " + longitute);
                Debug.LogToFile(startStop.GetStartString());
                Debug.LogToFile(startStop.GetStopString());

                Analytics.TrackLocation(latitude, longitute);
            }

            accelerometerProvider.SetForceDetectLimit(startStop.GetStartLimit());
            accelerometerProvider.SetAxisOffset(vehicle.AxisOffsetX,
                                                vehicle.AxisOffsetY,
                                                vehicle.AxisOffsetZ);

            runModeProvider.StopDetectionLimit = startStop.GetStopLimit();
        }
Esempio n. 2
0
        async void OnButtonRun(object sender, EventArgs args)
        {
            btnRun.IsEnabled = false;

            DataItemVehicle vehicle = Database.GetInstance().GetActiveProfile();

            // if gps is off -> demo mode
            if (Config.Run.DemoModeEnabled)
            {
                isDemoMode = (isGpsOk == false);
            }
            else
            {
                isDemoMode = false;                          // demo mode disabled by config
            }
            if (
                (vehicle.Calibration < PageCalibration.CALIBRATION_SUCCESS_LIMIT) // profile was never calibrated
                ||                                                                // OR
                (accelerometerRecorder.IsPositionEqual(vehicle) == false)         // position of calibrated device in car mount has changed
                )
            {
                // launch calibration page -> after that, the run page is shown automaticaly
                await Navigation.PushAsync(new PageCalibration(vehicle, accelerometerProvider, soundProvider, this));
            }
            else
            {
                // launch run page
                ShowPageRun();
            }

            btnRun.IsEnabled = true;
        }
Esempio n. 3
0
        void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            DataItemVehicle item = (DataItemVehicle)e.SelectedItem;

            if (item != null)
            {
                database.SaveActiveProfile(item);
            }
        }
Esempio n. 4
0
        public void UpdateVehicle(DataItemVehicle vehicle, string model, string color, float calibration)
        {
            vehicle.Model       = model;
            vehicle.Color       = color;
            vehicle.Calibration = calibration;

            database.SaveVehicle(vehicle);
            SetSelectedItem(vehicle);
        }
Esempio n. 5
0
        public void AddVehicle(string model, string color, float calibration)
        {
            var item = new DataItemVehicle {
                Model = model, Color = color, Calibration = calibration
            };

            database.SaveVehicle(item);
            vehicles.Add(item);
            SetSelectedItem(item);
        }
        async void OnButtonCalibration(object sender, EventArgs args)
        {
            btnCalibration.IsEnabled = false;
            isDirty         = true;
            itemCalibration = DataItem.CreateDefaultVehicle();
            await Navigation.PushAsync(new PageCalibration(itemCalibration, accelerometerProvider, soundProvider, null));

            Analytics.TrackEventProfile(Analytics.EVENT_PPROFILE_CALIBRATE);
            btnCalibration.IsEnabled = true;
        }
Esempio n. 7
0
 void SetSelectedItem(DataItemVehicle v)
 {
     // workaround to activate a selected item is to nullify the list
     if (v != null)
     {
         ListViewVehicles.SelectedItem = null;
         ListViewVehicles.ItemsSource  = null;
         ListViewVehicles.ItemsSource  = vehicles;
         ListViewVehicles.SelectedItem = v;
     }
 }
Esempio n. 8
0
        DataItemVehicle SearchVehicle(DataItemVehicle v)
        {
            for (int i = 0; i < vehicles.Count; i++)
            {
                if (vehicles[i].Id == v.Id)
                {
                    return(vehicles[i]);
                }
            }

            return(vehicles[0]);
        }
        public void Dispose() // IDisposable
        {
            imgButtonBack.GestureRecognizers.RemoveAt(0);
            imgButtonBack.Source  = null;
            imgButtonBack         = null;
            tgrButtonBack.Tapped -= OnButtonBackTapped;
            tgrButtonBack         = null;

            lblCaption = null;

            imgButtonHelp.GestureRecognizers.RemoveAt(0);
            imgButtonHelp.Source  = null;
            imgButtonHelp         = null;
            tgrButtonHelp.Tapped -= OnButtonHelpTapped;
            tgrButtonHelp         = null;

            btnCalibration.Clicked -= OnButtonCalibration;
            btnCalibration.Image    = null;
            btnCalibration          = null;

            btnVehicle.Clicked -= OnButtonVehicle;
            btnVehicle.Image    = null;
            btnVehicle          = null;

            entryVehicle.Completed -= OnEntryVehicleComplete;
            entryVehicle.Unfocused -= OnEntryVehicleComplete;
            entryVehicle            = null;

            btnColor.Image = null;
            btnColor       = null;

            if (btnDelete != null)
            {
                btnDelete.Clicked -= OnButtonDelete;
                btnDelete.Image    = null;
                btnDelete          = null;
            }

            for (int i = 0; i < colorButtons.Length; i++)
            {
                colorButtons[i].SizeChanged -= OnColorButtonSizeChanged;
                colorButtons[i].Clicked     -= OnColorButtonClicked;
                colorButtons[i]              = null;
            }

            storage               = null;
            item                  = null;
            itemCalibration       = null;
            accelerometerProvider = null;
            soundProvider         = null;
        }
        public void StoreAxisOffset(DataItemVehicle itemVehicle)
        {
            Sample average = GetAverage(); // get average of each axis for all samples

            // store to given profile
            itemVehicle.AxisOffsetX = (float)average.x;
            itemVehicle.AxisOffsetY = (float)average.y;
            itemVehicle.AxisOffsetZ = (float)average.z;

            Debug.LogToFile("axis offset stored to profile [x,y,z]: " +
                            average.x.ToString("0.00") + ", " +
                            average.y.ToString("0.00") + ", " +
                            average.z.ToString("0.00"));
        }
Esempio n. 11
0
        public static DataItemVehicle CreateDefaultVehicle()
        {
            DataItemVehicle d = new DataItemVehicle
            {
                Model       = Localization.pageProfileEditDefault,
                Color       = "#2AB3FF",
                Calibration = 0,
                AxisOffsetX = 0,
                AxisOffsetY = 0,
                AxisOffsetZ = 0
            };

            return(d);
        }
        public void Dispose() // IDisposable
        {
            imgButtonBack.Source = null;
            imgButtonBack.GestureRecognizers.RemoveAt(0);
            imgButtonBack         = null;
            tgrButtonBack.Tapped -= OnButtonBackTapped;
            tgrButtonBack         = null;

            lblCaption = null;

            imgButtonHelp.Source = null;
            imgButtonHelp.GestureRecognizers.RemoveAt(0);
            imgButtonHelp         = null;
            tgrButtonHelp.Tapped -= OnButtonHelpTapped;
            tgrButtonHelp         = null;

            lblHelp = null;

            imgCalibAnim1.Source       = null;
            imgCalibAnim1.SizeChanged -= OnLayoutSizeChanged;
            imgCalibAnim1              = null;

            imgCalibAnim2.Source = null;
            imgCalibAnim2        = null;

            imgCalibAnim3.Source = null;
            imgCalibAnim3        = null;

            imgCalibAnim4.Source = null;
            imgCalibAnim4        = null;

            lblText.SizeChanged -= OnLayoutSizeChanged;
            lblText              = null;

            btnOk.Image    = null;
            btnOk.Clicked -= OnButtonOkClicked;
            btnOk          = null;

            vehicle = null;
            accelerometerProvider = null;
            accelerometerRecorder = null;
            soundProvider         = null;
            calibrationFilter     = null;
            pageNavigation        = null;
        }
Esempio n. 13
0
        public void Store()
        {
            // refuse to store empty run
            if (events.Count == 0)
            {
                return;
            }

            Database        db          = Database.GetInstance();
            DataItemVehicle itemVehicle = db.GetActiveProfile();

            if (itemRun == null)
            {
                Debug.LogToFileEventText("run insert, event count: " + events.Count);

                // this run was never stored to the database
                itemRun           = new DataItemRun();
                itemRun.VehicleId = itemVehicle.Id;
                itemRun.Date      = DateTime.Now;
                itemRun.Mode      = mode;
                itemRun.Data      = GetEventsString();

                // attach peakA to the run
                accelerationRecorder.StorePeakAcceleration(itemVehicle, itemRun);

                // insert new run
                db.SaveRun(itemRun);
            }
            else
            {
                Debug.LogToFileEventText("run update, event count: " + events.Count);

                // update run with current events
                itemRun.Data = GetEventsString();

                // attach peakA to the run
                accelerationRecorder.StorePeakAcceleration(itemVehicle, itemRun);

                // update run
                db.UpdateRun(itemRun);
            }
        }
Esempio n. 14
0
        public void SaveActiveProfile(DataItemVehicle item)
        {
            lock (locker)
            {
                Debug.LogToFileMethod("item: " + item.Model);

                if (IsMetaEmpty())
                {
                    // empty database -> create and store default meta item
                    SaveMeta(DataItem.CreateDefaultMeta());
                }

                // the meta table always has one entry only -> get first
                DataItemMeta meta = GetMeta();

                // update active profile
                meta.ActiveProfile = item.Id;
                UpdateMeta(meta);
            }
        }
        public PageCalibration(DataItemVehicle item, IDeviceAcceleromter accelerometer, IDeviceSound sound, PageMain parentPage)
        {
            InitializeComponent();
            Debug.LogToFileMethod();

            NavigationPage.SetHasBackButton(this, false);
            NavigationPage.SetHasNavigationBar(this, false);

            vehicle = item;
            accelerometerProvider = accelerometer;
            soundProvider         = sound;
            state                 = CalibrationState.Init;
            timeMilliSeconds      = 0;
            calibrationFilter     = new MovingAverage(SAMPLE_DURATION_MS / SAMPLE_INTERVAL_MS);
            calibration           = 0;
            pageNavigation        = parentPage;
            accelerometerRecorder = new AccelerometerRecorder(false); // false: do not use queue mode

            InitLayout();
        }
        public bool IsPositionEqual(DataItemVehicle itemVehicle)
        {
            bool   result  = true;
            Sample average = GetAverage(); // get average of each axis for all samples

            if (Math.Abs((itemVehicle.AxisOffsetX - average.x)) > POSITION_DEVIATION_LIMIT)
            {
                result = false;
            }
            if (Math.Abs((itemVehicle.AxisOffsetY - average.y)) > POSITION_DEVIATION_LIMIT)
            {
                result = false;
            }
            if (Math.Abs((itemVehicle.AxisOffsetZ - average.z)) > POSITION_DEVIATION_LIMIT)
            {
                result = false;
            }

            return(result);
        }
Esempio n. 17
0
        public int SaveVehicle(DataItemVehicle item)
        {
            int result = 0;

            lock (locker)
            {
                if (item.Id != 0)
                {
                    Debug.LogToFileMethod("item update: " + item.Model);
                    database.Update(item);
                    result = item.Id;
                }
                else
                {
                    Debug.LogToFileMethod("item insert: " + item.Model);
                    result = database.Insert(item);
                }
            }

            return(result);
        }
        string GetColorPickerImageFromItem(DataItemVehicle itm)
        {
            string result = colorButtons[0].colorPickerImage;

            if (itm != null)
            {
                if (itm.Color != null)
                {
                    for (int i = 0; i < colorButtons.Length; i++)
                    {
                        string c = colorButtons[i].color;
                        if (itm.Color.Equals(c))
                        {
                            result = colorButtons[i].colorPickerImage;
                            break;
                        }
                    }
                }
            }

            return(result);
        }
Esempio n. 19
0
        string GetProfileButtonImage()
        {
            string          result = "@drawable/btn_profile_c1.png"; // blue
            DataItemVehicle v      = Database.GetInstance().GetActiveProfile();

            if (v.Color.Equals("#2AB3FF"))
            {
                result = "@drawable/btn_profile_c1.png";                              // blue
            }
            else if (v.Color.Equals("#35FF36"))
            {
                result = "@drawable/btn_profile_c2.png";                              // green
            }
            else if (v.Color.Equals("#FF6565"))
            {
                result = "@drawable/btn_profile_c3.png";                              // red
            }
            else if (v.Color.Equals("#FFA743"))
            {
                result = "@drawable/btn_profile_c4.png";                              // gold
            }
            else if (v.Color.Equals("#EF6AFF"))
            {
                result = "@drawable/btn_profile_c5.png";                              // pink
            }
            else if (v.Color.Equals("#FFFFFF"))
            {
                result = "@drawable/btn_profile_c6.png";                              // white
            }
            else if (v.Color.Equals("#2E2E2E"))
            {
                result = "@drawable/btn_profile_c7.png";                              // silver
            }
            else if (v.Color.Equals("#000000"))
            {
                result = "@drawable/btn_profile_c8.png";                              // black
            }
            return(result);
        }
        public PageProfileEdit(PageProfile page, DataItemVehicle vehicle, bool showDeleteButton, IDeviceAcceleromter accelerometer, IDeviceSound sound)
        {
            InitializeComponent();
            Debug.LogToFileMethod();

            NavigationPage.SetHasBackButton(this, false);
            NavigationPage.SetHasNavigationBar(this, false);

            storage = page;
            item    = vehicle;
            accelerometerProvider = accelerometer;
            soundProvider         = sound;
            isDirty = false;

            InitLayout(showDeleteButton, (item == null)); // if item is null -> create profile mode, not edit mode

            // init with default color
            color = colorButtons[0].color;

            if (item != null)
            {
                calibration       = item.Calibration;
                entryVehicle.Text = item.Model;

                if (item.Color != null)
                {
                    // overwite with given color
                    color = item.Color;
                }
            }
            else
            {
                calibration       = 0;
                entryVehicle.Text = Localization.pageProfileEditDefault;
            }
        }
Esempio n. 21
0
        public RunStartStop(DataItemVehicle itemVehicle)
        {
            Debug.LogToFileMethod();

            vehicle = itemVehicle;

            launchDetectionLimit  = 0;
            launchDetectionFactor = Settings.GetValueOrDefault(Settings.LaunchDetection, Settings.DefaultLaunchDetection);
            stopDetectionLimit    = 0;
            stopDetectionFactor   = Settings.GetValueOrDefault(Settings.StopDetection, Settings.DefaultStopDetection);

            if (vehicle.Calibration < PageCalibration.CALIBRATION_SUCCESS_LIMIT)
            {
                // profile was never calibrated -> use default
                launchDetectionLimit = 1 * launchDetectionFactor;
                stopDetectionLimit   = 1 * stopDetectionFactor;
            }
            else
            {
                // apply calibration to launch and stop detection
                launchDetectionLimit = vehicle.Calibration * launchDetectionFactor;
                stopDetectionLimit   = vehicle.Calibration * stopDetectionFactor;
            }
        }
Esempio n. 22
0
 public void RemoveVehicle(DataItemVehicle item)
 {
     database.DeleteVehicle(item.Id);
     vehicles.Remove(item);
     SetSelectedItem(vehicles[0]);
 }
        public void StorePeakAcceleration(DataItemVehicle itemVehicle, DataItemRun itemRun)
        {
            if (samples.Count == 0)
            {
                Debug.LogToFileMethod("peak-a: no samlpes");
                return;
            }

            if (isPeakAStored == true)
            {
                // refuse to process peakA again
                Debug.LogToFileEventText("peak-a: already found");
                return;
            }

            double peakA     = 0;
            double speed     = 0;
            double magnitude = 0;
            int    count     = samples.Count;

            // user calibrated profile before run -> get accelerometer offsets
            // to eleminate earth gravitation and slope of the device in the car mount
            double offsetX = itemVehicle.AxisOffsetX;
            double offsetY = itemVehicle.AxisOffsetY;
            double offsetZ = itemVehicle.AxisOffsetZ;

            // from collection to array with offset compensation ("normalize" to axis origin)
            ToArray(offsetX, offsetY, offsetZ);

            // apply low pass filter to each "normalized" axis
            OnlineFilter filter = OnlineFilter.CreateLowpass(ImpulseResponse.Finite,
                                                             FILTER_SAMPLE_RATE,
                                                             FILTER_CUT_OFF_RATE,
                                                             FILTER_ORDER);

            double[] filteredX = filter.ProcessSamples(samplesX);
            filter.Reset();

            double[] filteredY = filter.ProcessSamples(samplesY);
            filter.Reset();

            double[] filteredZ = filter.ProcessSamples(samplesZ);
            filter.Reset();

            // search max value of magnitude of all filtered axes
            for (int i = 0; i < count; i++)
            {
                // magnitude of all components
                magnitude = Math.Sqrt(filteredX[i] * filteredX[i] +
                                      filteredY[i] * filteredY[i] +
                                      filteredZ[i] * filteredZ[i]);

                // store if new max
                if (magnitude > peakA)
                {
                    peakA = magnitude;
                    speed = samplesS[i];
                }
            }

            // store to given run
            itemRun.PeakAcceleration = (float)peakA;

            Debug.LogToFileEventText("found peak-a [m/s^2]: " + peakA.ToString("0.00") +
                                     " at speed [m/s]: " + speed.ToString("0.00"));

            if ((count >= SIZE_MAX) && (peakA > 0))
            {
                isPeakAStored = true;
            }
        }