-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreen.cpp
323 lines (262 loc) · 9.84 KB
/
Screen.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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#include "main.h"
using std::string;
using std::to_string;
bool test1 = false;
bool test2 = false;
bool test3 = false;
//Main theme for display.
lv_theme_t * theme_main;
//Auton run page and countdown.
lv_obj_t *page;
lv_obj_t *label_cancel;
lv_obj_t * AutonSelectorButtons;
lv_obj_t * chart;
lv_obj_t *legand;
lv_chart_series_t * NavyLine;
lv_chart_series_t * BlueLine;
lv_chart_series_t * GreenLine;
lv_chart_series_t * LimeLine;
lv_chart_series_t * SilverLine;
lv_chart_series_t * WhiteLine;
lv_chart_series_t * PurpleLine;
lv_chart_series_t * OrangeLine;
//Create a Tab view object
lv_obj_t *tabview;
lv_obj_t *tab1;
lv_obj_t *tab2;
lv_obj_t *tab3;
bool toggleAuton = false;
//Called when cancel auton button is pressed.
static lv_res_t cancel_auton_btn_press(lv_obj_t * btn) {
//Deletes the page and all child objects.
lv_obj_del(page);
toggleAuton = false;
return LV_RES_OK; /*Return OK if the button is not deleted*/
}
//Called when auton run button is pressed.
static lv_res_t run_auton_btn_press(lv_obj_t * btn) {
//Creates page.
page = lv_page_create(tab1, NULL);
lv_obj_set_size(page, 460, 155);
lv_obj_align(page, NULL, LV_ALIGN_CENTER, 0, 0);
lv_page_set_sb_mode(page, LV_SB_MODE_OFF);
/*Cancel button for run auton page*/
lv_obj_t * btnCancel = lv_btn_create(page, NULL);
lv_obj_set_size(btnCancel, 200, 50);
lv_obj_align(btnCancel, page, LV_ALIGN_IN_TOP_MID, 0, 0);
lv_btn_set_action(btnCancel, LV_BTN_ACTION_CLICK, cancel_auton_btn_press);
/*Label for cancel auton*/
lv_obj_t * label = lv_label_create(btnCancel, NULL);
lv_label_set_text(label, "Cancel Auton");
/*Displays auton that is about to run*/
lv_obj_t * label_auton = lv_label_create(page, NULL);
switch (selectedAuton) {
case 1: lv_label_set_text(label_auton, "BlueSmall");
break;
case 2: lv_label_set_text(label_auton, "BlueSafe");
break;
case 3: lv_label_set_text(label_auton, "BlueLarge");
break;
case 4: lv_label_set_text(label_auton, "Skills");
break;
case 5: lv_label_set_text(label_auton, "RedLarge");
break;
case 6: lv_label_set_text(label_auton, "RedSafe");
break;
case 7: lv_label_set_text(label_auton, "RedSmall");
break;
}
lv_obj_align(label_auton, btnCancel, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
/*Countdown until auton is run*/
label_cancel = lv_label_create(page, NULL);
lv_label_set_text(label_cancel, "Auton Starting In 5 Seconds.");
lv_obj_align(label_cancel, label_auton, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
pros::delay(100);
toggleAuton = true;
return LV_RES_OK; /*Return OK if the button is not deleted*/
}
/*Called when a button from the button matrix is pressed*/
static lv_res_t btnm_action(lv_obj_t * btnm, const char *txt) {
//Changes the selected auton to the corresponding pressed button. Displays on controller.
if (strcmp(txt, "BSm") == 0) {
selectedAuton = 1;
}
else if (strcmp(txt, "BSaf") == 0) {
selectedAuton = 2;
}
else if (strcmp(txt, "BL") == 0) {
selectedAuton = 3;
}
else if (strcmp(txt, "Skills") == 0) {
selectedAuton = 4;
}
else if (strcmp(txt, "RL") == 0) {
selectedAuton = 5;
}
else if (strcmp(txt, "RSaf") == 0) {
selectedAuton = 6;
}
else if (strcmp(txt, "RSm") == 0) {
selectedAuton = 7;
}
return LV_RES_OK; /*Return OK because the button matrix is not deleted*/
}
static lv_res_t sw1_action(lv_obj_t *sw) {
lv_sw_get_state(sw) ? test1 = true : test1 = false;
return LV_RES_OK;
}
static lv_res_t sw2_action(lv_obj_t *sw) {
lv_sw_get_state(sw) ? test2 = true : test2 = false;
return LV_RES_OK;
}
static lv_res_t sw3_action(lv_obj_t *sw) {
lv_sw_get_state(sw) ? test3 = true : test3 = false;
return LV_RES_OK;
}
//Text object for displayed variables.
lv_obj_t * txt;
//Create a button descriptor string array
static const char * btnm_map[] = {"BSm", "BSaf", "BL", "Skills", "RL", "RSaf", "RSm", ""};
void runScreen() {
pros::Task startAuton_TR(startAuton, (void*)"PROS", TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "My Task");
pros::Task Diagnostics_TR(Diagnostics, (void*)"PROS", TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "Diagnostics Task");
//Sets theme to alien.
theme_main = lv_theme_alien_init(100, NULL);
lv_theme_set_current(theme_main);
tabview = lv_tabview_create(lv_scr_act(), NULL);
lv_tabview_set_sliding(tabview, false);
//Add 2 tabs (the tabs are page (lv_page) and can be scrolled
tab1 = lv_tabview_add_tab(tabview, "Auton Selection");
lv_page_set_sb_mode(tab1, LV_SB_MODE_OFF);
tab2 = lv_tabview_add_tab(tabview, "Debug Info");
lv_page_set_sb_mode(tab2, LV_SB_MODE_OFF);
tab3 = lv_tabview_add_tab(tabview, "Graph");
lv_page_set_sb_mode(tab3, LV_SB_MODE_OFF);
chart = lv_chart_create(tab3, NULL);
lv_chart_set_type(chart, LV_CHART_TYPE_COLUMN);
NavyLine = lv_chart_add_series(chart, LV_COLOR_NAVY);
BlueLine= lv_chart_add_series(chart, LV_COLOR_BLUE);
GreenLine= lv_chart_add_series(chart, LV_COLOR_GREEN);
LimeLine= lv_chart_add_series(chart, LV_COLOR_LIME);
SilverLine= lv_chart_add_series(chart, LV_COLOR_SILVER);
WhiteLine= lv_chart_add_series(chart, LV_COLOR_WHITE);
PurpleLine= lv_chart_add_series(chart, LV_COLOR_PURPLE);
OrangeLine= lv_chart_add_series(chart, LV_COLOR_ORANGE);
lv_obj_set_size(chart, 280, 155);
lv_chart_set_div_line_count(chart, 0, 0);
lv_chart_set_point_count(chart, 1);
lv_chart_set_range(chart, 0, 50);
legand = lv_label_create(tab3, NULL);
lv_obj_align(legand, NULL, LV_ALIGN_IN_TOP_MID, 80 , 30);
lv_label_set_text(legand, "Purple: Intake Motor\n"
"Orange: Outake Motor\n"
"Silver: Left Roller\n"
"White: Right Roller\n"
"Blue: Left Drive\n"
"Green: Right Drive");
//Creates box that conatins displayed variables.
lv_obj_t * box1;
box1 = lv_cont_create(tab2, NULL);
lv_obj_set_size(box1, 460, 155);
lv_obj_set_style(box1, &lv_style_pretty);
lv_obj_align(box1, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
//Adds the values to the box.
txt = lv_label_create(box1, NULL);
lv_obj_align(txt, box1, LV_ALIGN_IN_TOP_LEFT, 10, 1);
//Create a default button matrix
AutonSelectorButtons = lv_btnm_create(tab1, NULL);
lv_btnm_set_map(AutonSelectorButtons, btnm_map);
lv_btnm_set_toggle(AutonSelectorButtons, true, 0);
lv_btnm_set_action(AutonSelectorButtons, btnm_action);
lv_obj_set_size(AutonSelectorButtons, 460, 40);
lv_obj_align(AutonSelectorButtons, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
//Copy the button and set toggled state. (The release action is copied too)
// Auton Run Button.
lv_obj_t * btn1 = lv_btn_create(tab1, NULL);
lv_obj_set_size(btn1, 140, 40);
lv_obj_align(btn1, AutonSelectorButtons, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
lv_btn_set_action(btn1, LV_BTN_ACTION_CLICK, run_auton_btn_press);
//Add a label to the toggled button
lv_obj_t *label = lv_label_create(btn1, NULL);
lv_label_set_text(label, "Run");
//Create switches with labels
lv_obj_t *sw2 = lv_sw_create(tab1, NULL);
lv_obj_set_size(sw2, 60, 20);
lv_obj_align(sw2, AutonSelectorButtons, LV_ALIGN_IN_BOTTOM_MID, 0, 110);
lv_sw_set_action(sw2, sw2_action);
lv_obj_t *sw2_label = lv_label_create(tab1, NULL);
lv_label_set_text(sw2_label, "Test 2");
lv_obj_align(sw2_label, sw2, LV_ALIGN_OUT_TOP_MID, 0, -10);
lv_obj_t *sw1 = lv_sw_create(tab1, NULL);
lv_obj_set_size(sw1, 60, 20);
lv_obj_align(sw1, sw2, LV_ALIGN_OUT_LEFT_MID, -100, 0);
lv_sw_set_action(sw1, sw1_action);
lv_obj_t *sw1_label = lv_label_create(tab1, NULL);
lv_label_set_text(sw1_label, "Test 1");
lv_obj_align(sw1_label, sw1, LV_ALIGN_OUT_TOP_MID, 0, -10);
lv_obj_t *sw3 = lv_sw_create(tab1, NULL);
lv_obj_set_size(sw3, 60, 20);
lv_obj_align(sw3, sw2, LV_ALIGN_OUT_RIGHT_MID, 100, 0);
lv_sw_set_action(sw3, sw3_action);
lv_obj_t *sw3_label = lv_label_create(tab1, NULL);
lv_label_set_text(sw3_label, "Test 3");
lv_obj_align(sw3_label, sw3, LV_ALIGN_OUT_TOP_MID, 0, -10);
}
double firstLine;
double secondLine;
double thirdLine;
double forthLine;
double fithLine;
void updateLineVariable(int line, double value) {
switch (line){
case 1: firstLine = value;
break;
case 2: secondLine = value;
break;
case 3: thirdLine = value;
break;
case 4: forthLine = value;
break;
case 5: fithLine = value;
break;
}
lv_label_set_text(txt, ( "Robot Heading: " + to_string(firstLine) + '\n' +
"Top Ball Detector: " + to_string(secondLine) + '\n' +
"Bottom Ball Detector: " + to_string(thirdLine) + '\n' +
"Left Encoder: " + to_string(forthLine) + '\n' +
"Right Encoder: " + to_string(fithLine) + '\n' +
"Test switches: " + to_string(test1) + " " + to_string(test2) +
" " + to_string(test3) + '\n').c_str());
}
bool waitAuton = false;
long currentTime = pros::millis();
void startAuton(void* param) {
while(true) {
if (toggleAuton == true) {
if (!waitAuton) {
currentTime = pros::millis();
waitAuton = true;
printf("Setting time\n");
}
lv_label_set_text(label_cancel, ("Auton Starting In " +
to_string(5 - (((int)pros::millis() - (int)currentTime) / 1000)) +
" Seconds.").c_str());
if ((currentTime + 5000) < (pros::millis() + 5000) - 5000) {
toggleAuton = false;
waitAuton = false;
lv_obj_del(page);
printf("Deleted page\n");
autonomous();
printf("Starting auton\n");
}
}
else {
waitAuton = false;
}
pros::delay(20);
}
}
void SetAutonButton(int slot) {
slot-=1;
lv_btnm_set_toggle(AutonSelectorButtons, true, slot);
}