Esempio n. 1
0
        /// <summary>
        /// Prompts the user to unplug / replug the module to get it into recovery mode.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments.</param>
        private async void DfuRecoveryDialog_Shown(object sender, EventArgs e)
        {
            bool dfuCheck = MapleDevice.FindMaple().DfuMode;

            if (dfuCheck)
            {
                this.flashMulti.AppendLog("Waiting up to 30s for DFU device to disappear ...");

                // Wait 30s for the DFU device to disappear
                await Task.Run(() => { dfuCheck = MapleDevice.WaitForDFU(30000, true); });

                if (dfuCheck)
                {
                    // The module was unplugged
                    this.flashMulti.AppendLog(" gone.\r\n");
                }
                else
                {
                    // The module wasn't unplugged when the timer expired.
                    this.flashMulti.AppendLog(" timed out!\r\n");
                    MessageBox.Show("DFU device was not unplugged in time.", "Firmware Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.DialogResult = DialogResult.Cancel;
                    this.Close();
                    return;
                }
            }

            this.flashMulti.AppendLog("Waiting up to 30s for DFU device to appear ...");

            // Reset the progress bar
            this.timerProgressBar.Value = 0;

            // Wait for the DFU device to appear
            await Task.Run(() => { dfuCheck = MapleDevice.WaitForDFU(30000); });

            if (dfuCheck)
            {
                // The module was plugged in
                this.flashMulti.AppendLog(" got it.\r\n");
                this.DialogResult = DialogResult.OK;
                this.Close();
                return;
            }
            else
            {
                // The module wasn't plugged in when the timer expired
                this.flashMulti.AppendLog(" timed out!\r\n");
                MessageBox.Show("DFU device was not plugged in in time.", "Firmware Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.DialogResult = DialogResult.Cancel;
                this.Close();
                return;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Prompts the user to unplug / replug the module to get it into recovery mode.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments.</param>
        private async void DfuRecoveryDialog_Shown(object sender, EventArgs e)
        {
            // Check if we have a DFU device we need to see unplugged
            bool dfuCheck = MapleDevice.FindMaple().DfuMode;

            if (dfuCheck)
            {
                this.flashMulti.AppendLog("Waiting for DFU device to disappear ...");

                // Wait 30s for the DFU device to disappear and reappear
                await Task.Run(() => { dfuCheck = MapleDevice.WaitForDFU(30000, true); });

                // Handle user cancelling DFU recovery
                if (this.DialogResult == DialogResult.Cancel)
                {
                    return;
                }

                if (dfuCheck)
                {
                    // Wait 30s for the DFU device to disappear
                    await Task.Run(() => { dfuCheck = MapleDevice.WaitForDFU(30000, true); });

                    if (dfuCheck)
                    {
                        // The module was unplugged
                        this.flashMulti.AppendLog(" gone.\r\n");
                    }
                    else
                    {
                        // The module wasn't unplugged when the timer expired.
                        this.flashMulti.AppendLog(" timed out!\r\n");
                        using (new CenterWinDialog(this.flashMulti))
                        {
                            MessageBox.Show("DFU device was not unplugged in time.", "Firmware Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        this.DialogResult = DialogResult.Cancel;
                        this.Close();
                        return;
                    }
                }
            }

            this.flashMulti.AppendLog("Waiting for DFU device to appear ...");

            // Wait for the DFU device to appear
            await Task.Run(() => { dfuCheck = MapleDevice.WaitForDFU(30000 - (this.timerProgressBar.Value * 1000)); });

            // Handle user cancelling DFU recovery
            if (this.DialogResult == DialogResult.Cancel)
            {
                return;
            }

            if (dfuCheck)
            {
                // The module was plugged in
                this.flashMulti.AppendLog(" got it.\r\n");
                this.DialogResult = DialogResult.OK;
                this.Close();
                return;
            }
            else
            {
                // The module wasn't plugged in when the timer expired
                this.flashMulti.AppendLog(" timed out!\r\n");
                using (new CenterWinDialog(this))
                {
                    MessageBox.Show("DFU device was not plugged in in time.", "Firmware Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                this.DialogResult = DialogResult.Abort;
                this.Close();
                return;
            }
        }