Added analog button/potentiometer support (partial)
This commit is contained in:
parent
651b4d2461
commit
0ada09891c
@ -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<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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -295,6 +295,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;
|
||||
|
@ -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);
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
@ -176,7 +175,7 @@
|
||||
<td>short<br>on->off</td>
|
||||
<td>long<br>off->on</td>
|
||||
<td>double<br>N/A</td>
|
||||
</tr>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
|
File diff suppressed because one or more lines are too long
@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
// version code in format yymmddb (b = daily build)
|
||||
#define VERSION 2105201
|
||||
#define VERSION 2105211
|
||||
|
||||
//uncomment this if you have a "my_config.h" file you'd like to use
|
||||
//#define WLED_USE_MY_CONFIG
|
||||
|
Loading…
Reference in New Issue
Block a user