-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLiquidCrystal_CI.cpp
190 lines (164 loc) · 4.87 KB
/
LiquidCrystal_CI.cpp
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
#include "LiquidCrystal_CI.h"
#ifdef ARDUINO_CI_COMPILATION_MOCKS
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
LiquidCrystal_CI::LiquidCrystal_CI(uint8_t rs, uint8_t rw, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2,
uint8_t d3, uint8_t d4, uint8_t d5,
uint8_t d6, uint8_t d7)
: LiquidCrystal(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7) {
init(rs);
}
LiquidCrystal_CI::LiquidCrystal_CI(uint8_t rs, uint8_t enable, uint8_t d0,
uint8_t d1, uint8_t d2, uint8_t d3,
uint8_t d4, uint8_t d5, uint8_t d6,
uint8_t d7)
: LiquidCrystal(rs, enable, d0, d1, d2, d3, d4, d5, d6, d7) {
init(rs);
}
LiquidCrystal_CI::LiquidCrystal_CI(uint8_t rs, uint8_t rw, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2,
uint8_t d3)
: LiquidCrystal(rs, rw, enable, d0, d1, d2, d3) {
init(rs);
}
LiquidCrystal_CI::LiquidCrystal_CI(uint8_t rs, uint8_t enable, uint8_t d0,
uint8_t d1, uint8_t d2, uint8_t d3)
: LiquidCrystal(rs, enable, d0, d1, d2, d3) {
init(rs);
}
void LiquidCrystal_CI::init(uint8_t rs) {
_rs_pin = rs;
_col = 0;
_cols = 16;
_row = 0;
_rows = 1;
_autoscroll = false;
_display = false;
_cursor = false;
_blink = false;
_isInCreateChar = false;
_lines.clear();
_lines.resize(_rows);
for (int character = 0; character < 8; character++) {
for (int bite = 0; bite < 8; bite++) {
_customChars[character][bite] = B00000;
}
}
LiquidCrystal_CI::_instances[_rs_pin] = this;
}
void LiquidCrystal_CI::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
LiquidCrystal::begin(cols, lines, dotsize);
_col = 0;
_cols = cols;
_row = 0;
_rows = lines;
_autoscroll = false;
_display = false;
_cursor = false;
_blink = false;
_isInCreateChar = false;
_lines.clear();
_lines.resize(_rows);
}
/********** high level commands, for the user! */
void LiquidCrystal_CI::clear() {
LiquidCrystal::clear();
_lines.clear();
_lines.resize(_rows);
}
void LiquidCrystal_CI::home() {
LiquidCrystal::home();
_col = _row = 0;
}
void LiquidCrystal_CI::setCursor(uint8_t col, uint8_t row) {
LiquidCrystal::setCursor(col, row);
_col = col;
_row = row;
}
// Turn the display on/off (quickly)
void LiquidCrystal_CI::noDisplay() {
LiquidCrystal::noDisplay();
_display = false;
}
void LiquidCrystal_CI::display() {
LiquidCrystal::display();
_display = true;
}
// Turns the underline cursor on/off
void LiquidCrystal_CI::noCursor() {
LiquidCrystal::noCursor();
_cursor = false;
}
void LiquidCrystal_CI::cursor() {
LiquidCrystal::cursor();
_cursor = true;
}
// Turn on and off the blinking cursor
void LiquidCrystal_CI::noBlink() {
LiquidCrystal::noBlink();
_blink = false;
}
void LiquidCrystal_CI::blink() {
LiquidCrystal::blink();
_blink = true;
}
// These commands scroll the display without changing the RAM
void LiquidCrystal_CI::scrollDisplayLeft() {
LiquidCrystal::scrollDisplayLeft();
}
void LiquidCrystal_CI::scrollDisplayRight() {
LiquidCrystal::scrollDisplayRight();
}
// This is for text that flows Left to Right
void LiquidCrystal_CI::leftToRight() { LiquidCrystal::leftToRight(); }
// This is for text that flows Right to Left
void LiquidCrystal_CI::rightToLeft() { LiquidCrystal::rightToLeft(); }
// This will 'right justify' text from the cursor
void LiquidCrystal_CI::autoscroll() {
LiquidCrystal::autoscroll();
_autoscroll = true;
}
// This will 'left justify' text from the cursor
void LiquidCrystal_CI::noAutoscroll() {
LiquidCrystal::noAutoscroll();
_autoscroll = false;
}
// Allows us to fill the first 8 CGRAM locations
// with custom characters
void LiquidCrystal_CI::createChar(uint8_t location, uint8_t charmap[]) {
_isInCreateChar = true;
LiquidCrystal::createChar(location, charmap);
_isInCreateChar = false;
// fill the customChars with the charmap
for (int line = 0; line < 8; line++) {
_customChars[location][line] = charmap[line];
}
}
inline size_t LiquidCrystal_CI::write(uint8_t value) {
if (!_isInCreateChar) {
String line = _lines.at(_row);
int end = _autoscroll ? (_col - 1) : _col;
while (line.length() <= end) {
line += ' ';
}
if (_autoscroll) {
for (int i = 0; i < (_col - 1); i++) {
line.at(i) = line.at(i + 1);
}
--_col;
}
line.at(_col) = value;
++_col;
_lines.at(_row) = line;
}
return LiquidCrystal::write(value);
}
// override lower-level write to capture output
size_t LiquidCrystal_CI::write(const char *buffer, size_t size) {
return LiquidCrystal::write(buffer, size);
}
// private data and functions to support testing
LiquidCrystal_CI *LiquidCrystal_CI::_instances[MOCK_PINS_COUNT];
#endif