Inverted button support.
Config save/load fix.
This commit is contained in:
parent
c925b3d218
commit
a0fd02e0c0
@ -20,11 +20,26 @@ void shortPressAction(uint8_t b)
|
|||||||
bool isButtonPressed(uint8_t i)
|
bool isButtonPressed(uint8_t i)
|
||||||
{
|
{
|
||||||
if (btnPin[i]<0) return false;
|
if (btnPin[i]<0) return false;
|
||||||
//TODO: this may need switch statement (for inverted buttons)
|
switch (buttonType[i]) {
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
case BTN_TYPE_NONE:
|
||||||
if (buttonType[i]==BTN_TYPE_TOUCH && touchRead(btnPin[i]) <= touchThreshold) return true; else
|
case BTN_TYPE_RESERVED:
|
||||||
#endif
|
break;
|
||||||
|
case BTN_TYPE_PUSH:
|
||||||
|
case BTN_TYPE_SWITCH:
|
||||||
if (digitalRead(btnPin[i]) == LOW) return true;
|
if (digitalRead(btnPin[i]) == LOW) return true;
|
||||||
|
break;
|
||||||
|
case BTN_TYPE_PUSH_ACT_HIGH:
|
||||||
|
case BTN_TYPE_SWITCH_ACT_HIGH:
|
||||||
|
if (digitalRead(btnPin[i]) == HIGH) return true;
|
||||||
|
break;
|
||||||
|
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;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,9 +161,18 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
macroDoublePress[s] = 0;
|
macroDoublePress[s] = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//TODO: fix JSON API call (and new install)
|
// new install/missing configuration (button 0 has defaults)
|
||||||
|
if (fromFS)
|
||||||
|
for (uint8_t s=1; s<WLED_MAX_BUTTONS; s++) {
|
||||||
|
btnPin[s] = -1;
|
||||||
|
buttonType[s] = BTN_TYPE_NONE;
|
||||||
|
macroButton[s] = 0;
|
||||||
|
macroLongPress[s] = 0;
|
||||||
|
macroDoublePress[s] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
CJSON(touchThreshold,hw[F("btn")][F("tt")]);
|
CJSON(touchThreshold,hw[F("btn")][F("tt")]);
|
||||||
|
DEBUG_PRINTLN(F(" Done buttons."));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
JsonObject hw_btn_ins_0 = hw[F("btn")][F("ins")][0];
|
JsonObject hw_btn_ins_0 = hw[F("btn")][F("ins")][0];
|
||||||
@ -546,8 +555,10 @@ void serializeConfig() {
|
|||||||
|
|
||||||
// button(s)
|
// button(s)
|
||||||
JsonObject hw_btn = hw.createNestedObject("btn");
|
JsonObject hw_btn = hw.createNestedObject("btn");
|
||||||
|
hw_btn["max"] = WLED_MAX_BUTTONS; // just information about max number of buttons (not actually used)
|
||||||
JsonArray hw_btn_ins = hw_btn.createNestedArray("ins");
|
JsonArray hw_btn_ins = hw_btn.createNestedArray("ins");
|
||||||
|
|
||||||
|
// there is always at least one button
|
||||||
JsonObject hw_btn_ins_0 = hw_btn_ins.createNestedObject();
|
JsonObject hw_btn_ins_0 = hw_btn_ins.createNestedObject();
|
||||||
hw_btn_ins_0["type"] = buttonType[0];
|
hw_btn_ins_0["type"] = buttonType[0];
|
||||||
JsonArray hw_btn_ins_0_pin = hw_btn_ins_0.createNestedArray("pin");
|
JsonArray hw_btn_ins_0_pin = hw_btn_ins_0.createNestedArray("pin");
|
||||||
@ -559,13 +570,12 @@ void serializeConfig() {
|
|||||||
|
|
||||||
// additional buttons
|
// additional buttons
|
||||||
for (uint8_t i=1; i<WLED_MAX_BUTTONS; i++) {
|
for (uint8_t i=1; i<WLED_MAX_BUTTONS; i++) {
|
||||||
if (btnPin[i]<0) continue;
|
//if (btnPin[i]<0) continue;
|
||||||
JsonObject hw_btn_ins_0 = hw_btn_ins.createNestedObject();
|
hw_btn_ins_0 = hw_btn_ins.createNestedObject();
|
||||||
hw_btn_ins_0["type"] = buttonType[i];
|
hw_btn_ins_0["type"] = buttonType[i];
|
||||||
JsonArray hw_btn_ins_0_pin = hw_btn_ins_0.createNestedArray("pin");
|
hw_btn_ins_0_pin = hw_btn_ins_0.createNestedArray("pin");
|
||||||
hw_btn_ins_0_pin.add(btnPin[i]);
|
hw_btn_ins_0_pin.add(btnPin[i]);
|
||||||
|
hw_btn_ins_0_macros = hw_btn_ins_0.createNestedArray("macros");
|
||||||
JsonArray hw_btn_ins_0_macros = hw_btn_ins_0.createNestedArray("macros");
|
|
||||||
hw_btn_ins_0_macros.add(macroButton[i]);
|
hw_btn_ins_0_macros.add(macroButton[i]);
|
||||||
hw_btn_ins_0_macros.add(macroLongPress[i]);
|
hw_btn_ins_0_macros.add(macroLongPress[i]);
|
||||||
hw_btn_ins_0_macros.add(macroDoublePress[i]);
|
hw_btn_ins_0_macros.add(macroDoublePress[i]);
|
||||||
|
@ -291,7 +291,9 @@ Reverse (rotated 180°): <input type="checkbox" name="CV${i}">
|
|||||||
c += `<select name="${be}">`
|
c += `<select name="${be}">`
|
||||||
c += `<option value="0" ${t==0?"selected":""}>Disabled</option>`;
|
c += `<option value="0" ${t==0?"selected":""}>Disabled</option>`;
|
||||||
c += `<option value="2" ${t==2?"selected":""}>Pushbutton</option>`;
|
c += `<option value="2" ${t==2?"selected":""}>Pushbutton</option>`;
|
||||||
|
c += `<option value="2" ${t==3?"selected":""}>Push inverted</option>`;
|
||||||
c += `<option value="4" ${t==4?"selected":""}>Switch</option>`;
|
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="6" ${t==6?"selected":""}>Touch</option>`;
|
||||||
c += `</select>`;
|
c += `</select>`;
|
||||||
c += `<span style="cursor: pointer;" onclick="off('${bt}')"> ×</span><br>`;
|
c += `<span style="cursor: pointer;" onclick="off('${bt}')"> ×</span><br>`;
|
||||||
|
@ -172,10 +172,10 @@
|
|||||||
<table style="margin: 0 auto;" id="macros">
|
<table style="margin: 0 auto;" id="macros">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td>push<br>switch</td>
|
||||||
<td>short<br>on->off</td>
|
<td>short<br>on->off</td>
|
||||||
<td>long<br>off->on</td>
|
<td>long<br>off->on</td>
|
||||||
<td>double</td>
|
<td>double<br>N/A</td>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
File diff suppressed because one or more lines are too long
@ -151,7 +151,6 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
for (uint8_t i=0; i<WLED_MAX_BUTTONS; i++) {
|
for (uint8_t i=0; i<WLED_MAX_BUTTONS; i++) {
|
||||||
char bt[4] = "BT"; bt[2] = 48+i; bt[3] = 0; // button pin
|
char bt[4] = "BT"; bt[2] = 48+i; bt[3] = 0; // button pin
|
||||||
char be[4] = "BE"; be[2] = 48+i; be[3] = 0; // button type
|
char be[4] = "BE"; be[2] = 48+i; be[3] = 0; // button type
|
||||||
//if (request->hasArg(bt)) {
|
|
||||||
int hw_btn_pin = request->arg(bt).toInt();
|
int hw_btn_pin = request->arg(bt).toInt();
|
||||||
if (pinManager.allocatePin(hw_btn_pin,false)) {
|
if (pinManager.allocatePin(hw_btn_pin,false)) {
|
||||||
btnPin[i] = hw_btn_pin;
|
btnPin[i] = hw_btn_pin;
|
||||||
@ -161,7 +160,6 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
btnPin[i] = -1;
|
btnPin[i] = -1;
|
||||||
buttonType[i] = BTN_TYPE_NONE;
|
buttonType[i] = BTN_TYPE_NONE;
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
touchThreshold = request->arg(F("TT")).toInt();
|
touchThreshold = request->arg(F("TT")).toInt();
|
||||||
|
|
||||||
@ -342,7 +340,8 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
char mp[4] = "MP"; mp[2] = 48+i; mp[3] = 0; // short
|
char mp[4] = "MP"; mp[2] = 48+i; mp[3] = 0; // short
|
||||||
char ml[4] = "ML"; ml[2] = 48+i; ml[3] = 0; // long
|
char ml[4] = "ML"; ml[2] = 48+i; ml[3] = 0; // long
|
||||||
char md[4] = "MD"; md[2] = 48+i; md[3] = 0; // double
|
char md[4] = "MD"; md[2] = 48+i; md[3] = 0; // double
|
||||||
macroButton[i] = request->arg(mp).toInt();
|
//if (!request->hasArg(mp)) break;
|
||||||
|
macroButton[i] = request->arg(mp).toInt(); // these will default to 0 if not present
|
||||||
macroLongPress[i] = request->arg(ml).toInt();
|
macroLongPress[i] = request->arg(ml).toInt();
|
||||||
macroDoublePress[i] = request->arg(md).toInt();
|
macroDoublePress[i] = request->arg(md).toInt();
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// version code in format yymmddb (b = daily build)
|
// version code in format yymmddb (b = daily build)
|
||||||
#define VERSION 2105191
|
#define VERSION 2105201
|
||||||
|
|
||||||
//uncomment this if you have a "my_config.h" file you'd like to use
|
//uncomment this if you have a "my_config.h" file you'd like to use
|
||||||
//#define WLED_USE_MY_CONFIG
|
//#define WLED_USE_MY_CONFIG
|
||||||
|
Loading…
Reference in New Issue
Block a user