Rpi-hw  0.7.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
m7seg.hpp
1 /*
2  Title --- display/m7seg.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_DISPLAY_M7SEG_HPP_
23 #define _RPI_HW_DISPLAY_M7SEG_HPP_
24 
25 #include <thread>
26 #include <mutex>
27 
28 #include <rpi-hw/types.hpp>
29 #include <rpi-hw/exception.hpp>
30 #include <rpi-hw/math.hpp>
31 #include <rpi-hw/time.hpp>
32 
33 #include <rpi-hw/iface/base.hpp>
34 #include <rpi-hw/iface/output.hpp>
35 
36 #include <rpi-hw/display/s7seg.hpp>
37 
38 namespace rpihw { // Begin main namespace
39 
40 namespace display { // Begin displays namespace
41 
42 /*!
43  @class m7seg
44  @brief Multiple seven-segment display controller.
45 
46  @example display/m7seg0.cpp
47  @example display/m7seg1.cpp
48 */
49 class m7seg : public s7seg {
50 
51 public:
52 
53  /*!
54  @brief Constructor method.
55  @param[in] a The GPIO pin connected to the segment a.
56  @param[in] b The GPIO pin connected to the segment b.
57  @param[in] c The GPIO pin connected to the segment c.
58  @param[in] d The GPIO pin connected to the segment d.
59  @param[in] e The GPIO pin connected to the segment e.
60  @param[in] f The GPIO pin connected to the segment f.
61  @param[in] g The GPIO pin connected to the segment g.
62  */
63  m7seg( uint8_t a, uint8_t b, uint8_t c, uint8_t d,
64  uint8_t e, uint8_t f, uint8_t g );
65 
66  /*!
67  @brief Constructor method.
68  @param[in] a The GPIO pin connected to the segment a.
69  @param[in] b The GPIO pin connected to the segment b.
70  @param[in] c The GPIO pin connected to the segment c.
71  @param[in] d The GPIO pin connected to the segment d.
72  @param[in] e The GPIO pin connected to the segment e.
73  @param[in] f The GPIO pin connected to the segment f.
74  @param[in] g The GPIO pin connected to the segment g.
75  @param[in] dp The GPIO pin connected to the segment dp (decimal point).
76  */
77  m7seg( uint8_t a, uint8_t b, uint8_t c, uint8_t d,
78  uint8_t e, uint8_t f, uint8_t g, uint8_t dp );
79 
80  //! Destructor method.
81  virtual ~m7seg();
82 
83  /*!
84  @brief Sets the number of displays and the enabler interface.
85  @param[in] total Number of the displays.
86  @param[in] enabler Output interface used to enable the displays.
87  */
88  void setDisplays( size_t total, iface::output &enabler );
89 
90  /*!
91  @brief Sets the updating frequency.
92  @param[in] frequency The updating frequency in Hz.
93  */
94  void setFreq( float frequency );
95 
96  /*!
97  @brief Returns the updating frequency.
98  @return The updating frequency in Hz.
99  */
100  float getFreq() const;
101 
102  /*!
103  @brief Sets the value of the display.
104  @param[in] value The new value of the display.
105  */
106  void set( float value );
107 
108  /*!
109  @brief Sets the format of the display.
110  @param[in] decimals The number of decimals used to represent the value of the display.
111  @param[in] zeropad If \c true, zero pad the value of the display.
112  */
113  void format( uint8_t decimals, bool zeropad );
114 
115  //! Update the displays (threading function).
116  void render();
117 
118 protected:
119 
120  //! Number of the displays.
121  size_t m_ndisplay;
122 
123  //! Updating frequency (Hz).
124  float m_frequency;
125 
126  //! Number of decimals.
127  uint8_t m_decimals;
128 
129  //! Zeropad flag.
130  bool m_zeropad;
131 
132  //! Enabler interface.
134 
135  //! Rendering thread.
136  std::thread *m_thread;
137 
138  //! Mutex of the rendering thread.
139  std::mutex *m_mutex;
140 };
141 
142 } // End of displays namespace
143 
144 } // End of main namespace
145 
146 
147 // Include inline methods
148 #include <rpi-hw/display/m7seg-inl.hpp>
149 
150 #endif /* _RPI_HW_DISPLAY_M7SEG_HPP_ */
Output interface.
Definition: output.hpp:43
void setDisplays(size_t total, iface::output &enabler)
Sets the number of displays and the enabler interface.
Definition: m7seg-inl.hpp:30
bool m_zeropad
Zeropad flag.
Definition: m7seg.hpp:130
size_t m_ndisplay
Number of the displays.
Definition: m7seg.hpp:121
m7seg(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f, uint8_t g)
Constructor method.
void set(float value)
Sets the value of the display.
Seven-segment display controller.
Definition: s7seg.hpp:47
std::mutex * m_mutex
Mutex of the rendering thread.
Definition: m7seg.hpp:139
void render()
Update the displays (threading function).
void format(uint8_t decimals, bool zeropad)
Sets the format of the display.
virtual ~m7seg()
Destructor method.
float m_frequency
Updating frequency (Hz).
Definition: m7seg.hpp:124
float getFreq() const
Returns the updating frequency.
Definition: m7seg-inl.hpp:45
Multiple seven-segment display controller.
Definition: m7seg.hpp:49
iface::output * m_enabler
Enabler interface.
Definition: m7seg.hpp:133
std::thread * m_thread
Rendering thread.
Definition: m7seg.hpp:136
uint8_t m_decimals
Number of decimals.
Definition: m7seg.hpp:127
void setFreq(float frequency)
Sets the updating frequency.
Definition: m7seg-inl.hpp:38