-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcd.cpp
More file actions
165 lines (102 loc) · 3.81 KB
/
Copy pathlcd.cpp
File metadata and controls
165 lines (102 loc) · 3.81 KB
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
// this class is an output class it is not a bse layer it is what the
// intermedaite layer uses to actually does what it is suppose to do
// this class doesnt effect the internal structure it doesnt collide
// with the base layer and is just there as an ouput device this
// file will be just a warper library for the LiquidCrystal_I2C but
// the base function for the lcd remain the same across through out
// this means if we change the lcd later on we dont have to change
// the intermediate layer
#include "Libraries/LiquidCrystal/LiquidCrystal.h"
#include "Libraries/LiquidCrystal/LiquidCrystal.cpp"
namespace Lcd{
// all pins needs to be connected to gpio apperantly
// RS, E, D4, D5, D6, D7
LiquidCrystal lcd(
0, // RS
0, // E
0, // D4
0, // D5
0, // D6
0 // D7
);
int show_cool_down_duration_ms = 100; // this mimics fps and caps how many times
// you call the update a second
// READE __importat__ -> scheduled system
// worry if you update and your update does
// not go through it will get schedule for
// in the next time the update is timed out
// if two get schedule consecutively then
// only the one schedule can stay and only
// and the new one will be used if you edit
// the buffer it self thats fine but do not
// dispose of the buffer it will lead to
// errors, and any way at no point should
// you be reallocating any buffers in this
// project
bool is_show_scheduled = false;
char* scheduled_line_1;
char* scheduled_line_2;
bool show_cool_down() {
// this avoid internal bounce effect for the buttons
static unsigned long last_event_time = 0;
unsigned long now = millis();
if (now - last_event_time < show_cool_down_duration_ms) {
return false; // ignore event
}
last_event_time = now;
return true; // accept event
}
// those are warpper function
void set_cursor(int col, int row) {
lcd.setCursor(col, row);
}
void cursor_on() {
lcd.cursor();
}
void cursor_off() {
lcd.noCursor();
}
void blink_on() {
lcd.blink();
}
void blink_off() {
lcd.noBlink();
}
void print(char* line){
lcd.print(line);
}
void show(char* line1, char* line2) {
// note that line 1 should be 16 bytes long only
// and line 2 should follow the same structure
// do not use lcd. clear() this will block the
// thread, avoid it as much as possible
// this function does not set the cursor back
// where it was do it your self
// this will mimic running at certain fps
if (!show_cool_down()){
scheduled_line_1 = line1;
scheduled_line_2 = line2;
is_show_scheduled = true;
return;
}
set_cursor(0, 0);
print(line1);
set_cursor(0, 1);
print(line2);
}
void init(){
lcd.begin(16, 2); // Initialize the LCD
//lcd.backlight(); // Turn on the backlight <- this is only supported on the I2C module
}
void loop(){
// this loop is not optional it is required
// you can use the module it self without
// the loop but the schedule system will not
// work and then when navigating quickly the
// screen might not update
if (is_show_scheduled){
is_show_scheduled = false;
show(scheduled_line_1, scheduled_line_2);
}
}
}