-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSharpDisplay.h
224 lines (186 loc) · 6.38 KB
/
SharpDisplay.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#pragma once
//
// Lucky Resistor's Deluxe Data Logger
// ---------------------------------------------------------------------------
// (c)2015 by Lucky Resistor. See LICENSE for details.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
#include <Arduino.h>
namespace lr {
/// This is a compact driver for the LS013B4DN04 display from Sharp.
///
/// The driver uses fixed 8x8 pixel characters to show text on the display.
/// You can use special characters to draw simple boxes and lines.
///
/// See http://luckyresistor.me for details.
///
/// You can buy the display from Adafruit: http://www.adafruit.com/products/1393
///
/// Because there is only one instance of this class possible, it is
/// implemented as collection of functions to reduce the overall code size.
///
namespace SharpDisplay {
/// The scroll direction.
///
enum ScrollDirection : uint8_t {
ScrollUp,
ScrollDown,
ScrollLeft,
ScrollRight
};
/// The refresh interval
///
enum RefreshInterval : uint8_t {
NormalRefresh, ///< Refresh every ~100ms
SlowRefresh, ///< Refresh every second.
};
/// The type for the interrupt callback.
///
typedef void (*InterruptCallback)();
/// Call this method in the setup() method to initialize the driver.
///
/// This will start timer2 to automatically trigger the display refresh.
///
void begin(uint8_t chipSelectPin, uint8_t clockPin, uint8_t dataPin);
/// Change the refresh interval
///
void setRefreshInterval(RefreshInterval refreshInterval);
/// Set a function which is called for each interrupt.
///
void setInterruptCallback(InterruptCallback interruptCallback);
/// Set the font for the display.
///
/// You have to set a font initially.
/// The driver will not check if the font provides data for all 128
/// characters. To save space in the flash RAM, you can provide a font
/// which covers less than 128 characters. The behaviour for
/// higher characters is undefined in this case (random data is displayed).
///
/// The font has to be located in flash memory.
///
/// @param fontData A pointer to the font data in flash memory.
///
void setFont(const uint8_t *fontData);
/// Get the width of the display in characters.
///
inline uint8_t getScreenWidth() { return 12; }
/// Get the height of the display in characters.
///
inline uint8_t getScreenHeight() { return 12; }
/// Clears the display.
///
/// This will also clear the text buffer and fill the buffer with space (0x20).
/// It also sets the cursor at position 0, 0.
///
void clear();
/// Clears a range of rows.
///
void clearRows(uint8_t startRow, uint8_t rowCount = 1);
/// Enable/Disable inverse future text.
///
/// If you enable inverse text, any subsequent call of text writing methods
/// will write inverse text.
///
void setTextInverse(bool enable);
/// Set a single character on the screen.
///
/// The call of this method does not affect the cursor position.
///
/// @param row The row to set the character.
/// @param column The colum to set the character.
/// @param character The character to set at the given location.
///
void setCharacter(uint8_t row, uint8_t column, uint8_t character);
/// Get a single character from the screen.
///
/// @param row The row for the character.
/// @param column The column for the character.
/// @return The character the the given position.
///
char getCharacter(uint8_t row, uint8_t column);
/// Set the text for a single line.
///
/// If the text is longer than the line, the text is cut off.
/// If the text is shorter than the line, the rest of the line
/// is filled with spaces.
///
/// The call of this method does not affect the cursor position.
/// Any control characters are ignored.
///
/// @param row The row to write the text into.
/// @param text The text to write in the row.
///
void setLineText(uint8_t row, const String &text);
/// Set the text for a single line using null terminated text from flash memory.
///
void setLineText(uint8_t row, const char *prgMemText);
/// Fill a row with the given character.
///
void fillRow(uint8_t row, char c);
/// Set the inversion state of a row
///
/// @param row The row to set the inversion.
/// @param inverted true to set the row to inverse, false to set it not inverse.
///
void setLineInverted(uint8_t row, bool inverted);
/// Set the position of the cursor.
///
/// The cursor can be one column and row out of the
/// visible screen.
///
/// @param row The row for the cursor.
/// @param column The column for the cursor.
///
void setCursorPosition(uint8_t row, uint8_t column);
/// Get the current cursor position.
///
void getCursorPosition(uint8_t &row, uint8_t &column);
/// Write a single character at the cursor position on the screen.
///
/// @param character The character to write.
///
void writeCharacter(uint8_t c);
/// Write text at the cursor position on the screen.
///
/// The text will wrap around after the last charcater in the
/// column. The control character "newline" (\n) will add a
/// line break and continue on the next line. If the cursor
/// reaches the end of the screen, the screen contents are
/// scrolled up one row.
///
/// @param text The text to write to the screen.
///
void writeText(const String &text);
/// Write text at the cursor position on the screen.
///
/// The text will wrap around after the last charcater in the
/// column. The control character "newline" (\n) will add a
/// line break and continue on the next line. If the cursor
/// reaches the end of the screen, the screen contents are
/// scrolled up one row.
///
/// @param text The text to write to the screen in flash memory.
///
void writeText(const char *prgMemText);
/// Scroll the screen in the given direction.
///
/// The new areas are initialized with empty characters.
///
/// @param direction The scroll direction.
///
void scrollScreen(ScrollDirection direction);
}
}