2020-03-25 09:00:55 +01:00
|
|
|
#include "wled.h"
|
2020-03-25 10:14:23 +01:00
|
|
|
|
2016-12-31 00:38:51 +01:00
|
|
|
/*
|
|
|
|
* Physical IO
|
|
|
|
*/
|
|
|
|
|
2019-03-13 11:13:03 +01:00
|
|
|
void shortPressAction()
|
|
|
|
{
|
|
|
|
if (!macroButton)
|
|
|
|
{
|
|
|
|
toggleOnOff();
|
2020-02-22 16:17:32 +01:00
|
|
|
colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
|
2019-03-13 11:13:03 +01:00
|
|
|
} else {
|
2020-11-06 22:12:48 +01:00
|
|
|
applyPreset(macroButton);
|
2019-03-13 11:13:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-20 16:12:46 +02:00
|
|
|
bool isButtonPressed()
|
|
|
|
{
|
2021-01-17 00:20:31 +01:00
|
|
|
if (btnPin>=0 && digitalRead(btnPin) == LOW) return true;
|
2020-09-20 16:12:46 +02:00
|
|
|
#ifdef TOUCHPIN
|
|
|
|
if (touchRead(TOUCHPIN) <= TOUCH_THRESHOLD) return true;
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-13 11:13:03 +01:00
|
|
|
|
2016-11-19 19:39:17 +01:00
|
|
|
void handleButton()
|
|
|
|
{
|
2021-01-17 00:20:31 +01:00
|
|
|
if (btnPin<0 || !buttonEnabled) return;
|
2020-09-20 16:12:46 +02:00
|
|
|
|
|
|
|
if (isButtonPressed()) //pressed
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
2019-10-18 12:19:52 +02:00
|
|
|
if (!buttonPressedBefore) buttonPressedTime = millis();
|
2019-03-13 11:13:03 +01:00
|
|
|
buttonPressedBefore = true;
|
2019-10-18 12:19:52 +02:00
|
|
|
|
|
|
|
if (millis() - buttonPressedTime > 600) //long press
|
|
|
|
{
|
|
|
|
if (!buttonLongPressed)
|
|
|
|
{
|
2020-11-06 22:12:48 +01:00
|
|
|
if (macroLongPress) {applyPreset(macroLongPress);}
|
2019-10-18 12:19:52 +02:00
|
|
|
else _setRandomColor(false,true);
|
|
|
|
|
|
|
|
buttonLongPressed = true;
|
|
|
|
}
|
|
|
|
}
|
2019-03-13 11:13:03 +01:00
|
|
|
}
|
2020-09-20 16:12:46 +02:00
|
|
|
else if (!isButtonPressed() && buttonPressedBefore) //released
|
2019-03-13 11:13:03 +01:00
|
|
|
{
|
|
|
|
long dur = millis() - buttonPressedTime;
|
|
|
|
if (dur < 50) {buttonPressedBefore = false; return;} //too short "press", debounce
|
|
|
|
bool doublePress = buttonWaitTime;
|
|
|
|
buttonWaitTime = 0;
|
|
|
|
|
2019-10-18 12:19:52 +02:00
|
|
|
if (dur > 6000) //long press
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
2020-03-25 10:14:23 +01:00
|
|
|
WLED::instance().initAP(true);
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
2019-10-18 12:19:52 +02:00
|
|
|
else if (!buttonLongPressed) { //short press
|
2019-03-13 11:13:03 +01:00
|
|
|
if (macroDoublePress)
|
|
|
|
{
|
2020-11-06 22:12:48 +01:00
|
|
|
if (doublePress) applyPreset(macroDoublePress);
|
2019-03-13 11:13:03 +01:00
|
|
|
else buttonWaitTime = millis();
|
|
|
|
} else shortPressAction();
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
2019-03-13 11:13:03 +01:00
|
|
|
buttonPressedBefore = false;
|
2019-10-18 12:19:52 +02:00
|
|
|
buttonLongPressed = false;
|
2019-03-13 11:13:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (buttonWaitTime && millis() - buttonWaitTime > 450 && !buttonPressedBefore)
|
|
|
|
{
|
|
|
|
buttonWaitTime = 0;
|
|
|
|
shortPressAction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleIO()
|
|
|
|
{
|
|
|
|
handleButton();
|
|
|
|
|
|
|
|
//set relay when LEDs turn on
|
|
|
|
if (strip.getBrightness())
|
|
|
|
{
|
|
|
|
lastOnTime = millis();
|
|
|
|
if (offMode)
|
2020-10-12 20:13:13 +02:00
|
|
|
{
|
2021-01-17 00:20:31 +01:00
|
|
|
if (rlyPin>=0) {
|
|
|
|
pinMode(rlyPin, OUTPUT);
|
|
|
|
digitalWrite(rlyPin, rlyMde);
|
|
|
|
}
|
2019-03-13 11:13:03 +01:00
|
|
|
offMode = false;
|
|
|
|
}
|
|
|
|
} else if (millis() - lastOnTime > 600)
|
|
|
|
{
|
2021-01-17 00:20:31 +01:00
|
|
|
if (!offMode) {
|
|
|
|
#ifdef ESP8266
|
2021-01-21 01:21:16 +01:00
|
|
|
//turn off built-in LED if strip is turned off
|
|
|
|
pinMode(LED_BUILTIN, OUTPUT);
|
|
|
|
digitalWrite(LED_BUILTIN, HIGH);
|
2020-10-12 20:13:13 +02:00
|
|
|
#endif
|
2021-01-17 00:20:31 +01:00
|
|
|
if (rlyPin>=0) {
|
|
|
|
pinMode(rlyPin, OUTPUT);
|
|
|
|
digitalWrite(rlyPin, !rlyMde);
|
|
|
|
}
|
|
|
|
}
|
2019-03-13 11:13:03 +01:00
|
|
|
offMode = true;
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
|
|
|
}
|