1516X High Stakes 2.0
Codebase for 1516X High Stakes season
Loading...
Searching...
No Matches
selector.cpp
Go to the documentation of this file.
1#include "screen/selector.h"
2
3#include "main.h" // IWYU pragma: export
4#include "robot/auton.h"
5
6using namespace Robot;
7
8Autonomous::AUTON_ROUTINE selector_screen::lastAuton;
9
10selector_screen::selector_screen()
11{
12}
13
23void selector_screen::auton_ui_update(lv_event_t *e)
24{
25 lv_obj_t *tab1 = lv_event_get_current_target(e);
26 lv_obj_t *event_obj = lv_event_get_target(e);
27 lv_obj_t *autonLabel = lv_obj_get_child(tab1, 2);
28 lv_obj_t *allianceSwitch = lv_obj_get_child(tab1, 3);
29 lv_obj_t *skillSwitch = lv_obj_get_child(tab1, 4);
30 lv_obj_t *auton_dd = lv_obj_get_child(tab1, 5);
31
32 /* Autonomous selector follows this specification for updating the autonomous
33 * routine Skills - 0 Red Alliance - 1, 2, 3, ... ,n Blue Alliance - -1, -2,
34 * -3, ... ,-n
35 */
36 if (event_obj == auton_dd) {
41 int currentAutonIndex = lv_dropdown_get_selected(auton_dd) + 1;
42 bool currentAlliance = lv_obj_has_state(allianceSwitch, LV_STATE_CHECKED);
43 int autonNum = currentAlliance ? currentAutonIndex * -1 : currentAutonIndex;
45 }
46 /* Updates content of the dropdown list based on the alliance color, using
47 * the state of the alliance color switch, which is detected through
48 * "bubbling".
49 */
50 else if (event_obj == allianceSwitch) {
51 if (lv_obj_has_state(allianceSwitch, LV_STATE_CHECKED)) {
52 lv_dropdown_clear_options(auton_dd);
53 lv_dropdown_set_options(auton_dd, selector_screen::blueAutons);
54 lv_obj_set_style_border_color(auton_dd, lv_color_hex(0x0077c8), 0);
55 } else {
56 lv_dropdown_clear_options(auton_dd);
57 lv_dropdown_set_options(auton_dd, selector_screen::redAutons);
58 lv_obj_set_style_border_color(auton_dd, lv_color_hex(0xd22730), 0);
59 }
60 // Switches the autonomous routine to the opposite alliance color, accounts
61 // for option reset
63 } else {
64 if (lv_obj_has_state(skillSwitch, LV_STATE_CHECKED)) {
65 // Remembers the last competition autonomous
66 selector_screen::lastAuton = Autonomous::auton;
67
68 // Updates the autonomous routine to skills
70 lv_obj_add_state(allianceSwitch, LV_STATE_DISABLED);
71 lv_obj_add_state(auton_dd, LV_STATE_DISABLED);
72 } else {
73 Autonomous::AutonSwitcher(selector_screen::lastAuton);
74 lv_obj_clear_state(allianceSwitch, LV_STATE_DISABLED);
75 lv_obj_clear_state(auton_dd, LV_STATE_DISABLED);
76 }
77 }
78 lv_label_set_text_fmt(autonLabel, "Current Auton: %s", Autonomous::autonName.c_str());
79}
80
92void selector_screen::drive_update(lv_event_t *e)
93{
94 lv_obj_t *tab1 = lv_event_get_current_target(e);
95 lv_obj_t *drive_roller = lv_obj_get_child(tab1, -1);
96 lv_obj_t *driveLabel = lv_obj_get_child(tab1, -2);
97
98 int rollerIndex = lv_roller_get_selected(drive_roller);
99 std::string driveMode = Drivetrain::SwitchDrive(rollerIndex);
100
101 lv_label_set_text_fmt(driveLabel, "Current drive mode: %s", driveMode.c_str());
102}
103
113void selector_screen::selector()
114{
115 /*Create a Tab view object*/
116 lv_obj_t *tabview;
117 tabview = lv_tabview_create(lv_scr_act(), LV_DIR_TOP, 35);
118
119 /*Add 2 tabs*/
120 lv_obj_t *tab1 = lv_tabview_add_tab(tabview, "Autonomous select");
121 lv_obj_t *tab2 = lv_tabview_add_tab(tabview, "Drive select");
122
123 /*
124 * Both switches are "bubbled" to the tab view. This means that any event on
125 * the switches will be updated to the tab view.
126 */
127 lv_obj_add_event_cb(tab1, auton_ui_update, LV_EVENT_VALUE_CHANGED, NULL);
128 lv_obj_add_event_cb(tab2, drive_update, LV_EVENT_VALUE_CHANGED, NULL);
129 lv_obj_t *tabButtons = lv_tabview_get_tab_btns(tabview);
130 lv_obj_set_style_bg_color(tabButtons, lv_color_hex(0x4d0000), 0);
131 lv_obj_set_style_text_font(tabButtons, &lv_font_montserrat_18, 0);
132
133 lv_obj_t *label1 = lv_label_create(tab1);
134 lv_obj_t *label2 = lv_label_create(tab1);
135 lv_obj_t *autonName = lv_label_create(tab1);
136 lv_label_set_text(label1, "Alliance");
137 lv_label_set_text(label2, "Enable Skills");
138 lv_label_set_text_fmt(autonName, "Current Auton: %s", Autonomous::autonName.c_str());
139 lv_obj_align(label1, LV_ALIGN_TOP_LEFT, 0, 10);
140 lv_obj_align(label2, LV_ALIGN_LEFT_MID, 0, 0);
141 lv_obj_align(autonName, LV_ALIGN_BOTTOM_MID, 0, 0);
142 lv_obj_set_style_text_font(label1, &lv_font_montserrat_20, 0);
143 lv_obj_set_style_text_font(label2, &lv_font_montserrat_20, 0);
144 lv_obj_set_style_text_font(autonName, &lv_font_montserrat_16, 0);
145
146 /*Add alliance color switch*/
147 lv_obj_t *matchSwitch = lv_switch_create(tab1);
148 lv_obj_add_flag(matchSwitch, LV_OBJ_FLAG_EVENT_BUBBLE);
149 lv_obj_set_style_bg_color(matchSwitch, lv_palette_main(LV_PALETTE_RED), LV_STATE_DEFAULT);
150 lv_obj_set_size(matchSwitch, lv_pct(21), lv_pct(27));
151 lv_obj_set_style_pad_all(matchSwitch, -5, LV_PART_KNOB);
152 lv_obj_align(matchSwitch, LV_ALIGN_TOP_MID, 0, 0);
153
154 /*Add skills switch*/
155 lv_obj_t *skillSwitch = lv_switch_create(tab1);
156 lv_obj_add_flag(skillSwitch, LV_OBJ_FLAG_EVENT_BUBBLE);
157 lv_obj_set_size(skillSwitch, lv_pct(21), lv_pct(27));
158 lv_obj_set_style_pad_all(skillSwitch, -5, LV_PART_KNOB);
159 lv_obj_align(skillSwitch, LV_ALIGN_CENTER, 0, 0);
160
161 /*Create a drop down list for available autons */
162 lv_obj_t *auton_dd = lv_dropdown_create(tab1);
163 lv_obj_add_flag(auton_dd, LV_OBJ_FLAG_EVENT_BUBBLE);
164 lv_dropdown_set_options(auton_dd, selector_screen::redAutons);
165 lv_obj_set_style_max_height(auton_dd, 50, 0);
166 lv_obj_set_size(auton_dd, lv_pct(35), lv_pct(35));
167 lv_obj_set_style_pad_top(auton_dd, 10, 0);
168 lv_obj_set_style_pad_bottom(auton_dd, 10, 0);
169 lv_obj_set_style_border_width(auton_dd, 4, 0);
170 lv_obj_set_style_border_color(auton_dd, lv_color_hex(0xd22730), 0);
171 lv_obj_set_style_border_color(auton_dd, lv_color_hex(0x7a7a7a), LV_STATE_DISABLED);
172 lv_obj_align(auton_dd, LV_ALIGN_TOP_RIGHT, 0, 0);
173
174 // Drive select tab
175 lv_obj_t *driveName = lv_label_create(tab2);
176 lv_label_set_text_fmt(driveName, "Current drive mode:");
177 lv_obj_align(driveName, LV_ALIGN_BOTTOM_MID, 0, 0);
178 lv_obj_set_style_text_font(driveName, &lv_font_montserrat_18, 0);
179
180 lv_obj_t *drive_roller = lv_roller_create(tab2);
181 lv_obj_add_flag(drive_roller, LV_OBJ_FLAG_EVENT_BUBBLE);
182 lv_roller_set_options(drive_roller, selector_screen::driveModes, LV_ROLLER_MODE_INFINITE);
183
184 // Changed when highlighted
185 lv_obj_set_style_bg_color(drive_roller, lv_color_hex(0xf97e2c), LV_PART_SELECTED);
186 lv_obj_set_style_text_font(drive_roller, &lv_font_montserrat_24, LV_PART_SELECTED);
187 lv_roller_set_visible_row_count(drive_roller, 3);
188 lv_obj_center(drive_roller);
189 lv_obj_align(drive_roller, LV_ALIGN_TOP_MID, 0, 0);
190}
static std::string autonName
The name of the autonomous program.
Definition auton.h:33
static AUTON_ROUTINE auton
Sets the number of the autonomous program to use.
Definition auton.h:26
static void AutonSwitcher(int autonNum)
Switches the autonomous program.
Definition auton.cpp:131
static std::string SwitchDrive(int driveMode)
Switches the DriveTrain mode between arcade and tank drive.
Definition auton.h:8