Addet touch button and touch threshold.

Fixed some errors.
This commit is contained in:
Blaz Kristan 2021-05-19 20:23:35 +02:00
parent d40a555531
commit 4104dec87f
8 changed files with 21 additions and 9 deletions

View File

@ -19,10 +19,12 @@ void shortPressAction(uint8_t b)
bool isButtonPressed(uint8_t i)
{
if (btnPin[i]>=0 && digitalRead(btnPin[i]) == LOW) return true;
#ifdef TOUCHPIN
if (touchRead(TOUCHPIN) <= TOUCH_THRESHOLD) return true;
if (btnPin[i]<0) return false;
//TODO: this may need switch statement (for inverted buttons)
#ifdef ARDUINO_ARCH_ESP32
if (buttonType[i]==BTN_TYPE_TOUCH && touchRead(btnPin[i]) <= touchThreshold) return true; else
#endif
if (digitalRead(btnPin[i]) == LOW) return true;
return false;
}

View File

@ -163,6 +163,8 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
} else {
//TODO: fix JSON API call (and new install)
}
CJSON(touchThreshold,hw[F("btn")][F("touch-thershold")]);
/*
JsonObject hw_btn_ins_0 = hw[F("btn")][F("ins")][0];
CJSON(buttonType, hw_btn_ins_0["type"]);
@ -568,6 +570,7 @@ void serializeConfig() {
hw_btn_ins_0_macros.add(macroLongPress[i]);
hw_btn_ins_0_macros.add(macroDoublePress[i]);
}
hw_btn[F("touch-threshold")] = touchThreshold;
JsonObject hw_ir = hw.createNestedObject("ir");
hw_ir["pin"] = irPin;

View File

@ -159,6 +159,7 @@
#define BTN_TYPE_PUSH_ACT_HIGH 3 //not implemented
#define BTN_TYPE_SWITCH 4
#define BTN_TYPE_SWITCH_ACT_HIGH 5 //not implemented
#define BTN_TYPE_TOUCH 6
//Ethernet board types
#define WLED_NUM_ETH_TYPES 5

View File

@ -288,10 +288,11 @@ Reverse (rotated 180°): <input type="checkbox" name="CV${i}">
var bt = "BT" + i;
var be = "BE" + i;
c += `Button ${i} pin: <input type="number" min="-1" max="40" name="${bt}" onchange="UI()" value="${p}">`;
c += `<select name="${bt}">`
c += `<option name="${be}" value="0" ${t==0?"selected":""}>Disabled</option>`;
c += `<option name="${be}" value="2" ${t==2?"selected":""}>Pushbutton</option>`;
c += `<option name="${be}" value="4" ${t==4?"selected":""}>Switch</option>`;
c += `<select name="${be}">`
c += `<option value="0" ${t==0?"selected":""}>Disabled</option>`;
c += `<option value="2" ${t==2?"selected":""}>Pushbutton</option>`;
c += `<option value="4" ${t==4?"selected":""}>Switch</option>`;
c += `<option value="6" ${t==6?"selected":""}>Touch</option>`;
c += `</select>`;
c += `<span style="cursor: pointer;" onclick="off('${bt}')">&nbsp;&#215;</span><br>`;
gId("btns").innerHTML = c;
@ -353,6 +354,7 @@ Reverse (rotated 180°): <input type="checkbox" name="CV${i}">
Use less than <span id="wreason">800 LEDs per pin</span> for the best experience!<br>
</div><hr style="width:260px">
<div id="btns"></div>
Touch threshold: <input type="number" min="0" max="100" name="TT" required><br>
IR pin: <input type="number" min="-1" max="40" name="IR" onchange="UI()"><select name="IT">
<option value="0">Remote disabled</option>
<option value="1">24-key RGB</option>

File diff suppressed because one or more lines are too long

View File

@ -163,6 +163,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
}
//}
}
touchThreshold = request->arg(F("TT")).toInt();
strip.ablMilliampsMax = request->arg(F("MA")).toInt();
strip.milliampsPerLed = request->arg(F("LA")).toInt();

View File

@ -437,6 +437,7 @@ WLED_GLOBAL bool buttonPressedBefore[WLED_MAX_BUTTONS] _INIT({false});
WLED_GLOBAL bool buttonLongPressed[WLED_MAX_BUTTONS] _INIT({false});
WLED_GLOBAL unsigned long buttonPressedTime[WLED_MAX_BUTTONS] _INIT({0});
WLED_GLOBAL unsigned long buttonWaitTime[WLED_MAX_BUTTONS] _INIT({0});
WLED_GLOBAL byte touchThreshold _INIT(TOUCH_THRESHOLD);
// notifications
WLED_GLOBAL bool notifyDirectDefault _INIT(notifyDirect);

View File

@ -399,6 +399,7 @@ void getSettingsJS(byte subPage, char* dest)
oappend(itoa(buttonType[i],nS,10));
oappend(SET_F(");"));
}
sappend('v',SET_F("TT"),touchThreshold);
sappend('v',SET_F("IR"),irPin);
sappend('v',SET_F("IT"),irEnabled);
}