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
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);
28
29 /* Autonomous selector follows this specification for updating the autonomous
30 * routine Skills - 0 Red Alliance - 1, 2, 3, ... ,n Blue Alliance - -1, -2,
31 * -3, ... ,-n
32 */
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;
42 }
43 /* Updates content of the dropdown list based on the alliance color, using
44 * the state of the alliance color switch, which is detected through
45 * "bubbling".
46 */
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);
52 } else {
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);
56 }
57 // Switches the autonomous routine to the opposite alliance color, accounts
58 // for option reset
60 } else {
61 if (lv_obj_has_state(skillSwitch, LV_STATE_CHECKED)) {
62 // Remembers the last competition autonomous
63 selector_screen::lastAuton = Autonomous::auton;
64
65 // Updates the autonomous routine to skills
67 lv_obj_add_state(allianceSwitch, LV_STATE_DISABLED);
68 lv_obj_add_state(auton_dd, LV_STATE_DISABLED);
69 } else {
70 Autonomous::AutonSwitcher(selector_screen::lastAuton);
71 lv_obj_clear_state(allianceSwitch, LV_STATE_DISABLED);
72 lv_obj_clear_state(auton_dd, LV_STATE_DISABLED);
73 }
74 }
75 lv_label_set_text_fmt(autonLabel, "Current Auton: %s", Autonomous::autonName.c_str());
76}
77
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);
93
94 int rollerIndex = lv_roller_get_selected(drive_roller);
95 std::string driveMode = Drivetrain::SwitchDrive(rollerIndex);
96
97 lv_label_set_text_fmt(driveLabel, "Current drive mode: %s", driveMode.c_str());
98}
99
109void selector_screen::selector() {
110 /*Create a Tab view object*/
111 lv_obj_t *tabview;
112 tabview = lv_tabview_create(lv_scr_act(), LV_DIR_TOP, 35);
113
114 /*Add 2 tabs*/
115 lv_obj_t *tab1 = lv_tabview_add_tab(tabview, "Autonomous select");
116 lv_obj_t *tab2 = lv_tabview_add_tab(tabview, "Drive select");
117
118 /*
119 * Both switches are "bubbled" to the tab view. This means that any event on
120 * the switches will be updated to the tab view.
121 */
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);
127
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");
133 lv_label_set_text_fmt(autonName, "Current Auton: %s", Autonomous::autonName.c_str());
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);
140
141 /*Add alliance color switch*/
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);
148
149 /*Add skills switch*/
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);
155
156 /*Create a drop down list for available autons */
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);
168
169 // Drive select tab
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);
174
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);
178
179 // Changed when highlighted
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);
185}
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:52
static std::string SwitchDrive(int driveMode)
Switches the DriveTrain mode between arcade and tank drive.
Definition auton.h:8