Skip to content

Commit

Permalink
fix template initialisation for config button classes
Browse files Browse the repository at this point in the history
  • Loading branch information
pa-pa committed Mar 28, 2018
1 parent 9ec0958 commit 923fe6b
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Button.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace as {
template <uint8_t OFFSTATE=HIGH,uint8_t ONSTATE=LOW,WiringPinMode MODE=INPUT_PULLUP>
class StateButton: public Alarm {

#define DEBOUNCETIME millis2ticks(200)
#define DEBOUNCETIME millis2ticks(50)

public:
enum States {
Expand Down Expand Up @@ -142,6 +142,8 @@ class StateButton: public Alarm {
nexttick = DEBOUNCETIME;
}
break;
default:
break;
}
if( nexttick != 0 ) {
sysclock.cancel(*this);
Expand All @@ -164,14 +166,15 @@ class StateButton: public Alarm {
typedef StateButton<HIGH,LOW,INPUT_PULLUP> Button;

template <class DEVTYPE,uint8_t OFFSTATE=HIGH,uint8_t ONSTATE=LOW,WiringPinMode MODE=INPUT_PULLUP>
class ConfigButton : public StateButton<HIGH,LOW,INPUT_PULLUP> {
class ConfigButton : public StateButton<OFFSTATE,ONSTATE,MODE> {
DEVTYPE& device;
public:
typedef StateButton<HIGH,LOW,INPUT_PULLUP> ButtonType;
typedef StateButton<OFFSTATE,ONSTATE,MODE> ButtonType;

ConfigButton (DEVTYPE& dev,uint8_t longpresstime=3) : device(dev) {
setLongPressTime(seconds2ticks(longpresstime));
this->setLongPressTime(seconds2ticks(longpresstime));
}
virtual ~ConfigButton () {}
virtual void state (uint8_t s) {
uint8_t old = ButtonType::state();
ButtonType::state(s);
Expand All @@ -180,7 +183,7 @@ class ConfigButton : public StateButton<HIGH,LOW,INPUT_PULLUP> {
}
else if( s == ButtonType::longpressed ) {
if( old == ButtonType::longpressed ) {
device.reset(); // long pressed again - reset
// device.reset(); // long pressed again - reset
}
else {
device.led().set(LedStates::key_long);
Expand All @@ -190,14 +193,15 @@ class ConfigButton : public StateButton<HIGH,LOW,INPUT_PULLUP> {
};

template <class DEVTYPE,uint8_t OFFSTATE=HIGH,uint8_t ONSTATE=LOW,WiringPinMode MODE=INPUT_PULLUP>
class ConfigToggleButton : public StateButton<HIGH,LOW,INPUT_PULLUP> {
class ConfigToggleButton : public StateButton<OFFSTATE,ONSTATE,MODE> {
DEVTYPE& device;
public:
typedef StateButton<HIGH,LOW,INPUT_PULLUP> ButtonType;
typedef StateButton<OFFSTATE,ONSTATE,MODE> ButtonType;

ConfigToggleButton (DEVTYPE& dev,uint8_t longpresstime=3) : device(dev) {
setLongPressTime(seconds2ticks(longpresstime));
this->setLongPressTime(seconds2ticks(longpresstime));
}
virtual ~ConfigToggleButton () {}
virtual void state (uint8_t s) {
uint8_t old = ButtonType::state();
ButtonType::state(s);
Expand Down

0 comments on commit 923fe6b

Please sign in to comment.