void ResetTrip(IPeripheral selectedPeripheral)
        {
            Device.BeginInvokeOnMainThread(async() =>
            {
                pies = await App.Current.MainPage.DisplayAlert("Reset Trip", "Are you sure you would like to reset your trip?", "Ok", "Cancel");


                if (pies == true)
                {
                    Endd = true;
                    Thread.SpinWait(200);
                    TextToSend = "MR";
                    Thread.SpinWait(200);

                    _savedCharacteristic?.Write(Encoding.UTF8.GetBytes($"{TextToSend}")).Subscribe(
                        result =>
                    {
                        Thread.SpinWait(200);

                        //ShowMessage("Yay", Encoding.UTF8.GetString(Encoding.UTF8.GetBytes($"{TextToSend}"), 0, Encoding.UTF8.GetBytes($"{TextToSend}").Length));
                    },
                        exception =>
                    {
                        //ShowMessage("Error", Encoding.UTF8.GetString(Encoding.UTF8.GetBytes($"{TextToPrint}"), 0, Encoding.UTF8.GetBytes($"{TextToPrint}").Length));
                    });
                    conn();
                    Thread.SpinWait(600);
                }
            });
        }
        void ConnectPrinter(IPeripheral selectedPeripheral)
        {
            if (!selectedPeripheral.IsConnected())
            {
                selectedPeripheral.Connect();
            }

            _perifDisposable = selectedPeripheral.WhenAnyCharacteristicDiscovered().Subscribe((characteristic) =>
            {
                System.Diagnostics.Debug.WriteLine(characteristic.Description);
                if (characteristic.CanWrite() && characteristic.CanRead() && characteristic.CanNotify())
                {
                    IsReadyToPrint       = true;
                    _savedCharacteristic = characteristic;


                    conn();
                    TriggerSettings();
                    Thread.SpinWait(800);

                    flagg       = "!!";
                    TextToPrint = "0";
                    PrintText();
                    Thread.SpinWait(300);
                    System.Diagnostics.Debug.WriteLine($"Writing {characteristic.Uuid} - {characteristic.CanRead()} - {characteristic.CanIndicate()} - {characteristic.CanNotify()}");
                    _perifDisposable.Dispose();
                }
            });
        }
 void DiscPrinter(IPeripheral selectedPeripheral)
 {
     Endd = true;
     Thread.SpinWait(200);
     //if (selectedPeripheral.IsConnected())
     //  selectedPeripheral.CancelConnection();
     //flagD = true;
     Application.Current.MainPage.Navigation.PopAsync();
 }
        void ResetTank(IPeripheral selectedPeripheral)
        {
            Device.BeginInvokeOnMainThread(async() =>
            {
                string action = await App.Current.MainPage.DisplayActionSheet("Full or Partial refuel?", "Cancel", null, "Full Tank", "Partial Refuel");


                if (action == "Full Tank")
                {
                    Endd = true;
                    Thread.SpinWait(200);
                    TextToSend = "MT";
                    Thread.SpinWait(200);

                    _savedCharacteristic?.Write(Encoding.UTF8.GetBytes($"{TextToSend}")).Subscribe(
                        result =>
                    {
                        Thread.SpinWait(200);

                        //ShowMessage("Yay", Encoding.UTF8.GetString(Encoding.UTF8.GetBytes($"{TextToSend}"), 0, Encoding.UTF8.GetBytes($"{TextToSend}").Length));
                    },
                        exception =>
                    {
                        //ShowMessage("Error", Encoding.UTF8.GetString(Encoding.UTF8.GetBytes($"{TextToPrint}"), 0, Encoding.UTF8.GetBytes($"{TextToPrint}").Length));
                    });
                    conn();

                    Thread.SpinWait(600);
                }
                if (action == "Partial Refuel")
                {
                    Endd = true;
                    Thread.SpinWait(200);

                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        TextToPrint = await App.Current.MainPage.DisplayPromptAsync("Partial Refuel", "How much fuel have you added to the tank *1000? (20.69L = 20,690)", "Save", "Cancel", "10,000L", 8, keyboard: Keyboard.Numeric);
                        //CheckIfOK(TextToPrint);
                        if (TextToPrint != null)
                        {
                            savesettingsPART();
                            Thread.SpinWait(650);
                        }
                        conn();
                        flagg       = "!!";
                        TextToPrint = "0";
                        PrintText();
                    });

                    conn();
                    Thread.SpinWait(600);
                }
            });
        }
        public InfoPageViewModel(IPeripheral peripheral)
        {
            SettingCommand1  = new Command(savesettingsQ);
            SettingCommand2  = new Command(savesettingsR);
            SettingCommand3  = new Command(savesettingsS);
            SettingCommand4  = new Command(savesettingsT);
            SettingCommand5  = new Command(savesettingsU);
            SettingCommand6  = new Command(savesettingsV);
            SettingCommand7  = new Command(savesettingsW);
            SettingCommand8  = new Command(savesettingsX);
            SettingCommand9  = new Command(savesettingsY);
            SettingCommand10 = new Command(savesettingsZ);

            SettingCommand       = new Command <IPeripheral>(SettingsView);
            TripCommand          = new Command <IPeripheral>(ResetTrip);
            TankCommand          = new Command <IPeripheral>(ResetTank);
            ConnectDeviceCommand = new Command <IPeripheral>(ConnectPrinter);
            Disconnect           = new Command <IPeripheral>(DiscPrinter);
            ConnectDeviceCommand.Execute(peripheral);
        }
        void SettingsView(IPeripheral selectedPeripheral)
        {
            TriggerSettings();
            Device.BeginInvokeOnMainThread(async() =>
            {
                string action = await App.Current.MainPage.DisplayActionSheet("Select a Setting to change", "Cancel", null, "VSS Pulses/KM", "Microsec/Litre", "Pulses/2Rev", "Imperial/Metric", "Tank Size", "Inj Delay", "VSS Delay", "Inj Type", "Volt Offset");

                conn();
                flagg       = "!!";
                TextToPrint = "0";
                PrintText();
                Thread.SpinWait(300);

                if (action == "VSS Pulses/KM")
                {
                    TriggerSettings();
                    string crap = Convert.ToString(SvssPulses);
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        TextToPrint = await App.Current.MainPage.DisplayPromptAsync("VSS Pulses/KM", "The amount of pulses recieved per KM", "Save", "Cancel", crap, 8, keyboard: Keyboard.Numeric, crap);
                        //CheckIfOK(TextToPrint);
                        if (TextToPrint != null)
                        {
                            savesettingsR();
                            Thread.SpinWait(650);
                        }
                        conn();
                        flagg       = "!!";
                        TextToPrint = "0";
                        PrintText();
                    });
                }
                if (action == "Microsec/Litre")
                {
                    TriggerSettings();
                    string crap = Convert.ToString(SmicroSec);
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        TextToPrint = await App.Current.MainPage.DisplayPromptAsync("Microsec/Litre", "How many Microseconds of injector time for 1 Litre", "Save", "Cancel", crap, 8, keyboard: Keyboard.Numeric, crap);
                        //CheckIfOK(TextToPrint);
                        if (TextToPrint != null)
                        {
                            savesettingsS();
                            Thread.SpinWait(50);
                        }
                        conn();
                        flagg       = "!!";
                        TextToPrint = "0";
                        PrintText();
                    });
                }
                if (action == "Pulses/2Rev")
                {
                    TriggerSettings();
                    string crap = Convert.ToString(SperRev);
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        TextToPrint = await App.Current.MainPage.DisplayPromptAsync("Pulses/2Rev", "Inj pulses per 2 engine cycles, for RPM readout", "Save", "Cancel", crap, 8, keyboard: Keyboard.Numeric, crap);
                        //CheckIfOK(TextToPrint);
                        if (TextToPrint != null)
                        {
                            savesettingsT();
                            Thread.SpinWait(50);
                        }
                        conn();
                        flagg       = "!!";
                        TextToPrint = "0";
                        PrintText();
                    });
                }
                if (action == "Imperial/Metric")
                {
                    TriggerSettings();
                    string crap = Convert.ToString(STripReset);
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        TextToPrint = await App.Current.MainPage.DisplayPromptAsync("Imperial/Metric", "1 for Imperial, 2 for Metric", "Save", "Cancel", crap, 1, keyboard: Keyboard.Numeric, crap);
                        //CheckIfOK(TextToPrint);
                        if (TextToPrint == "1")
                        {
                            savesettingsU();
                            Thread.SpinWait(50);
                        }
                        if (TextToPrint == "2")
                        {
                            savesettingsU();
                            Thread.SpinWait(50);
                        }

                        conn();
                        flagg       = "!!";
                        TextToPrint = "0";
                        PrintText();
                    });
                }
                if (action == "Tank Size")
                {
                    TriggerSettings();
                    string crap = Convert.ToString(Stanksize);
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        TextToPrint = await App.Current.MainPage.DisplayPromptAsync("Tank Size", "Tank size *1000 (50L = 50,000)", "Save", "Cancel", crap, 8, keyboard: Keyboard.Numeric, crap);
                        //CheckIfOK(TextToPrint);
                        if (TextToPrint != null)
                        {
                            savesettingsV();
                            Thread.SpinWait(50);
                        }

                        conn();
                        flagg       = "!!";
                        TextToPrint = "0";
                        PrintText();
                    });
                }
                if (action == "Inj Delay")
                {
                    TriggerSettings();
                    string crap = Convert.ToString(Sinjsettle);
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        TextToPrint = await App.Current.MainPage.DisplayPromptAsync("Inj delay", "Micro second delay of Inj pulse signal for smothing", "Save", "Cancel", crap, 8, keyboard: Keyboard.Numeric, crap);
                        //CheckIfOK(TextToPrint);
                        if (TextToPrint != null)
                        {
                            savesettingsW();
                            Thread.SpinWait(50);
                        }

                        conn();
                        flagg       = "!!";
                        TextToPrint = "0";
                        PrintText();
                    });
                }
                if (action == "VSS Delay")
                {
                    TriggerSettings();
                    string crap = Convert.ToString(Svsspause);
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        TextToPrint = await App.Current.MainPage.DisplayPromptAsync("VSS Delay", "For smothing VSS signal", "Save", "Cancel", crap, 8, keyboard: Keyboard.Numeric, crap);
                        //CheckIfOK(TextToPrint);
                        if (TextToPrint != null)
                        {
                            savesettingsX();
                            Thread.SpinWait(50);
                        }

                        conn();
                        flagg       = "!!";
                        TextToPrint = "0";
                        PrintText();
                    });
                }
                if (action == "Inj Type")
                {
                    TriggerSettings();
                    string crap = Convert.ToString(SinjEdge);
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        TextToPrint = await App.Current.MainPage.DisplayPromptAsync("Injector Type", "0 Normal, 1 Inverse, 2 Peak and Hold", "Save", "Cancel", crap, 1, keyboard: Keyboard.Numeric, crap);
                        //CheckIfOK(TextToPrint);
                        if (TextToPrint == "0")
                        {
                            savesettingsY();
                            Thread.SpinWait(50);
                        }
                        if (TextToPrint == "1")
                        {
                            savesettingsY();
                            Thread.SpinWait(50);
                        }
                        if (TextToPrint == "2")
                        {
                            savesettingsY();
                            Thread.SpinWait(50);
                        }

                        conn();
                        flagg       = "!!";
                        TextToPrint = "0";
                        PrintText();
                    });
                }
                if (action == "Volt Offset")
                {
                    TriggerSettings();
                    string crap = Convert.ToString(Svolt);
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        TextToPrint = await App.Current.MainPage.DisplayPromptAsync("Volt Offset", "Adjust this figure for Voltage accuracy", "Save", "Cancel", crap, 5, keyboard: Keyboard.Numeric, crap);
                        //CheckIfOK(TextToPrint);
                        if (TextToPrint != null)
                        {
                            savesettingsZ();
                            Thread.SpinWait(50);
                        }

                        conn();
                        flagg       = "!!";
                        TextToPrint = "0";
                        PrintText();
                    });
                }
            });
        }