AceButton  1.2
An adjustable, compact, event-driven (ACE) button library for Arduino.
AdjustableButtonConfig.h
1 /*
2 MIT License
3 
4 Copyright (c) 2018 Brian T. Park
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24 
25 #ifndef ACE_BUTTON_ADJUSTABLE_BUTTON_CONFIG_H
26 #define ACE_BUTTON_ADJUSTABLE_BUTTON_CONFIG_H
27 
28 #include "ButtonConfig.h"
29 
30 namespace ace_button {
31 
40  public:
42  initInternal();
43  }
44 
45  virtual void init() override {
47  initInternal();
48  }
49 
50  virtual uint16_t getDebounceDelay() override {
51  return mDebounceDelay;
52  }
53 
54  virtual uint16_t getClickDelay() override {
55  return mClickDelay;
56  }
57 
58  virtual uint16_t getDoubleClickDelay() override {
59  return mDoubleClickDelay;
60  }
61 
62  virtual uint16_t getLongPressDelay() override {
63  return mLongPressDelay;
64  }
65 
66  virtual uint16_t getRepeatPressDelay() override {
67  return mRepeatPressDelay;
68  }
69 
70  virtual uint16_t getRepeatPressInterval() override {
71  return mRepeatPressInterval;
72  }
73 
75  void setDebounceDelay(uint16_t debounceDelay) {
76  mDebounceDelay = debounceDelay;
77  }
78 
80  void setClickDelay(uint16_t clickDelay) {
81  mClickDelay = clickDelay;
82  }
83 
85  void setDoubleClickDelay(uint16_t doubleClickDelay) {
86  mDoubleClickDelay = doubleClickDelay;
87  }
88 
90  void setLongPressDelay(uint16_t longPressDelay) {
91  mLongPressDelay = longPressDelay;
92  }
93 
95  void setRepeatPressDelay(uint16_t repeatPressDelay) {
96  mRepeatPressDelay = repeatPressDelay;
97  }
98 
100  void setRepeatPressInterval(uint16_t repeatPressInterval) {
101  mRepeatPressInterval = repeatPressInterval;
102  }
103 
104  private:
105  // Disable copy-constructor and assignment operator
107  AdjustableButtonConfig& operator=(const AdjustableButtonConfig&) = delete;
108 
109  // This method must remain non-virtual so that it can be called safely from
110  // the constructor.
111  void initInternal() {
112  mDebounceDelay = kDebounceDelay;
113  mClickDelay = kClickDelay;
114  mDoubleClickDelay = kDoubleClickDelay;
115  mLongPressDelay = kLongPressDelay;
116  mRepeatPressDelay = kRepeatPressDelay;
117  mRepeatPressInterval = kRepeatPressInterval;
118  }
119 
120  uint16_t mDebounceDelay;
121  uint16_t mClickDelay;
122  uint16_t mDoubleClickDelay;
123  uint16_t mLongPressDelay;
124  uint16_t mRepeatPressDelay;
125  uint16_t mRepeatPressInterval;
126 };
127 
128 }
129 #endif
static const uint16_t kRepeatPressInterval
Default value returned by getRepeatPressInterval().
Definition: ButtonConfig.h:101
virtual uint16_t getRepeatPressDelay() override
Milliseconds that a button needs to be Pressed down before the start of the sequence of RepeatPressed...
static const uint16_t kDebounceDelay
Default value returned by getDebounceDelay().
Definition: ButtonConfig.h:86
virtual void init() override
Initialize to its pristine state, except for the EventHandler which is unchanged. ...
virtual void init()
Initialize to its pristine state, except for the EventHandler which is unchanged. ...
Definition: ButtonConfig.h:302
void setRepeatPressInterval(uint16_t repeatPressInterval)
Set the repeatPressInterval.
void setLongPressDelay(uint16_t longPressDelay)
Set the longPressDelay.
A subclass of ButtonConfig which allows the user to override the varous timing parameters of ButtonCo...
virtual uint16_t getRepeatPressInterval() override
Milliseconds between two successive RepeatPressed events.
void setDebounceDelay(uint16_t debounceDelay)
Set the debounceDelay.
virtual uint16_t getDoubleClickDelay() override
Milliseconds between the first and second click to register as a double-click.
Class that defines the timing parameters and event handler of an AceButton or a group of AceButton in...
Definition: ButtonConfig.h:69
virtual uint16_t getLongPressDelay() override
Milliseconds for a long press event.
virtual uint16_t getClickDelay() override
Milliseconds to wait for a possible click.
virtual uint16_t getDebounceDelay() override
Milliseconds to wait for debouncing.
static const uint16_t kDoubleClickDelay
Default value returned by getDoubleClickDelay().
Definition: ButtonConfig.h:92
static const uint16_t kClickDelay
Default value returned by getClickDelay().
Definition: ButtonConfig.h:89
static const uint16_t kRepeatPressDelay
Default value returned by getRepeatPressDelay().
Definition: ButtonConfig.h:98
void setClickDelay(uint16_t clickDelay)
Set the clickDelay.
static const uint16_t kLongPressDelay
Default value returned by getLongPressDelay().
Definition: ButtonConfig.h:95
void setRepeatPressDelay(uint16_t repeatPressDelay)
Set the repeatPressDelay.
void setDoubleClickDelay(uint16_t doubleClickDelay)
Set the doubleClickDelay.