Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
benlye committed Sep 27, 2019
1 parent 71edb5c commit e187c3d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
46 changes: 23 additions & 23 deletions src/flash-multi/FlashMulti.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ namespace Flash_Multi
public partial class FlashMulti : Form
{
/// <summary>
/// Buffer for verbose output logging.
/// The number of steps required for a flash.
/// </summary>
private string outputLineBuffer = string.Empty;
internal int FlashSteps = 0;

/// <summary>
/// Keep track of the current avrdude activity.
/// The current flash step.
/// </summary>
private string avrdudeActivity = string.Empty;
internal int FlashStep = 1;

/// <summary>
/// The number of steps required for an avrdude flash.
/// Buffer for verbose output logging.
/// </summary>
internal int AvrdudeSteps = 0;
private string outputLineBuffer = string.Empty;

/// <summary>
/// The current avrdude flash step.
/// Keep track of the current avrdude activity.
/// </summary>
internal int AvrdudeFlashStep = 1;
private string avrdudeActivity = string.Empty;

/// <summary>
/// Initializes a new instance of the <see cref="FlashMulti"/> class.
Expand Down Expand Up @@ -208,48 +208,48 @@ public void CharOutputHandler(char data)
// Handle progress from avrdude
if (this.outputLineBuffer == "avrdude.exe: erasing chip")
{
this.AppendLog($"[{this.AvrdudeFlashStep}/{this.AvrdudeSteps}] Erasing flash ... ");
this.AppendLog($"[{this.FlashStep}/{this.FlashSteps}] Erasing flash ... ");
this.avrdudeActivity = "erasing";
this.AvrdudeFlashStep++;
this.FlashStep++;
}

if (this.outputLineBuffer == "avrdude.exe: writing lock (1 bytes):" && this.avrdudeActivity == "erasing")
{
this.AppendLog($"done\r\n[{this.AvrdudeFlashStep}/{this.AvrdudeSteps}] Setting fuses ... ");
this.AppendLog($"done\r\n[{this.FlashStep}/{this.FlashSteps}] Setting fuses ... ");
this.avrdudeActivity = "fuses";
this.AvrdudeFlashStep++;
this.FlashStep++;
}

if (this.outputLineBuffer.StartsWith("avrdude.exe: writing flash ") && this.outputLineBuffer.EndsWith("):"))
{
if (this.avrdudeActivity == "writebootloader" && this.AvrdudeSteps == 5)
if (this.avrdudeActivity == "writebootloader" && this.FlashSteps == 5)
{
// Writing firmware after bootloader
this.AppendLog($"done\r\n[{this.AvrdudeFlashStep}/{this.AvrdudeSteps}] Writing firmware ... ");
this.AppendLog($"done\r\n[{this.FlashStep}/{this.FlashSteps}] Writing firmware ... ");
this.avrdudeActivity = "writefirmware";
this.AvrdudeFlashStep++;
this.FlashStep++;
}
else if (this.avrdudeActivity == "fuses" && this.AvrdudeSteps == 4)
else if (this.avrdudeActivity == "fuses" && this.FlashSteps == 4)
{
// Writing firmware after fuses
this.AppendLog($"done\r\n[{this.AvrdudeFlashStep}/{this.AvrdudeSteps}] Writing flash ... ");
this.AppendLog($"done\r\n[{this.FlashStep}/{this.FlashSteps}] Writing flash ... ");
this.avrdudeActivity = "writefirmware";
this.AvrdudeFlashStep++;
this.FlashStep++;
}
else if (this.avrdudeActivity == "fuses" && this.AvrdudeSteps == 5)
else if (this.avrdudeActivity == "fuses" && this.FlashSteps == 5)
{
// Writing bootloader after fuses
this.AppendLog($"done\r\n[{this.AvrdudeFlashStep}/{this.AvrdudeSteps}] Writing bootloader ... ");
this.AppendLog($"done\r\n[{this.FlashStep}/{this.FlashSteps}] Writing bootloader ... ");
this.avrdudeActivity = "writebootloader";
this.AvrdudeFlashStep++;
this.FlashStep++;
}
}

if (this.outputLineBuffer == "avrdude.exe: reading on-chip flash data:" && this.avrdudeActivity == "writefirmware")
{
this.avrdudeActivity = "verifyfirmware";
this.AppendLog($"done\r\n[{this.AvrdudeFlashStep}/{this.AvrdudeSteps}] Verifying flash ...");
this.AvrdudeFlashStep++;
this.AppendLog($"done\r\n[{this.FlashStep}/{this.FlashSteps}] Verifying flash ...");
this.FlashStep++;
}

if (this.outputLineBuffer == "avrdude.exe done. Thank you." && this.avrdudeActivity == "verifyfirmware")
Expand Down
1 change: 0 additions & 1 deletion src/flash-multi/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public static int Run(FlashMulti flashMulti, string command, string args)
}
}


// Loop until the process finishes
myProcess.WaitForExit();

Expand Down
6 changes: 3 additions & 3 deletions src/flash-multi/UsbAspDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ public static async Task WriteFlash(FlashMulti flashMulti, string fileName, bool
int returnCode = -1;

// First step in flash process
flashMulti.AvrdudeFlashStep = 1;
flashMulti.FlashStep = 1;

// Total number of steps in flash process
flashMulti.AvrdudeSteps = 4;
flashMulti.FlashSteps = 4;

// Fuses
string unlockBits = "0x3F";
Expand All @@ -110,7 +110,7 @@ public static async Task WriteFlash(FlashMulti flashMulti, string fileName, bool
if (writeBootloader)
{
// Increase the total number of steps
flashMulti.AvrdudeSteps = 5;
flashMulti.FlashSteps = 5;

// Set the high fuses
highFuses = "0xD6";
Expand Down

0 comments on commit e187c3d

Please sign in to comment.