knx/src/button.cpp

40 lines
808 B
C++
Raw Normal View History

2018-04-09 23:58:35 +02:00
#include "button.h"
#include "state.h"
#include "knx_facade.h"
2018-11-07 00:32:36 +01:00
#ifdef USE_STATES
2018-04-09 23:58:35 +02:00
unsigned long buttonTimestamp = 0;
2018-11-07 00:32:36 +01:00
void buttonDown()
{
buttonTimestamp = millis();
attachInterrupt(knx.buttonPin(), buttonUp, RISING);
}
#endif
2018-04-09 23:58:35 +02:00
void buttonUp()
{
2018-11-07 00:32:36 +01:00
#ifdef USE_STATES
2018-04-09 23:58:35 +02:00
if (millis() - buttonTimestamp > 1000)
{
Serial.println("long button press");
currentState->longButtonPress();
}
else
{
Serial.println("short button press");
currentState->shortButtonPress();
}
attachInterrupt(knx.buttonPin(), buttonDown, FALLING);
2018-11-07 00:32:36 +01:00
#else if (knx.progMode())
{
digitalWrite(knx.ledPin(), LOW);
knx.progMode(false);
}
else
{
digitalWrite(knx.ledPin(), HIGH);
knx.progMode(true);
}
#endif
2018-04-09 23:58:35 +02:00
}