Skip to content

Commit

Permalink
add recording space warning
Browse files Browse the repository at this point in the history
  • Loading branch information
NuclearPhoenixx committed Feb 2, 2024
1 parent 5a1c9d0 commit 60498e2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
10 changes: 9 additions & 1 deletion software/ogd_pico/FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@

#include <LittleFS.h> // Needed to interface with the FS on flash

uint8_t getUsedPercentageFS() {
FSInfo fsinfo;
LittleFS.info(fsinfo);

return round(float(fsinfo.usedBytes) / fsinfo.totalBytes * 100.0);
}


void fsInfo([[maybe_unused]] String *args) {
FSInfo fsinfo;
LittleFS.info(fsinfo);
Expand All @@ -24,7 +32,7 @@ void fsInfo([[maybe_unused]] String *args) {

println("Total Size: \t" + String(fsinfo.totalBytes / 1000.0) + " kB");
print("Used Size: \t\t" + String(fsinfo.usedBytes / 1000.0) + " kB");
cleanPrintln(" / " + String(float(fsinfo.usedBytes) / fsinfo.totalBytes * 100) + " %");
cleanPrintln(" / " + String(getUsedPercentageFS()) + " %");
println("Data Dir Size: \t" + String(dirSize / 1000.0) + " kB");
// Uncomment these for advanced users
//println("Block Size: " + String(fsinfo.blockSize / 1000.0) + " kB");
Expand Down
2 changes: 2 additions & 0 deletions software/ogd_pico/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

const String DATA_DIR_PATH = "/data/";

uint8_t getUsedPercentageFS();

void fsInfo(String *args);
void readDirFS(String *args);
void readFileFS(String *args);
Expand Down
13 changes: 10 additions & 3 deletions software/ogd_pico/ogd_pico.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
## except you know exactly what you are doing!
## Flash with default settings and
## Flash Size: "2MB (Sketch: 1MB, FS: 1MB)"
TODO: (?) Adafruit TinyUSB lib: WebUSB support
TODO: Retry a coincidence detection feature
TODO: Add cps line trend to geiger mode
TODO: Add custom display font
Expand Down Expand Up @@ -390,6 +388,9 @@ void recordCycle() {
doc.shrinkToFit();

File saveFile = LittleFS.open(DATA_DIR_PATH + recordingFile, "w"); // Open read and write
if (!saveFile) {
println("Could not create file to save recording data!", true);
}
serializeJson(doc, saveFile);
saveFile.close();

Expand All @@ -410,6 +411,12 @@ void recordStart(String *args) {
return;
}

// Check and warn if the filesystem is almost full
if (getUsedPercentageFS() > 90) {
println("WARNING: Filesystem is almost full. Check if you have enough space for an additional recording.", true);
println("The device might not be able to save the data. Delete old files if you need more free space.", true);
}

// Find the position of the first space
const int spaceChar = command.indexOf(' ');

Expand Down

0 comments on commit 60498e2

Please sign in to comment.