Added analog button support.
Inverted switch fix.
This commit is contained in:
parent
69099fcdd7
commit
042c756be8
@ -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,52 @@ void handleSwitch(uint8_t b)
|
||||
}
|
||||
|
||||
|
||||
void handleAnalog(uint8_t b)
|
||||
{
|
||||
static uint8_t oldRead[WLED_MAX_BUTTONS];
|
||||
#ifdef ESP8266
|
||||
uint8_t aRead = analogRead(A0) >> 2; // convert 10bit read to 8bit
|
||||
#else
|
||||
uint8_t aRead = analogRead(btnPin[b]) >> 4; // convert 12bit read to 8bit
|
||||
#endif
|
||||
|
||||
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<WLED_MAX_BUTTONS; b++) {
|
||||
if (btnPin[b]<0 || !(buttonType[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;
|
||||
}
|
||||
|
||||
|
@ -160,6 +160,7 @@
|
||||
#define BTN_TYPE_SWITCH 4
|
||||
#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
|
||||
|
@ -288,6 +288,7 @@ Reverse (rotated 180°): <input type="checkbox" name="CV${i}">
|
||||
c += `<option value="4" ${t==4?"selected":""}>Switch</option>`;
|
||||
c += `<option value="5" ${t==4?"selected":""}>Switch inverted</option>`;
|
||||
c += `<option value="6" ${t==6?"selected":""}>Touch</option>`;
|
||||
c += `<option value="7" ${t==7?"selected":""}>Analog</option>`;
|
||||
c += `</select>`;
|
||||
c += `<span style="cursor: pointer;" onclick="off('${bt}')"> ×</span><br>`;
|
||||
gId("btns").innerHTML = c;
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user