Skip to content

Commit

Permalink
Button 0 long press factory reset
Browse files Browse the repository at this point in the history
JS simplification
  • Loading branch information
Aircoookie committed Mar 14, 2022
1 parent 1b2134d commit 1bc698a
Show file tree
Hide file tree
Showing 6 changed files with 2,246 additions and 2,236 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

### Builds after release 0.12.0

#### Build 2203140

- Added factory reset by pressing button 0 for >10 seconds
- Added ability to set presets from DMX Effect mode
- Simplified label hiding JS in user interface
- Fixed JSON `{"live":true}` indefinite realtime mode

#### Build 2203080

- Disabled auto white mode in segments with no RGB bus
Expand Down
21 changes: 14 additions & 7 deletions wled00/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* Physical IO
*/

#define WLED_DEBOUNCE_THRESHOLD 50 //only consider button input of at least 50ms as valid (debouncing)
#define WLED_LONG_PRESS 600 //long press if button is released after held for at least 600ms
#define WLED_DOUBLE_PRESS 350 //double press if another press within 350ms after a short press
#define WLED_LONG_REPEATED_ACTION 300 //how often a repeated action (e.g. dimming) is fired on long press on button IDs >0
#define WLED_LONG_AP 6000 //how long the button needs to be held to activate WLED-AP
#define WLED_DEBOUNCE_THRESHOLD 50 // only consider button input of at least 50ms as valid (debouncing)
#define WLED_LONG_PRESS 600 // long press if button is released after held for at least 600ms
#define WLED_DOUBLE_PRESS 350 // double press if another press within 350ms after a short press
#define WLED_LONG_REPEATED_ACTION 300 // how often a repeated action (e.g. dimming) is fired on long press on button IDs >0
#define WLED_LONG_AP 5000 // how long button 0 needs to be held to activate WLED-AP
#define WLED_LONG_FACTORY_RESET 10000 // how long button 0 needs to be held to trigger a factory reset

static const char _mqtt_topic_button[] PROGMEM = "%s/button/%d"; // optimize flash usage

Expand Down Expand Up @@ -236,8 +237,14 @@ void handleButton()
bool doublePress = buttonWaitTime[b]; //did we have a short press before?
buttonWaitTime[b] = 0;

if (b == 0 && dur > WLED_LONG_AP) { //long press on button 0 (when released)
WLED::instance().initAP(true);
if (b == 0 && dur > WLED_LONG_AP) { // long press on button 0 (when released)
if (dur > WLED_LONG_FACTORY_RESET) { // factory reset if pressed > 10 seconds
WLED_FS.format();
clearEEPROM();
doReboot = true;
} else {
WLED::instance().initAP(true);
}
} else if (!buttonLongPressed[b]) { //short press
if (b != 1 && !macroDoublePress[b]) { //don't wait for double press on buttons without a default action if no double press macro set
shortPressAction(b);
Expand Down
4 changes: 4 additions & 0 deletions wled00/data/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ button {
.tab-label {
margin: 0 0 -5px 0;
padding-bottom: 4px;
display: var(--bhd);
}

.overlay {
Expand Down Expand Up @@ -538,12 +539,14 @@ input[type=range]:active + .sliderbubble {
display: none;
}

/* Slider wrapper div */
.sliderwrap {
height: 30px;
width: 240px;
position: relative;
}

/* Segment power button + brightness slider wrapper div */
.sbs {
margin: 0px -20px 5px -6px;
}
Expand All @@ -553,6 +556,7 @@ input[type=range]:active + .sliderbubble {
margin-left: -7px;
}

/* Dynamically hide brightness slider label */
.hd {
display: var(--bhd);
}
Expand Down
11 changes: 3 additions & 8 deletions wled00/data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,9 @@ function applyCfg()
if (bg) sCol('--c-1', bg);
if (lastinfo.leds) updateUI(); // update component visibility
var l = cfg.comp.labels;
var e = d.querySelectorAll('.tab-label');
for (var i of e)
i.style.display = l ? "block":"none";
e = d.querySelector('.hd');
e.style.display = l ? "block":"none";
sCol('--tbp',l ? "14px 14px 10px 14px":"10px 22px 4px 22px");
sCol('--bbp',l ? "9px 0 7px 0":"10px 0 4px 0");
sCol('--bhd',l ? "block":"none");
sCol('--bhd',l ? "block":"none"); // hides/shows button labels
sCol('--bmt',l ? "0px":"5px");
sCol('--t-b', cfg.theme.alpha.tab);
size();
Expand Down Expand Up @@ -1076,12 +1071,12 @@ function readState(s,command=false) {
}

colors = i.col;
for (let e = 2; e >= 0; e--)
for (let e = 0; e < 3; e++)
{
if (i.col[e].length > 3) whites[e] = parseInt(i.col[e][3]);
setCSL(e);
selectSlot(csel);
}
selectSlot(csel);
if (i.cct != null && i.cct>=0) d.getElementById("sliderA").value = i.cct;

d.getElementById('sliderSpeed').value = i.sx;
Expand Down
Loading

0 comments on commit 1bc698a

Please sign in to comment.