mirror of
https://github.com/wled/WLED.git
synced 2025-07-23 02:36:39 +00:00
Bigger buffer testing
This commit is contained in:
parent
d2ffb3ca9d
commit
b0828a6280
@ -198,10 +198,10 @@ void clearEEPROM();
|
|||||||
void writeStringToEEPROM(uint16_t pos, char* str, uint16_t len);
|
void writeStringToEEPROM(uint16_t pos, char* str, uint16_t len);
|
||||||
void readStringFromEEPROM(uint16_t pos, char* str, uint16_t len);
|
void readStringFromEEPROM(uint16_t pos, char* str, uint16_t len);
|
||||||
void saveSettingsToEEPROM();
|
void saveSettingsToEEPROM();
|
||||||
void loadSettingsFromEEPROM(bool first);
|
void loadSettingsFromEEPROM();
|
||||||
void savedToPresets();
|
void savedToPresets();
|
||||||
bool applyPreset(byte index, bool loadBri = true);
|
bool applyPreset(byte index);
|
||||||
void savePreset(byte index, bool persist = true, const char* pname = nullptr, byte prio = 5, JsonObject saveobj = JsonObject());
|
void savePreset(byte index, bool persist = true, const char* pname = nullptr, JsonObject saveobj = JsonObject());
|
||||||
void deletePreset(byte index);
|
void deletePreset(byte index);
|
||||||
void loadMacro(byte index, char* m);
|
void loadMacro(byte index, char* m);
|
||||||
void applyMacro(byte index);
|
void applyMacro(byte index);
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include "esp_spiffs.h" //FS info bare IDF function until FS wrapper is available for ESP32
|
#include "esp_spiffs.h" //FS info bare IDF function until FS wrapper is available for ESP32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FS_BUFSIZE 256
|
#define FS_BUFSIZE 512
|
||||||
|
|
||||||
//allow presets to be added until this percentage of FS space is used
|
//allow presets to be added until this percentage of FS space is used
|
||||||
#define FS_QUOTA 75
|
#define FS_QUOTA 75
|
||||||
@ -86,16 +86,16 @@ bool bufferedFindSpace(uint16_t targetLen, File f) {
|
|||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
while (count < bufsize) {
|
while (count < bufsize) {
|
||||||
if(buf[count] != ' ')
|
|
||||||
index = 0; // reset index if not space
|
|
||||||
|
|
||||||
if(buf[count] == ' ') {
|
if(buf[count] == ' ') {
|
||||||
if(++index >= targetLen) { // return true if space long enough
|
if(++index >= targetLen) { // return true if space long enough
|
||||||
f.seek((f.position() - bufsize) + count +1 - targetLen);
|
f.seek((f.position() - bufsize) + count +1 - targetLen);
|
||||||
DEBUGFS_PRINTF("Found at pos %d, took %d ms", f.position(), millis() - s);
|
DEBUGFS_PRINTF("Found at pos %d, took %d ms", f.position(), millis() - s);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
index = 0; // reset index if not space
|
||||||
}
|
}
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ bool bufferedFindObjectEnd(File f) {
|
|||||||
uint16_t objDepth = 0; //num of '{' minus num of '}'. return once 0
|
uint16_t objDepth = 0; //num of '{' minus num of '}'. return once 0
|
||||||
uint16_t bufsize = 0, count = 0;
|
uint16_t bufsize = 0, count = 0;
|
||||||
//size_t start = f.position();
|
//size_t start = f.position();
|
||||||
byte buf[256];
|
byte buf[FS_BUFSIZE];
|
||||||
|
|
||||||
while (f.position() < f.size() -1) {
|
while (f.position() < f.size() -1) {
|
||||||
bufsize = f.read(buf, FS_BUFSIZE);
|
bufsize = f.read(buf, FS_BUFSIZE);
|
||||||
@ -297,7 +297,7 @@ bool readObjectFromFile(const char* file, const char* key, JsonDocument* dest)
|
|||||||
if (!bufferedFind(key, f)) //key does not exist in file
|
if (!bufferedFind(key, f)) //key does not exist in file
|
||||||
{
|
{
|
||||||
f.close();
|
f.close();
|
||||||
DEBUGFS_PRINTLN("Obj not found.");
|
DEBUGFS_PRINTLN(F("Obj not found."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,9 +148,6 @@ bool deserializeState(JsonObject root)
|
|||||||
strip.applyToAllSelected = false;
|
strip.applyToAllSelected = false;
|
||||||
bool stateResponse = root[F("v")] | false;
|
bool stateResponse = root[F("v")] | false;
|
||||||
|
|
||||||
int ps = root[F("ps")] | -1;
|
|
||||||
if (ps >= 0) applyPreset(ps);
|
|
||||||
|
|
||||||
bri = root["bri"] | bri;
|
bri = root["bri"] | bri;
|
||||||
|
|
||||||
bool on = root["on"] | (bri > 0);
|
bool on = root["on"] | (bri > 0);
|
||||||
@ -240,17 +237,17 @@ bool deserializeState(JsonObject root)
|
|||||||
|
|
||||||
colorUpdated(noNotification ? NOTIFIER_CALL_MODE_NO_NOTIFY : NOTIFIER_CALL_MODE_DIRECT_CHANGE);
|
colorUpdated(noNotification ? NOTIFIER_CALL_MODE_NO_NOTIFY : NOTIFIER_CALL_MODE_DIRECT_CHANGE);
|
||||||
|
|
||||||
//write presets to flash directly?
|
int ps = root[F("psave")] | -1;
|
||||||
bool persistSaves = !(root[F("np")] | false);
|
|
||||||
|
|
||||||
ps = root[F("psave")] | -1;
|
|
||||||
if (ps > 0) {
|
if (ps > 0) {
|
||||||
savePreset(ps, persistSaves, root["n"], root["p"] | 50, root["o"].as<JsonObject>());
|
savePreset(ps, true, nullptr, root);
|
||||||
} else {
|
} else {
|
||||||
ps = root[F("pdel")] | -1; //deletion
|
ps = root[F("pdel")] | -1; //deletion
|
||||||
if (ps > 0) {
|
if (ps > 0) {
|
||||||
deletePreset(ps);
|
deletePreset(ps);
|
||||||
}
|
}
|
||||||
|
ps = root[F("ps")] | -1; //load preset (clears state request!)
|
||||||
|
if (ps >= 0) applyPreset(ps);
|
||||||
|
|
||||||
//HTTP API commands
|
//HTTP API commands
|
||||||
const char* httpwin = root["win"];
|
const char* httpwin = root["win"];
|
||||||
if (httpwin) {
|
if (httpwin) {
|
||||||
|
@ -296,7 +296,7 @@ void handleNightlight()
|
|||||||
if (bri == 0 || nightlightActive) return;
|
if (bri == 0 || nightlightActive) return;
|
||||||
|
|
||||||
if (presetCycCurr < presetCycleMin || presetCycCurr > presetCycleMax) presetCycCurr = presetCycleMin;
|
if (presetCycCurr < presetCycleMin || presetCycCurr > presetCycleMax) presetCycCurr = presetCycleMin;
|
||||||
applyPreset(presetCycCurr,presetApplyBri);
|
applyPreset(presetCycCurr);
|
||||||
presetCycCurr++;
|
presetCycCurr++;
|
||||||
if (presetCycCurr > 16) presetCycCurr = 1;
|
if (presetCycCurr > 16) presetCycCurr = 1;
|
||||||
colorUpdated(NOTIFIER_CALL_MODE_PRESET_CYCLE);
|
colorUpdated(NOTIFIER_CALL_MODE_PRESET_CYCLE);
|
||||||
|
@ -486,15 +486,12 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
if (v > 100) presetCycleTime = v/100;
|
if (v > 100) presetCycleTime = v/100;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = req.indexOf(F("PA=")); //apply brightness from preset
|
|
||||||
if (pos > 0) presetApplyBri = (req.charAt(pos+3) != '0');
|
|
||||||
|
|
||||||
pos = req.indexOf(F("PS=")); //saves current in preset
|
pos = req.indexOf(F("PS=")); //saves current in preset
|
||||||
if (pos > 0) savePreset(getNumVal(&req, pos), persistSaves);
|
if (pos > 0) savePreset(getNumVal(&req, pos));
|
||||||
|
|
||||||
//apply preset
|
//apply preset
|
||||||
if (updateVal(&req, "PL=", &presetCycCurr, presetCycleMin, presetCycleMax)) {
|
if (updateVal(&req, "PL=", &presetCycCurr, presetCycleMin, presetCycleMax)) {
|
||||||
applyPreset(presetCycCurr, presetApplyBri);
|
applyPreset(presetCycCurr);
|
||||||
}
|
}
|
||||||
|
|
||||||
//set brightness
|
//set brightness
|
||||||
|
@ -85,13 +85,10 @@ void WLED::loop()
|
|||||||
handleHue();
|
handleHue();
|
||||||
handleBlynk();
|
handleBlynk();
|
||||||
|
|
||||||
if (presetToApply) {
|
/*if (presetToApply) {
|
||||||
StaticJsonDocument<1024> temp;
|
applyPreset(presetToApply);
|
||||||
errorFlag = !readObjectFromFileUsingId("/presets.json", presetToApply, &temp);
|
|
||||||
serializeJson(temp, Serial);
|
|
||||||
deserializeState(temp.as<JsonObject>());
|
|
||||||
presetToApply = 0;
|
presetToApply = 0;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
|
|
||||||
@ -192,7 +189,7 @@ void WLED::setup()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
DEBUG_PRINTLN(F("Load EEPROM"));
|
DEBUG_PRINTLN(F("Load EEPROM"));
|
||||||
loadSettingsFromEEPROM(true);
|
loadSettingsFromEEPROM();
|
||||||
beginStrip();
|
beginStrip();
|
||||||
userSetup();
|
userSetup();
|
||||||
usermods.setup();
|
usermods.setup();
|
||||||
@ -252,8 +249,7 @@ void WLED::beginStrip()
|
|||||||
pinMode(BTNPIN, INPUT_PULLUP);
|
pinMode(BTNPIN, INPUT_PULLUP);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (bootPreset > 0)
|
if (bootPreset > 0) applyPreset(bootPreset);
|
||||||
applyPreset(bootPreset, turnOnAtBoot);
|
|
||||||
colorUpdated(NOTIFIER_CALL_MODE_INIT);
|
colorUpdated(NOTIFIER_CALL_MODE_INIT);
|
||||||
|
|
||||||
// init relay pin
|
// init relay pin
|
||||||
|
@ -167,10 +167,12 @@ WLED_GLOBAL char otaPass[33] _INIT(DEFAULT_OTA_PASS);
|
|||||||
// Hardware CONFIG (only changeble HERE, not at runtime)
|
// Hardware CONFIG (only changeble HERE, not at runtime)
|
||||||
// LED strip pin, button pin and IR pin changeable in NpbWrapper.h!
|
// LED strip pin, button pin and IR pin changeable in NpbWrapper.h!
|
||||||
|
|
||||||
WLED_GLOBAL byte presetToApply _INIT(0);
|
//WLED_GLOBAL byte presetToApply _INIT(0);
|
||||||
|
|
||||||
|
#if AUXPIN >= 0
|
||||||
WLED_GLOBAL byte auxDefaultState _INIT(0); // 0: input 1: high 2: low
|
WLED_GLOBAL byte auxDefaultState _INIT(0); // 0: input 1: high 2: low
|
||||||
WLED_GLOBAL byte auxTriggeredState _INIT(0); // 0: input 1: high 2: low
|
WLED_GLOBAL byte auxTriggeredState _INIT(0); // 0: input 1: high 2: low
|
||||||
|
#endif
|
||||||
WLED_GLOBAL char ntpServerName[33] _INIT("0.wled.pool.ntp.org"); // NTP server to use
|
WLED_GLOBAL char ntpServerName[33] _INIT("0.wled.pool.ntp.org"); // NTP server to use
|
||||||
|
|
||||||
// WiFi CONFIG (all these can be changed via web UI, no need to set them here)
|
// WiFi CONFIG (all these can be changed via web UI, no need to set them here)
|
||||||
@ -425,7 +427,6 @@ WLED_GLOBAL byte presetCycleMin _INIT(1), presetCycleMax _INIT(5);
|
|||||||
WLED_GLOBAL uint16_t presetCycleTime _INIT(12);
|
WLED_GLOBAL uint16_t presetCycleTime _INIT(12);
|
||||||
WLED_GLOBAL unsigned long presetCycledTime _INIT(0);
|
WLED_GLOBAL unsigned long presetCycledTime _INIT(0);
|
||||||
WLED_GLOBAL byte presetCycCurr _INIT(presetCycleMin);
|
WLED_GLOBAL byte presetCycCurr _INIT(presetCycleMin);
|
||||||
WLED_GLOBAL bool presetApplyBri _INIT(true);
|
|
||||||
WLED_GLOBAL bool saveCurrPresetCycConf _INIT(false);
|
WLED_GLOBAL bool saveCurrPresetCycConf _INIT(false);
|
||||||
|
|
||||||
// realtime
|
// realtime
|
||||||
@ -476,6 +477,7 @@ WLED_GLOBAL uint16_t olen _INIT(0);
|
|||||||
WLED_GLOBAL size_t fsBytesUsed _INIT(0);
|
WLED_GLOBAL size_t fsBytesUsed _INIT(0);
|
||||||
WLED_GLOBAL size_t fsBytesTotal _INIT(0);
|
WLED_GLOBAL size_t fsBytesTotal _INIT(0);
|
||||||
WLED_GLOBAL unsigned long presetsModifiedTime _INIT(0L);
|
WLED_GLOBAL unsigned long presetsModifiedTime _INIT(0L);
|
||||||
|
WLED_GLOBAL JsonDocument* fileDoc;
|
||||||
|
|
||||||
// presets
|
// presets
|
||||||
WLED_GLOBAL uint16_t savedPresets _INIT(0);
|
WLED_GLOBAL uint16_t savedPresets _INIT(0);
|
||||||
|
@ -249,7 +249,7 @@ void saveSettingsToEEPROM()
|
|||||||
EEPROM.write(2207, (presetCycleTime >> 8) & 0xFF);
|
EEPROM.write(2207, (presetCycleTime >> 8) & 0xFF);
|
||||||
EEPROM.write(2208, presetCycleMin);
|
EEPROM.write(2208, presetCycleMin);
|
||||||
EEPROM.write(2209, presetCycleMax);
|
EEPROM.write(2209, presetCycleMax);
|
||||||
EEPROM.write(2210, presetApplyBri);
|
// was EEPROM.write(2210, presetApplyBri);
|
||||||
// was EEPROM.write(2211, presetApplyCol);
|
// was EEPROM.write(2211, presetApplyCol);
|
||||||
// was EEPROM.write(2212, presetApplyFx);
|
// was EEPROM.write(2212, presetApplyFx);
|
||||||
saveCurrPresetCycConf = false;
|
saveCurrPresetCycConf = false;
|
||||||
@ -295,7 +295,7 @@ void saveSettingsToEEPROM()
|
|||||||
/*
|
/*
|
||||||
* Read all configuration from flash
|
* Read all configuration from flash
|
||||||
*/
|
*/
|
||||||
void loadSettingsFromEEPROM(bool first)
|
void loadSettingsFromEEPROM()
|
||||||
{
|
{
|
||||||
if (EEPROM.read(233) != 233) //first boot/reset to default
|
if (EEPROM.read(233) != 233) //first boot/reset to default
|
||||||
{
|
{
|
||||||
@ -343,7 +343,7 @@ void loadSettingsFromEEPROM(bool first)
|
|||||||
staticSubnet[3] = EEPROM.read(245);
|
staticSubnet[3] = EEPROM.read(245);
|
||||||
|
|
||||||
briS = EEPROM.read(249); bri = briS;
|
briS = EEPROM.read(249); bri = briS;
|
||||||
if (!EEPROM.read(369) && first)
|
if (!EEPROM.read(369))
|
||||||
{
|
{
|
||||||
bri = 0; briLast = briS;
|
bri = 0; briLast = briS;
|
||||||
}
|
}
|
||||||
@ -559,7 +559,7 @@ void loadSettingsFromEEPROM(bool first)
|
|||||||
if (lastEEPROMversion < 21) presetCycleTime /= 100; //was stored in ms, now is in tenths of a second
|
if (lastEEPROMversion < 21) presetCycleTime /= 100; //was stored in ms, now is in tenths of a second
|
||||||
presetCycleMin = EEPROM.read(2208);
|
presetCycleMin = EEPROM.read(2208);
|
||||||
presetCycleMax = EEPROM.read(2209);
|
presetCycleMax = EEPROM.read(2209);
|
||||||
presetApplyBri = EEPROM.read(2210);
|
//was presetApplyBri = EEPROM.read(2210);
|
||||||
//was presetApplyCol = EEPROM.read(2211);
|
//was presetApplyCol = EEPROM.read(2211);
|
||||||
//was presetApplyFx = EEPROM.read(2212);
|
//was presetApplyFx = EEPROM.read(2212);
|
||||||
}
|
}
|
||||||
@ -627,19 +627,31 @@ void savedToPresets()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool applyPreset(byte index, bool loadBri)
|
bool applyPreset(byte index)
|
||||||
{
|
{
|
||||||
StaticJsonDocument<1024> temp;
|
if (fileDoc) {
|
||||||
errorFlag = readObjectFromFileUsingId("/presets.json", index, &temp) ? ERR_NONE : ERR_FS_PLOAD;
|
errorFlag = readObjectFromFileUsingId("/presets.json", index, fileDoc) ? ERR_NONE : ERR_FS_PLOAD;
|
||||||
serializeJson(temp, Serial);
|
#ifdef WLED_DEBUG_FS
|
||||||
deserializeState(temp.as<JsonObject>());
|
serializeJson(*fileDoc, Serial);
|
||||||
|
#endif
|
||||||
|
deserializeState(fileDoc->as<JsonObject>());
|
||||||
|
} else {
|
||||||
|
WLED_DEBUG_FS(F("Make read buf"));
|
||||||
|
DynamicJsonDocument fDoc(JSON_BUFFER_SIZE);
|
||||||
|
errorFlag = readObjectFromFileUsingId("/presets.json", index, &fDoc) ? ERR_NONE : ERR_FS_PLOAD;
|
||||||
|
#ifdef WLED_DEBUG_FS
|
||||||
|
serializeJson(fDoc, Serial);
|
||||||
|
#endif
|
||||||
|
deserializeState(fDoc.as<JsonObject>());
|
||||||
|
}
|
||||||
|
|
||||||
if (!errorFlag) {
|
if (!errorFlag) {
|
||||||
currentPreset = index;
|
currentPreset = index;
|
||||||
isPreset = true;
|
isPreset = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
if (index == 255 || index == 0)
|
/*if (index == 255 || index == 0)
|
||||||
{
|
{
|
||||||
loadSettingsFromEEPROM(false);//load boot defaults
|
loadSettingsFromEEPROM(false);//load boot defaults
|
||||||
return true;
|
return true;
|
||||||
@ -681,29 +693,36 @@ bool applyPreset(byte index, bool loadBri)
|
|||||||
}
|
}
|
||||||
currentPreset = index;
|
currentPreset = index;
|
||||||
isPreset = true;
|
isPreset = true;
|
||||||
return true;
|
return true;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void savePreset(byte index, bool persist, const char* pname, byte priority, JsonObject saveobj)
|
void savePreset(byte index, bool persist, const char* pname, JsonObject saveobj)
|
||||||
{
|
{
|
||||||
StaticJsonDocument<1024> doc;
|
bool docAlloc = fileDoc;
|
||||||
JsonObject sObj = doc.to<JsonObject>();
|
JsonObject sObj = saveobj;
|
||||||
|
|
||||||
if (saveobj.isNull()) {
|
if (!docAlloc) {
|
||||||
DEBUGFS_PRINTLN("Save current state");
|
DEBUGFS_PRINTLN(F("Allocating saving buffer"));
|
||||||
serializeState(doc.to<JsonObject>(), true);
|
fileDoc = new DynamicJsonDocument(JSON_BUFFER_SIZE);
|
||||||
currentPreset = index;
|
sObj = fileDoc->to<JsonObject>();
|
||||||
} else {
|
|
||||||
DEBUGFS_PRINTLN("Save custom");
|
|
||||||
sObj.set(saveobj);
|
|
||||||
}
|
|
||||||
sObj["p"] = priority;
|
|
||||||
if (pname) sObj["n"] = pname;
|
if (pname) sObj["n"] = pname;
|
||||||
|
} else {
|
||||||
|
DEBUGFS_PRINTLN(F("Reuse recv buffer"));
|
||||||
|
sObj.remove(F("psave"));
|
||||||
|
sObj.remove(F("v"));
|
||||||
|
}
|
||||||
|
|
||||||
writeObjectToFileUsingId("/presets.json", index, &doc);
|
if (!sObj["o"]) {
|
||||||
|
DEBUGFS_PRINTLN(F("Save current state"));
|
||||||
|
serializeState(sObj, true);
|
||||||
|
currentPreset = index;
|
||||||
|
}
|
||||||
|
sObj.remove("o");
|
||||||
|
|
||||||
|
writeObjectToFileUsingId("/presets.json", index, fileDoc);
|
||||||
|
if (!docAlloc) delete fileDoc;
|
||||||
presetsModifiedTime = now(); //unix time
|
presetsModifiedTime = now(); //unix time
|
||||||
updateFSInfo();
|
updateFSInfo();
|
||||||
return;
|
|
||||||
|
|
||||||
/*if (index > 16) return;
|
/*if (index > 16) return;
|
||||||
if (index < 1) {saveSettingsToEEPROM();return;}
|
if (index < 1) {saveSettingsToEEPROM();return;}
|
||||||
|
@ -85,7 +85,9 @@ void initServer()
|
|||||||
if (error || root.isNull()) {
|
if (error || root.isNull()) {
|
||||||
request->send(400, "application/json", F("{\"error\":9}")); return;
|
request->send(400, "application/json", F("{\"error\":9}")); return;
|
||||||
}
|
}
|
||||||
|
fileDoc = &jsonBuffer;
|
||||||
verboseResponse = deserializeState(root);
|
verboseResponse = deserializeState(root);
|
||||||
|
fileDoc = nullptr;
|
||||||
}
|
}
|
||||||
if (verboseResponse) { //if JSON contains "v"
|
if (verboseResponse) { //if JSON contains "v"
|
||||||
serveJson(request); return;
|
serveJson(request); return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user