mirror of
https://github.com/wled/WLED.git
synced 2025-04-19 12:27:17 +00:00
Some optimisations and fixes
This commit is contained in:
parent
abb08e2aaf
commit
e48a1ec814
@ -160,9 +160,9 @@ class UsermodBattery : public Usermod
|
||||
device[F("sw")] = versionString;
|
||||
|
||||
sprintf_P(buf, PSTR("homeassistant/%s/%s/%s/config"), type, mqttClientID, uid);
|
||||
DEBUG_PRINTLN(buf);
|
||||
DEBUGUM_PRINTLN(buf);
|
||||
size_t payload_size = serializeJson(doc, json_str);
|
||||
DEBUG_PRINTLN(json_str);
|
||||
DEBUGUM_PRINTLN(json_str);
|
||||
|
||||
mqtt->publish(buf, 0, true, json_str, payload_size);
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ void PIRsensorSwitch::switchStrip(bool switchOn)
|
||||
if (m_offOnly && bri && (switchOn || (!PIRtriggered && !switchOn))) return; //if lights on and off only, do nothing
|
||||
if (PIRtriggered && switchOn) return; //if already on and triggered before, do nothing
|
||||
PIRtriggered = switchOn;
|
||||
DEBUGUM_PRINT(F("PIR: strip=")); DEBUGUM_PRINTLN(switchOn?"on":"off");
|
||||
DEBUGUM_PRINTF_P(PSTR("PIR: strip=%s\n"), switchOn?"on":"off");
|
||||
if (switchOn) {
|
||||
if (m_onPreset) {
|
||||
if (currentPlaylist>0 && !offMode) {
|
||||
@ -384,7 +384,7 @@ void PIRsensorSwitch::setup()
|
||||
#endif
|
||||
sensorPinState[i] = digitalRead(PIRsensorPin[i]);
|
||||
} else {
|
||||
DEBUGUM_PRINT(F("PIRSensorSwitch pin ")); DEBUGUM_PRINTLN(i); DEBUGUM_PRINTLN(F(" allocation failed."));
|
||||
DEBUGUM_PRINTF_P(PSTR("PIRSensorSwitch: pin %d allocation failed.\n"), i);
|
||||
PIRsensorPin[i] = -1; // allocation failed
|
||||
}
|
||||
}
|
||||
@ -471,7 +471,7 @@ void PIRsensorSwitch::addToJsonInfo(JsonObject &root)
|
||||
|
||||
void PIRsensorSwitch::onStateChange(uint8_t mode) {
|
||||
if (!initDone) return;
|
||||
DEBUGUM_PRINT(F("PIR: offTimerStart=")); DEBUGUM_PRINTLN(offTimerStart);
|
||||
DEBUGUM_PRINTF_P(PSTR("PIR: offTimerStart=%lu\n"), offTimerStart);
|
||||
if (m_override && PIRtriggered && offTimerStart) { // debounce
|
||||
// checking PIRtriggered and offTimerStart will prevent cancellation upon On trigger
|
||||
DEBUGUM_PRINTLN(F("PIR: Canceled."));
|
||||
@ -561,12 +561,12 @@ bool PIRsensorSwitch::readFromConfig(JsonObject &root)
|
||||
|
||||
if (!initDone) {
|
||||
// reading config prior to setup()
|
||||
DEBUGUM_PRINTLN(F(" config loaded."));
|
||||
DEBUGUM_PRINTLN(F(": config loaded."));
|
||||
} else {
|
||||
for (int i = 0; i < PIR_SENSOR_MAX_SENSORS; i++)
|
||||
if (oldPin[i] >= 0) PinManager::deallocatePin(oldPin[i], PinOwner::UM_PIR);
|
||||
setup();
|
||||
DEBUGUM_PRINTLN(F(" config (re)loaded."));
|
||||
DEBUGUM_PRINTLN(F(": config (re)loaded."));
|
||||
}
|
||||
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
||||
return !(pins.isNull() || pins.size() != PIR_SENSOR_MAX_SENSORS);
|
||||
|
@ -122,8 +122,7 @@ float UsermodTemperature::readDallas() {
|
||||
if (OneWire::crc8(data,8) != data[8]) {
|
||||
DEBUGUM_PRINTLN(F("CRC error reading temperature."));
|
||||
for (unsigend i=0; i < 9; i++) DEBUGUM_PRINTF_P(PSTR("0x%02X "), data[i]);
|
||||
DEBUGUM_PRINT(F(" => "));
|
||||
DEBUGUM_PRINTF_P(PSTR("0x%02X\n"), OneWire::crc8(data,8));
|
||||
DEBUGUM_PRINTF_P(PSTR(" => 0x%02X\n"), OneWire::crc8(data,8));
|
||||
}
|
||||
#endif
|
||||
switch(sensorFound) {
|
||||
@ -161,8 +160,7 @@ void UsermodTemperature::readTemperature() {
|
||||
lastMeasurement = millis();
|
||||
waitingForConversion = false;
|
||||
//DEBUGUM_PRINTF_P(PSTR("Read temperature %2.1f.\n"), temperature); // does not work properly on 8266
|
||||
DEBUGUM_PRINT(F("Read temperature "));
|
||||
DEBUGUM_PRINTLN(temperature);
|
||||
DEBUGUM_PRINTF_P(PSTR("Read temperature %3.1f\n"), (double)temperature);
|
||||
}
|
||||
|
||||
bool UsermodTemperature::findSensor() {
|
||||
@ -415,12 +413,12 @@ bool UsermodTemperature::readFromConfig(JsonObject &root) {
|
||||
if (!initDone) {
|
||||
// first run: reading from cfg.json
|
||||
temperaturePin = newTemperaturePin;
|
||||
DEBUGUM_PRINTLN(F(" config loaded."));
|
||||
DEBUGUM_PRINTLN(F(": config loaded."));
|
||||
} else {
|
||||
DEBUGUM_PRINTLN(F(" config (re)loaded."));
|
||||
DEBUGUM_PRINTLN(F(": config (re)loaded."));
|
||||
// changing paramters from settings page
|
||||
if (newTemperaturePin != temperaturePin) {
|
||||
DEBUGUM_PRINTLN(F("Re-init temperature."));
|
||||
DEBUGUM_PRINTLN(F(" Re-init temperature."));
|
||||
// deallocate pin and release memory
|
||||
delete oneWire;
|
||||
PinManager::deallocatePin(temperaturePin, PinOwner::UM_Temperature);
|
||||
|
@ -173,8 +173,7 @@ class BobLightUsermod : public Usermod {
|
||||
numLights = lightcount;
|
||||
|
||||
#if WLED_DEBUG_USERMODS
|
||||
DEBUGUM_PRINTLN(F("Fill light data: "));
|
||||
DEBUGUM_PRINTF_P(PSTR(" lights %d\n"), numLights);
|
||||
DEBUGUM_PRINTF_P(PSTR("Fill light data:\n lights %d\n"), numLights);
|
||||
for (int i=0; i<numLights; i++) {
|
||||
DEBUGUM_PRINTF_P(PSTR(" light %s scan %2.1f %2.1f %2.1f %2.1f\n"), lights[i].lightname, lights[i].vscan[0], lights[i].vscan[1], lights[i].hscan[0], lights[i].hscan[1]);
|
||||
}
|
||||
@ -190,8 +189,7 @@ class BobLightUsermod : public Usermod {
|
||||
void setup() override {
|
||||
uint16_t totalLights = bottom + left + top + right;
|
||||
if ( totalLights > strip.getLengthTotal() ) {
|
||||
DEBUGUM_PRINTLN(F("BobLight: Too many lights."));
|
||||
DEBUGUM_PRINTF_P(PSTR("%d+%d+%d+%d>%d\n"), bottom, left, top, right, strip.getLengthTotal());
|
||||
DEBUGUM_PRINTF_P(PSTR("BobLight: Too many lights.\n%d+%d+%d+%d>%d\n"), bottom, left, top, right, strip.getLengthTotal());
|
||||
totalLights = strip.getLengthTotal();
|
||||
top = bottom = (uint16_t) roundf((float)totalLights * 16.0f / 50.0f);
|
||||
left = right = (uint16_t) roundf((float)totalLights * 9.0f / 50.0f);
|
||||
|
@ -399,7 +399,7 @@ void MultiRelay::switchRelay(uint8_t relay, bool mode) {
|
||||
state |= (_relay[i].invert ? !_relay[i].state : _relay[i].state) << pin; // fill relay states for all pins
|
||||
}
|
||||
IOexpanderWrite(addrPcf8574, state);
|
||||
DEBUGUM_PRINT(F("Writing to PCF8574: ")); DEBUGUM_PRINTLN(state);
|
||||
DEBUGUM_PRINTF_P(PSTR("Writing to PCF8574: %d\n"), (int)state);
|
||||
} else if (_relay[relay].pin < 100) {
|
||||
pinMode(_relay[relay].pin, OUTPUT);
|
||||
digitalWrite(_relay[relay].pin, _relay[relay].invert ? !_relay[relay].state : _relay[relay].state);
|
||||
@ -781,8 +781,8 @@ bool MultiRelay::readFromConfig(JsonObject &root) {
|
||||
int8_t oldPin[MULTI_RELAY_MAX_RELAYS];
|
||||
|
||||
JsonObject top = root[FPSTR(_name)];
|
||||
DEBUGUM_PRINT(FPSTR(_name));
|
||||
if (top.isNull()) {
|
||||
DEBUGUM_PRINT(FPSTR(_name));
|
||||
DEBUGUM_PRINTLN(F(": No config found. (Using defaults.)"));
|
||||
return false;
|
||||
}
|
||||
@ -809,10 +809,9 @@ bool MultiRelay::readFromConfig(JsonObject &root) {
|
||||
_relay[i].delay = min(600,max(0,abs((int)_relay[i].delay))); // bounds checking max 10min
|
||||
}
|
||||
|
||||
DEBUGUM_PRINT(FPSTR(_name));
|
||||
if (!initDone) {
|
||||
// reading config prior to setup()
|
||||
DEBUGUM_PRINTLN(F(" config loaded."));
|
||||
DEBUGUM_PRINTLN(F(": config loaded."));
|
||||
} else {
|
||||
// deallocate all pins 1st
|
||||
for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++)
|
||||
@ -821,7 +820,7 @@ bool MultiRelay::readFromConfig(JsonObject &root) {
|
||||
}
|
||||
// allocate new pins
|
||||
setup();
|
||||
DEBUGUM_PRINTLN(F(" config (re)loaded."));
|
||||
DEBUGUM_PRINTLN(F(": config (re)loaded."));
|
||||
}
|
||||
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
||||
return !top[FPSTR(_pcf8574)].isNull();
|
||||
|
@ -1268,8 +1268,8 @@ bool FourLineDisplayUsermod::readFromConfig(JsonObject& root) {
|
||||
int8_t oldPin[3]; for (unsigned i=0; i<3; i++) oldPin[i] = ioPin[i];
|
||||
|
||||
JsonObject top = root[FPSTR(_name)];
|
||||
DEBUGUM_PRINT(FPSTR(_name));
|
||||
if (top.isNull()) {
|
||||
DEBUGUM_PRINT(FPSTR(_name));
|
||||
DEBUGUM_PRINTLN(F(": No config found. (Using defaults.)"));
|
||||
return false;
|
||||
}
|
||||
@ -1293,13 +1293,12 @@ bool FourLineDisplayUsermod::readFromConfig(JsonObject& root) {
|
||||
else
|
||||
ioFrequency = min(3400, max(100, (int)(top[FPSTR(_busClkFrequency)] | ioFrequency/1000))) * 1000; // limit frequency
|
||||
|
||||
DEBUGUM_PRINT(FPSTR(_name));
|
||||
if (!initDone) {
|
||||
// first run: reading from cfg.json
|
||||
type = newType;
|
||||
DEBUGUM_PRINTLN(F(" config loaded."));
|
||||
DEBUGUM_PRINTLN(F(": config loaded."));
|
||||
} else {
|
||||
DEBUGUM_PRINTLN(F(" config (re)loaded."));
|
||||
DEBUGUM_PRINTLN(F(": config (re)loaded."));
|
||||
// changing parameters from settings page
|
||||
bool pinsChanged = false;
|
||||
for (unsigned i=0; i<3; i++) if (ioPin[i] != oldPin[i]) { pinsChanged = true; break; }
|
||||
|
@ -392,13 +392,13 @@ byte RotaryEncoderUIUsermod::readPin(uint8_t pin) {
|
||||
* modes_alpha_indexes and palettes_alpha_indexes.
|
||||
*/
|
||||
void RotaryEncoderUIUsermod::sortModesAndPalettes() {
|
||||
DEBUGUM_PRINT(F("Sorting modes: ")); DEBUGUM_PRINTLN(strip.getModeCount());
|
||||
DEBUGUM_PRINTF_P(PSTR("Sorting modes: %d\n"), (int)strip.getModeCount());
|
||||
//modes_qstrings = re_findModeStrings(JSON_mode_names, strip.getModeCount());
|
||||
modes_qstrings = strip.getModeDataSrc();
|
||||
modes_alpha_indexes = re_initIndexArray(strip.getModeCount());
|
||||
re_sortModes(modes_qstrings, modes_alpha_indexes, strip.getModeCount(), MODE_SORT_SKIP_COUNT);
|
||||
|
||||
DEBUGUM_PRINT(F("Sorting palettes: ")); DEBUGUM_PRINT(strip.getPaletteCount()); DEBUGUM_PRINT('/'); DEBUGUM_PRINTLN(strip.customPalettes.size());
|
||||
DEBUGUM_PRINTF_P(PSTR("Sorting palettes: %u/%u"), (unsigned)strip.getPaletteCount(), strip.customPalettes.size());
|
||||
palettes_qstrings = re_findModeStrings(JSON_palette_names, strip.getPaletteCount());
|
||||
palettes_alpha_indexes = re_initIndexArray(strip.getPaletteCount());
|
||||
if (strip.customPalettes.size()) {
|
||||
@ -1102,8 +1102,8 @@ void RotaryEncoderUIUsermod::appendConfigData() {
|
||||
bool RotaryEncoderUIUsermod::readFromConfig(JsonObject &root) {
|
||||
// we look for JSON object: {"Rotary-Encoder":{"DT-pin":12,"CLK-pin":14,"SW-pin":13}}
|
||||
JsonObject top = root[FPSTR(_name)];
|
||||
DEBUGUM_PRINT(FPSTR(_name));
|
||||
if (top.isNull()) {
|
||||
DEBUGUM_PRINT(FPSTR(_name));
|
||||
DEBUGUM_PRINTLN(F(": No config found. (Using defaults.)"));
|
||||
return false;
|
||||
}
|
||||
@ -1124,29 +1124,28 @@ bool RotaryEncoderUIUsermod::readFromConfig(JsonObject &root) {
|
||||
usePcf8574 = top[FPSTR(_pcf8574)] | usePcf8574;
|
||||
addrPcf8574 = top[FPSTR(_pcfAddress)] | addrPcf8574;
|
||||
|
||||
DEBUGUM_PRINT(FPSTR(_name));
|
||||
if (!initDone) {
|
||||
// first run: reading from cfg.json
|
||||
pinA = newDTpin;
|
||||
pinB = newCLKpin;
|
||||
pinC = newSWpin;
|
||||
DEBUGUM_PRINTLN(F(" config loaded."));
|
||||
DEBUGUM_PRINTLN(F(": config loaded."));
|
||||
} else {
|
||||
DEBUGUM_PRINTLN(F(" config (re)loaded."));
|
||||
DEBUGUM_PRINTLN(F(": config (re)loaded."));
|
||||
// changing parameters from settings page
|
||||
if (pinA!=newDTpin || pinB!=newCLKpin || pinC!=newSWpin || pinIRQ!=newIRQpin) {
|
||||
if (oldPcf8574) {
|
||||
if (pinIRQ >= 0) {
|
||||
detachInterrupt(pinIRQ);
|
||||
PinManager::deallocatePin(pinIRQ, PinOwner::UM_RotaryEncoderUI);
|
||||
DEBUGUM_PRINTLN(F("Deallocated old IRQ pin."));
|
||||
DEBUGUM_PRINTLN(F(" Deallocated old IRQ pin."));
|
||||
}
|
||||
pinIRQ = newIRQpin<100 ? newIRQpin : -1; // ignore PCF8574 pins
|
||||
} else {
|
||||
PinManager::deallocatePin(pinA, PinOwner::UM_RotaryEncoderUI);
|
||||
PinManager::deallocatePin(pinB, PinOwner::UM_RotaryEncoderUI);
|
||||
PinManager::deallocatePin(pinC, PinOwner::UM_RotaryEncoderUI);
|
||||
DEBUGUM_PRINTLN(F("Deallocated old pins."));
|
||||
DEBUGUM_PRINTLN(F(" Deallocated old pins."));
|
||||
}
|
||||
pinA = newDTpin;
|
||||
pinB = newCLKpin;
|
||||
|
@ -89,8 +89,7 @@ void WS2812FX::setUpMatrix() {
|
||||
int8_t *gapTable = nullptr;
|
||||
|
||||
if (isFile && requestJSONBufferLock(20)) {
|
||||
DEBUGFX_PRINT(F("Reading LED gap from "));
|
||||
DEBUGFX_PRINTLN(fileName);
|
||||
DEBUGFX_PRINTF_P(PSTR("Reading LED gap from %s\n"), fileName);
|
||||
// read the array into global JSON buffer
|
||||
if (readObjectFromFile(fileName, nullptr, pDoc)) {
|
||||
// the array is similar to ledmap, except it has only 3 values:
|
||||
|
@ -163,8 +163,7 @@ bool IRAM_ATTR_YN Segment::allocateData(size_t len) {
|
||||
deallocateData(); // if the old buffer was smaller release it first
|
||||
if (Segment::getUsedSegmentData() + len > MAX_SEGMENT_DATA) {
|
||||
// not enough memory
|
||||
DEBUGFX_PRINT(F("!!! Effect RAM depleted: "));
|
||||
DEBUGFX_PRINTF_P(PSTR("%d/%d !!!\n"), len, Segment::getUsedSegmentData());
|
||||
DEBUGFX_PRINTF_P(PSTR("!!! Effect RAM depleted: %d/%d !!!\n"), len, Segment::getUsedSegmentData());
|
||||
errorFlag = ERR_NORAM;
|
||||
return false;
|
||||
}
|
||||
@ -492,10 +491,7 @@ void Segment::setUp(uint16_t i1, uint16_t i2, uint8_t grp, uint8_t spc, uint16_t
|
||||
}
|
||||
if (ofs < UINT16_MAX) offset = ofs;
|
||||
|
||||
DEBUGFX_PRINT(F("setUp segment: ")); DEBUGFX_PRINT(i1);
|
||||
DEBUGFX_PRINT(','); DEBUGFX_PRINT(i2);
|
||||
DEBUGFX_PRINT(F(" -> ")); DEBUGFX_PRINT(i1Y);
|
||||
DEBUGFX_PRINT(','); DEBUGFX_PRINTLN(i2Y);
|
||||
DEBUGFX_PRINTF_P(PSTR("setUp segment: %d,%d -> %d,%d\n"), (int)i1, (int)i2, (int)i1Y, (int)i2Y);
|
||||
markForReset();
|
||||
if (boundsUnchanged) return;
|
||||
|
||||
@ -1248,13 +1244,13 @@ void WS2812FX::finalizeInit() {
|
||||
// Pin should not be already allocated, read/only or defined for current bus
|
||||
while (PinManager::isPinAllocated(defPin[j]) || !PinManager::isPinOk(defPin[j],true)) {
|
||||
if (validPin) {
|
||||
DEBUG_PRINTLN(F("Some of the provided pins cannot be used to configure this LED output."));
|
||||
DEBUGFX_PRINTLN(F("Some of the provided pins cannot be used to configure this LED output."));
|
||||
defPin[j] = 1; // start with GPIO1 and work upwards
|
||||
validPin = false;
|
||||
} else if (defPin[j] < WLED_NUM_PINS) {
|
||||
defPin[j]++;
|
||||
} else {
|
||||
DEBUG_PRINTLN(F("No available pins left! Can't configure output."));
|
||||
DEBUGFX_PRINTLN(F("No available pins left! Can't configure output."));
|
||||
return;
|
||||
}
|
||||
// is the newly assigned pin already defined or used previously?
|
||||
@ -1780,8 +1776,7 @@ void WS2812FX::loadCustomPalettes() {
|
||||
|
||||
StaticJsonDocument<1536> pDoc; // barely enough to fit 72 numbers
|
||||
if (WLED_FS.exists(fileName)) {
|
||||
DEBUGFX_PRINT(F("Reading palette from "));
|
||||
DEBUGFX_PRINTLN(fileName);
|
||||
DEBUGFX_PRINTF_P(PSTR("Reading palette from %s\n"), fileName);
|
||||
|
||||
if (readObjectFromFile(fileName, nullptr, &pDoc)) {
|
||||
JsonArray pal = pDoc[F("palette")];
|
||||
@ -1841,7 +1836,7 @@ bool WS2812FX::deserializeMap(uint8_t n) {
|
||||
if (!isFile || !requestJSONBufferLock(7)) return false;
|
||||
|
||||
if (!readObjectFromFile(fileName, nullptr, pDoc)) {
|
||||
DEBUGFX_PRINT(F("ERROR Invalid ledmap in ")); DEBUGFX_PRINTLN(fileName);
|
||||
DEBUGFX_PRINTF_P(PSTR("ERROR Invalid ledmap in %s\n"), fileName);
|
||||
releaseJSONBufferLock();
|
||||
return false; // if file does not load properly then exit
|
||||
}
|
||||
@ -1857,7 +1852,7 @@ bool WS2812FX::deserializeMap(uint8_t n) {
|
||||
customMappingTable = new uint16_t[getLengthTotal()];
|
||||
|
||||
if (customMappingTable) {
|
||||
DEBUGFX_PRINT(F("Reading LED map from ")); DEBUGFX_PRINTLN(fileName);
|
||||
DEBUGFX_PRINTF_P(PSTR("Reading LED map from %s\n"), fileName);
|
||||
JsonArray map = root[F("map")];
|
||||
if (!map.isNull() && map.size()) { // not an empty map
|
||||
customMappingSize = min((unsigned)map.size(), (unsigned)getLengthTotal());
|
||||
|
@ -158,11 +158,7 @@ bool oappend(const char* txt)
|
||||
{
|
||||
unsigned len = strlen(txt);
|
||||
if ((obuf == nullptr) || (olen + len >= SETTINGS_STACK_BUF_SIZE)) { // sanity checks
|
||||
#ifdef WLED_DEBUG
|
||||
DEBUG_PRINT(F("oappend() buffer overflow. Cannot append "));
|
||||
DEBUG_PRINT(len); DEBUG_PRINT(F(" bytes \t\""));
|
||||
DEBUG_PRINT(txt); DEBUG_PRINTLN(F("\""));
|
||||
#endif
|
||||
DEBUG_PRINTF_P(PSTR("oappend() buffer overflow. Cannot append %u bytes ->\"%s\"\n"), len, txt);
|
||||
return false; // buffer full
|
||||
}
|
||||
strcpy(obuf + olen, txt);
|
||||
|
Loading…
x
Reference in New Issue
Block a user