-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcd.c
150 lines (133 loc) · 3.35 KB
/
lcd.c
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
const int L_BUTTON = 1;
const int C_BUTTON = 2;
const int R_BUTTON = 4;
const int NONE_BUTTONS = 0;
int askPos() {
string opt[] = {
"left",
"right"
};
string str = "Side?";
int option = displayLCDMenu(opt, 2, str);
return option;
}
int askRoutine() {
string options[] = {
"Not this one",
"Or this one",
"Nothing",
"Back wall",
"Stars",
};
string str = "Which Routine?";
int opt = displayLCDMenu(options, 5, str);
return opt;
}
int displayLCDMenu(string* optionsP, int length, string prompt) {
clearScreen();
VERIFY(strlen(prompt) <= 16);
displayLCDCenteredString(0, prompt);
int currentSelected = 0;
while(true) {
int index = currentSelected % length;
//mod function is broken with negatives? another robotc bug
if(index < 0) {
index = (length + index)%length;
}
string str = *(optionsP + index);
displayLCDCenteredString(1, str);
waitForPress();
int btn = nLCDButtons;
if(btn == R_BUTTON) {
currentSelected++;
} else if(btn == L_BUTTON) {
currentSelected--;
} else if(btn == C_BUTTON) {
return index;
}
waitForRelease();
}
return 0;
}
int promptInt(int maxInt, int minInt, int startInt, int increment,string prompt) {
clearScreen();
displayLCDCenteredString(0, prompt);
int currentInt = startInt;
while(true) {
string str;
sprintf(str, "%d", currentInt);
displayLCDCenteredString(1, str);
waitForPress();
int btn = nLCDButtons;
int previous = currentInt;
if(btn == R_BUTTON) {
currentInt = min(maxInt, currentInt + increment);
} else if(btn == L_BUTTON) {
currentInt = max(minInt, currentInt - increment);
} else if(btn == C_BUTTON) {
return currentInt;
}
waitForRelease();
}
}
void clearScreen() {
clearLCDLine(0);
clearLCDLine(1);
}
void checkBattery() {
bLCDBacklight = true;
string mainBattery, expanderBattery;
int mainBatteryLevel, expanderBatteryLevel;
clearScreen();
while(nLCDButtons != R_BUTTON) {
mainBatteryLevel = getBatteryLevelVoltage();
expanderBatteryLevel = getExpanderBatteryVoltage();
//Display the Primary Robot battery voltage
displayLCDString(0, 0, "Primary: ");
sprintf(mainBattery, "%1.2f%c", mainBatteryLevel,'V'); //Build the value to be displayed
displayNextLCDString(mainBattery);
//Display the Backup battery voltage
displayLCDString(1, 0, "Expander: ");
sprintf(expanderBattery, "%1.2f%c", getExpanderBatteryVoltage(), 'V'); //Build the value to be displayed
displayNextLCDString(expanderBattery);
if(mainBatteryLevel < MIN_BATT_VOLT || expanderBatteryLevel < MIN_BATT_VOLT) {
startTask(flashScreen);
}
wait1Msec(100);
}
stopTask(flashScreen);
}
bool askPole() {
string options[] = {
"True",
"False"
};
string str = "Pole?";
int opt = displayLCDMenu(options, 2, str);
return opt == true;
}
task flashScreen() {
while(true) {
bLCDBacklight = false;
wait1Msec(500);
bLCDBacklight = true;
wait1Msec(500);
}
}
bool confirmChoiceWithUser(string prompt, string choice) {
string opt[] = {"yes", "no"};
stringConcatenate(prompt, " ");
stringConcatenate(prompt, choice);
stringConcatenate(prompt, "?");
return true;
}
void waitForRelease() {
while(nLCDButtons != NONE_BUTTONS){
wait1Msec(100);
}
}
void waitForPress() {
while(nLCDButtons == NONE_BUTTONS) {
wait1Msec(100);
}
}