Merge branch 'mdev' into audio_fastpath

This commit is contained in:
Frank
2023-05-30 20:44:10 +02:00
8 changed files with 980 additions and 940 deletions

View File

@@ -158,7 +158,7 @@ void ShtUsermod::cleanup()
* @return void
*/
void ShtUsermod::publishTemperatureAndHumidityViaMqtt() {
#ifdef WLED_ENABLED_MQTT
#ifdef WLED_ENABLE_MQTT
if (!WLED_MQTT_CONNECTED) return;
char buf[128];
@@ -179,7 +179,7 @@ void ShtUsermod::publishTemperatureAndHumidityViaMqtt() {
* @return void
*/
void ShtUsermod::publishHomeAssistantAutodiscovery() {
#ifdef WLED_ENABLED_MQTT
#ifdef WLED_ENABLE_MQTT
if (!WLED_MQTT_CONNECTED) return;
char json_str[1024], buf[128];
@@ -225,7 +225,7 @@ void ShtUsermod::publishHomeAssistantAutodiscovery() {
*
* @return void
*/
#ifdef WLED_ENABLED_MQTT
#ifdef WLED_ENABLE_MQTT
void ShtUsermod::appendDeviceToMqttDiscoveryMessage(JsonDocument& root) {
JsonObject device = root.createNestedObject(F("dev"));
device[F("ids")] = escapedMac.c_str();
@@ -339,7 +339,7 @@ void ShtUsermod::loop()
* @return void
*/
void ShtUsermod::onMqttConnect(bool sessionPresent) {
#ifdef WLED_ENABLED_MQTT
#ifdef WLED_ENABLE_MQTT
if (haMqttDiscovery && !haMqttDiscoveryDone) publishHomeAssistantAutodiscovery();
#endif
}

View File

@@ -394,7 +394,8 @@ typedef struct Segment {
uint16_t aux0; // custom var
uint16_t aux1; // custom var
byte* data; // effect data pointer
CRGB* leds; // local leds[] array (may be a pointer to global)
CRGB* ledsrgb; // local leds[] array (may be a pointer to global) //WLEDMM rename to ledsrgb to search on them (temp?)
uint16_t ledsrgbSize; //WLEDMM
static CRGB *_globalLeds; // global leds[] array
static uint16_t maxWidth, maxHeight; // these define matrix width & height (max. segment dimensions)
void *jMap = nullptr; //WLEDMM jMap
@@ -479,7 +480,8 @@ typedef struct Segment {
aux0(0),
aux1(0),
data(nullptr),
leds(nullptr),
ledsrgb(nullptr),
ledsrgbSize(0), //WLEDMM
_capabilities(0),
_dataLen(0),
_t(nullptr)
@@ -497,13 +499,13 @@ typedef struct Segment {
~Segment() {
//#ifdef WLED_DEBUG
//Serial.print(F("Destroying segment:"));
//if (name) Serial.printf(" %s (%p)", name, name);
//if (data) Serial.printf(" %d (%p)", (int)_dataLen, data);
//if (leds) Serial.printf(" [%u]", length()*sizeof(CRGB));
//Serial.println();
Serial.print(F("Destroying segment:"));
if (name) Serial.printf(" %s (%p)", name, name);
if (data) Serial.printf(" %d (%p)", (int)_dataLen, data);
if (ledsrgb) Serial.printf(" [%u]", length()*sizeof(CRGB));
Serial.println();
//#endif
if (!Segment::_globalLeds && leds) free(leds);
if (!Segment::_globalLeds && ledsrgb) free(ledsrgb);
if (name) delete[] name;
if (_t) delete _t;
deallocateData();
@@ -513,7 +515,7 @@ typedef struct Segment {
Segment& operator= (Segment &&orig) noexcept; // move assignment
#ifdef WLED_DEBUG
size_t getSize() const { return sizeof(Segment) + (data?_dataLen:0) + (name?strlen(name):0) + (_t?sizeof(Transition):0) + (!Segment::_globalLeds && leds?sizeof(CRGB)*10000:0); }
size_t getSize() const { return sizeof(Segment) + (data?_dataLen:0) + (name?strlen(name):0) + (_t?sizeof(Transition):0) + (!Segment::_globalLeds && ledsrgb?sizeof(CRGB)*length():0); }
#endif
inline bool getOption(uint8_t n) const { return ((options >> n) & 0x01); }
@@ -532,6 +534,8 @@ typedef struct Segment {
static uint16_t getUsedSegmentData(void) { return _usedSegmentData; }
static void addUsedSegmentData(int len) { _usedSegmentData += len; }
void allocLeds(); //WLEDMM
void set(uint16_t i1, uint16_t i2, uint8_t grp=1, uint8_t spc=0, uint16_t ofs=UINT16_MAX, uint16_t i1Y=0, uint16_t i2Y=1);
bool setColor(uint8_t slot, uint32_t c); //returns true if changed
void setCCT(uint16_t k);

View File

@@ -206,7 +206,7 @@ void IRAM_ATTR_YN Segment::setPixelColorXY(int x, int y, uint32_t col) //WLEDMM:
if (Segment::maxHeight==1) return; // not a matrix set-up
if (x >= virtualWidth() || y >= virtualHeight() || x<0 || y<0) return; // if pixel would fall out of virtual segment just exit
if (leds) leds[XY(x,y)] = col;
if (ledsrgb) ledsrgb[XY(x,y)] = col;
uint8_t _bri_t = currentBri(on ? opacity : 0);
if (!_bri_t && !transitional) return;
@@ -302,7 +302,7 @@ void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa, bool fast
// returns RGBW values of pixel
uint32_t Segment::getPixelColorXY(uint16_t x, uint16_t y) {
int i = XY(x,y);
if (leds) return RGBW32(leds[i].r, leds[i].g, leds[i].b, 0);
if (ledsrgb) return RGBW32(ledsrgb[i].r, ledsrgb[i].g, ledsrgb[i].b, 0);
if (reverse ) x = virtualWidth() - x - 1;
if (reverse_y) y = virtualHeight() - y - 1;
if (transpose) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed

View File

@@ -83,40 +83,55 @@ uint16_t Segment::maxHeight = 1;
// copy constructor
Segment::Segment(const Segment &orig) {
//DEBUG_PRINTLN(F("-- Copy segment constructor --"));
memcpy((void*)this, (void*)&orig, sizeof(Segment));
USER_PRINTLN(F("-- Copy segment constructor --"));
memcpy((void*)this, (void*)&orig, sizeof(Segment)); //WLEDMM copy to this
name = nullptr;
data = nullptr;
_dataLen = 0;
_t = nullptr;
if (leds && !Segment::_globalLeds) leds = nullptr;
if (ledsrgb && !Segment::_globalLeds) ledsrgb = nullptr; //WLEDMM constructor so there was nothing. ledsrgb not freed as still used by orig!
if (orig.name) { name = new char[strlen(orig.name)+1]; if (name) strcpy(name, orig.name); }
if (orig.data) { if (allocateData(orig._dataLen)) memcpy(data, orig.data, orig._dataLen); }
if (orig._t) { _t = new Transition(orig._t->_dur, orig._t->_briT, orig._t->_cctT, orig._t->_colorT); }
if (orig.leds && !Segment::_globalLeds) { leds = (CRGB*)malloc(sizeof(CRGB)*10000); if (leds) memcpy(leds, orig.leds, sizeof(CRGB)*10000); }
if (orig.ledsrgb && !Segment::_globalLeds) { allocLeds(); if (ledsrgb) memcpy(ledsrgb, orig.ledsrgb, sizeof(CRGB)*length()); }
jMap = nullptr; //WLEDMM jMap
}
//WLEDMM: recreate ledsrgb if more space needed (will not free ledsrgb!)
void Segment::allocLeds() {
if (!ledsrgb || sizeof(CRGB)*length() > ledsrgbSize) {
USER_PRINTF("allocLeds %d from %d\n", sizeof(CRGB)*length(), ledsrgb?ledsrgbSize:0);
ledsrgb = (CRGB*)malloc(sizeof(CRGB)*length());
ledsrgbSize = ledsrgb?sizeof(CRGB)*length():0;
}
else {
USER_PRINTF("reuse Leds %d from %d\n", sizeof(CRGB)*length(), ledsrgb?ledsrgbSize:0);
}
}
// move constructor
Segment::Segment(Segment &&orig) noexcept {
//DEBUG_PRINTLN(F("-- Move segment constructor --"));
USER_PRINTLN(F("-- Move segment constructor --"));
memcpy((void*)this, (void*)&orig, sizeof(Segment));
orig.name = nullptr;
orig.data = nullptr;
orig._dataLen = 0;
orig._t = nullptr;
orig.leds = nullptr;
orig.ledsrgb = nullptr; //WLEDMM: do not free as moved to here (constructor so there where no leds)
orig.jMap = nullptr; //WLEDMM jMap
}
// copy assignment
Segment& Segment::operator= (const Segment &orig) {
//DEBUG_PRINTLN(F("-- Copying segment --"));
USER_PRINTLN(F("-- Copying segment --"));
if (this != &orig) {
// clean destination
if (name) delete[] name;
if (_t) delete _t;
if (leds && !Segment::_globalLeds) free(leds);
// WLEDMM reuse leds instead of removing themn
// if (ledsrgb && !Segment::_globalLeds) free(ledsrgb); //WLEDMM: nullify below!
CRGB* oldLeds = ledsrgb;
uint16_t oldLedsSize = ledsrgbSize;
deallocateData();
// copy source
memcpy((void*)this, (void*)&orig, sizeof(Segment));
@@ -125,12 +140,12 @@ Segment& Segment::operator= (const Segment &orig) {
data = nullptr;
_dataLen = 0;
_t = nullptr;
if (!Segment::_globalLeds) leds = nullptr;
if (!Segment::_globalLeds) {ledsrgb = oldLeds; ledsrgbSize = oldLedsSize;};// WLEDMM reuse leds instead of ledsrgb = nullptr;
// copy source data
if (orig.name) { name = new char[strlen(orig.name)+1]; if (name) strcpy(name, orig.name); }
if (orig.data) { if (allocateData(orig._dataLen)) memcpy(data, orig.data, orig._dataLen); }
if (orig._t) { _t = new Transition(orig._t->_dur, orig._t->_briT, orig._t->_cctT, orig._t->_colorT); }
if (orig.leds && !Segment::_globalLeds) { leds = (CRGB*)malloc(sizeof(CRGB)*10000); if (leds) memcpy(leds, orig.leds, sizeof(CRGB)*10000); }
if (orig.ledsrgb && !Segment::_globalLeds) { allocLeds(); if (ledsrgb) memcpy(ledsrgb, orig.ledsrgb, sizeof(CRGB)*length()); }
jMap = nullptr; //WLEDMM jMap
}
return *this;
@@ -138,18 +153,18 @@ Segment& Segment::operator= (const Segment &orig) {
// move assignment
Segment& Segment::operator= (Segment &&orig) noexcept {
//DEBUG_PRINTLN(F("-- Moving segment --"));
USER_PRINTLN(F("-- Moving segment --"));
if (this != &orig) {
if (name) delete[] name; // free old name
deallocateData(); // free old runtime data
if (_t) delete _t;
if (leds && !Segment::_globalLeds) free(leds);
if (ledsrgb && !Segment::_globalLeds) free(ledsrgb); //WLEDMM: not needed anymore as we will use leds from copy. no need to nullify ledsrgb as it gets new value in memcpy
memcpy((void*)this, (void*)&orig, sizeof(Segment));
orig.name = nullptr;
orig.data = nullptr;
orig._dataLen = 0;
orig._t = nullptr;
orig.leds = nullptr;
orig.ledsrgb = nullptr; //WLEDMM: do not free as moved to here
orig.jMap = nullptr; //WLEDMM jMap
}
return *this;
@@ -190,7 +205,8 @@ void Segment::deallocateData() {
*/
void Segment::resetIfRequired() {
if (reset) {
if (leds && !Segment::_globalLeds) { free(leds); leds = nullptr; }
//WLEDMM no need to free leds as we will reuse them
// if (ledsrgb && !Segment::_globalLeds) { free(ledsrgb); ledsrgb = nullptr; }
if (transitional && _t) { transitional = false; delete _t; _t = nullptr; }
deallocateData();
next_time = 0; step = 0; call = 0; aux0 = 0; aux1 = 0;
@@ -202,17 +218,17 @@ void Segment::setUpLeds() {
// deallocation happens in resetIfRequired() as it is called when segment changes or in destructor
if (Segment::_globalLeds)
#ifndef WLED_DISABLE_2D
leds = &Segment::_globalLeds[start + startY*Segment::maxWidth];
ledsrgb = &Segment::_globalLeds[start + startY*Segment::maxWidth];
#else
leds = &Segment::_globalLeds[start];
#endif
else if ((leds == nullptr) /*&& (length() > 0)*/) { //softhack007 quickfix - avoid malloc(0) which is undefined behaviour (should not happen, but i've seen it)
else if ((ledsrgb == nullptr) && (length() > 0)) { //softhack007 quickfix - avoid malloc(0) which is undefined behaviour (should not happen, but i've seen it)
//#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM)
//if (psramFound())
// leds = (CRGB*)ps_malloc(sizeof(CRGB)*10000 /*length()*/); // softhack007 disabled; putting leds into psram leads to horrible slowdown on WROVER boards
// ledsrgb = (CRGB*)ps_malloc(sizeof(CRGB)*length()); // softhack007 disabled; putting leds into psram leads to horrible slowdown on WROVER boards
//else
//#endif
leds = (CRGB*)malloc(sizeof(CRGB)*10000 /*length()*/);
allocLeds(); //WLEDMM
}
}
@@ -881,7 +897,7 @@ void IRAM_ATTR_YN Segment::setPixelColor(int i, uint32_t col) //WLEDMM: IRAM_ATT
}
#endif
if (leds) leds[i] = col;
if (ledsrgb) ledsrgb[i] = col;
uint16_t len = length();
uint8_t _bri_t = currentBri(on ? opacity : 0);
@@ -1007,7 +1023,7 @@ uint32_t Segment::getPixelColor(int i)
}
#endif
if (leds) return RGBW32(leds[i].r, leds[i].g, leds[i].b, 0);
if (ledsrgb) return RGBW32(ledsrgb[i].r, ledsrgb[i].g, ledsrgb[i].b, 0);
if (reverse) i = virtualLength() - i - 1;
i *= groupLength();
@@ -1864,6 +1880,7 @@ void WS2812FX::restartRuntime() {
}
void WS2812FX::resetSegments(bool boundsOnly) { //WLEDMM add boundsonly
USER_PRINTF("resetSegments %d %dx%d\n", boundsOnly, Segment::maxWidth, Segment::maxHeight);
if (!boundsOnly) {
_segments.clear(); // destructs all Segment as part of clearing
#ifndef WLED_DISABLE_2D
@@ -1875,6 +1892,7 @@ void WS2812FX::resetSegments(bool boundsOnly) { //WLEDMM add boundsonly
_mainSegment = 0;
} else { //WLEDMM boundsonly
for (segment &seg : _segments) {
bool recreateLeds = false;
#ifndef WLED_DISABLE_2D
seg.start = 0;
seg.stop = Segment::maxWidth;
@@ -1884,9 +1902,9 @@ void WS2812FX::resetSegments(bool boundsOnly) { //WLEDMM add boundsonly
seg.start = 0;
seg.stop = _length;
#endif
seg.allocLeds();
}
}
}
void WS2812FX::makeAutoSegments(bool forceReset) {

View File

@@ -1082,8 +1082,8 @@ function ddpAll() {
ins.push(output);
start+=node.count;
}
console.log("ins", ins);
callNode("4.3.2.1", "cfg", {"hw":{"led":{"ins":ins}}});
console.log("ins", lastinfo.ip,JSON.stringify({"hw":{"led":{"ins":ins}}}));
callNode(lastinfo.ip, "cfg", {"hw":{"led":{"ins":ins}}});
}
function populateNodes(i,n)
@@ -1103,7 +1103,7 @@ function populateNodes(i,n)
//WLEDMM add this node to nodes
let thisNode = {};
thisNode.name = i.name;
thisNode.ip = locip; //not working for ap node yet...
thisNode.ip = i.ip;
n.nodes.push(thisNode);
n.nodes.sort((a,b) => (a.name).localeCompare(b.name));

File diff suppressed because it is too large Load Diff

View File

@@ -53,6 +53,7 @@ void onMqttConnect(bool sessionPresent)
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
static char *payloadStr;
DEBUG_PRINT(F("MQTT msg: "));
DEBUG_PRINTLN(topic);
@@ -62,11 +63,22 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
DEBUG_PRINTLN(F("no payload -> leave"));
return;
}
//make a copy of the payload to 0-terminate it
char* payloadStr = new char[len+1];
if (payloadStr == nullptr) return; //no mem
strncpy(payloadStr, payload, len);
payloadStr[len] = '\0';
if (index == 0) { // start (1st partial packet or the only packet)
if (payloadStr) delete[] payloadStr; // fail-safe: release buffer
payloadStr = new char[total+1]; // allocate new buffer
}
if (payloadStr == nullptr) return; // buffer not allocated
// copy (partial) packet to buffer and 0-terminate it if it is last packet
char* buff = payloadStr + index;
memcpy(buff, payload, len);
if (index + len >= total) { // at end
payloadStr[total] = '\0'; // terminate c style string
} else {
DEBUG_PRINTLN(F("Partial packet received."));
return; // process next packet
}
DEBUG_PRINTLN(payloadStr);
size_t topicPrefixLen = strlen(mqttDeviceTopic);
@@ -80,6 +92,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
// Non-Wled Topic used here. Probably a usermod subscribed to this topic.
usermods.onMqttMessage(topic, payloadStr);
delete[] payloadStr;
payloadStr = nullptr;
return;
}
}
@@ -87,16 +100,20 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
//Prefix is stripped from the topic at this point
if (strcmp_P(topic, PSTR("/col")) == 0) {
colorFromDecOrHexString(col, (char*)payloadStr);
colorFromDecOrHexString(col, payloadStr);
colorUpdated(CALL_MODE_DIRECT_CHANGE);
} else if (strcmp_P(topic, PSTR("/api")) == 0) {
if (!requestJSONBufferLock(15)) { delete[] payloadStr; return; }
if (payload[0] == '{') { //JSON API
if (!requestJSONBufferLock(15)) {
delete[] payloadStr;
payloadStr = nullptr;
return;
}
if (payloadStr[0] == '{') { //JSON API
deserializeJson(doc, payloadStr);
deserializeState(doc.as<JsonObject>());
} else { //HTTP API
String apireq = "win"; apireq += '&'; // reduce flash string usage
apireq += (char*)payloadStr;
apireq += payloadStr;
handleSet(nullptr, apireq);
}
releaseJSONBufferLock();
@@ -108,6 +125,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
parseMQTTBriPayload(payloadStr);
}
delete[] payloadStr;
payloadStr = nullptr;
}

View File

@@ -415,7 +415,7 @@ void getSettingsJS(AsyncWebServerRequest* request, byte subPage, char* dest) //W
char rf[4] = "RF"; rf[2] = 48+s; rf[3] = 0; //off refresh
char aw[4] = "AW"; aw[2] = 48+s; aw[3] = 0; //auto white mode
char wo[4] = "WO"; wo[2] = 48+s; wo[3] = 0; //swap channels
char sp[4] = "SP"; sp[2] = 48+s; sp[3] = 0; //bus clock speed
// char sp[4] = "SP"; sp[2] = 48+s; sp[3] = 0; //bus clock speed WLEDMM to do bus
oappend(SET_F("addLEDs(1);"));
uint8_t pins[5];
uint8_t nPins = bus->getPins(pins);