From 407b8439e4288960f66f18b81fd3cf71a4731343 Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Mon, 20 Oct 2025 19:29:33 +0200 Subject: [PATCH 1/8] Add Save and Erase button for onboard logging --- locales/en/messages.json | 4 ++++ src/js/tabs/onboard_logging.js | 21 ++++++++++++++++++++- src/tabs/onboard_logging.html | 2 ++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/locales/en/messages.json b/locales/en/messages.json index 03e3271bab..0aa32d213e 100755 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -3558,6 +3558,10 @@ "dataflashSaveFileDepreciationHint": { "message": "This method is slow and inherently prone to error / file corruption, because the MSP connection itself has intrinsic, fundamental limitations that make it unsuitable for file transfers. It may work for small log files only. Do not create support requests if file transfers fail when saved using this method. The recommended method is to use '$t(onboardLoggingRebootMscText.message)' (below) to activate the Mass Storage Mode, and access your flight controller as a storage device to download the log files." }, + "dataflashButtonSaveAndErase": { + "message": "Save & Erase", + "description": "Button text to save blackbox logs to file and then erase the flash" + }, "dataflashButtonErase": { "message": "Erase flash" }, diff --git a/src/js/tabs/onboard_logging.js b/src/js/tabs/onboard_logging.js index 0461344ce6..ea4832d5a1 100644 --- a/src/js/tabs/onboard_logging.js +++ b/src/js/tabs/onboard_logging.js @@ -478,7 +478,19 @@ onboard_logging.initialize = function (callback) { }); } - function flash_save_begin() { + function conditionallyEraseFlash(maxBytes, nextAddress) { + if (!isNaN(maxBytes) && nextAddress >= maxBytes) { + $(".dataflash-confirm-erase").addClass("erasing"); + MSP.send_message(MSPCodes.MSP_DATAFLASH_ERASE, false, false, poll_for_erase_completion); + } else { + gui_log( + i18n.getMessage("dataflashSaveIncompleteWarning") || + "Downloaded size did not match expected size - not erasing flash.", + ); + } + } + + function flash_save_begin(alsoErase = false) { if (GUI.connected_to) { self.blockSize = self.BLOCK_SIZE; @@ -515,6 +527,10 @@ onboard_logging.initialize = function (callback) { mark_saving_dialog_done(startTime, nextAddress, totalBytesCompressed); } FileSystem.closeFile(openedFile); + // Optionally erase after successful full download + if (!saveCancelled && alsoErase) { + conditionallyEraseFlash(maxBytes, nextAddress); + } } else { if (!self.writeError) { mspHelper.dataflashRead(nextAddress, self.blockSize, onChunkRead); @@ -528,6 +544,9 @@ onboard_logging.initialize = function (callback) { // A zero-byte block indicates end-of-file, so we're done mark_saving_dialog_done(startTime, nextAddress, totalBytesCompressed); FileSystem.closeFile(openedFile); + if (alsoErase) { + conditionallyEraseFlash(maxBytes, nextAddress); + } } } else { // There was an error with the received block (address didn't match the one we asked for), retry diff --git a/src/tabs/onboard_logging.html b/src/tabs/onboard_logging.html index e206e1c37a..411c4c80bb 100644 --- a/src/tabs/onboard_logging.html +++ b/src/tabs/onboard_logging.html @@ -110,7 +110,9 @@

+ +

From 4345031332d6f7e7bdd3cac01f98241649ffad8a Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Mon, 20 Oct 2025 19:47:41 +0200 Subject: [PATCH 2/8] Add missing handler --- src/js/tabs/onboard_logging.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/js/tabs/onboard_logging.js b/src/js/tabs/onboard_logging.js index ea4832d5a1..b597fe33ac 100644 --- a/src/js/tabs/onboard_logging.js +++ b/src/js/tabs/onboard_logging.js @@ -103,6 +103,7 @@ onboard_logging.initialize = function (callback) { $(".tab-onboard_logging a.erase-flash-cancel").click(flash_erase_cancel); $(".tab-onboard_logging a.save-flash").click(flash_save_begin); + $(".tab-onboard_logging a.save-flash-erase").click(() => flash_save_begin(true)); $(".tab-onboard_logging a.save-flash-cancel").click(flash_save_cancel); $(".tab-onboard_logging a.save-flash-dismiss").click(dismiss_saving_dialog); } @@ -355,7 +356,7 @@ onboard_logging.initialize = function (callback) { true, ); - $("a.regular-button erase-flash, a.regular-button.require-msc-supported.save-flash").toggleClass( + $("a.regular-button.erase-flash, a.regular-button.require-msc-supported.save-flash").toggleClass( "disabled", FC.DATAFLASH.usedSize === 0, ); From 7f50936f434bef5d7e201c5610c424424148f14c Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Mon, 20 Oct 2025 19:54:19 +0200 Subject: [PATCH 3/8] Update disabled state toggle --- src/js/tabs/onboard_logging.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/js/tabs/onboard_logging.js b/src/js/tabs/onboard_logging.js index b597fe33ac..137595bd2d 100644 --- a/src/js/tabs/onboard_logging.js +++ b/src/js/tabs/onboard_logging.js @@ -356,10 +356,9 @@ onboard_logging.initialize = function (callback) { true, ); - $("a.regular-button.erase-flash, a.regular-button.require-msc-supported.save-flash").toggleClass( - "disabled", - FC.DATAFLASH.usedSize === 0, - ); + $( + "a.regular-button.erase-flash, a.regular-button.save-flash-erase, a.regular-button.require-msc-supported.save-flash", + ).toggleClass("disabled", FC.DATAFLASH.usedSize === 0); $(".tab-onboard_logging") .toggleClass("sdcard-error", FC.SDCARD.state === MSP.SDCARD_STATE_FATAL) From 4841e2bfb16213b17017f75c1dafcf73e8faa2f8 Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Mon, 20 Oct 2025 20:08:13 +0200 Subject: [PATCH 4/8] Nitpicks --- src/js/tabs/onboard_logging.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/js/tabs/onboard_logging.js b/src/js/tabs/onboard_logging.js index 137595bd2d..e7efb91cbe 100644 --- a/src/js/tabs/onboard_logging.js +++ b/src/js/tabs/onboard_logging.js @@ -479,7 +479,8 @@ onboard_logging.initialize = function (callback) { } function conditionallyEraseFlash(maxBytes, nextAddress) { - if (!isNaN(maxBytes) && nextAddress >= maxBytes) { + if (Number.isFinite(maxBytes) && nextAddress >= maxBytes) { + eraseCancelled = false; $(".dataflash-confirm-erase").addClass("erasing"); MSP.send_message(MSPCodes.MSP_DATAFLASH_ERASE, false, false, poll_for_erase_completion); } else { @@ -510,7 +511,7 @@ onboard_logging.initialize = function (callback) { // Did we receive any data? if (chunkDataView.byteLength > 0) { nextAddress += chunkDataView.byteLength; - if (isNaN(bytesCompressed) || isNaN(totalBytesCompressed)) { + if (Number.isNaN(bytesCompressed) || Number.isNaN(totalBytesCompressed)) { totalBytesCompressed = null; } else { totalBytesCompressed += bytesCompressed; From 81f49ac662688aa7460f073aed8159439f70837b Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Mon, 20 Oct 2025 20:10:51 +0200 Subject: [PATCH 5/8] Nitpicks 2 --- src/js/tabs/onboard_logging.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/js/tabs/onboard_logging.js b/src/js/tabs/onboard_logging.js index e7efb91cbe..d641304d24 100644 --- a/src/js/tabs/onboard_logging.js +++ b/src/js/tabs/onboard_logging.js @@ -102,8 +102,16 @@ onboard_logging.initialize = function (callback) { $(".tab-onboard_logging a.erase-flash-confirm").click(flash_erase); $(".tab-onboard_logging a.erase-flash-cancel").click(flash_erase_cancel); - $(".tab-onboard_logging a.save-flash").click(flash_save_begin); - $(".tab-onboard_logging a.save-flash-erase").click(() => flash_save_begin(true)); + $(".tab-onboard_logging a.save-flash").on("click", (e) => { + e.preventDefault(); + flash_save_begin(false); + }); + + $(".tab-onboard_logging a.save-flash-erase").on("click", (e) => { + e.preventDefault(); + flash_save_begin(true); + }); + $(".tab-onboard_logging a.save-flash-cancel").click(flash_save_cancel); $(".tab-onboard_logging a.save-flash-dismiss").click(dismiss_saving_dialog); } From bdd06e9ffe617631e407b19c4ee3da52e2e86c29 Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Wed, 22 Oct 2025 21:42:51 +0200 Subject: [PATCH 6/8] Remove unsupported --- locales/en/messages.json | 3 --- src/tabs/onboard_logging.html | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/locales/en/messages.json b/locales/en/messages.json index 0aa32d213e..91176e1f00 100755 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -3549,9 +3549,6 @@ "dataflashButtonSaveFile": { "message": "Save flash to file..." }, - "dataflashButtonSaveFileDeprecated": { - "message": "Save flash to file... (unsupported)" - }, "dataflashSavetoFileNote": { "message": "Directly saving flash to file is slow and inherently prone to error / file corruption.
In some cases it will work for small files, but this is not supported and support requests for it will be closed without comment - use Mass Storage mode instead." }, diff --git a/src/tabs/onboard_logging.html b/src/tabs/onboard_logging.html index 411c4c80bb..b34ee12d56 100644 --- a/src/tabs/onboard_logging.html +++ b/src/tabs/onboard_logging.html @@ -113,7 +113,7 @@

- +

From 9380578415a92ce17d0fc46316272311a202b512 Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Wed, 22 Oct 2025 22:00:49 +0200 Subject: [PATCH 7/8] Repeat check for not cancelled for consistency --- src/js/tabs/onboard_logging.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/tabs/onboard_logging.js b/src/js/tabs/onboard_logging.js index d641304d24..4f093099b4 100644 --- a/src/js/tabs/onboard_logging.js +++ b/src/js/tabs/onboard_logging.js @@ -553,7 +553,7 @@ onboard_logging.initialize = function (callback) { // A zero-byte block indicates end-of-file, so we're done mark_saving_dialog_done(startTime, nextAddress, totalBytesCompressed); FileSystem.closeFile(openedFile); - if (alsoErase) { + if (!saveCancelled && alsoErase) { conditionallyEraseFlash(maxBytes, nextAddress); } } From 888ff0bfd1b3a41fe5f938ae7992412bdc376b97 Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Wed, 22 Oct 2025 22:11:28 +0200 Subject: [PATCH 8/8] Only close dialog when open --- src/js/tabs/onboard_logging.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/js/tabs/onboard_logging.js b/src/js/tabs/onboard_logging.js index 4f093099b4..c434decd54 100644 --- a/src/js/tabs/onboard_logging.js +++ b/src/js/tabs/onboard_logging.js @@ -610,7 +610,10 @@ onboard_logging.initialize = function (callback) { flash_update_summary(function () { if (CONFIGURATOR.connectionValid && !eraseCancelled) { if (FC.DATAFLASH.ready) { - $(".dataflash-confirm-erase")[0].close(); + const dialog = $(".dataflash-confirm-erase")[0]; + if (dialog?.open) { + dialog.close(); + } if (getConfig("showNotifications").showNotifications) { NotificationManager.showNotification("Betaflight Configurator", { body: i18n.getMessage("flashEraseDoneNotification"),