From 99fa437b6ab61d0c043c47e6cc80906781548ba1 Mon Sep 17 00:00:00 2001 From: Cory Charlton Date: Wed, 19 Jun 2024 13:25:58 -0700 Subject: [PATCH 1/4] Improve output during backup/flash process --- .../Esp32Operations.cs | 20 +++++++++++-------- nanoFirmwareFlasher.Library/EspTool.cs | 8 ++++---- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/nanoFirmwareFlasher.Library/Esp32Operations.cs b/nanoFirmwareFlasher.Library/Esp32Operations.cs index 2aeb693e..919ba145 100644 --- a/nanoFirmwareFlasher.Library/Esp32Operations.cs +++ b/nanoFirmwareFlasher.Library/Esp32Operations.cs @@ -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(); @@ -513,7 +506,11 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( 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..."); + } // compose path to partition file string partitionCsvFile = Path.Combine(firmware.LocationPath, $"partitions_nanoclr_{Esp32DeviceInfo.GetFlashSizeAsString(esp32Device.FlashSize).ToLowerInvariant()}.csv"); @@ -543,6 +540,13 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( } } + Console.ForegroundColor = ConsoleColor.White; + + if (verbosity >= VerbosityLevel.Normal) + { + Console.Write($"Flashing firmware..."); + } + // write to flash operationResult = espTool.WriteFlash(firmware.FlashPartitions); diff --git a/nanoFirmwareFlasher.Library/EspTool.cs b/nanoFirmwareFlasher.Library/EspTool.cs index c9b2f6a4..9f6d5c50 100644 --- a/nanoFirmwareFlasher.Library/EspTool.cs +++ b/nanoFirmwareFlasher.Library/EspTool.cs @@ -474,7 +474,7 @@ internal ExitCodes BackupConfigPartition( false, true, false, - null, + (char)8, out string messages)) { throw new ReadEsp32FlashException(messages); @@ -745,12 +745,12 @@ 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) { // need to print the first line of the progress message - Console.Write("\r"); + Console.WriteLine(); progressStarted = true; } @@ -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++) From dd7153a3d8aa8c7f861522c54abdfb5dd0f661a8 Mon Sep 17 00:00:00 2001 From: Cory Charlton Date: Wed, 19 Jun 2024 13:25:58 -0700 Subject: [PATCH 2/4] Improve output during backup/flash process --- .../Esp32Operations.cs | 20 +++++++++++-------- nanoFirmwareFlasher.Library/EspTool.cs | 8 ++++---- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/nanoFirmwareFlasher.Library/Esp32Operations.cs b/nanoFirmwareFlasher.Library/Esp32Operations.cs index 2aeb693e..919ba145 100644 --- a/nanoFirmwareFlasher.Library/Esp32Operations.cs +++ b/nanoFirmwareFlasher.Library/Esp32Operations.cs @@ -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(); @@ -513,7 +506,11 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( 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..."); + } // compose path to partition file string partitionCsvFile = Path.Combine(firmware.LocationPath, $"partitions_nanoclr_{Esp32DeviceInfo.GetFlashSizeAsString(esp32Device.FlashSize).ToLowerInvariant()}.csv"); @@ -543,6 +540,13 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( } } + Console.ForegroundColor = ConsoleColor.White; + + if (verbosity >= VerbosityLevel.Normal) + { + Console.Write($"Flashing firmware..."); + } + // write to flash operationResult = espTool.WriteFlash(firmware.FlashPartitions); diff --git a/nanoFirmwareFlasher.Library/EspTool.cs b/nanoFirmwareFlasher.Library/EspTool.cs index c9b2f6a4..9f6d5c50 100644 --- a/nanoFirmwareFlasher.Library/EspTool.cs +++ b/nanoFirmwareFlasher.Library/EspTool.cs @@ -474,7 +474,7 @@ internal ExitCodes BackupConfigPartition( false, true, false, - null, + (char)8, out string messages)) { throw new ReadEsp32FlashException(messages); @@ -745,12 +745,12 @@ 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) { // need to print the first line of the progress message - Console.Write("\r"); + Console.WriteLine(); progressStarted = true; } @@ -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++) From 7bcc43fecfc371873bd263f2c070e3816a495026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Tue, 25 Jun 2024 09:25:52 +0100 Subject: [PATCH 3/4] Tweaking progress output --- .../Esp32Operations.cs | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/nanoFirmwareFlasher.Library/Esp32Operations.cs b/nanoFirmwareFlasher.Library/Esp32Operations.cs index 919ba145..2a870e3f 100644 --- a/nanoFirmwareFlasher.Library/Esp32Operations.cs +++ b/nanoFirmwareFlasher.Library/Esp32Operations.cs @@ -505,13 +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"); @@ -535,15 +535,24 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( configPartitionBackup, configPartitionAddress, configPartitionSize); - + + if (verbosity >= VerbosityLevel.Normal) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("OK"); + } + firmware.FlashPartitions.Add(configPartitionAddress, configPartitionBackup); } } Console.ForegroundColor = ConsoleColor.White; - if (verbosity >= VerbosityLevel.Normal) + 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..."); } @@ -552,8 +561,18 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( 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)); @@ -698,7 +717,7 @@ public static async System.Threading.Tasks.Task DeployApplicationAsyn if (verbosity >= VerbosityLevel.Normal) { Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine("OK".PadRight(110)); + Console.WriteLine(.PadRight(110)); // warn user if reboot is not possible if (espTool.CouldntResetTarget) From a9d8f76d562a8a6bdf9e46fce6645f8447f3ac1c Mon Sep 17 00:00:00 2001 From: Cory Charlton Date: Tue, 25 Jun 2024 14:03:21 -0700 Subject: [PATCH 4/4] Further refinement of the output --- nanoFirmwareFlasher.Library/Esp32Operations.cs | 8 +++++--- nanoFirmwareFlasher.Library/EspTool.cs | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/nanoFirmwareFlasher.Library/Esp32Operations.cs b/nanoFirmwareFlasher.Library/Esp32Operations.cs index 2a870e3f..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 { @@ -538,8 +538,10 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( if (verbosity >= VerbosityLevel.Normal) { + Console.ForegroundColor = ConsoleColor.White; + Console.Write($"Backup configuration..."); Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine("OK"); + Console.WriteLine("OK".PadRight(110)); } firmware.FlashPartitions.Add(configPartitionAddress, configPartitionBackup); @@ -717,7 +719,7 @@ public static async System.Threading.Tasks.Task DeployApplicationAsyn if (verbosity >= VerbosityLevel.Normal) { Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine(.PadRight(110)); + Console.WriteLine("OK".PadRight(110)); // warn user if reboot is not possible if (espTool.CouldntResetTarget) diff --git a/nanoFirmwareFlasher.Library/EspTool.cs b/nanoFirmwareFlasher.Library/EspTool.cs index 9f6d5c50..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; } @@ -750,7 +750,7 @@ private bool RunEspTool( if (!progressStarted) { // need to print the first line of the progress message - Console.WriteLine(); + Console.Write("\r"); progressStarted = true; }