AceButton  1.10.0
An adjustable, compact, event-driven button library for Arduino.
LadderButtonConfig.h
1 /*
2 MIT License
3 
4 Copyright (c) 2020 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_LADDER_BUTTON_CONFIG_H
26 #define ACE_BUTTON_LADDER_BUTTON_CONFIG_H
27 
28 #include "ButtonConfig.h"
29 
30 // Unit test
31 class LadderButtonConfig_extractIndex;
32 
33 namespace ace_button {
34 
35 class AceButton;
36 
41  public:
42 
61  LadderButtonConfig(uint8_t pin, uint8_t numLevels, const uint16_t levels[],
62  uint8_t numButtons, AceButton* const buttons[],
63  uint8_t defaultReleasedState = HIGH);
64 
72  int readButton(uint8_t pin) override;
73 
90  void checkButtons() const;
91 
93  uint8_t getNoButtonPin() const {
94  return mNumLevels - 1;
95  }
96 
97  protected:
104  virtual uint8_t getVirtualPin() const;
105 
106  private:
107  // Allow unit test to access extractIndex().
108  friend class ::LadderButtonConfig_extractIndex;
109 
110  // Disable copy-constructor and assignment operator
111  LadderButtonConfig(const LadderButtonConfig&) = delete;
112  LadderButtonConfig& operator=(const LadderButtonConfig&) = delete;
113 
118  static uint8_t extractIndex(uint8_t numLevels, uint16_t const levels[],
119  uint16_t level);
120 
121  private:
122  // Arranged for efficient packing on 32-bit processors
123  uint8_t const mPin;
124  uint8_t const mNumLevels;
125  uint8_t const mNumButtons;
126  uint8_t const mPressedState;
127  uint16_t const* const mLevels;
128  AceButton* const* const mButtons;
129 };
130 
131 }
132 
133 #endif
An Adjustable Compact Event-driven (ACE) Button library that debounces and dispatches button events t...
Definition: AceButton.h:54
Class that defines the timing parameters and event handler of an AceButton or a group of AceButton in...
Definition: ButtonConfig.h:66
A ButtonConfig that handles multiple buttons using a resistor ladder.
uint8_t getNoButtonPin() const
The virtual button pin number corresponding to "no button" pressed.
LadderButtonConfig(uint8_t pin, uint8_t numLevels, const uint16_t levels[], uint8_t numButtons, AceButton *const buttons[], uint8_t defaultReleasedState=HIGH)
Constructor.
int readButton(uint8_t pin) override
Return state of the button corresponding to the virtual 'pin' number.
virtual uint8_t getVirtualPin() const
Return the virtual pin number corresponding to current state of the ADC as returned by the analogRead...
void checkButtons() const
Read the single mPin once, calculate the virtual pin number of the pressed button (if any),...