Skip to content

Commit

Permalink
Various state changed logic simplifications
Browse files Browse the repository at this point in the history
Changed main segment, must be selected
  • Loading branch information
Aircoookie committed Feb 16, 2022
1 parent 7aef551 commit 7b969bb
Show file tree
Hide file tree
Showing 34 changed files with 279 additions and 373 deletions.
8 changes: 4 additions & 4 deletions usermods/Enclosure_with_OLED_temp_ESP07/usermod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ void userLoop() {
needRedraw = true;
} else if (knownBrightness != bri) {
needRedraw = true;
} else if (knownMode != strip.getMode()) {
} else if (knownMode != strip.getMainSegment().mode) {
needRedraw = true;
} else if (knownPalette != strip.getSegment(0).palette) {
} else if (knownPalette != strip.getMainSegment().palette) {
needRedraw = true;
}

Expand All @@ -126,8 +126,8 @@ void userLoop() {
#endif
knownIp = apActive ? IPAddress(4, 3, 2, 1) : WiFi.localIP();
knownBrightness = bri;
knownMode = strip.getMode();
knownPalette = strip.getSegment(0).palette;
knownMode = strip.getMainSegment().mode;
knownPalette = strip.getMainSegment().palette;
u8x8.clear();
u8x8.setFont(u8x8_font_chroma48medium8_r);

Expand Down
8 changes: 4 additions & 4 deletions usermods/Enclosure_with_OLED_temp_ESP07/usermod_bme280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ void userLoop() {
needRedraw = true;
} else if (knownBrightness != bri) {
needRedraw = true;
} else if (knownMode != strip.getMode()) {
} else if (knownMode != strip.getMainSegment().mode) {
needRedraw = true;
} else if (knownPalette != strip.getSegment(0).palette) {
} else if (knownPalette != strip.getMainSegment().palette) {
needRedraw = true;
}

Expand All @@ -169,8 +169,8 @@ void userLoop() {
#endif
knownIp = apActive ? IPAddress(4, 3, 2, 1) : WiFi.localIP();
knownBrightness = bri;
knownMode = strip.getMode();
knownPalette = strip.getSegment(0).palette;
knownMode = strip.getMainSegment().mode;
knownPalette = strip.getMainSegment().palette;
u8x8.clear();
u8x8.setFont(u8x8_font_chroma48medium8_r);

Expand Down
6 changes: 3 additions & 3 deletions usermods/PIR_sensor_switch/PIR_Highlight_Standby
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class PIRsensorSwitch : public Usermod {
private:
// PIR sensor pin
const uint8_t PIRsensorPin = 13; // D7 on D1 mini
// notification mode for colorUpdated()
// notification mode for stateUpdated()
const byte NotifyUpdateMode = CALL_MODE_NO_NOTIFY; // CALL_MODE_DIRECT_CHANGE
// 1 min delay before switch off after the sensor state goes LOW
uint32_t m_switchOffDelay = 60000;
Expand Down Expand Up @@ -127,7 +127,7 @@ class PIRsensorSwitch : public Usermod {
if (bri != briHighlight) {
bri = briHighlight; // set current highlight brightness to last set highlight brightness
}
colorUpdated(NotifyUpdateMode);
stateUpdated(NotifyUpdateMode);
highlightActive = true; // flag highlight is on
}
else { // **pir timer has elapsed**
Expand Down Expand Up @@ -157,7 +157,7 @@ class PIRsensorSwitch : public Usermod {
}
applyMacro(macroLongPress); // apply standby lighting without brightness
}
colorUpdated(NotifyUpdateMode);
stateUpdated(NotifyUpdateMode);
highlightActive = false; // flag highlight is off
}
}
Expand Down
6 changes: 3 additions & 3 deletions usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class PIRsensorSwitch : public Usermod
bool savedState = false;

uint32_t offTimerStart = 0; // off timer start time
byte NotifyUpdateMode = CALL_MODE_NO_NOTIFY; // notification mode for colorUpdated(): CALL_MODE_NO_NOTIFY or CALL_MODE_DIRECT_CHANGE
byte NotifyUpdateMode = CALL_MODE_NO_NOTIFY; // notification mode for stateUpdated(): CALL_MODE_NO_NOTIFY or CALL_MODE_DIRECT_CHANGE
byte sensorPinState = LOW; // current PIR sensor pin state
bool initDone = false; // status of initialization
bool PIRtriggered = false;
Expand Down Expand Up @@ -136,7 +136,7 @@ class PIRsensorSwitch : public Usermod
// preset not assigned
if (bri == 0) {
bri = briLast;
colorUpdated(NotifyUpdateMode);
stateUpdated(NotifyUpdateMode);
}
} else {
if (m_offPreset) {
Expand All @@ -159,7 +159,7 @@ class PIRsensorSwitch : public Usermod
if (bri != 0) {
briLast = bri;
bri = 0;
colorUpdated(NotifyUpdateMode);
stateUpdated(NotifyUpdateMode);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions usermods/ST7789_display/ST7789_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ class St7789DisplayUsermod : public Usermod {
{
needRedraw = true;
}
else if (knownMode != strip.getMode())
else if (knownMode != strip.getMainSegment().mode)
{
needRedraw = true;
}
else if (knownPalette != strip.getSegment(0).palette)
else if (knownPalette != strip.getMainSegment().palette)
{
needRedraw = true;
}
Expand All @@ -148,8 +148,8 @@ class St7789DisplayUsermod : public Usermod {
#endif
knownIp = apActive ? IPAddress(4, 3, 2, 1) : WiFi.localIP();
knownBrightness = bri;
knownMode = strip.getMode();
knownPalette = strip.getSegment(0).palette;
knownMode = strip.getMainSegment().mode;
knownPalette = strip.getMainSegment().palette;

tft.fillScreen(TFT_BLACK);
tft.setTextSize(2);
Expand Down
8 changes: 4 additions & 4 deletions usermods/TTGO-T-Display/usermod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ void userLoop() {
needRedraw = true;
} else if (knownBrightness != bri) {
needRedraw = true;
} else if (knownMode != strip.getMode()) {
} else if (knownMode != strip.getMainSegment().mode) {
needRedraw = true;
} else if (knownPalette != strip.getSegment(0).palette) {
} else if (knownPalette != strip.getMainSegment().palette) {
needRedraw = true;
}

Expand All @@ -136,8 +136,8 @@ void userLoop() {
#endif
knownIp = apActive ? IPAddress(4, 3, 2, 1) : WiFi.localIP();
knownBrightness = bri;
knownMode = strip.getMode();
knownPalette = strip.getSegment(0).palette;
knownMode = strip.getMainSegment().mode;
knownPalette = strip.getMainSegment().palette;

tft.fillScreen(TFT_BLACK);
tft.setTextSize(2);
Expand Down
2 changes: 1 addition & 1 deletion usermods/VL53L0X_gestures/usermod_vl53l0x_gestures.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class UsermodVL53L0XGestures : public Usermod {
// set brightness according to range
bri = (VL53L0X_MAX_RANGE_MM - max(range, VL53L0X_MIN_RANGE_OFFSET)) * 255 / (VL53L0X_MAX_RANGE_MM - VL53L0X_MIN_RANGE_OFFSET);
DEBUG_PRINTF(F("new brightness: %d"), bri);
colorUpdated(1);
stateUpdated(1);
}
} else if (wasMotionBefore) { //released
long dur = millis() - motionStartTime;
Expand Down
8 changes: 4 additions & 4 deletions usermods/Wemos_D1_mini+Wemos32_mini_shield/usermod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ void userLoop() {
needRedraw = true;
} else if (knownBrightness != bri) {
needRedraw = true;
} else if (knownMode != strip.getMode()) {
} else if (knownMode != strip.getMainSegment().mode) {
needRedraw = true;
} else if (knownPalette != strip.getSegment(0).palette) {
} else if (knownPalette != strip.getMainSegment().palette) {
needRedraw = true;
}

Expand All @@ -163,8 +163,8 @@ void userLoop() {
#endif
knownIp = apActive ? IPAddress(4, 3, 2, 1) : WiFi.localIP();
knownBrightness = bri;
knownMode = strip.getMode();
knownPalette = strip.getSegment(0).palette;
knownMode = strip.getMainSegment().mode;
knownPalette = strip.getMainSegment().palette;
u8x8.clear();
u8x8.setFont(u8x8_font_chroma48medium8_r);

Expand Down
8 changes: 4 additions & 4 deletions usermods/Wemos_D1_mini+Wemos32_mini_shield/usermod_bme280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ void userLoop() {
needRedraw = true;
} else if (knownBrightness != bri) {
needRedraw = true;
} else if (knownMode != strip.getMode()) {
} else if (knownMode != strip.getMainSegment().mode) {
needRedraw = true;
} else if (knownPalette != strip.getSegment(0).palette) {
} else if (knownPalette != strip.getMainSegment().palette) {
needRedraw = true;
}

Expand All @@ -169,8 +169,8 @@ void userLoop() {
#endif
knownIp = apActive ? IPAddress(4, 3, 2, 1) : WiFi.localIP();
knownBrightness = bri;
knownMode = strip.getMode();
knownPalette = strip.getSegment(0).palette;
knownMode = strip.getMainSegment().mode;
knownPalette = strip.getMainSegment().palette;
u8x8.clear();
u8x8.setFont(u8x8_font_chroma48medium8_r);

Expand Down
8 changes: 0 additions & 8 deletions usermods/battery_keypad_controller/wled06_usermod.ino
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,27 @@ void userLoop()
switch (myKey) {
case '1':
applyPreset(1);
colorUpdated(CALL_MODE_FX_CHANGED);
break;
case '2':
applyPreset(2);
colorUpdated(CALL_MODE_FX_CHANGED);
break;
case '3':
applyPreset(3);
colorUpdated(CALL_MODE_FX_CHANGED);
break;
case '4':
applyPreset(4);
colorUpdated(CALL_MODE_FX_CHANGED);
break;
case '5':
applyPreset(5);
colorUpdated(CALL_MODE_FX_CHANGED);
break;
case '6':
applyPreset(6);
colorUpdated(CALL_MODE_FX_CHANGED);
break;
case 'A':
applyPreset(7);
colorUpdated(CALL_MODE_FX_CHANGED);
break;
case 'B':
applyPreset(8);
colorUpdated(CALL_MODE_FX_CHANGED);
break;

case '7':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class UsermodSSDR : public Usermod {
uint16_t brightness = map(lux, 0, 1000, umSSDRBrightnessMin, umSSDRBrightnessMax);
if (bri != brightness) {
bri = brightness;
colorUpdated(1);
stateUpdated(1);
}
}
umSSDRLastRefresh = millis();
Expand Down
2 changes: 1 addition & 1 deletion usermods/stairway_wipe_basic/stairway-wipe-usermod-v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class StairwayWipeUsermod : public Usermod {
transitionDelayTemp = 4000; //fade out slowly
#endif
bri = 0;
colorUpdated(CALL_MODE_NOTIFICATION);
stateUpdated(CALL_MODE_NOTIFICATION);
wipeState = 0;
userVar0 = 0;
previousUserVar0 = 0;
Expand Down
2 changes: 1 addition & 1 deletion usermods/stairway_wipe_basic/wled06_usermod.ino
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void turnOff()
transitionDelayTemp = 4000; //fade out slowly
#endif
bri = 0;
colorUpdated(CALL_MODE_NOTIFICATION);
stateUpdated(CALL_MODE_NOTIFICATION);
wipeState = 0;
userVar0 = 0;
previousUserVar0 = 0;
Expand Down
8 changes: 4 additions & 4 deletions usermods/usermod_v2_auto_save/usermod_v2_auto_save.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class AutoSaveUsermod : public Usermod {
knownBrightness = bri;
knownEffectSpeed = effectSpeed;
knownEffectIntensity = effectIntensity;
knownMode = strip.getMode();
knownPalette = strip.getSegment(0).palette;
knownMode = strip.getMainSegment().mode;
knownPalette = strip.getMainSegment().palette;
}

// gets called every time WiFi is (re-)connected. Initialize own network
Expand All @@ -106,8 +106,8 @@ class AutoSaveUsermod : public Usermod {
if (!autoSaveAfterSec || !enabled || strip.isUpdating() || currentPreset>0) return; // setting 0 as autosave seconds disables autosave

unsigned long now = millis();
uint8_t currentMode = strip.getMode();
uint8_t currentPalette = strip.getSegment(0).palette;
uint8_t currentMode = strip.getMainSegment().mode;
uint8_t currentPalette = strip.getMainSegment().palette;

unsigned long wouldAutoSaveAfter = now + autoSaveAfterSec*1000;
if (knownBrightness != bri) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ class FourLineDisplayUsermod : public Usermod {
(knownBrightness != bri) ||
(knownEffectSpeed != effectSpeed) ||
(knownEffectIntensity != effectIntensity) ||
(knownMode != strip.getMode()) ||
(knownPalette != strip.getSegment(0).palette)) {
(knownMode != strip.getMainSegment().mode) ||
(knownPalette != strip.getMainSegment().palette)) {
knownHour = 99; // force time update
lastRedraw = now; // update lastRedraw marker
} else if (sleepMode && !displayTurnedOff && ((now - lastRedraw)/1000)%5 == 0) {
Expand Down Expand Up @@ -398,8 +398,8 @@ class FourLineDisplayUsermod : public Usermod {
knownSsid = apActive ? WiFi.softAPSSID() : WiFi.SSID();
knownIp = apActive ? IPAddress(4, 3, 2, 1) : Network.localIP();
knownBrightness = bri;
knownMode = strip.getMode();
knownPalette = strip.getSegment(0).palette;
knownMode = strip.getMainSegment().mode;
knownPalette = strip.getMainSegment().palette;
knownEffectSpeed = effectSpeed;
knownEffectIntensity = effectIntensity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,8 @@ class RotaryEncoderUIUsermod : public Usermod {
}

void lampUdated() {
bool fxChanged = strip.setEffectConfig(effectCurrent, effectSpeed, effectIntensity, effectPalette);

//call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (No notification)
// 6: fx changed 7: hue 8: preset cycle 9: blynk 10: alexa
colorUpdated(CALL_MODE_DIRECT_CHANGE);
updateInterfaces(CALL_MODE_DIRECT_CHANGE);
colorUpdated(CALL_MODE_BUTTON);
updateInterfaces(CALL_MODE_BUTTON);
}

void changeBrightness(bool increase) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,11 @@ class RotaryEncoderUIUsermod : public Usermod {
}

void lampUdated() {
//bool fxChanged = strip.setEffectConfig(effectCurrent, effectSpeed, effectIntensity, effectPalette);
//call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (No notification)
// 6: fx changed 7: hue 8: preset cycle 9: blynk 10: alexa
setValuesFromMainSeg(); //to make transition work on main segment
colorUpdated(CALL_MODE_DIRECT_CHANGE);
updateInterfaces(CALL_MODE_DIRECT_CHANGE);
//setValuesFromMainSeg(); //to make transition work on main segment (should no longer be required)
stateUpdated(CALL_MODE_BUTTON);
updateInterfaces(CALL_MODE_BUTTON);
}

void changeBrightness(bool increase) {
Expand Down
Loading

0 comments on commit 7b969bb

Please sign in to comment.