From c66e018c48efd0c0a0e2fba93c9f3de2f2bdc13f Mon Sep 17 00:00:00 2001 From: Cory Charlton Date: Wed, 26 Jun 2024 02:53:49 -0700 Subject: [PATCH] Improve output during backup/flash process (#281) --- .../Esp32Operations.cs | 47 ++++++++++++++----- nanoFirmwareFlasher.Library/EspTool.cs | 8 ++-- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/nanoFirmwareFlasher.Library/Esp32Operations.cs b/nanoFirmwareFlasher.Library/Esp32Operations.cs index 2aeb693e..cca27c95 100644 --- a/nanoFirmwareFlasher.Library/Esp32Operations.cs +++ b/nanoFirmwareFlasher.Library/Esp32Operations.cs @@ -484,7 +484,7 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( if (verbosity >= VerbosityLevel.Normal) { Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine("OK"); + Console.WriteLine("OK".PadRight(110)); } else { @@ -495,13 +495,6 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( if (operationResult == ExitCodes.OK) { - Console.ForegroundColor = ConsoleColor.White; - - if (verbosity >= VerbosityLevel.Normal) - { - Console.Write($"Flashing firmware..."); - } - int configPartitionAddress = 0; int configPartitionSize = 0; string configPartitionBackup = Path.GetRandomFileName(); @@ -512,9 +505,13 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( // check if the update file includes a partition table if (File.Exists(Path.Combine(firmware.LocationPath, $"partitions_nanoclr_{Esp32DeviceInfo.GetFlashSizeAsString(esp32Device.FlashSize).ToLowerInvariant()}.csv"))) { - // can't do this without a partition table - + if (verbosity >= VerbosityLevel.Normal) + { + Console.ForegroundColor = ConsoleColor.White; + Console.Write($"Backup configuration..."); + } + // can't do this without a partition table // compose path to partition file string partitionCsvFile = Path.Combine(firmware.LocationPath, $"partitions_nanoclr_{Esp32DeviceInfo.GetFlashSizeAsString(esp32Device.FlashSize).ToLowerInvariant()}.csv"); @@ -538,18 +535,46 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( configPartitionBackup, configPartitionAddress, configPartitionSize); - + + if (verbosity >= VerbosityLevel.Normal) + { + Console.ForegroundColor = ConsoleColor.White; + Console.Write($"Backup configuration..."); + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("OK".PadRight(110)); + } + firmware.FlashPartitions.Add(configPartitionAddress, configPartitionBackup); } } + Console.ForegroundColor = ConsoleColor.White; + + if (verbosity < VerbosityLevel.Normal) + { + // output the start of operation message for verbosity lower than normal + // otherwise the progress from esptool is shown + Console.ForegroundColor = ConsoleColor.White; + Console.Write($"Flashing firmware..."); + } + // write to flash operationResult = espTool.WriteFlash(firmware.FlashPartitions); if (operationResult == ExitCodes.OK) { + if (verbosity < VerbosityLevel.Normal) + { + // operation completed output + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("OK".PadRight(110)); + } + if (verbosity >= VerbosityLevel.Normal) { + // output the full message as usual after the progress from esptool + Console.ForegroundColor = ConsoleColor.White; + Console.Write($"Flashing firmware..."); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("OK".PadRight(110)); diff --git a/nanoFirmwareFlasher.Library/EspTool.cs b/nanoFirmwareFlasher.Library/EspTool.cs index c9b2f6a4..e7d629fa 100644 --- a/nanoFirmwareFlasher.Library/EspTool.cs +++ b/nanoFirmwareFlasher.Library/EspTool.cs @@ -263,7 +263,7 @@ public Esp32DeviceInfo GetDeviceDetails( if (Verbosity >= VerbosityLevel.Normal) { Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine("OK"); + Console.WriteLine("OK".PadRight(110)); Console.ForegroundColor = ConsoleColor.White; } @@ -474,7 +474,7 @@ internal ExitCodes BackupConfigPartition( false, true, false, - null, + (char)8, out string messages)) { throw new ReadEsp32FlashException(messages); @@ -745,7 +745,7 @@ private bool RunEspTool( // try to find a progress message string progress = FindProgress(messageBuilder, progressTestChar.Value); - if (progress != null && Verbosity >= VerbosityLevel.Detailed) + if (progress != null && Verbosity >= VerbosityLevel.Normal) { if (!progressStarted) { @@ -764,7 +764,7 @@ private bool RunEspTool( } else { - if (Verbosity >= VerbosityLevel.Detailed) + if (Verbosity >= VerbosityLevel.Normal) { // need to clear all progress lines for (int i = 0; i < messageBuilder.Length; i++)