2016-12-31 00:38:51 +01:00
|
|
|
/*
|
|
|
|
* Physical IO
|
|
|
|
*/
|
|
|
|
|
2016-11-19 19:39:17 +01:00
|
|
|
void handleButton()
|
|
|
|
{
|
2019-02-20 15:10:23 +01:00
|
|
|
if (buttonEnabled && millis() - buttonReleasedTime > 20) //debounce
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
2019-02-20 15:10:23 +01:00
|
|
|
if (digitalRead(BTNPIN) == LOW && !buttonPressedBefore) //pressed
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
2018-01-15 00:20:23 +01:00
|
|
|
buttonPressedTime = millis();
|
2016-11-19 19:39:17 +01:00
|
|
|
buttonPressedBefore = true;
|
|
|
|
}
|
2019-02-20 15:10:23 +01:00
|
|
|
else if (digitalRead(BTNPIN) == HIGH && buttonPressedBefore) //released
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
2019-02-20 15:10:23 +01:00
|
|
|
if (buttonReleasedTime == 0) {
|
|
|
|
buttonReleasedTime = millis();
|
|
|
|
} else {
|
|
|
|
if (digitalRead(BTNPIN) == HIGH)
|
2018-03-06 23:47:08 +01:00
|
|
|
{
|
2019-02-20 15:10:23 +01:00
|
|
|
if (buttonReleasedTime - buttonPressedTime > 7000) {initAP();}
|
|
|
|
else if (buttonReleasedTime - buttonPressedTime > 700)
|
2018-03-06 23:47:08 +01:00
|
|
|
{
|
2019-02-20 15:10:23 +01:00
|
|
|
if (macroLongPress != 0) {applyMacro(macroLongPress);}
|
|
|
|
else _setRandomColor(false,true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (macroButton == 0)
|
|
|
|
{
|
|
|
|
toggleOnOff();
|
|
|
|
colorUpdated(2);
|
|
|
|
} else {
|
|
|
|
applyMacro(macroButton);
|
|
|
|
}
|
2018-03-06 23:47:08 +01:00
|
|
|
}
|
2019-02-20 15:10:23 +01:00
|
|
|
buttonPressedBefore = false;
|
2018-03-06 23:47:08 +01:00
|
|
|
}
|
2019-02-20 15:10:23 +01:00
|
|
|
buttonReleasedTime = 0;
|
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
|
|
|
}
|