UM optimizations.

This commit is contained in:
Blaz Kristan 2021-12-31 18:25:27 +01:00
parent 603dee7661
commit 40323e3afe
2 changed files with 13 additions and 7 deletions

View File

@ -37,7 +37,7 @@ class UsermodTemperature : public Usermod {
// used to determine when we can read the sensors temperature // used to determine when we can read the sensors temperature
// we have to wait at least 93.75 ms after requestTemperatures() is called // we have to wait at least 93.75 ms after requestTemperatures() is called
unsigned long lastTemperaturesRequest; unsigned long lastTemperaturesRequest;
float temperature = -100.0f; // default to -100, DS18B20 only goes down to -50C float temperature = -127.0f; // default to -127, DS18B20 only goes down to -50C
// indicates requestTemperatures has been called but the sensor measurement is not complete // indicates requestTemperatures has been called but the sensor measurement is not complete
bool waitingForConversion = false; bool waitingForConversion = false;
// flag set at startup if DS18B20 sensor not found, avoids trying to keep getting // flag set at startup if DS18B20 sensor not found, avoids trying to keep getting
@ -60,7 +60,6 @@ class UsermodTemperature : public Usermod {
if (oneWire->reset()) { // if reset() fails there are no OneWire devices if (oneWire->reset()) { // if reset() fails there are no OneWire devices
oneWire->skip(); // skip ROM oneWire->skip(); // skip ROM
oneWire->write(0xBE); // read (temperature) from EEPROM oneWire->write(0xBE); // read (temperature) from EEPROM
delayMicroseconds(250);
oneWire->read_bytes(data, 9); // first 2 bytes contain temperature oneWire->read_bytes(data, 9); // first 2 bytes contain temperature
#ifdef WLED_DEBUG #ifdef WLED_DEBUG
if (OneWire::crc8(data,8) != data[8]) { if (OneWire::crc8(data,8) != data[8]) {
@ -85,7 +84,8 @@ class UsermodTemperature : public Usermod {
break; break;
} }
} }
return retVal; for (byte i=1; i<9; i++) data[0] &= data[i];
return data[0]==0xFF ? -127.0f : retVal;
} }
void requestTemperatures() { void requestTemperatures() {
@ -176,7 +176,7 @@ class UsermodTemperature : public Usermod {
} }
// we were waiting for a conversion to complete, have we waited log enough? // we were waiting for a conversion to complete, have we waited log enough?
if (now - lastTemperaturesRequest >= 100 /* 93.75ms per the datasheet but can be up to 750ms */) { if (now - lastTemperaturesRequest >= 750 /* 93.75ms per the datasheet but can be up to 750ms */) {
readTemperature(); readTemperature();
if (WLED_MQTT_CONNECTED) { if (WLED_MQTT_CONNECTED) {

View File

@ -386,7 +386,8 @@ class FourLineDisplayUsermod : public Usermod {
setFlipMode(flip); setFlipMode(flip);
setContrast(contrast); //Contrast setup will help to preserve OLED lifetime. In case OLED need to be brighter increase number up to 255 setContrast(contrast); //Contrast setup will help to preserve OLED lifetime. In case OLED need to be brighter increase number up to 255
setPowerSave(0); setPowerSave(0);
drawString(0, 0, "Loading..."); //drawString(0, 0, "Loading...");
overlay(PSTR("Loading..."),3000,0);
} }
// gets called every time WiFi is (re-)connected. Initialize own network // gets called every time WiFi is (re-)connected. Initialize own network
@ -484,6 +485,7 @@ class FourLineDisplayUsermod : public Usermod {
if (forceRedraw) { if (forceRedraw) {
knownHour = 99; knownHour = 99;
needRedraw = true; needRedraw = true;
clear();
} else if ((bri == 0 && powerON) || (bri > 0 && !powerON)) { //trigger power icon } else if ((bri == 0 && powerON) || (bri > 0 && !powerON)) { //trigger power icon
powerON = !powerON; powerON = !powerON;
drawStatusIcons(); drawStatusIcons();
@ -526,6 +528,7 @@ class FourLineDisplayUsermod : public Usermod {
if (sleepMode && !displayTurnedOff && (now - lastRedraw > screenTimeout)) { if (sleepMode && !displayTurnedOff && (now - lastRedraw > screenTimeout)) {
// We will still check if there is a change in redraw() // We will still check if there is a change in redraw()
// and turn it back on if it changed. // and turn it back on if it changed.
clear();
sleepOrClock(true); sleepOrClock(true);
} else if (displayTurnedOff && clockMode) { } else if (displayTurnedOff && clockMode) {
showTime(); showTime();
@ -539,6 +542,7 @@ class FourLineDisplayUsermod : public Usermod {
if (displayTurnedOff) { if (displayTurnedOff) {
// Turn the display back on // Turn the display back on
sleepOrClock(false); sleepOrClock(false);
clear();
} }
// Update last known values. // Update last known values.
@ -705,6 +709,7 @@ class FourLineDisplayUsermod : public Usermod {
if (type == NONE || !enabled) return false; if (type == NONE || !enabled) return false;
knownHour = 99; knownHour = 99;
if (displayTurnedOff) { if (displayTurnedOff) {
clear();
// Turn the display back on // Turn the display back on
sleepOrClock(false); sleepOrClock(false);
redraw(true); redraw(true);
@ -729,8 +734,10 @@ class FourLineDisplayUsermod : public Usermod {
if (glyphType > 0) { if (glyphType > 0) {
if (lineHeight == 2) drawGlyph(5, 0, glyphType, u8x8_font_benji_custom_icons_6x6, true); if (lineHeight == 2) drawGlyph(5, 0, glyphType, u8x8_font_benji_custom_icons_6x6, true);
else drawGlyph(7, lineHeight, glyphType, u8x8_font_benji_custom_icons_2x2, true); else drawGlyph(7, lineHeight, glyphType, u8x8_font_benji_custom_icons_2x2, true);
if (line1) drawString(0, 3*lineHeight, line1);
} else {
if (line1) drawString(0, 2*(lineHeight-1), line1);
} }
if (line1) drawString(0, 3*lineHeight, line1);
overlayUntil = millis() + showHowLong; overlayUntil = millis() + showHowLong;
} }
@ -777,7 +784,6 @@ class FourLineDisplayUsermod : public Usermod {
* Enable sleep (turn the display off) or clock mode. * Enable sleep (turn the display off) or clock mode.
*/ */
void sleepOrClock(bool enabled) { void sleepOrClock(bool enabled) {
clear();
if (enabled) { if (enabled) {
if (clockMode) { if (clockMode) {
knownMinute = knownHour = 99; knownMinute = knownHour = 99;