-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcd_pages.ino
167 lines (148 loc) · 4.07 KB
/
lcd_pages.ino
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
enum LcdPages {
none,
product_info,
scanning_codes,
no_codes_found,
codes_found
};
LcdPages lcdpage = none;
void LCD_ProductInfo() {
if(lcdpage != product_info)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Skuzzle MX5 Diag");
lcd.setCursor(0,1);
lcd.print("Ver: 1.0 ");
lcdpage = product_info;
}
}
constexpr float LOADING_DELAY = 100;
constexpr int LCD_SCAN_ARRAY_SIZE = 20;
const char lcd_scan_array[LCD_SCAN_ARRAY_SIZE][16] PROGMEM = {
"# ",
"## ",
"### ",
"#### ",
" #### ",
" #### ",
" #### ",
" #### ",
" #### ",
" #### ",
" #### ",
" #### ",
" #### ",
" #### ",
" #### ",
" ####",
" ###",
" ##",
" #",
" "
};
int lcd_scan_position = 0;
float lcd_scan_change_millis = 0;
void LCD_ScanningCodes() {
if(lcdpage != scanning_codes) {
lcd.clear();
lcd.setCursor(0,0);
lcd.println("Scanning codes ");
lcdpage = scanning_codes;
}
for (int i = 0; i < 16; i++) {
lcd.setCursor(i,1);
lcd.print((char)pgm_read_word(&(lcd_scan_array[lcd_scan_position][i])));
}
if (lcd_scan_position < LCD_SCAN_ARRAY_SIZE) {
if (millis() - lcd_scan_change_millis > LOADING_DELAY) {
lcd_scan_position++;
lcd_scan_change_millis = millis();
}
}
else {
lcd_scan_position = 0;
}
}
void LCD_NoCodesFound(){
if(lcdpage != no_codes_found) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("*No fault found*");
lcdpage = no_codes_found;
}
}
constexpr float SCROLL_CHARACTER_DELAY = 300;
float character_display_timer = 0;
int displayed_code = 1;
int displayed_character = 0;
bool second_loop = false;
bool end_scroll_flag = false;
char code_string[MAX_LENGTH_OF_STRING];
char code_display_string[16] = {" "};
bool first_loop = true;
void LCD_CodesFound() {
if(lcdpage != codes_found) {
lcd.clear();
lcdpage = codes_found;
}
if (displayed_code == number_of_codes_present){
displayed_code = 1;
}
if (first_loop) { //First loop through to set the start time of the loop
DisplayCode(displayed_code);
first_loop = false;
}
if (end_scroll_flag) { //Advance to next present code
DisplayCode(displayed_code);
end_scroll_flag = false;
}
if (displayed_code > number_of_codes_present) { //Restart loop if showing last code
DisplayCode(0);
}
lcd.setCursor(0,0);
lcd.print("code "); lcd.print(displayed_code); lcd.print("/"); lcd.print(number_of_codes_present - 1); lcd.print(": ");
if (millis() - character_display_timer > SCROLL_CHARACTER_DELAY) {
//advances code_display_string to show code_string[] constantly scrolling
if (displayed_character > MAX_LENGTH_OF_STRING) { //reset scroll to first character
displayed_character = 0;
if (second_loop){
displayed_code++;
end_scroll_flag = true;
second_loop = false;
}
else {
second_loop = true;
}
}
else {
for (int i = 0; i < 16; i++) {
if(displayed_character + i < MAX_LENGTH_OF_STRING){
code_display_string[i] = code_string[displayed_character + i];
}
else{
code_display_string[i] = "#"; //@TODO why does this display as a blank space rather than #
}
}
displayed_character++;
}
character_display_timer = millis();
}
lcd.setCursor(0,1);
lcd.println(code_display_string);
}
void DisplayCode(int i) { //Changes the displayed code for the codes_found page
character_display_timer = millis();
displayed_code = i;
displayed_character = 0;
GetCodeString(i);
for (int k = 0; k < 16; k++) {
code_display_string[k] = code_string[k];
}
}
void GetCodeString(int i) { //gets full string of the current code to be displayed
int faultcode = fault_array[i];
for (int j = 0; j < MAX_LENGTH_OF_STRING; j++) {
code_string[j] = (char)pgm_read_word(&(FAULT_CODE_LOOKUP_TABLE[faultcode][j]));
}
}