Skip to content

Commit

Permalink
Use DFU recovery if maple-reset fails
Browse files Browse the repository at this point in the history
  • Loading branch information
benlye committed Jul 15, 2019
1 parent cb6990a commit 600e6e9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
36 changes: 20 additions & 16 deletions src/flash-multi/DfuRecoveryDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,29 @@ public DfuRecoveryDialog(FlashMulti flashMulti)
/// <param name="e">Event arguments.</param>
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 ...");
Expand Down
19 changes: 15 additions & 4 deletions src/flash-multi/MapleDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand All @@ -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
Expand Down

0 comments on commit 600e6e9

Please sign in to comment.