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
40 class LadderButtonConfig : public ButtonConfig {
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
ace_button::AceButton
An Adjustable Compact Event-driven (ACE) Button library that debounces and dispatches button events t...
Definition: AceButton.h:54
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
A ButtonConfig that handles multiple buttons using a resistor ladder.
Definition: LadderButtonConfig.h:40
ace_button::LadderButtonConfig::getNoButtonPin
uint8_t getNoButtonPin() const
The virtual button pin number corresponding to "no button" pressed.
Definition: LadderButtonConfig.h:93
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::getVirtualPin
virtual uint8_t getVirtualPin() const
Return the virtual pin number corresponding to current state of the ADC as returned by the analogRead...
Definition: LadderButtonConfig.cpp:74
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