Missing presets.json on factory reset bugfix.

Clarification on loading ledmaps in UI.
Added manual ledmap loading.
pull/2894/head
Blaz Kristan 2022-11-16 20:55:21 +01:00
rodzic f104fb0586
commit c47d6cffa8
11 zmienionych plików z 3819 dodań i 3772 usunięć

Wyświetl plik

@ -964,7 +964,8 @@ void WS2812FX::finalizeInit(void)
} }
//segments are created in makeAutoSegments(); //segments are created in makeAutoSegments();
setBrightness(_brightness); loadCustomPalettes(); // (re)load all custom palettes
deserializeMap(); // (re)load default ledmap
} }
void WS2812FX::service() { void WS2812FX::service() {
@ -1500,6 +1501,7 @@ void WS2812FX::loadCustomPalettes()
{ {
byte tcp[72]; //support gradient palettes with up to 18 entries byte tcp[72]; //support gradient palettes with up to 18 entries
CRGBPalette16 targetPalette; CRGBPalette16 targetPalette;
customPalettes.clear(); // start fresh
for (int index = 0; index<10; index++) { for (int index = 0; index<10; index++) {
char fileName[32]; char fileName[32];
sprintf_P(fileName, PSTR("/palette%d.json"), index); sprintf_P(fileName, PSTR("/palette%d.json"), index);

Wyświetl plik

@ -740,7 +740,7 @@ input[type=range]::-moz-range-thumb {
margin-top: var(--bmt); margin-top: var(--bmt);
} }
#picker, #rgbwrap, #kwrap, #wwrap, #wbal, #vwrap, #qcs-w, #hexw, #pall { #picker, #rgbwrap, #kwrap, #wwrap, #wbal, #vwrap, #qcs-w, #hexw, #pall, #ledmap {
margin: 0 auto; margin: 0 auto;
width: 260px; width: 260px;
} }
@ -898,6 +898,10 @@ div.sel-p:after {
select.sel-ple { select.sel-ple {
text-align: center; text-align: center;
} }
select.sel-sg {
margin: 5px 0;
height: 40px;
}
option { option {
background-color: var(--c-3); background-color: var(--c-3);
color: var(--c-f); color: var(--c-f);

Wyświetl plik

@ -311,6 +311,7 @@
<button class="btn btn-s" id="rsbtn" onclick="rSegs()">Reset segments</button> <button class="btn btn-s" id="rsbtn" onclick="rSegs()">Reset segments</button>
</div> </div>
<p>Transition: <input id="tt" class="noslide" type="number" min="0" max="65.5" step="0.1" value="0.7">&nbsp;s</p> <p>Transition: <input id="tt" class="noslide" type="number" min="0" max="65.5" step="0.1" value="0.7">&nbsp;s</p>
<p id="ledmap" class="hide"></p>
</div> </div>
<div id="Presets" class="tabcontent"> <div id="Presets" class="tabcontent">

Wyświetl plik

@ -810,6 +810,16 @@ function populateSegments(s)
if (segCount < 2) gId(`segd${lSeg}`).style.display = "none"; if (segCount < 2) gId(`segd${lSeg}`).style.display = "none";
if (!isM && !noNewSegs && (cfg.comp.seglen?parseInt(gId(`seg${lSeg}s`).value):0)+parseInt(gId(`seg${lSeg}e`).value)<ledCount) gId(`segr${lSeg}`).style.display = "inline"; if (!isM && !noNewSegs && (cfg.comp.seglen?parseInt(gId(`seg${lSeg}s`).value):0)+parseInt(gId(`seg${lSeg}e`).value)<ledCount) gId(`segr${lSeg}`).style.display = "inline";
gId('segutil2').style.display = (segCount > 1) ? "block":"none"; // rsbtn parent gId('segutil2').style.display = (segCount > 1) ? "block":"none"; // rsbtn parent
if (Array.isArray(li.maps) && li.maps.length>1) {
let cont = `Ledmap:&nbsp;<select class="sel-sg" onchange="requestJson({'ledmap':parseInt(this.value)})"><option value="" selected>Unchanged</option>`;
for (const k of (li.maps||[])) cont += `<option value="${k}">${k==0?'Default':'ledmap'+k+'.json'}</option>`;
cont += "</select></div>";
gId("ledmap").innerHTML = cont;
gId("ledmap").classList.remove("hide");
} else {
gId("ledmap").classList.add("hide");
}
} }
function populateEffects() function populateEffects()
@ -1819,9 +1829,9 @@ ${makePlSel(plJson[i].end?plJson[i].end:0, true)}
<input type="checkbox" id="p${i}sbchk"> <input type="checkbox" id="p${i}sbchk">
<span class="checkmark"></span> <span class="checkmark"></span>
</label>`; </label>`;
if (Array.isArray(lastinfo.maps) && lastinfo.maps.length>0) { if (Array.isArray(lastinfo.maps) && lastinfo.maps.length>1) {
content += `<div class="lbl-l">Ledmap:&nbsp;<div class="sel-p"><select class="sel-p" id="p${i}lmp"><option value="">None</option>`; content += `<div class="lbl-l">Ledmap:&nbsp;<div class="sel-p"><select class="sel-p" id="p${i}lmp"><option value="">Unchanged</option>`;
for (const k of (lastinfo.maps||[])) content += `<option value="${k}"${(i>0 && pJson[i].ledmap==k)?" selected":""}>${k}</option>`; for (const k of (lastinfo.maps||[])) content += `<option value="${k}"${(i>0 && pJson[i].ledmap==k)?" selected":""}>${k==0?'Default':'ledmap'+k+'.json'}</option>`;
content += "</select></div></div>"; content += "</select></div></div>";
} }
} }

Wyświetl plik

@ -195,6 +195,7 @@ void handlePlaylist();
void serializePlaylist(JsonObject obj); void serializePlaylist(JsonObject obj);
//presets.cpp //presets.cpp
void initPresetsFile();
void handlePresets(); void handlePresets();
bool applyPreset(byte index, byte callMode = CALL_MODE_DIRECT_CHANGE); bool applyPreset(byte index, byte callMode = CALL_MODE_DIRECT_CHANGE);
inline bool applyTemporaryPreset() {return applyPreset(255);}; inline bool applyTemporaryPreset() {return applyPreset(255);};

Plik diff jest za duży Load Diff

Plik diff jest za duży Load Diff

Plik diff jest za duży Load Diff

Wyświetl plik

@ -11,6 +11,7 @@ static char *tmpRAMbuffer = nullptr;
static volatile byte presetToApply = 0; static volatile byte presetToApply = 0;
static volatile byte callModeToApply = 0; static volatile byte callModeToApply = 0;
static volatile byte presetToSave = 0; static volatile byte presetToSave = 0;
static volatile int8_t saveLedmap = -1;
static char quickLoad[3]; static char quickLoad[3];
static char saveName[33]; static char saveName[33];
static bool includeBri = true, segBounds = true, selectedOnly = false, playlistSave = false;; static bool includeBri = true, segBounds = true, selectedOnly = false, playlistSave = false;;
@ -25,6 +26,7 @@ static void doSaveState() {
if (!requestJSONBufferLock(10)) return; // will set fileDoc if (!requestJSONBufferLock(10)) return; // will set fileDoc
initPresetsFile(); // just in case if someone deleted presets.json using /edit
JsonObject sObj = doc.to<JsonObject>(); JsonObject sObj = doc.to<JsonObject>();
DEBUG_PRINTLN(F("Serialize current state")); DEBUG_PRINTLN(F("Serialize current state"));
@ -36,6 +38,7 @@ static void doSaveState() {
} }
sObj["n"] = saveName; sObj["n"] = saveName;
if (quickLoad[0]) sObj[F("ql")] = quickLoad; if (quickLoad[0]) sObj[F("ql")] = quickLoad;
if (saveLedmap >= 0) sObj[F("ledmap")] = saveLedmap;
/* /*
#ifdef WLED_DEBUG #ifdef WLED_DEBUG
DEBUG_PRINTLN(F("Serialized preset")); DEBUG_PRINTLN(F("Serialized preset"));
@ -69,6 +72,7 @@ static void doSaveState() {
updateFSInfo(); updateFSInfo();
// clean up // clean up
saveLedmap = -1;
presetToSave = 0; presetToSave = 0;
saveName[0] = '\0'; saveName[0] = '\0';
quickLoad[0] = '\0'; quickLoad[0] = '\0';
@ -79,7 +83,7 @@ bool getPresetName(byte index, String& name)
{ {
if (!requestJSONBufferLock(9)) return false; if (!requestJSONBufferLock(9)) return false;
bool presetExists = false; bool presetExists = false;
if (readObjectFromFileUsingId("/presets.json", index, &doc)) if (readObjectFromFileUsingId(getName(), index, &doc))
{ {
JsonObject fdo = doc.as<JsonObject>(); JsonObject fdo = doc.as<JsonObject>();
if (fdo["n"]) { if (fdo["n"]) {
@ -91,6 +95,22 @@ bool getPresetName(byte index, String& name)
return presetExists; return presetExists;
} }
void initPresetsFile()
{
if (WLED_FS.exists(getName())) return;
StaticJsonDocument<64> doc;
JsonObject sObj = doc.to<JsonObject>();
sObj.createNestedObject("0");
File f = WLED_FS.open(getName(), "w");
if (!f) {
errorFlag = ERR_FS_GENERAL;
return;
}
serializeJson(doc, f);
f.close();
}
bool applyPreset(byte index, byte callMode) bool applyPreset(byte index, byte callMode)
{ {
DEBUG_PRINT(F("Request to apply preset: ")); DEBUG_PRINT(F("Request to apply preset: "));
@ -188,6 +208,7 @@ void savePreset(byte index, const char* pname, JsonObject sObj)
includeBri = sObj["ib"].as<bool>() || index==255; // temporary preset needs brightness includeBri = sObj["ib"].as<bool>() || index==255; // temporary preset needs brightness
segBounds = sObj["sb"].as<bool>() || index==255; // temporary preset needs bounds segBounds = sObj["sb"].as<bool>() || index==255; // temporary preset needs bounds
selectedOnly = sObj[F("sc")].as<bool>(); selectedOnly = sObj[F("sc")].as<bool>();
saveLedmap = sObj[F("ledmap")] | -1;
sObj.remove("ib"); sObj.remove("ib");
sObj.remove("sb"); sObj.remove("sb");
sObj.remove(F("sc")); sObj.remove(F("sc"));
@ -198,6 +219,7 @@ void savePreset(byte index, const char* pname, JsonObject sObj)
presetToSave = 0; // we will save API immediately presetToSave = 0; // we will save API immediately
if (index < 251 && fileDoc) { if (index < 251 && fileDoc) {
if (sObj["n"].isNull()) sObj["n"] = saveName; if (sObj["n"].isNull()) sObj["n"] = saveName;
initPresetsFile(); // just in case if someone deleted presets.json using /edit
writeObjectToFileUsingId(getName(index), index, fileDoc); writeObjectToFileUsingId(getName(index), index, fileDoc);
presetsModifiedTime = toki.second(); //unix time presetsModifiedTime = toki.second(); //unix time
updateFSInfo(); updateFSInfo();

Wyświetl plik

@ -361,6 +361,8 @@ void WLED::setup()
} }
#ifdef WLED_ADD_EEPROM_SUPPORT #ifdef WLED_ADD_EEPROM_SUPPORT
else deEEP(); else deEEP();
#else
initPresetsFile();
#endif #endif
updateFSInfo(); updateFSInfo();
@ -452,8 +454,6 @@ void WLED::beginStrip()
{ {
// Initialize NeoPixel Strip and button // Initialize NeoPixel Strip and button
strip.finalizeInit(); // busses created during deserializeConfig() strip.finalizeInit(); // busses created during deserializeConfig()
strip.loadCustomPalettes();
strip.deserializeMap();
strip.makeAutoSegments(); strip.makeAutoSegments();
strip.setBrightness(0); strip.setBrightness(0);
strip.setShowCallback(handleOverlayDraw); strip.setShowCallback(handleOverlayDraw);

Wyświetl plik

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2211130 #define VERSION 2211160
//uncomment this if you have a "my_config.h" file you'd like to use //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG