Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions wled00/fcn_declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ bool writeObjectToFile(const char* file, const char* key, const JsonDocument* co
bool readObjectFromFileUsingId(const char* file, uint16_t id, JsonDocument* dest, const JsonDocument* filter = nullptr);
bool readObjectFromFile(const char* file, const char* key, JsonDocument* dest, const JsonDocument* filter = nullptr);
void updateFSInfo();
size_t getFsBytesUsed();
size_t getFsBytesTotal();
void closeFile();
inline bool writeObjectToFileUsingId(const String &file, uint16_t id, const JsonDocument* content) { return writeObjectToFileUsingId(file.c_str(), id, content); };
inline bool writeObjectToFile(const String &file, const char* key, const JsonDocument* content) { return writeObjectToFile(file.c_str(), key, content); };
Expand Down
10 changes: 10 additions & 0 deletions wled00/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@

#define FS_BUFSIZE 256

// Filesystem usage stats, refreshed by updateFSInfo() - previously WLED_GLOBAL,
// a leftover from when all state lived in one big extern block regardless of
// who used it. json.cpp only ever reads these (status report), so it gets
// by-value getters rather than a mutable reference - an accidental write from
// outside this file is now a build error instead of a silent bug.
static size_t fsBytesUsed = 0;
static size_t fsBytesTotal = 0;
size_t getFsBytesUsed() { return fsBytesUsed; }
size_t getFsBytesTotal() { return fsBytesTotal; }

/*
* Structural requirements for files managed by writeObjectToFile() and readObjectFromFile() utilities:
* 1. File must be a string representation of a valid JSON object
Expand Down
4 changes: 2 additions & 2 deletions wled00/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,8 @@ void serializeInfo(JsonObject root)
wifi_info[F("ap")] = apActive;

JsonObject fs_info = root.createNestedObject("fs");
fs_info["u"] = fsBytesUsed / 1000;
fs_info["t"] = fsBytesTotal / 1000;
fs_info["u"] = getFsBytesUsed() / 1000;
fs_info["t"] = getFsBytesTotal() / 1000;
fs_info[F("pmt")] = presetsModifiedTime;

root[F("ndc")] = nodeListEnabled ? (int)Nodes.size() : -1;
Expand Down
3 changes: 1 addition & 2 deletions wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,7 @@ WLED_GLOBAL time_t sunset _INIT(0);
WLED_GLOBAL Toki toki _INIT(Toki());

// General filesystem
WLED_GLOBAL size_t fsBytesUsed _INIT(0);
WLED_GLOBAL size_t fsBytesTotal _INIT(0);
// fsBytesUsed/fsBytesTotal are private to file.cpp - use getFsBytesUsed()/getFsBytesTotal() instead.
WLED_GLOBAL unsigned long presetsModifiedTime _INIT(0L);
WLED_GLOBAL bool doCloseFile _INIT(false);

Expand Down
Loading