Skip to content

Commit

Permalink
Show SDC in DataFlash component
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Dec 3, 2024
1 parent e0c62d6 commit 8ffb2c0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/components/data-flash/DataFlash.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/js/serial_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
32 changes: 24 additions & 8 deletions src/js/update_dataflash_global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
Expand All @@ -28,15 +32,27 @@ 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',
});

$(".dataflash-contents_global").css({
display: 'none',
});
}
}
}

0 comments on commit 8ffb2c0

Please sign in to comment.