Rpi-hw  0.7.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
input.hpp
1 /*
2  Title --- iface/input.hpp
3 
4  Copyright (C) 2013 Giacomo Trudu - wicker25[at]gmail[dot]com
5 
6  This file is part of Rpi-hw.
7 
8  Rpi-hw is free software: you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation version 3 of the License.
11 
12  Rpi-hw is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with Rpi-hw. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 
22 #ifndef _RPI_HW_IFACE_INPUT_HPP_
23 #define _RPI_HW_IFACE_INPUT_HPP_
24 
25 #include <initializer_list>
26 #include <vector>
27 
28 #include <rpi-hw/types.hpp>
29 #include <rpi-hw/exception.hpp>
30 #include <rpi-hw/math.hpp>
31 #include <rpi-hw/utils.hpp>
32 
33 #include <rpi-hw/iface/base.hpp>
34 
35 namespace rpihw { // Begin main namespace
36 
37 namespace iface { // Begin interfaces namespace
38 
39 /*!
40  @class input
41  @brief Input interface.
42 */
43 class input : public iface::base {
44 
45 public:
46 
47  /*!
48  @brief Constructor method.
49  @param[in] pins Sequence of `uint8_t` containing the GPIO pins.
50  @param[in] pull_mode The pull resistor mode.
51  */
52  input( std::initializer_list< uint8_t > pins, uint8_t pull_mode = PULL_DOWN );
53 
54  /*!
55  @brief Constructor method.
56  @param[in] pins Vector containing the GPIO pins.
57  @param[in] pull_mode The pull resistor mode.
58  */
59  input( const std::vector< uint8_t > &pins, uint8_t pull_mode = PULL_DOWN );
60 
61  //! Destructor method.
62  virtual ~input();
63 
64  /*!
65  @brief Sets an input pin.
66  @param[in] index The index position of the input pin.
67  @param[in] pin The new GPIO pin.
68  */
69  virtual void setPin( uint8_t index, uint8_t pin );
70 
71  /*!
72  @brief Reads from the interface.
73  @return The data read from the interface.
74  */
75  virtual size_t read() const;
76 
77  /*!
78  @brief Reads from the interface.
79  @param[in] index The index position of the interface pin.
80  @return The data read from the interface.
81  */
82  virtual bool read( uint8_t index ) const;
83 
84 protected:
85 
86  //! The pull resistor mode.
87  uint8_t m_pull_mode;
88 };
89 
90 } // End of interfaces namespace
91 
92 } // End of main namespace
93 
94 
95 // Include inline methods
96 #include <rpi-hw/iface/input-inl.hpp>
97 
98 #endif /* _RPI_HW_IFACE_INPUT_HPP_ */
virtual void setPin(uint8_t index, uint8_t pin)
Sets an input pin.
Definition: input-inl.hpp:30
Generic interface.
Definition: base.hpp:48
uint8_t m_pull_mode
The pull resistor mode.
Definition: input.hpp:87
Input interface.
Definition: input.hpp:43
virtual ~input()
Destructor method.
input(std::initializer_list< uint8_t > pins, uint8_t pull_mode=PULL_DOWN)
Constructor method.
virtual size_t read() const
Reads from the interface.