-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathselection.cpp
133 lines (107 loc) · 3.34 KB
/
selection.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
#include "main.h"
#include "selection.h"
namespace selector{
int auton;
int autonCount;
const char *btnmMap[] = {"","","","","","","","","","",""}; // up to 10 autons
lv_obj_t *tabview;
lv_obj_t *redBtnm;
lv_obj_t *blueBtnm;
lv_res_t redBtnmAction(lv_obj_t *btnm, const char *txt){
//printf("red button: %s released\n", txt);
for(int i = 0; i < autonCount; i++){
if(strcmp(txt, btnmMap[i]) == 0){
auton = i+1;
}
}
return LV_RES_OK; // return OK because the button matrix is not deleted
}
lv_res_t blueBtnmAction(lv_obj_t *btnm, const char *txt)
{
//printf("blue button: %s released\n", txt);
for(int i = 0; i < autonCount; i++){
if(strcmp(txt, btnmMap[i]) == 0){
auton = -(i+1);
}
}
return LV_RES_OK; // return OK because the button matrix is not deleted
}
lv_res_t skillsBtnAction(lv_obj_t *btn){
//printf("skills pressed");
auton = 0;
return LV_RES_OK;
}
int tabWatcher() {
int activeTab = lv_tabview_get_tab_act(tabview);
while(1){
int currentTab = lv_tabview_get_tab_act(tabview);
if(currentTab != activeTab){
activeTab = currentTab;
if(activeTab == 0){
if(auton == 0) auton = 1;
auton = abs(auton);
lv_btnm_set_toggle(redBtnm, true, abs(auton)-1);
}else if(activeTab == 1){
if(auton == 0) auton = -1;
auton = -abs(auton);
lv_btnm_set_toggle(blueBtnm, true, abs(auton)-1);
}else{
auton = 0;
}
}
pros::delay(20);
}
}
void init(int hue, int default_auton, const char **autons){
int i = 0;
do{
memcpy(&btnmMap[i], &autons[i], sizeof(&autons));
i++;
}while(strcmp(autons[i], "") != 0);
autonCount = i;
auton = default_auton;
// lvgl theme
lv_theme_t *th = lv_theme_alien_init(hue, NULL); //Set a HUE value and keep font default RED
lv_theme_set_current(th);
// create a tab view object
tabview = lv_tabview_create(lv_scr_act(), NULL);
// add 3 tabs (the tabs are page (lv_page) and can be scrolled
lv_obj_t *redTab = lv_tabview_add_tab(tabview, "Red");
lv_obj_t *blueTab = lv_tabview_add_tab(tabview, "Blue");
lv_obj_t *skillsTab = lv_tabview_add_tab(tabview, "Skills");
//set default tab
if(auton < 0){
lv_tabview_set_tab_act(tabview, 1, LV_ANIM_NONE);
}else if(auton == 0){
lv_tabview_set_tab_act(tabview, 2, LV_ANIM_NONE);
}
// add content to the tabs
// button matrix
redBtnm = lv_btnm_create(redTab, NULL);
lv_btnm_set_map(redBtnm, btnmMap);
lv_btnm_set_action(redBtnm, redBtnmAction);
lv_btnm_set_toggle(redBtnm, true, abs(auton)-1);//3
lv_obj_set_size(redBtnm, 450, 50);
lv_obj_set_pos(redBtnm, 0, 100);
lv_obj_align(redBtnm, NULL, LV_ALIGN_CENTER, 0, 0);
// blue tab
blueBtnm = lv_btnm_create(blueTab, NULL);
lv_btnm_set_map(blueBtnm, btnmMap);
lv_btnm_set_action(blueBtnm, *blueBtnmAction);
lv_btnm_set_toggle(blueBtnm, true, abs(auton)-1);
lv_obj_set_size(blueBtnm, 450, 50);
lv_obj_set_pos(blueBtnm, 0, 100);
lv_obj_align(blueBtnm, NULL, LV_ALIGN_CENTER, 0, 0);
// skills tab
lv_obj_t *skillsBtn = lv_btn_create(skillsTab, NULL);
lv_obj_t *label = lv_label_create(skillsBtn, NULL);
lv_label_set_text(label, "Skills");
lv_btn_set_action(skillsBtn, LV_BTN_ACTION_CLICK, *skillsBtnAction);
// lv_btn_set_state(skillsBtn, LV_BTN_STATE_TGL_REL);
lv_obj_set_size(skillsBtn, 450, 50);
lv_obj_set_pos(skillsBtn, 0, 100);
lv_obj_align(skillsBtn, NULL, LV_ALIGN_CENTER, 0, 0);
// start tab watcher
pros::Task tabWatcher_task(tabWatcher);
}
} // namespace selector