LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
auton_selector.hpp
Go to the documentation of this file.
1#pragma once
2#include <cstdint>
3#include <functional>
4#include <string>
5#include <vector>
6
7#include "light/lvgl.h"
8
19namespace light {
20
22struct Auton {
23 std::string name;
24 std::string description;
25 std::function<void()> fn;
26 const lv_img_dsc_t* banner = nullptr;
27};
28
37 public:
38 ~AutonSelector() { teardown_ui(); }
39
50 void add(const std::string& name, const std::string& desc, std::function<void()> fn);
51
53 void add(const std::string& name, const std::string& desc, std::function<void()> fn,
54 const lv_img_dsc_t* banner);
55
57 void init();
58
60 void run();
61
63 void show();
64
66 int selected() const { return selected_idx_; }
67
68 private:
69 std::vector<Auton> autons_;
70 int selected_idx_ = 0;
71 lv_obj_t* screen_ = nullptr;
72 lv_obj_t* img_obj_ = nullptr;
73 lv_obj_t* preview_cont_ = nullptr;
74 lv_obj_t* pid_cont_ = nullptr;
75 lv_obj_t* odom_cont_ = nullptr;
76 lv_obj_t* odom_x_lbl_ = nullptr;
77 lv_obj_t* odom_y_lbl_ = nullptr;
78 lv_obj_t* odom_theta_lbl_ = nullptr;
79 lv_timer_t* odom_timer_ = nullptr;
80 // Last-rendered text per label — skip lv_label_set_text (and its
81 // invalidation) when the formatted value is unchanged.
82 char odom_x_last_[16] = {};
83 char odom_y_last_[16] = {};
84 char odom_th_last_[16] = {};
85 lv_obj_t* toggle_lbl_ = nullptr;
86 int right_panel_mode_ = 0; // 0=preview, 1=pid, 2=odom
87 std::vector<lv_obj_t*> btn_objs_;
88 // Targets of LV_ANIM_REPEAT_INFINITE animations — must be lv_anim_del'd
89 // before their parents are freed, otherwise the anim timer keeps firing
90 // exec_cb on dangling memory and faults inside lv_obj_set_x/y.
91 std::vector<lv_obj_t*> infinite_anim_targets_;
92
93 // compact PID panel state
94 lv_obj_t* pid_tab_btns_[4] = {};
95 lv_obj_t* pid_val_labels_[4][4] = {};
96 int active_pid_tab_ = 0;
97 double pid_vals_[4][4] = {};
98
99 void build_ui();
100 void teardown_ui();
101 void build_right_preview(lv_obj_t* parent);
102 void build_right_pid(lv_obj_t* parent);
103 void build_right_odom(lv_obj_t* parent);
104 void switch_panel(int mode);
105 void select_pid_tab(int idx);
106 void refresh_pid_labels();
107 void init_pid_vals();
108 void apply_pid_vals();
109 void select(int idx);
110
111 // persistent full-screen view shown during/after autonomous
112 lv_obj_t* run_screen_ = nullptr;
113 lv_obj_t* run_img_cont_ = nullptr;
114 lv_obj_t* run_info_cont_ = nullptr;
115 lv_obj_t* run_toggle_lbl_ = nullptr;
116 lv_obj_t* run_back_lbl_ = nullptr;
117 lv_obj_t* run_img_ = nullptr;
118 bool run_show_img_ = false;
119 // Signals run() (auton task) that the deferred LVGL setup in
120 // run_screen_load_async has finished running on the LVGL task.
121 std::atomic<bool> run_setup_done_{false};
122 void build_run_screen();
123 void activate_run_screen();
124 void start_run_anim();
125 void switch_run_view(bool show_img);
126 static void run_screen_load_async(void* p);
127 static void run_toggle_cb(lv_event_t* e);
128 static void run_back_cb(lv_event_t* e);
129
130 static void btn_cb(lv_event_t* e);
131 static void toggle_cb(lv_event_t* e);
132 static void pid_tab_cb(lv_event_t* e);
133 static void pid_adj_cb(lv_event_t* e);
134 static void pid_apply_cb(lv_event_t* e);
135 static void odom_timer_cb(lv_timer_t* timer);
136};
137
139extern AutonSelector auton_selector;
140
141} // namespace light
142
void register_autons()
Defined in src/auton_config.cpp.
On-brain auton picker UI.
void show()
Activate the picker screen.
void add(const std::string &name, const std::string &desc, std::function< void()> fn, const lv_img_dsc_t *banner)
add() variant with a scrolling banner image shown inside the button.
void add(const std::string &name, const std::string &desc, std::function< void()> fn)
Register an autonomous routine.
void run()
Invoke the currently selected routine (call from autonomous()).
void init()
Build the LVGL UI.
Initialize once via init(); poll getPose/setPose from any task.
Definition pid.hpp:22
AutonSelector auton_selector
Process-wide singleton selector instance.
One registered autonomous routine.
const lv_img_dsc_t * banner
Optional scrolling image strip.
std::string name
Display name on the picker.
std::function< void()> fn
Routine to invoke when selected.
std::string description
Long-form description shown in the side panel.