jp112

StateButton inverted

Nov 3rd, 2018
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.42 KB | None | 0 0
  1. class RemoteChannel : public Channel<Hal, RemoteList1, EmptyList, DefList4, PEERS_PER_RemoteChannel, SwList0>, public StateButton<LOW,HIGH,INPUT> {
  2.   private:
  3.     uint8_t       repeatcnt;
  4.  
  5.   public:
  6.     typedef Channel<Hal, RemoteList1, EmptyList, DefList4, PEERS_PER_RemoteChannel, SwList0> BaseChannel;
  7.  
  8.     RemoteChannel () : BaseChannel() {}
  9.     virtual ~RemoteChannel () {}
  10.  
  11.     StateButton& button () {
  12.       return *(StateButton*)this;
  13.     }
  14.  
  15.     uint8_t status () const {
  16.       return 0;
  17.     }
  18.  
  19.     uint8_t flags () const {
  20.       return 0;
  21.     }
  22.  
  23.     virtual void state(uint8_t s) {
  24.       DHEX(BaseChannel::number());
  25.       StateButton::state(s);
  26.       RemoteEventMsg& msg = (RemoteEventMsg&)this->device().message();
  27.       DPRINT("BATTERY IS LOW? "); DDECLN(this->device().battery().low());
  28.       msg.init(this->device().nextcount(), this->number(), repeatcnt, (s == longreleased || s == longpressed), this->device().battery().low());
  29.       if ( s == released || s == longreleased) {
  30.         this->device().sendPeerEvent(msg, *this);
  31.         repeatcnt++;
  32.       }
  33.       else if (s == longpressed) {
  34.         this->device().broadcastPeerEvent(msg, *this);
  35.       }
  36.     }
  37.  
  38.     uint8_t state() const {
  39.       return StateButton::state();
  40.     }
  41.  
  42.     bool pressed () const {
  43.       uint8_t s = state();
  44.       return s == StateButton::pressed || s == StateButton::debounce || s == StateButton::longpressed;
  45.     }
  46. };
Advertisement
Add Comment
Please, Sign In to add comment