diff --git a/src/flash-multi/DfuRecoveryDialog.cs b/src/flash-multi/DfuRecoveryDialog.cs index 826a47a..350ac6d 100644 --- a/src/flash-multi/DfuRecoveryDialog.cs +++ b/src/flash-multi/DfuRecoveryDialog.cs @@ -51,25 +51,29 @@ public DfuRecoveryDialog(FlashMulti flashMulti) /// Event arguments. private async void DfuRecoveryDialog_Shown(object sender, EventArgs e) { - this.flashMulti.AppendLog("Waiting up to 30s for DFU device to disappear ..."); - - // Wait 30s for the DFU device to disappear - bool dfuCheck = false; - await Task.Run(() => { dfuCheck = MapleDevice.WaitForDFU(30000, true); }); + bool dfuCheck = MapleDevice.FindMaple().DfuMode; 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 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 ..."); diff --git a/src/flash-multi/MapleDevice.cs b/src/flash-multi/MapleDevice.cs index 2508db3..a1a30da 100644 --- a/src/flash-multi/MapleDevice.cs +++ b/src/flash-multi/MapleDevice.cs @@ -177,10 +177,20 @@ public static async void WriteFlash(FlashMulti flashMulti, string fileName, stri } else { - flashMulti.AppendLog(" failed!"); - MessageBox.Show("Failed to find module in DFU mode.", "Firmware Update", MessageBoxButtons.OK, MessageBoxIcon.Error); - flashMulti.EnableControls(true); - return; + flashMulti.AppendLog(" failed!\r\n"); + flashMulti.AppendLog("Attempting DFU Recovery Mode.\r\n"); + + // Show the recovery mode dialog + DfuRecoveryDialog recoveryDialog = new DfuRecoveryDialog(flashMulti); + var recoveryResult = recoveryDialog.ShowDialog(); + + // Error out if we didn't made it into recovery mode + if (recoveryResult != DialogResult.OK) + { + flashMulti.AppendLog("DFU Recovery Mode failed."); + flashMulti.EnableControls(true); + return; + } } } @@ -190,6 +200,7 @@ public static async void WriteFlash(FlashMulti flashMulti, string fileName, stri commandArgs = string.Format("-R -a 2 -d 1EAF:0003 -D \"{0}\"", fileName, comPort); await Task.Run(() => { returnCode = RunCommand.Run(flashMulti, command, commandArgs); }); + if (returnCode != 0) { // First attempt failed so we need to try bootloader recovery