Skip to content

Commit

Permalink
fix counter for InternalButton long press
Browse files Browse the repository at this point in the history
  • Loading branch information
pa-pa committed Dec 27, 2017
1 parent 9287ee7 commit 0daeedf
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Button.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,30 +232,34 @@ class ConfigToggleButton : public StateButton<HIGH,LOW,INPUT_PULLUP> {
template <class DEVTYPE,uint8_t OFFSTATE=HIGH,uint8_t ONSTATE=LOW,WiringPinMode MODE=INPUT_PULLUP>
class InternalButton : public StateButton<HIGH,LOW,INPUT_PULLUP> {
DEVTYPE& device;
uint8_t num;
uint8_t num, counter;
public:
typedef StateButton<HIGH,LOW,INPUT_PULLUP> ButtonType;

InternalButton (DEVTYPE& dev,uint8_t n,uint8_t longpresstime=4) : device(dev), num(n) {
InternalButton (DEVTYPE& dev,uint8_t n,uint8_t longpresstime=4) : device(dev), num(n), counter(0) {
setLongPressTime(decis2ticks(longpresstime));
}
virtual void state (uint8_t s) {
ButtonType::state(s);
if( s == ButtonType::released ) {
RemoteEventMsg& msg = fillMsg(false);
device.process(msg);
counter++;
}
else if( s == ButtonType::longpressed ) {
RemoteEventMsg& msg = fillMsg(true);
device.process(msg);
}
else if( s == ButtonType::longreleased ) {
counter++;
}
}
RemoteEventMsg& fillMsg (bool lg) {
RemoteEventMsg& msg = (RemoteEventMsg&)device.message();
HMID self;
device.getDeviceID(self);
uint8_t cnt = device.nextcount();
msg.init(cnt,num,cnt,lg,false);
msg.init(cnt,num,counter,lg,false);
msg.to(self);
msg.from(self);
return msg;
Expand Down

0 comments on commit 0daeedf

Please sign in to comment.