2020-04-10 12:30:08 +02:00
|
|
|
#include "wled.h"
|
|
|
|
|
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 {
|
|
|
|
applyMacro(macroButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-19 19:39:17 +01:00
|
|
|
void handleButton()
|
|
|
|
{
|
2019-05-01 03:09:08 +02:00
|
|
|
#ifdef BTNPIN
|
2019-03-13 11:13:03 +01:00
|
|
|
if (!buttonEnabled) return;
|
|
|
|
|
2019-10-18 12:19:52 +02:00
|
|
|
if (digitalRead(BTNPIN) == LOW) //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)
|
|
|
|
{
|
|
|
|
if (macroLongPress) {applyMacro(macroLongPress);}
|
|
|
|
else _setRandomColor(false,true);
|
|
|
|
|
|
|
|
buttonLongPressed = true;
|
|
|
|
}
|
|
|
|
}
|
2019-03-13 11:13:03 +01:00
|
|
|
}
|
|
|
|
else if (digitalRead(BTNPIN) == HIGH && buttonPressedBefore) //released
|
|
|
|
{
|
|
|
|
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-04-10 12:30:08 +02: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)
|
|
|
|
{
|
|
|
|
if (doublePress) applyMacro(macroDoublePress);
|
|
|
|
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();
|
|
|
|
}
|
2019-05-01 03:09:08 +02:00
|
|
|
#endif
|
2019-03-13 11:13:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void handleIO()
|
|
|
|
{
|
|
|
|
handleButton();
|
|
|
|
|
|
|
|
//set relay when LEDs turn on
|
|
|
|
if (strip.getBrightness())
|
|
|
|
{
|
|
|
|
lastOnTime = millis();
|
|
|
|
if (offMode)
|
|
|
|
{
|
|
|
|
#if RLYPIN >= 0
|
|
|
|
digitalWrite(RLYPIN, RLYMDE);
|
|
|
|
#endif
|
|
|
|
offMode = false;
|
|
|
|
}
|
|
|
|
} else if (millis() - lastOnTime > 600)
|
|
|
|
{
|
|
|
|
#if RLYPIN >= 0
|
|
|
|
if (!offMode) digitalWrite(RLYPIN, !RLYMDE);
|
|
|
|
#endif
|
|
|
|
offMode = true;
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
2017-01-27 22:59:01 +01:00
|
|
|
|
2019-02-20 15:10:23 +01:00
|
|
|
#if AUXPIN >= 0
|
2017-01-27 22:59:01 +01:00
|
|
|
//output
|
|
|
|
if (auxActive || auxActiveBefore)
|
|
|
|
{
|
|
|
|
if (!auxActiveBefore)
|
|
|
|
{
|
|
|
|
auxActiveBefore = true;
|
|
|
|
switch (auxTriggeredState)
|
|
|
|
{
|
2018-11-18 00:31:45 +01:00
|
|
|
case 0: pinMode(AUXPIN, INPUT); break;
|
|
|
|
case 1: pinMode(AUXPIN, OUTPUT); digitalWrite(AUXPIN, HIGH); break;
|
|
|
|
case 2: pinMode(AUXPIN, OUTPUT); digitalWrite(AUXPIN, LOW); break;
|
2017-01-27 22:59:01 +01:00
|
|
|
}
|
|
|
|
auxStartTime = millis();
|
|
|
|
}
|
|
|
|
if ((millis() - auxStartTime > auxTime*1000 && auxTime != 255) || !auxActive)
|
|
|
|
{
|
|
|
|
auxActive = false;
|
|
|
|
auxActiveBefore = false;
|
|
|
|
switch (auxDefaultState)
|
|
|
|
{
|
2018-11-18 00:31:45 +01:00
|
|
|
case 0: pinMode(AUXPIN, INPUT); break;
|
|
|
|
case 1: pinMode(AUXPIN, OUTPUT); digitalWrite(AUXPIN, HIGH); break;
|
|
|
|
case 2: pinMode(AUXPIN, OUTPUT); digitalWrite(AUXPIN, LOW); break;
|
2017-01-27 22:59:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-20 15:10:23 +01:00
|
|
|
#endif
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|