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 <functional>
3#include <string>
4#include <vector>
5
6#include "light/lvgl.h"
7
18namespace light {
19
21struct Auton {
22 std::string name;
23 std::string description;
24 std::function<void()> fn;
25 const lv_img_dsc_t* banner = nullptr;
26};
27
36 public:
37 ~AutonSelector() { teardown_ui(); }
38
49 void add(const std::string& name, const std::string& desc, std::function<void()> fn);
50
52 void add(const std::string& name, const std::string& desc, std::function<void()> fn,
53 const lv_img_dsc_t* banner);
54
56 void init();
57
59 void run();
60
62 void show();
63
65 int selected() const { return selected_idx_; }
66
67 private:
68 std::vector<Auton> autons_;
69 int selected_idx_ = 0;
70 lv_obj_t* screen_ = nullptr;
71 lv_obj_t* img_obj_ = nullptr;
72 lv_obj_t* preview_cont_ = nullptr;
73 lv_obj_t* pid_cont_ = nullptr;
74 lv_obj_t* odom_cont_ = nullptr;
75 lv_obj_t* odom_x_lbl_ = nullptr;
76 lv_obj_t* odom_y_lbl_ = nullptr;
77 lv_obj_t* odom_theta_lbl_ = nullptr;
78 lv_timer_t* odom_timer_ = nullptr;
79 // Last-rendered text per label — skip lv_label_set_text (and its
80 // invalidation) when the formatted value is unchanged.
81 char odom_x_last_[16] = {};
82 char odom_y_last_[16] = {};
83 char odom_th_last_[16] = {};
84 lv_obj_t* toggle_lbl_ = nullptr;
85 int right_panel_mode_ = 0; // 0=preview, 1=pid, 2=odom
86 std::vector<lv_obj_t*> btn_objs_;
87
88 // compact PID panel state
89 lv_obj_t* pid_tab_btns_[4] = {};
90 lv_obj_t* pid_val_labels_[4][4] = {};
91 int active_pid_tab_ = 0;
92 double pid_vals_[4][4] = {};
93
94 void build_ui();
95 void teardown_ui();
96 void build_right_preview(lv_obj_t* parent);
97 void build_right_pid(lv_obj_t* parent);
98 void build_right_odom(lv_obj_t* parent);
99 void switch_panel(int mode);
100 void select_pid_tab(int idx);
101 void refresh_pid_labels();
102 void init_pid_vals();
103 void apply_pid_vals();
104 void select(int idx);
105
106 // persistent full-screen view shown during/after autonomous
107 lv_obj_t* run_screen_ = nullptr;
108 lv_obj_t* run_img_cont_ = nullptr;
109 lv_obj_t* run_info_cont_ = nullptr;
110 lv_obj_t* run_toggle_lbl_ = nullptr;
111 lv_obj_t* run_back_lbl_ = nullptr;
112 lv_obj_t* run_img_ = nullptr;
113 bool run_show_img_ = false;
114 void build_run_screen();
115 void start_run_anim();
116 void switch_run_view(bool show_img);
117 static void run_toggle_cb(lv_event_t* e);
118 static void run_back_cb(lv_event_t* e);
119
120 static void btn_cb(lv_event_t* e);
121 static void toggle_cb(lv_event_t* e);
122 static void pid_tab_cb(lv_event_t* e);
123 static void pid_adj_cb(lv_event_t* e);
124 static void pid_apply_cb(lv_event_t* e);
125 static void odom_timer_cb(lv_timer_t* timer);
126};
127
129extern AutonSelector auton_selector;
130
131} // namespace light
132
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.
Public LightLib odometry / pose-estimation API.
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.