Rpi-hw  0.7.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
hd44780-inl.hpp
1 /*
2  Title --- display/hd44780-inl.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_HD44780_INL_HPP_
23 #define _RPI_HW_DISPLAY_HD44780_INL_HPP_
24 
25 namespace rpihw { // Begin main namespace
26 
27 namespace display { // Begin displays namespace
28 
29 inline void
30 hd44780::cmd( uint8_t data ) {
31 
32  // Set RS value to low
33  m_mode->write( 0, 0 );
34 
35  // Send the command to the display
36  sendSerial( data, 5000 );
37 }
38 
39 inline uint8_t
41 
42  // Return cursor x position
43  return m_pos_x;
44 }
45 
46 inline uint8_t
48 
49  // Return cursor x position
50  return m_pos_y;
51 }
52 
53 inline uint8_t
54 hd44780::getChar( uint8_t x, uint8_t y ) const {
55 
56  // Return a character from the buffer
57  return m_buffer[ x + y * m_width ];
58 }
59 
60 inline void
61 hd44780::write( uint8_t x, uint8_t y, uint8_t c ) {
62 
63  // Set the position of the cursor on the display
64  move( x, y );
65 
66  // Write the character on the display
67  write( c );
68 }
69 
70 inline void
71 hd44780::write( const std::string &text, uint8_t flags ) {
72 
73  // Align the text and write it on the display
74  write( utils::align( text, m_width, flags ) );
75 }
76 
77 inline void
78 hd44780::write( uint8_t x, uint8_t y, const std::string &text ) {
79 
80  // Set the position of the cursor on the display
81  move( x, y );
82 
83  // Write the string on the display
84  write( text );
85 }
86 
87 inline void
88 hd44780::write( uint8_t x, uint8_t y, const std::string &text, uint8_t flags ) {
89 
90  // Set the position of the cursor on the display
91  move( x, y );
92 
93  // Write the string on the display
94  write( text, flags );
95 }
96 
97 inline void
98 hd44780::write( const std::u32string &text, uint8_t flags ) {
99 
100  // Align the text and write it on the display
101  write( utils::align( text, m_width, flags ) );
102 }
103 
104 inline void
105 hd44780::write( uint8_t x, uint8_t y, const std::u32string &text ) {
106 
107  // Set the position of the cursor on the display
108  move( x, y );
109 
110  // Write the unicode string on the display
111  write( text );
112 }
113 
114 inline void
115 hd44780::write( uint8_t x, uint8_t y, const std::u32string &text, uint8_t flags ) {
116 
117  // Set the position of the cursor on the display
118  move( x, y );
119 
120  // Write the unicode string on the display
121  write( text, flags );
122 }
123 
124 inline void
125 hd44780::write( const std::wstring &text, uint8_t flags ) {
126 
127  // Align the text and write it on the display
128  write( utils::align( text, m_width, flags ) );
129 }
130 
131 inline void
132 hd44780::write( uint8_t x, uint8_t y, const std::wstring &text ) {
133 
134  // Set the position of the cursor on the display
135  move( x, y );
136 
137  // Write the unicode string on the display
138  write( text );
139 }
140 
141 inline void
142 hd44780::write( uint8_t x, uint8_t y, const std::wstring &text, uint8_t flags ) {
143 
144  // Set the position of the cursor on the display
145  move( x, y );
146 
147  // Write the unicode string on the display
148  write( text, flags );
149 }
150 
151 inline void
152 hd44780::setTypingDelay( size_t delay ) {
153 
154  // Set the typing delay
155  m_typing_delay = delay;
156 }
157 
158 inline size_t
160 
161  // Return the typing delay
162  return m_typing_delay;
163 }
164 
165 inline void
166 hd44780::setAutoscroll( uint8_t mode ) {
167 
168  // Set the autoscroll mode
169  m_autoscroll = mode;
170 }
171 
172 } // End of displays namespace
173 
174 } // End of main namespace
175 
176 #endif /* _RPI_HW_DISPLAY_HD44780_INL_HPP_ */
uint8_t getCursorX() const
Returns the current x-position of the cursor.
Definition: hd44780-inl.hpp:40
std::vector< uint8_t > m_buffer
Text buffer.
Definition: hd44780.hpp:399
uint8_t m_pos_x
Cursor position.
Definition: hd44780.hpp:403
uint8_t getChar(uint8_t x, uint8_t y) const
Reads a character from the buffer at specified position.
Definition: hd44780-inl.hpp:54
uint8_t m_width
Size of the display.
Definition: hd44780.hpp:389
void sendSerial(uint8_t data, size_t delay=0)
Sends a serial data to the display (a nibble at a time).
void write(uint8_t c)
Writes a character on the display.
void move(uint8_t x, uint8_t y)
Sets the position of the cursor on the display.
virtual void write(size_t data)
Writes a data on the interface.
uint8_t m_autoscroll
Autoscroll mode.
Definition: hd44780.hpp:410
std::basic_string< T > align(const std::basic_string< T > &text, size_t width, uint8_t flags)
Aligns a text.
Definition: utils-inl.hpp:66
iface::output * m_mode
Output interface to the control pins.
Definition: hd44780.hpp:379
void setTypingDelay(size_t delay)
Sets the typing delay between individual characters (milliseconds).
uint8_t getCursorY() const
Returns the current y-position of the cursor.
Definition: hd44780-inl.hpp:47
size_t getTypingDelay() const
Returns the typing delay between individual characters (milliseconds).
size_t m_typing_delay
Typing delay (milliseconds).
Definition: hd44780.hpp:407
void setAutoscroll(uint8_t mode)
Sets the autoscroll mode.
void cmd(uint8_t data)
Sends a command to the display.
Definition: hd44780-inl.hpp:30