AceButton  1.6.1
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 
81  void checkButtons() const;
82 
84  uint8_t getNoButtonPin() const {
85  return mNumLevels - 1;
86  }
87 
88  protected:
94  virtual uint8_t getVirtualPin() const;
95 
96  private:
97  // Allow unit test to access extractIndex().
98  friend class ::LadderButtonConfig_extractIndex;
99 
100  // Disable copy-constructor and assignment operator
101  LadderButtonConfig(const LadderButtonConfig&) = delete;
102  LadderButtonConfig& operator=(const LadderButtonConfig&) = delete;
103 
108  static uint8_t extractIndex(uint8_t numLevels, uint16_t const levels[],
109  uint16_t level);
110 
111  private:
112  // Arranged for efficient packing on 32-bit processors
113  uint8_t const mPin;
114  uint8_t const mNumLevels;
115  uint8_t const mNumButtons;
116  uint8_t const mPressedState;
117  uint16_t const* const mLevels;
118  AceButton* const* const mButtons;
119 };
120 
121 }
122 
123 #endif
ace_button::LadderButtonConfig::LadderButtonConfig
LadderButtonConfig(uint8_t pin, uint8_t numLevels, const uint16_t levels[], uint8_t numButtons, AceButton *const buttons[], uint8_t defaultReleasedState=HIGH)
Constructor.
Definition: LadderButtonConfig.cpp:30
ace_button::LadderButtonConfig::readButton
int readButton(uint8_t pin) override
Return state of the button corresponding to the virtual 'pin' number.
Definition: LadderButtonConfig.cpp:53
ace_button::LadderButtonConfig::checkButtons
void checkButtons() const
Read the single mPin once, calculate the virtual pin number of the pressed button (if any),...
Definition: LadderButtonConfig.cpp:58
ace_button::LadderButtonConfig
A ButtonConfig that handles multiple buttons using a resistor ladder.
Definition: LadderButtonConfig.h:40
ace_button::AceButton
An Adjustable Compact Event-driven (ACE) Button library that debounces and dispatches button events t...
Definition: AceButton.h:50
ace_button::LadderButtonConfig::getVirtualPin
virtual uint8_t getVirtualPin() const
Return the virtual pin number corresponding to current state of the ADC.
Definition: LadderButtonConfig.cpp:74
ace_button::ButtonConfig
Class that defines the timing parameters and event handler of an AceButton or a group of AceButton in...
Definition: ButtonConfig.h:66
ace_button::LadderButtonConfig::getNoButtonPin
uint8_t getNoButtonPin() const
The virtual button pin number corresponding to "no button" pressed.
Definition: LadderButtonConfig.h:84