1#include "screen/selector.h"
10selector_screen::selector_screen() {}
21void selector_screen::auton_ui_update(lv_event_t *e) {
22 lv_obj_t *tab1 = lv_event_get_current_target(e);
23 lv_obj_t *event_obj = lv_event_get_target(e);
24 lv_obj_t *autonLabel = lv_obj_get_child(tab1, 2);
25 lv_obj_t *allianceSwitch = lv_obj_get_child(tab1, 3);
26 lv_obj_t *skillSwitch = lv_obj_get_child(tab1, 4);
27 lv_obj_t *auton_dd = lv_obj_get_child(tab1, 5);
33 if (event_obj == auton_dd) {
38 int currentAutonIndex = lv_dropdown_get_selected(auton_dd) + 1;
39 bool currentAlliance = lv_obj_has_state(allianceSwitch, LV_STATE_CHECKED);
40 int autonNum = currentAlliance ? currentAutonIndex * -1 : currentAutonIndex;
47 else if (event_obj == allianceSwitch) {
48 if (lv_obj_has_state(allianceSwitch, LV_STATE_CHECKED)) {
49 lv_dropdown_clear_options(auton_dd);
50 lv_dropdown_set_options(auton_dd, selector_screen::blueAutons);
51 lv_obj_set_style_border_color(auton_dd, lv_color_hex(0x0077c8), 0);
53 lv_dropdown_clear_options(auton_dd);
54 lv_dropdown_set_options(auton_dd, selector_screen::redAutons);
55 lv_obj_set_style_border_color(auton_dd, lv_color_hex(0xd22730), 0);
61 if (lv_obj_has_state(skillSwitch, LV_STATE_CHECKED)) {
67 lv_obj_add_state(allianceSwitch, LV_STATE_DISABLED);
68 lv_obj_add_state(auton_dd, LV_STATE_DISABLED);
71 lv_obj_clear_state(allianceSwitch, LV_STATE_DISABLED);
72 lv_obj_clear_state(auton_dd, LV_STATE_DISABLED);
89void selector_screen::drive_update(lv_event_t *e) {
90 lv_obj_t *tab1 = lv_event_get_current_target(e);
91 lv_obj_t *drive_roller = lv_obj_get_child(tab1, -1);
92 lv_obj_t *driveLabel = lv_obj_get_child(tab1, -2);
94 int rollerIndex = lv_roller_get_selected(drive_roller);
97 lv_label_set_text_fmt(driveLabel,
"Current drive mode: %s", driveMode.c_str());
109void selector_screen::selector() {
112 tabview = lv_tabview_create(lv_scr_act(), LV_DIR_TOP, 35);
115 lv_obj_t *tab1 = lv_tabview_add_tab(tabview,
"Autonomous select");
116 lv_obj_t *tab2 = lv_tabview_add_tab(tabview,
"Drive select");
122 lv_obj_add_event_cb(tab1, auton_ui_update, LV_EVENT_VALUE_CHANGED, NULL);
123 lv_obj_add_event_cb(tab2, drive_update, LV_EVENT_VALUE_CHANGED, NULL);
124 lv_obj_t *tabButtons = lv_tabview_get_tab_btns(tabview);
125 lv_obj_set_style_bg_color(tabButtons, lv_color_hex(0x4d0000), 0);
126 lv_obj_set_style_text_font(tabButtons, &lv_font_montserrat_18, 0);
128 lv_obj_t *label1 = lv_label_create(tab1);
129 lv_obj_t *label2 = lv_label_create(tab1);
130 lv_obj_t *autonName = lv_label_create(tab1);
131 lv_label_set_text(label1,
"Alliance");
132 lv_label_set_text(label2,
"Enable Skills");
134 lv_obj_align(label1, LV_ALIGN_TOP_LEFT, 0, 10);
135 lv_obj_align(label2, LV_ALIGN_LEFT_MID, 0, 0);
136 lv_obj_align(autonName, LV_ALIGN_BOTTOM_MID, 0, 0);
137 lv_obj_set_style_text_font(label1, &lv_font_montserrat_20, 0);
138 lv_obj_set_style_text_font(label2, &lv_font_montserrat_20, 0);
139 lv_obj_set_style_text_font(autonName, &lv_font_montserrat_16, 0);
142 lv_obj_t *matchSwitch = lv_switch_create(tab1);
143 lv_obj_add_flag(matchSwitch, LV_OBJ_FLAG_EVENT_BUBBLE);
144 lv_obj_set_style_bg_color(matchSwitch, lv_palette_main(LV_PALETTE_RED), LV_STATE_DEFAULT);
145 lv_obj_set_size(matchSwitch, lv_pct(21), lv_pct(27));
146 lv_obj_set_style_pad_all(matchSwitch, -5, LV_PART_KNOB);
147 lv_obj_align(matchSwitch, LV_ALIGN_TOP_MID, 0, 0);
150 lv_obj_t *skillSwitch = lv_switch_create(tab1);
151 lv_obj_add_flag(skillSwitch, LV_OBJ_FLAG_EVENT_BUBBLE);
152 lv_obj_set_size(skillSwitch, lv_pct(21), lv_pct(27));
153 lv_obj_set_style_pad_all(skillSwitch, -5, LV_PART_KNOB);
154 lv_obj_align(skillSwitch, LV_ALIGN_CENTER, 0, 0);
157 lv_obj_t *auton_dd = lv_dropdown_create(tab1);
158 lv_obj_add_flag(auton_dd, LV_OBJ_FLAG_EVENT_BUBBLE);
159 lv_dropdown_set_options(auton_dd, selector_screen::redAutons);
160 lv_obj_set_style_max_height(auton_dd, 50, 0);
161 lv_obj_set_size(auton_dd, lv_pct(35), lv_pct(35));
162 lv_obj_set_style_pad_top(auton_dd, 10, 0);
163 lv_obj_set_style_pad_bottom(auton_dd, 10, 0);
164 lv_obj_set_style_border_width(auton_dd, 4, 0);
165 lv_obj_set_style_border_color(auton_dd, lv_color_hex(0xd22730), 0);
166 lv_obj_set_style_border_color(auton_dd, lv_color_hex(0x7a7a7a), LV_STATE_DISABLED);
167 lv_obj_align(auton_dd, LV_ALIGN_TOP_RIGHT, 0, 0);
170 lv_obj_t *driveName = lv_label_create(tab2);
171 lv_label_set_text_fmt(driveName,
"Current drive mode:");
172 lv_obj_align(driveName, LV_ALIGN_BOTTOM_MID, 0, 0);
173 lv_obj_set_style_text_font(driveName, &lv_font_montserrat_18, 0);
175 lv_obj_t *drive_roller = lv_roller_create(tab2);
176 lv_obj_add_flag(drive_roller, LV_OBJ_FLAG_EVENT_BUBBLE);
177 lv_roller_set_options(drive_roller, selector_screen::driveModes, LV_ROLLER_MODE_INFINITE);
180 lv_obj_set_style_bg_color(drive_roller, lv_color_hex(0xf97e2c), LV_PART_SELECTED);
181 lv_obj_set_style_text_font(drive_roller, &lv_font_montserrat_24, LV_PART_SELECTED);
182 lv_roller_set_visible_row_count(drive_roller, 3);
183 lv_obj_center(drive_roller);
184 lv_obj_align(drive_roller, LV_ALIGN_TOP_MID, 0, 0);
static std::string autonName
The name of the autonomous program.
static AUTON_ROUTINE auton
Sets the number of the autonomous program to use.
static void AutonSwitcher(int autonNum)
Switches the autonomous program.
static std::string SwitchDrive(int driveMode)
Switches the DriveTrain mode between arcade and tank drive.