Skip to content

Commit c66e018

Browse files
authored
Improve output during backup/flash process (#281)
1 parent 6f50e27 commit c66e018

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

nanoFirmwareFlasher.Library/Esp32Operations.cs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
484484
if (verbosity >= VerbosityLevel.Normal)
485485
{
486486
Console.ForegroundColor = ConsoleColor.Green;
487-
Console.WriteLine("OK");
487+
Console.WriteLine("OK".PadRight(110));
488488
}
489489
else
490490
{
@@ -495,13 +495,6 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
495495

496496
if (operationResult == ExitCodes.OK)
497497
{
498-
Console.ForegroundColor = ConsoleColor.White;
499-
500-
if (verbosity >= VerbosityLevel.Normal)
501-
{
502-
Console.Write($"Flashing firmware...");
503-
}
504-
505498
int configPartitionAddress = 0;
506499
int configPartitionSize = 0;
507500
string configPartitionBackup = Path.GetRandomFileName();
@@ -512,9 +505,13 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
512505
// check if the update file includes a partition table
513506
if (File.Exists(Path.Combine(firmware.LocationPath, $"partitions_nanoclr_{Esp32DeviceInfo.GetFlashSizeAsString(esp32Device.FlashSize).ToLowerInvariant()}.csv")))
514507
{
515-
// can't do this without a partition table
516-
508+
if (verbosity >= VerbosityLevel.Normal)
509+
{
510+
Console.ForegroundColor = ConsoleColor.White;
511+
Console.Write($"Backup configuration...");
512+
}
517513

514+
// can't do this without a partition table
518515
// compose path to partition file
519516
string partitionCsvFile = Path.Combine(firmware.LocationPath, $"partitions_nanoclr_{Esp32DeviceInfo.GetFlashSizeAsString(esp32Device.FlashSize).ToLowerInvariant()}.csv");
520517

@@ -538,18 +535,46 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
538535
configPartitionBackup,
539536
configPartitionAddress,
540537
configPartitionSize);
541-
538+
539+
if (verbosity >= VerbosityLevel.Normal)
540+
{
541+
Console.ForegroundColor = ConsoleColor.White;
542+
Console.Write($"Backup configuration...");
543+
Console.ForegroundColor = ConsoleColor.Green;
544+
Console.WriteLine("OK".PadRight(110));
545+
}
546+
542547
firmware.FlashPartitions.Add(configPartitionAddress, configPartitionBackup);
543548
}
544549
}
545550

551+
Console.ForegroundColor = ConsoleColor.White;
552+
553+
if (verbosity < VerbosityLevel.Normal)
554+
{
555+
// output the start of operation message for verbosity lower than normal
556+
// otherwise the progress from esptool is shown
557+
Console.ForegroundColor = ConsoleColor.White;
558+
Console.Write($"Flashing firmware...");
559+
}
560+
546561
// write to flash
547562
operationResult = espTool.WriteFlash(firmware.FlashPartitions);
548563

549564
if (operationResult == ExitCodes.OK)
550565
{
566+
if (verbosity < VerbosityLevel.Normal)
567+
{
568+
// operation completed output
569+
Console.ForegroundColor = ConsoleColor.Green;
570+
Console.WriteLine("OK".PadRight(110));
571+
}
572+
551573
if (verbosity >= VerbosityLevel.Normal)
552574
{
575+
// output the full message as usual after the progress from esptool
576+
Console.ForegroundColor = ConsoleColor.White;
577+
Console.Write($"Flashing firmware...");
553578
Console.ForegroundColor = ConsoleColor.Green;
554579
Console.WriteLine("OK".PadRight(110));
555580

nanoFirmwareFlasher.Library/EspTool.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public Esp32DeviceInfo GetDeviceDetails(
263263
if (Verbosity >= VerbosityLevel.Normal)
264264
{
265265
Console.ForegroundColor = ConsoleColor.Green;
266-
Console.WriteLine("OK");
266+
Console.WriteLine("OK".PadRight(110));
267267
Console.ForegroundColor = ConsoleColor.White;
268268
}
269269

@@ -474,7 +474,7 @@ internal ExitCodes BackupConfigPartition(
474474
false,
475475
true,
476476
false,
477-
null,
477+
(char)8,
478478
out string messages))
479479
{
480480
throw new ReadEsp32FlashException(messages);
@@ -745,7 +745,7 @@ private bool RunEspTool(
745745

746746
// try to find a progress message
747747
string progress = FindProgress(messageBuilder, progressTestChar.Value);
748-
if (progress != null && Verbosity >= VerbosityLevel.Detailed)
748+
if (progress != null && Verbosity >= VerbosityLevel.Normal)
749749
{
750750
if (!progressStarted)
751751
{
@@ -764,7 +764,7 @@ private bool RunEspTool(
764764
}
765765
else
766766
{
767-
if (Verbosity >= VerbosityLevel.Detailed)
767+
if (Verbosity >= VerbosityLevel.Normal)
768768
{
769769
// need to clear all progress lines
770770
for (int i = 0; i < messageBuilder.Length; i++)

0 commit comments

Comments
 (0)