RTLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
button.h
Go to the documentation of this file.
1 /*
2  * This file is part of RTLib.
3  *
4  * Copyright (C) 2017-2018 Derppening <david.18.19.21@gmail.com>
5  *
6  * RTLib is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * RTLib is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with RTLib. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef RTLIB_LIB_BUTTON_H_
21 #define RTLIB_LIB_BUTTON_H_
22 
23 #include <cstdint>
24 
25 #include "config/config.h"
26 #include "core/gpio.h"
27 
28 static_assert(LIB_USE_BUTTON > 0, "Button library is disabled in your configuration.");
29 
36 class Button {
37  public:
41  struct Config {
47  uint8_t id;
56  uint8_t pullup;
57  };
58 
64  explicit Button(const Config& config);
65 
69  ~Button() = default;
70 
76  Button(Button&& other) noexcept = default;
83  Button& operator=(Button&& other) noexcept = default;
84 
91  Button(const Button&) = delete;
98  Button& operator=(const Button&) = delete;
99 
108  bool Read();
109 
110  protected:
114  CORE_NS::GPIO* GetGpio() { return &gpio_; }
115 
116  private:
117  CORE_NS::GPIO gpio_;
118  bool polarity_;
119 };
120 
121 #endif // RTLIB_LIB_BUTTON_H_
uint8_t pullup
Specifies default state of the button.
Definition: button.h:56
Helper file for selecting which GPIO class to enable.
HAL implementation for buttons.
Definition: button.h:36
Helper file for selecting device configurations.
bool Read()
Reads the state of the button.
Definition: button.cpp:66
uint8_t id
ID of the button.
Definition: button.h:47
~Button()=default
Default trivial destructor.
Button(const Config &config)
Default constructor for Button.
Definition: button.cpp:54
CORE_NS::GPIO * GetGpio()
Definition: button.h:114
Configuration for button.
Definition: button.h:41