Example #1
0
        async void ReadData()
        {
            bool error = false;

            try
            {
                Wait = new WaitActivity();
                await Navigation.PushModalAsync(Wait);
                await Connect();
            }
            catch (Exception e)
            {
                await DisplayAlert("Alert", e.Message, "OK");

                error = true;
                return;
            }
            finally
            {
                await Navigation.PopModalAsync();
            }

            if (error)
            {
                await Navigation.PopAsync();

                return;
            }
        }
Example #2
0
        async private void Upload_Pressed(object sender, EventArgs e)
        {
            if (imageProcessed == null)
            {
                await DisplayAlert("Warning", "Please take a phone firstly.", "OK");

                return;
            }
            byte[] buffer = DumpImageBitData(imageProcessed);
            if (buffer.Length != IMAGE_HEIGHT * IMAGE_WIDTH / 8 * 2)
            {
                throw new Exception("internal error");
            }
            TotalSize = buffer.Length;

            Wait = new WaitActivity();
            DeviceDisplay.KeepScreenOn = true;
            bool r = false;
            await Navigation.PushModalAsync(Wait);

            try
            {
                BleDevice.UpdateConnectionInterval(ConnectionInterval.High);
                int MtuSize = Math.Max(Utils.BLE_MIN_MTU_SIZE, await BleDevice.RequestMtuAsync(80) - 4);
                r = await Upload(buffer, MtuSize, OnProgress);

                if (!r && (MtuSize > Utils.BLE_MIN_MTU_SIZE))
                {
                    Wait.Message = "Your device's BLE subsystem seems broken, retry...";
                    r            = await Upload(buffer, Utils.BLE_MIN_MTU_SIZE, OnProgress);
                }
            }
            finally
            {
                await Navigation.PopModalAsync();

                DeviceDisplay.KeepScreenOn = false;
                Wait = null;
            }

            if (!r)
            {
                await DisplayAlert("Warning", "Upload failed.", "OK");
            }
            else
            {
                await NotifyWaitMsg();
            }
        }