Example #1
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;
            }
        }