From 8ffb2c011ea44b0099c617be4ae2610932e136b8 Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Tue, 3 Dec 2024 12:06:33 +0100 Subject: [PATCH] Show SDC in DataFlash component --- src/components/data-flash/DataFlash.vue | 8 +++++-- src/js/msp/MSPHelper.js | 1 + src/js/serial_backend.js | 1 + src/js/update_dataflash_global.js | 32 ++++++++++++++++++------- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/components/data-flash/DataFlash.vue b/src/components/data-flash/DataFlash.vue index cc5ee76148..38d8a74540 100644 --- a/src/components/data-flash/DataFlash.vue +++ b/src/components/data-flash/DataFlash.vue @@ -46,10 +46,14 @@ export default { } const kilobytes = bytes / 1024; if (kilobytes < 1024) { - return `${Math.round(kilobytes)}kB`; + return `${Math.round(kilobytes)}KB`; } const megabytes = kilobytes / 1024; - return `${megabytes.toFixed(1)}MB`; + if (megabytes < 1024) { + return `${megabytes.toFixed(1)}MB`; + } + const gigabytes = megabytes / 1024; + return `${gigabytes.toFixed(1)}GB`; }, indicatorWidth() { if (!this.supportDataflash) return; diff --git a/src/js/msp/MSPHelper.js b/src/js/msp/MSPHelper.js index 73c98d4be3..9e604e7250 100644 --- a/src/js/msp/MSPHelper.js +++ b/src/js/msp/MSPHelper.js @@ -1361,6 +1361,7 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.SDCARD.filesystemLastError = data.readU8(); FC.SDCARD.freeSizeKB = data.readU32(); FC.SDCARD.totalSizeKB = data.readU32(); + update_dataflash_global(); break; case MSPCodes.MSP_BLACKBOX_CONFIG: FC.BLACKBOX.supported = (data.readU8() & 1) != 0; diff --git a/src/js/serial_backend.js b/src/js/serial_backend.js index 5db7ba518e..3f2032ab29 100644 --- a/src/js/serial_backend.js +++ b/src/js/serial_backend.js @@ -635,6 +635,7 @@ function onConnect() { MSP.send_message(MSPCodes.MSP_FEATURE_CONFIG, false, false); MSP.send_message(MSPCodes.MSP_BATTERY_CONFIG, false, false); MSP.send_message(MSPCodes.MSP_DATAFLASH_SUMMARY, false, false); + MSP.send_message(MSPCodes.MSP_SDCARD_SUMMARY, false, false); if (FC.CONFIG.boardType === 0 || FC.CONFIG.boardType === 2) { startLiveDataRefreshTimer(); diff --git a/src/js/update_dataflash_global.js b/src/js/update_dataflash_global.js index 588c6b029b..6f32f667e3 100644 --- a/src/js/update_dataflash_global.js +++ b/src/js/update_dataflash_global.js @@ -13,13 +13,17 @@ export function update_dataflash_global() { } const megabytes = kilobytes / 1024; - - return `${megabytes.toFixed(1)}MB`; + if (megabytes < 1024) { + return `${megabytes.toFixed(1)}MB`; + } + const gigabytes = megabytes / 1024; + return `${gigabytes.toFixed(1)}GB`; } - const supportsDataflash = FC.DATAFLASH.totalSize > 0; + const supportsDataflash = FC.DATAFLASH.supported && FC.DATAFLASH.totalSize > 0; + const supportsDatacard = FC.SDCARD.supported && FC.SDCARD.totalSizeKB > 0; - if (supportsDataflash){ + if (supportsDataflash || supportsDatacard) { $(".noflash_global").css({ display: 'none', }); @@ -28,9 +32,21 @@ export function update_dataflash_global() { display: 'block', }); - $(".dataflash-progress_global").val(`${100-(FC.DATAFLASH.totalSize - FC.DATAFLASH.usedSize) / FC.DATAFLASH.totalSize * 100}`); - $(".dataflash-contents_global div").text(`Dataflash: free ${formatFilesize(FC.DATAFLASH.totalSize - FC.DATAFLASH.usedSize)}`); - } else { + let dataflashProgress; + let dataflashProgressText; + + if (supportsDataflash) { + dataflashProgress = 100 - (FC.DATAFLASH.totalSize - FC.DATAFLASH.usedSize) / FC.DATAFLASH.totalSize * 100; + dataflashProgressText = `Dataflash: free ${formatFilesize(FC.DATAFLASH.totalSize - FC.DATAFLASH.usedSize)}`; + } + if (supportsDatacard) { + dataflashProgress = 100 - FC.SDCARD.freeSizeKB / FC.SDCARD.totalSizeKB * 100; + dataflashProgressText = `SD Card: free ${formatFilesize(FC.SDCARD.freeSizeKB * 1024)}`; + } + + $(".dataflash-progress_global").val(dataflashProgress); + $(".dataflash-contents_global div").text(dataflashProgressText); + } else { $(".noflash_global").css({ display: 'block', }); @@ -38,5 +54,5 @@ export function update_dataflash_global() { $(".dataflash-contents_global").css({ display: 'none', }); - } + } }