Improved heap usage by 2k

This commit is contained in:
cschwinne 2019-03-11 19:30:49 +01:00
parent 202eb0d854
commit 46e4350013
7 changed files with 36 additions and 35 deletions

View File

@ -739,16 +739,16 @@ uint16_t WS2812FX::mode_chase_rainbow(void) {
/*
* Sec flashes running on prim.
*/
#define FLASH_COUNT 4
uint16_t WS2812FX::mode_chase_flash(void) {
const static uint8_t flash_count = 4;
uint8_t flash_step = SEGMENT_RUNTIME.counter_mode_call % ((flash_count * 2) + 1);
uint8_t flash_step = SEGMENT_RUNTIME.counter_mode_call % ((FLASH_COUNT * 2) + 1);
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0));
}
uint16_t delay = 10 + ((30 * (uint16_t)(255 - SEGMENT.speed)) / SEGMENT_LENGTH);
if(flash_step < (flash_count * 2)) {
if(flash_step < (FLASH_COUNT * 2)) {
if(flash_step % 2 == 0) {
uint16_t n = SEGMENT_RUNTIME.counter_mode_step;
uint16_t m = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH;
@ -769,15 +769,14 @@ uint16_t WS2812FX::mode_chase_flash(void) {
* Prim flashes running, followed by random color.
*/
uint16_t WS2812FX::mode_chase_flash_random(void) {
const static uint8_t flash_count = 4;
uint8_t flash_step = SEGMENT_RUNTIME.counter_mode_call % ((flash_count * 2) + 1);
uint8_t flash_step = SEGMENT_RUNTIME.counter_mode_call % ((FLASH_COUNT * 2) + 1);
for(uint16_t i=0; i < SEGMENT_RUNTIME.counter_mode_step; i++) {
setPixelColor(SEGMENT.start + i, color_wheel(SEGMENT_RUNTIME.aux_param));
}
uint16_t delay = 1 + ((10 * (uint16_t)(255 - SEGMENT.speed)) / SEGMENT_LENGTH);
if(flash_step < (flash_count * 2)) {
if(flash_step < (FLASH_COUNT * 2)) {
uint16_t n = SEGMENT_RUNTIME.counter_mode_step;
uint16_t m = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH;
if(flash_step % 2 == 0) {

View File

@ -248,7 +248,6 @@ bool aOtaEnabled = true; //ArduinoOTA allows easy updates d
uint16_t userVar0 = 0, userVar1 = 0;
//internal global variable declarations
//color
byte col[]{255, 159, 0, 0}; //target RGB(W) color
@ -400,9 +399,9 @@ IPAddress ntpServerIP;
unsigned int ntpLocalPort = 2390;
#define NTP_PACKET_SIZE 48
//string temp buffer
//string temp buffer (now stored in stack locally)
#define OMAX 2048
char obuf[OMAX];
char* obuf;
uint16_t olen = 0;
String messageHead, messageSub;

View File

@ -574,16 +574,12 @@ void savePreset(byte index)
}
String loadMacro(byte index)
char* loadMacro(byte index)
{
index-=1;
String m="";
char m[65];
if (index > 15) return m;
for (int i = 1024+64*index; i < 1088+64*index; i++)
{
if (EEPROM.read(i) == 0) break;
m += char(EEPROM.read(i));
}
readStringFromEEPROM(1024+64*index, m, 64);
return m;
}

View File

@ -3,9 +3,10 @@
*/
//build XML response to HTTP /win API request
void XML_response(AsyncWebServerRequest *request, bool includeTheme)
char* XML_response(AsyncWebServerRequest *request, bool includeTheme)
{
olen = 0;
char sbuf[1024];
olen = 0; obuf = sbuf;
oappend("<?xml version=\"1.0\" ?><vs><ac>");
oappendi((nightlightActive && nightlightFade) ? briT : bri);
oappend("</ac>");
@ -97,7 +98,8 @@ void XML_response(AsyncWebServerRequest *request, bool includeTheme)
oappend("</cf></th>");
}
oappend("</vs>");
if (request != nullptr) request->send(200, "text/xml", obuf);
if (request != nullptr) request->send(200, "text/xml", sbuf);
return sbuf;
}
//append a numeric setting to string buffer
@ -155,13 +157,15 @@ void sappends(char stype, char* key, char* val)
//get values for settings form in javascript
void getSettingsJS(byte subPage)
char* getSettingsJS(byte subPage)
{
//0: menu 1: wifi 2: leds 3: ui 4: sync 5: time 6: sec
DEBUG_PRINT("settings resp");
DEBUG_PRINTLN(subPage);
olen = 0; obuf[0] = 0; //clear buffer
if (subPage <1 || subPage >6) return;
char sbuf[2048];
olen = 0; obuf = sbuf;
if (subPage <1 || subPage >6) return sbuf;
if (subPage == 1) {
sappends('s',"CS",clientSSID);
@ -345,7 +349,7 @@ void getSettingsJS(byte subPage)
for (int i=1;i<17;i++)
{
sprintf(k+1,"%i",i);
sappends('s',k,(char*)loadMacro(i).c_str());
sappends('s',k,loadMacro(i));
}
sappend('v',"MB",macroBoot);
@ -381,6 +385,7 @@ void getSettingsJS(byte subPage)
oappend(") OK\";");
}
oappend("}</script>");
return sbuf;
}

View File

@ -135,13 +135,13 @@ void handleNotifications()
if (packetSize > UDP_IN_MAXSIZE || packetSize < 3) return;
realtimeIP = rgbUdp.remoteIP();
DEBUG_PRINTLN(rgbUdp.remoteIP());
olen = 0;
rgbUdp.read(obuf, packetSize);
uint8_t lbuf[packetSize];
rgbUdp.read(lbuf, packetSize);
arlsLock(realtimeTimeoutMs);
uint16_t id = 0;
for (uint16_t i = 0; i < packetSize -2; i += 3)
{
setRealtimePixel(id, obuf[i], obuf[i+1], obuf[i+2], 0);
setRealtimePixel(id, lbuf[i], lbuf[i+1], lbuf[i+2], 0);
id++; if (id >= ledCount) break;
}
@ -153,9 +153,8 @@ void handleNotifications()
if (packetSize > UDP_IN_MAXSIZE) return;
if(packetSize && notifierUdp.remoteIP() != WiFi.localIP()) //don't process broadcasts we send ourselves
{
olen = 0;
notifierUdp.read(obuf, packetSize);
char* udpIn = obuf;
uint8_t udpIn[packetSize];
notifierUdp.read(udpIn, packetSize);
//wled notifier, block if realtime packets active
if (udpIn[0] == 0 && !realtimeActive && receiveNotifications)

View File

@ -88,10 +88,9 @@ void publishMqtt()
strcat(subuf, "/c");
mqtt->publish(subuf, 0, true, s);
XML_response(nullptr, false);
strcpy(subuf, mqttDeviceTopic);
strcat(subuf, "/v");
mqtt->publish(subuf, 0, true, obuf);
mqtt->publish(subuf, 0, true, XML_response(nullptr, false));
}

View File

@ -266,6 +266,8 @@ String msgProcessor(const String& var)
void serveMessage(AsyncWebServerRequest* request, uint16_t code, String headl, String subl="", byte optionT=255)
{
char buf[512];
obuf = buf;
olen = 0;
getCSSColors();
messageHead = headl;
@ -278,7 +280,11 @@ void serveMessage(AsyncWebServerRequest* request, uint16_t code, String headl, S
String settingsProcessor(const String& var)
{
if (var == "CSS") return String(obuf);
if (var == "CSS") {
char* buf = getSettingsJS(optionType);
getCSSColors();
return buf;
}
if (var == "SCSS") return String(PAGE_settingsCss);
return String();
}
@ -306,10 +312,8 @@ void serveSettings(AsyncWebServerRequest* request)
#ifdef WLED_DISABLE_MOBILE_UI //disable welcome page if not enough storage
if (subPage == 255) {serveIndex(request); return;}
#endif
getSettingsJS(subPage);
getCSSColors();
optionType = subPage;
switch (subPage)
{