RAM optimizations:

- changed int16_t to byte for currentPreset and currentPlaylist
- removed presetCycXxxxx variables
This commit is contained in:
Blaz Kristan 2021-10-06 18:43:12 +02:00
parent 7b21c1bcbe
commit 9f230ae339
6 changed files with 15 additions and 14 deletions

View File

@ -223,7 +223,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
if (root["on"].is<const char*>() && root["on"].as<const char*>()[0] == 't') toggleOnOff(); if (root["on"].is<const char*>() && root["on"].as<const char*>()[0] == 't') toggleOnOff();
int tr = -1; int tr = -1;
if (!presetId || currentPlaylist < 0) { //do not apply transition time from preset if playlist active, as it would override playlist transition times if (!presetId || !currentPlaylist) { //do not apply transition time from preset if playlist active, as it would override playlist transition times
tr = root[F("transition")] | -1; tr = root[F("transition")] | -1;
if (tr >= 0) if (tr >= 0)
{ {
@ -415,8 +415,8 @@ void serializeState(JsonObject root, bool forPreset, bool includeBri, bool segme
if (!forPreset) { if (!forPreset) {
if (errorFlag) {root[F("error")] = errorFlag; errorFlag = ERR_NONE;} if (errorFlag) {root[F("error")] = errorFlag; errorFlag = ERR_NONE;}
root[F("ps")] = currentPreset; root[F("ps")] = currentPreset>0 ? currentPreset : -1;
root[F("pl")] = currentPlaylist; root[F("pl")] = currentPlaylist>0 ? currentPlaylist : -1;
usermods.addToJsonState(root); usermods.addToJsonState(root);

View File

@ -111,7 +111,7 @@ void colorUpdated(int callMode)
{ {
effectChanged = false; effectChanged = false;
if (realtimeTimeout == UINT32_MAX) realtimeTimeout = 0; if (realtimeTimeout == UINT32_MAX) realtimeTimeout = 0;
currentPreset = -1; //something changed, so we are no longer in the preset currentPreset = 0; //something changed, so we are no longer in the preset
notify(callMode); notify(callMode);

View File

@ -47,7 +47,8 @@ void unloadPlaylist() {
delete[] playlistEntries; delete[] playlistEntries;
playlistEntries = nullptr; playlistEntries = nullptr;
} }
currentPlaylist = playlistIndex = -1; currentPlaylist = 0;
playlistIndex = -1;
playlistLen = playlistEntryDur = playlistOptions = 0; playlistLen = playlistEntryDur = playlistOptions = 0;
DEBUG_PRINTLN(F("Playlist unloaded.")); DEBUG_PRINTLN(F("Playlist unloaded."));
} }
@ -118,7 +119,8 @@ int16_t loadPlaylist(JsonObject playlistObj, byte presetId) {
void handlePlaylist() { void handlePlaylist() {
if (currentPlaylist < 0 || playlistEntries == nullptr) return; static unsigned long presetCycledTime = 0;
if (!currentPlaylist || playlistEntries == nullptr) return;
if (millis() - presetCycledTime > (100*playlistEntryDur)) { if (millis() - presetCycledTime > (100*playlistEntryDur)) {
presetCycledTime = millis(); presetCycledTime = millis();

View File

@ -650,6 +650,9 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
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)); if (pos > 0) savePreset(getNumVal(&req, pos));
byte presetCycleMin = 1;
byte presetCycleMax = 5;
byte presetCycCurr;
pos = req.indexOf(F("P1=")); //sets first preset for cycle pos = req.indexOf(F("P1=")); //sets first preset for cycle
if (pos > 0) presetCycleMin = getNumVal(&req, pos); if (pos > 0) presetCycleMin = getNumVal(&req, pos);

View File

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2110041 #define VERSION 2110061
//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
@ -513,11 +513,7 @@ WLED_GLOBAL byte timerWeekday[] _INIT_N(({ 255, 255, 255, 255, 255, 255, 255, 25
WLED_GLOBAL bool blynkEnabled _INIT(false); WLED_GLOBAL bool blynkEnabled _INIT(false);
//playlists //playlists
WLED_GLOBAL unsigned long presetCycledTime _INIT(0); WLED_GLOBAL byte currentPlaylist _INIT(0);
WLED_GLOBAL int16_t currentPlaylist _INIT(-1);
//still used for "PL=~" HTTP API command
WLED_GLOBAL byte presetCycleMin _INIT(1), presetCycleMax _INIT(5);
WLED_GLOBAL byte presetCycCurr _INIT(presetCycleMin);
// realtime // realtime
WLED_GLOBAL byte realtimeMode _INIT(REALTIME_MODE_INACTIVE); WLED_GLOBAL byte realtimeMode _INIT(REALTIME_MODE_INACTIVE);
@ -569,7 +565,7 @@ WLED_GLOBAL JsonDocument* fileDoc;
WLED_GLOBAL bool doCloseFile _INIT(false); WLED_GLOBAL bool doCloseFile _INIT(false);
// presets // presets
WLED_GLOBAL int16_t currentPreset _INIT(-1); WLED_GLOBAL byte currentPreset _INIT(0);
WLED_GLOBAL byte errorFlag _INIT(0); WLED_GLOBAL byte errorFlag _INIT(0);

View File

@ -60,7 +60,7 @@ void XML_response(AsyncWebServerRequest *request, char* dest)
oappend(SET_F("</wv><ws>")); oappend(SET_F("</wv><ws>"));
oappendi(colSec[3]); oappendi(colSec[3]);
oappend(SET_F("</ws><ps>")); oappend(SET_F("</ws><ps>"));
oappendi((currentPreset < 1) ? 0:currentPreset); oappendi(currentPreset);
oappend(SET_F("</ps><cy>")); oappend(SET_F("</ps><cy>"));
oappendi(currentPlaylist > 0); oappendi(currentPlaylist > 0);
oappend(SET_F("</cy><ds>")); oappend(SET_F("</cy><ds>"));