Skip to content

Commit

Permalink
Presets work
Browse files Browse the repository at this point in the history
  • Loading branch information
Aircoookie committed Sep 13, 2020
1 parent 96713ef commit 1263f5e
Showing 4 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
@@ -365,5 +365,5 @@ build_flags = ${common.build_flags_esp8266} ${common.debug_flags} ${common.build

[env:travis_esp32]
extends = env:esp32dev
build_type = debug
; build_type = debug
build_flags = ${common.build_flags_esp32} ${common.debug_flags} ${common.build_flags_all_features}
17 changes: 4 additions & 13 deletions wled00/file.cpp
Original file line number Diff line number Diff line change
@@ -4,15 +4,6 @@
* Utility for SPIFFS filesystem
*/

//filesystem
#ifndef WLED_DISABLE_FILESYSTEM
#include <FS.h>
#ifdef ARDUINO_ARCH_ESP32
#include "SPIFFS.h"
#endif
#include "SPIFFSEditor.h"
#endif

#ifndef WLED_DISABLE_FILESYSTEM

//find() that reads and buffers data from file stream in 256-byte blocks.
@@ -62,7 +53,6 @@ bool bufferedFindSpace(uint16_t targetLen, File f) {
#endif

if (!f || !f.size()) return false;
DEBUGFS_PRINTF("Filesize %d\n", f.size());

uint16_t index = 0;
uint16_t bufsize = 0, count = 0;
@@ -94,7 +84,7 @@ bool bufferedFindSpace(uint16_t targetLen, File f) {
bool appendObjectToFile(File f, const char* key, JsonDocument* content, uint32_t s)
{
#ifdef WLED_DEBUG_FS
DEBUG_PRINTLN("Append");
DEBUGFS_PRINTLN("Append");
uint32_t s1 = millis();
#endif
uint32_t pos = 0;
@@ -108,6 +98,7 @@ bool appendObjectToFile(File f, const char* key, JsonDocument* content, uint32_t
if (f.position() > 2) f.write(','); //add comma if not first object
f.print(key);
serializeJson(*content, f);
DEBUGFS_PRINTF("Inserted, took %d ms (total %d)", millis() - s1, millis() - s);
return true;
}

@@ -188,15 +179,15 @@ bool writeObjectToFile(const char* file, const char* key, JsonDocument* content)

if (!content->isNull() && measureJson(*content) <= oldLen) //replace
{
DEBUG_PRINTLN("replace");
DEBUGFS_PRINTLN("replace");
f.seek(pos);
serializeJson(*content, f);
//pad rest
for (uint32_t i = f.position(); i < pos2; i++) {
f.write(' ');
}
} else { //delete
DEBUG_PRINTLN("delete");
DEBUGFS_PRINTLN("delete");
pos -= strlen(key);
if (pos > 3) pos--; //also delete leading comma if not first object
f.seek(pos);
6 changes: 5 additions & 1 deletion wled00/wled.h
Original file line number Diff line number Diff line change
@@ -123,7 +123,11 @@
#endif

//Filesystem to use for preset and config files. SPIFFS or LittleFS on ESP8266, SPIFFS only on ESP32
#define WLED_FS LittleFS
#ifdef ESP8266
#define WLED_FS LittleFS
#else
#define WLED_FS SPIFFS
#endif

// remove flicker because PWM signal of RGB channels can become out of phase (part of core as of Arduino core v2.7.0)
//#if defined(WLED_USE_ANALOG_LEDS) && defined(ESP8266)
12 changes: 7 additions & 5 deletions wled00/wled_eeprom.cpp
Original file line number Diff line number Diff line change
@@ -675,15 +675,17 @@ bool applyPreset(byte index, bool loadBri)
void savePreset(byte index, bool persist, const char* pname, byte priority, JsonObject saveobj)
{
StaticJsonDocument<1024> doc;
JsonObject sObj = doc.to<JsonObject>();

if (saveobj.isNull()) {
Serial.println("Save current state");
DEBUGFS_PRINTLN("Save current state");
serializeState(doc.to<JsonObject>(), true);
} else {
Serial.println("Save custom");
doc = saveobj;
DEBUGFS_PRINTLN("Save custom");
sObj.set(saveobj);
}
doc["p"] = priority;
if (pname) doc["n"] = pname;
sObj["p"] = priority;
if (pname) sObj["n"] = pname;

//serializeJson(doc, Serial);
writeObjectToFileUsingId("/presets.json", index, &doc);

0 comments on commit 1263f5e

Please sign in to comment.