diff --git a/wled00/button.cpp b/wled00/button.cpp index 26218c154..80402b86d 100644 --- a/wled00/button.cpp +++ b/wled00/button.cpp @@ -35,8 +35,6 @@ bool isButtonPressed(uint8_t i) case BTN_TYPE_TOUCH: #ifdef ARDUINO_ARCH_ESP32 if (touchRead(btnPin[i]) <= touchThreshold) return true; - DEBUG_PRINT(F("Touch value: ")); - DEBUG_PRINTLN(touchRead(btnPin[i])); #endif break; } @@ -70,13 +68,53 @@ void handleSwitch(uint8_t b) } +void handleAnalog(uint8_t b) +{ + static uint8_t oldRead[WLED_MAX_BUTTONS]; + #ifdef ESP8266 + #define ANALOGPIN A0 + #else + #define ANALOGPIN btnPin[b] + #endif + uint8_t aRead = analogRead(ANALOGPIN) >> 4; // convert 12bit read to 8bit + + if (oldRead[b] == aRead) return; // no change in reading + + // if no macro for "short press" and "long press" is defined use brightness control + if (!macroButton[b] && !macroLongPress[b]) { + // if "double press" macro is 250 or greater use global brightness + if (macroDoublePress[b]>=250) { + // if change in analog read was detected change global brightness + bri = aRead; + } else { + // otherwise use "double press" for segment selection + //uint8_t mainSeg = strip.getMainSegmentId(); + WS2812FX::Segment& seg = strip.getSegment(macroDoublePress[b]); + if (aRead == 0) { + seg.setOption(SEG_OPTION_ON, 0, macroDoublePress[b]); // off + } else { + seg.setOpacity(aRead, macroDoublePress[b]); + seg.setOption(SEG_OPTION_ON, 1, macroDoublePress[b]); + } + } + } else { + //TODO: + // we can either trigger a preset depending on the level (between short and long entries) + // or use it for RGBW direct control + } + colorUpdated(NOTIFIER_CALL_MODE_DIRECT_CHANGE); +} + void handleButton() { for (uint8_t b=0; b BTN_TYPE_NONE)) continue; + if (buttonType[b] == BTN_TYPE_ANALOG) { // button is not a button but a potentiometer + handleAnalog(b); continue; + } - if (buttonType[b] == BTN_TYPE_SWITCH) { //button is not momentary, but switch. This is only suitable on pins whose on-boot state does not matter (NOT gpio0) + if (buttonType[b] == BTN_TYPE_SWITCH || buttonType[b] == BTN_TYPE_SWITCH_ACT_HIGH) { //button is not momentary, but switch. This is only suitable on pins whose on-boot state does not matter (NOT gpio0) handleSwitch(b); continue; } diff --git a/wled00/const.h b/wled00/const.h index 6dfda5ff2..2596eb9b8 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -156,10 +156,11 @@ #define BTN_TYPE_NONE 0 #define BTN_TYPE_RESERVED 1 #define BTN_TYPE_PUSH 2 -#define BTN_TYPE_PUSH_ACT_HIGH 3 //not implemented +#define BTN_TYPE_PUSH_ACT_HIGH 3 #define BTN_TYPE_SWITCH 4 -#define BTN_TYPE_SWITCH_ACT_HIGH 5 //not implemented +#define BTN_TYPE_SWITCH_ACT_HIGH 5 #define BTN_TYPE_TOUCH 6 +#define BTN_TYPE_ANALOG 7 //Ethernet board types #define WLED_NUM_ETH_TYPES 5 diff --git a/wled00/data/settings_leds.htm b/wled00/data/settings_leds.htm index c4ea65610..94ab99f3f 100644 --- a/wled00/data/settings_leds.htm +++ b/wled00/data/settings_leds.htm @@ -295,6 +295,7 @@ Reverse (rotated 180°): c += ``; c += ``; c += ``; + c += ``; c += ``; c += ` ×
`; gId("btns").innerHTML = c; diff --git a/wled00/data/settings_time.htm b/wled00/data/settings_time.htm index 0515de1f3..85f27213d 100644 --- a/wled00/data/settings_time.htm +++ b/wled00/data/settings_time.htm @@ -76,11 +76,11 @@ } } function addRow(i,p,l,d) { - var t = gId("macros"); // table - var rCnt = t.rows.length; // get the number of rows. - var tr = t.insertRow(rCnt); // table row. + var t = gId("macros"); + var rCnt = t.rows.length; + var tr = t.insertRow(rCnt); - var td = document.createElement('td'); // TABLE DEFINITION. + var td = document.createElement('td'); td = tr.insertCell(0); td.innerHTML = `Button ${i}:`; td = tr.insertCell(1); @@ -93,7 +93,6 @@ function GetV() { //values injected by server while sending HTML - addRow(0,23,4,0); }