Ejemplo n.º 1
0
        public ThermoFOTAViewer(IDevice ADevice, IReadOnlyList <IService> services)
        {
            BleDevice = ADevice;
            if (BleDevice == null)
            {
                return;
            }

            driver             = new BleDriver(GUID_SERVICE, GUID_CHAR_OTA_VER, GUID_CHAR_OTA_CTRL, GUID_CHAR_OTA_DATA);
            ota                = new OTA(FOTA_SERVER, driver);
            ota.StatusChanged += Ota_StatusChanged;
            ota.Progress      += Ota_Progress;

            InitUI();

            var tapGestureRecognizer = new TapGestureRecognizer();

            tapGestureRecognizer.NumberOfTapsRequired = 1;
            tapGestureRecognizer.Tapped += Summary_Tapped;

            Summary.GestureRecognizers.Add(tapGestureRecognizer);
            Summary_Tapped(null, null);
            Action.Clicked += Action_Clicked;

            driver.Init(ADevice, services);
            ota.CheckUpdate();
        }
Ejemplo n.º 2
0
        private async void Action_Clicked(object sender, EventArgs e)
        {
            switch (ota.Status)
            {
            case OTA.OTAStatus.ServerError:
            case OTA.OTAStatus.UpToDate:
                ota.updateURL = urlInput.Text;
                await ota.CheckUpdate();

                break;

            case OTA.OTAStatus.UpdateAvailable:
                Wait = new WaitActivity();
                DeviceDisplay.KeepScreenOn = true;
                bool r = false;
                await Navigation.PushModalAsync(Wait);

                try
                {
                    BleDevice.UpdateConnectionInterval(ConnectionInterval.High);
                    int MtuSize = await BleDevice.RequestMtuAsync(250);

                    r = await ota.Update(Math.Max(23, MtuSize - 4));
                }
                finally
                {
                    await Navigation.PopModalAsync();

                    DeviceDisplay.KeepScreenOn = false;
                }

                if (r)
                {
                    var adapter = CrossBluetoothLE.Current.Adapter;

                    //adapter.DeviceConnectionLost
                    //adapter.DeviceDisconnected -= Adapter_DeviceDisconnected;

                    await adapter.DisconnectDeviceAsync(BleDevice);
                    await DisplayAlert("Congratulations!", "FOTA successfully completed", "OK");

                    await Navigation.PopAsync();
                }
                break;

            default:
                break;
            }
        }