1516X Push Back 1.0
1516X's robot code for the 2025-2026 VEX Robotics Competition
Loading...
Searching...
No Matches
motorDashboard.cpp File Reference
#include "main.h"
#include "robodash/api.h"
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include "globals.h"

Go to the source code of this file.

Classes

struct  MotorDisplayData

Macros

#define TEMP_WARNING_THRESHOLD   55.0
#define HISTORY_MAX_POINTS   25

Functions

static void close_modal_cb (lv_event_t *e)
static void motor_click_cb (lv_event_t *e)
static void update_temps_cb (lv_timer_t *timer)
void init_motor_dashboard ()

Variables

std::vector< MotorDisplayDatamotorList
MotorDisplayDataactiveMotor = nullptr
lv_obj_t * modal_overlay = nullptr
lv_obj_t * chart_modal = nullptr
lv_obj_t * temp_chart = nullptr
lv_chart_series_t * temp_series = nullptr
lv_obj_t * modal_title = nullptr

Macro Definition Documentation

◆ HISTORY_MAX_POINTS

#define HISTORY_MAX_POINTS   25

Definition at line 13 of file motorDashboard.cpp.

Referenced by init_motor_dashboard().

◆ TEMP_WARNING_THRESHOLD

#define TEMP_WARNING_THRESHOLD   55.0

Definition at line 12 of file motorDashboard.cpp.

Referenced by motor_click_cb(), and update_temps_cb().

Function Documentation

◆ close_modal_cb()

void close_modal_cb ( lv_event_t * e)
static

Definition at line 36 of file motorDashboard.cpp.

36 {
37 lv_obj_add_flag(chart_modal, LV_OBJ_FLAG_HIDDEN);
38 lv_obj_add_flag(modal_overlay, LV_OBJ_FLAG_HIDDEN);
39 activeMotor = nullptr;
40}
MotorDisplayData * activeMotor
lv_obj_t * chart_modal
lv_obj_t * modal_overlay

References activeMotor, chart_modal, and modal_overlay.

Referenced by init_motor_dashboard().

◆ init_motor_dashboard()

void init_motor_dashboard ( )

Definition at line 100 of file motorDashboard.cpp.

100 {
101 rd_view_t* motor_view = rd_view_create("Motors");
102
103 lv_obj_t* parent = rd_view_obj(motor_view);
104 lv_obj_set_style_bg_color(parent, lv_color_hex(0x1E1E1E), 0);
105
106 lv_obj_t* btn_container = lv_obj_create(parent);
107 lv_obj_set_size(btn_container, LV_PCT(100), LV_PCT(100));
108 lv_obj_set_style_bg_opa(btn_container, 0, 0);
109 lv_obj_set_style_border_width(btn_container, 0, 0);
110
111 lv_obj_set_layout(btn_container, LV_LAYOUT_FLEX);
112 lv_obj_set_flex_flow(btn_container, LV_FLEX_FLOW_ROW_WRAP);
113 lv_obj_set_flex_align(btn_container, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
114
115 motorList = {
116 MotorDisplayData("Right Drive\n", [](){ return rightMotors.get_temperature(); }),
117 MotorDisplayData("Left Drive\n", [](){ return leftMotors.get_temperature(); }),
118 MotorDisplayData("Intake\n", [](){ return intakeMotor.get_temperature(); }),
119 MotorDisplayData("Outtake\n", [](){ return outtakeMotor.get_temperature(); }),
120 MotorDisplayData("Storage\n", [](){ return storageMotor.get_temperature(); })
121 };
122
123 for(auto& md : motorList) {
124 md.history.assign(HISTORY_MAX_POINTS, 20);
125
126 md.btn = lv_btn_create(btn_container);
127 lv_obj_set_size(md.btn, 100, 100);
128 lv_obj_set_style_radius(md.btn, 8, 0);
129 lv_obj_set_style_bg_color(md.btn, lv_color_hex(0x2A3D8F), 0);
130 lv_obj_set_style_shadow_width(md.btn, 0, 0);
131 lv_obj_clear_flag(md.btn, LV_OBJ_FLAG_SCROLLABLE);
132 lv_obj_add_event_cb(md.btn, motor_click_cb, LV_EVENT_CLICKED, &md);
133
134 md.label = lv_label_create(md.btn);
135 lv_label_set_text(md.label, md.name.c_str());
136 lv_obj_align(md.label, LV_ALIGN_TOP_MID, 0, 15);
137 lv_obj_set_style_text_align(md.label, LV_TEXT_ALIGN_CENTER, 0);
138 lv_obj_set_style_text_color(md.label, lv_color_hex(0xFFFFFF), 0);
139
140 lv_obj_t* vent = lv_obj_create(md.btn);
141 lv_obj_set_size(vent, 50, 25);
142 lv_obj_align(vent, LV_ALIGN_BOTTOM_MID, 0, -12);
143 lv_obj_set_style_bg_color(vent, lv_color_hex(0x111111), 0);
144 lv_obj_set_style_bg_opa(vent, 100, 0);
145 lv_obj_set_style_border_width(vent, 1, 0);
146 lv_obj_set_style_border_color(vent, lv_color_hex(0x000000), 0);
147 lv_obj_clear_flag(vent, LV_OBJ_FLAG_CLICKABLE);
148 lv_obj_clear_flag(vent, LV_OBJ_FLAG_SCROLLABLE);
149 }
150
151 modal_overlay = lv_obj_create(parent);
152 lv_obj_set_size(modal_overlay, LV_PCT(100), LV_PCT(100));
153 lv_obj_set_style_bg_color(modal_overlay, lv_color_hex(0x000000), 0);
154 lv_obj_set_style_bg_opa(modal_overlay, LV_OPA_50, 0);
155 lv_obj_set_style_border_width(modal_overlay, 0, 0);
156 lv_obj_add_flag(modal_overlay, LV_OBJ_FLAG_HIDDEN);
157 lv_obj_add_flag(modal_overlay, LV_OBJ_FLAG_CLICKABLE);
158
159 chart_modal = lv_obj_create(parent);
160 lv_obj_set_size(chart_modal, 400, 200);
161 lv_obj_center(chart_modal);
162 lv_obj_set_style_bg_color(chart_modal, lv_color_hex(0x222222), 0);
163 lv_obj_set_style_border_color(chart_modal, lv_color_hex(0x555555), 0);
164 lv_obj_set_style_border_width(chart_modal, 2, 0);
165 lv_obj_add_flag(chart_modal, LV_OBJ_FLAG_HIDDEN);
166
167 modal_title = lv_label_create(chart_modal);
168 lv_label_set_text(modal_title, "Motor Name");
169 lv_obj_align(modal_title, LV_ALIGN_TOP_MID, 0, 0);
170 lv_obj_set_style_text_color(modal_title, lv_color_hex(0xFFFFFF), 0);
171
172 lv_obj_t* close_btn = lv_btn_create(chart_modal);
173 lv_obj_set_size(close_btn, 60, 30);
174 lv_obj_align(close_btn, LV_ALIGN_TOP_RIGHT, 0, -10);
175 lv_obj_t* close_lbl = lv_label_create(close_btn);
176 lv_label_set_text(close_lbl, "Close");
177 lv_obj_center(close_lbl);
178 lv_obj_add_event_cb(close_btn, close_modal_cb, LV_EVENT_CLICKED, NULL);
179
180 temp_chart = lv_chart_create(chart_modal);
181 lv_obj_set_size(temp_chart, 330, 145);
182 lv_obj_align(temp_chart, LV_ALIGN_BOTTOM_MID, 0, 0);
183 lv_chart_set_type(temp_chart, LV_CHART_TYPE_LINE);
184
185 lv_chart_set_range(temp_chart, LV_CHART_AXIS_PRIMARY_Y, 10, 60);
186 lv_chart_set_axis_tick(temp_chart, LV_CHART_AXIS_PRIMARY_Y, 10, 5, 8, 1, true, 40);
187
188 lv_chart_set_point_count(temp_chart, HISTORY_MAX_POINTS);
189 temp_series = lv_chart_add_series(temp_chart, lv_color_hex(0x4CAF50), LV_CHART_AXIS_PRIMARY_Y);
190
191 lv_timer_create(update_temps_cb, 10000, NULL);
192}
pros::Motor storageMotor(2, pros::v5::MotorGears::blue)
pros::Motor outtakeMotor(3, pros::MotorGears::blue)
lemlib::Drivetrain drivebase & leftMotors
Definition globals.cpp:21
pros::Motor intakeMotor(-1, pros::v5::MotorGears::blue)
pros::MotorGroup rightMotors({17, 19, -18}, pros::MotorGears::blue)
static void close_modal_cb(lv_event_t *e)
#define HISTORY_MAX_POINTS
lv_obj_t * modal_title
lv_obj_t * temp_chart
static void motor_click_cb(lv_event_t *e)
lv_chart_series_t * temp_series
std::vector< MotorDisplayData > motorList
static void update_temps_cb(lv_timer_t *timer)

References chart_modal, close_modal_cb(), HISTORY_MAX_POINTS, intakeMotor(), leftMotors, modal_overlay, modal_title, motor_click_cb(), motorList, outtakeMotor(), rightMotors(), storageMotor(), temp_chart, temp_series, and update_temps_cb().

Referenced by initialize().

◆ motor_click_cb()

void motor_click_cb ( lv_event_t * e)
static

Definition at line 42 of file motorDashboard.cpp.

42 {
43 MotorDisplayData* md = (MotorDisplayData*)lv_event_get_user_data(e);
44 activeMotor = md;
45
46 lv_label_set_text(modal_title, md->name.c_str());
47
48 lv_coord_t latest = md->history.empty() ? 20 : md->history.back();
49
50 if (latest >= TEMP_WARNING_THRESHOLD) {
51 lv_chart_set_series_color(temp_chart, temp_series, lv_color_hex(0xFF4A4A));
52 } else {
53 lv_chart_set_series_color(temp_chart, temp_series, lv_color_hex(0x4CAF50));
54 }
55
56 lv_chart_set_ext_y_array(temp_chart, temp_series, md->history.data());
57 lv_chart_refresh(temp_chart);
58
59 lv_obj_move_foreground(modal_overlay);
60 lv_obj_move_foreground(chart_modal);
61
62 lv_obj_clear_flag(modal_overlay, LV_OBJ_FLAG_HIDDEN);
63 lv_obj_clear_flag(chart_modal, LV_OBJ_FLAG_HIDDEN);
64}
#define TEMP_WARNING_THRESHOLD
std::vector< lv_coord_t > history

References activeMotor, chart_modal, MotorDisplayData::history, modal_overlay, modal_title, MotorDisplayData::name, temp_chart, temp_series, and TEMP_WARNING_THRESHOLD.

Referenced by init_motor_dashboard().

◆ update_temps_cb()

void update_temps_cb ( lv_timer_t * timer)
static

Definition at line 66 of file motorDashboard.cpp.

66 {
67 for(auto& md : motorList) {
68 double rawTemp = md.getTemp();
69 lv_coord_t currentTemp = (lv_coord_t)rawTemp;
70
71 std::rotate(md.history.begin(), md.history.begin() + 1, md.history.end());
72 md.history.back() = currentTemp;
73
74 char buf[32];
75 snprintf(buf, sizeof(buf), "%s\n%d°C", md.name.c_str(), currentTemp);
76 lv_label_set_text(md.label, buf);
77
78 bool nowOverheating = (rawTemp >= TEMP_WARNING_THRESHOLD);
79 if (nowOverheating != md.isOverheating) {
80 md.isOverheating = nowOverheating;
81 if (nowOverheating) {
82 lv_obj_set_style_bg_color(md.btn, lv_color_hex(0xD32F2F), 0);
83 } else {
84 lv_obj_set_style_bg_color(md.btn, lv_color_hex(0x2A3D8F), 0);
85 }
86 }
87
88 if (!lv_obj_has_flag(chart_modal, LV_OBJ_FLAG_HIDDEN) && activeMotor == &md) {
89 if (currentTemp >= TEMP_WARNING_THRESHOLD) {
90 lv_chart_set_series_color(temp_chart, temp_series, lv_color_hex(0xFF4A4A));
91 } else {
92 lv_chart_set_series_color(temp_chart, temp_series, lv_color_hex(0x4CAF50));
93 }
94
95 lv_chart_refresh(temp_chart);
96 }
97 }
98}

References activeMotor, chart_modal, motorList, temp_chart, temp_series, and TEMP_WARNING_THRESHOLD.

Referenced by init_motor_dashboard().

Variable Documentation

◆ activeMotor

MotorDisplayData* activeMotor = nullptr

Definition at line 28 of file motorDashboard.cpp.

Referenced by close_modal_cb(), motor_click_cb(), and update_temps_cb().

◆ chart_modal

lv_obj_t* chart_modal = nullptr

◆ modal_overlay

lv_obj_t* modal_overlay = nullptr

Definition at line 30 of file motorDashboard.cpp.

Referenced by close_modal_cb(), init_motor_dashboard(), and motor_click_cb().

◆ modal_title

lv_obj_t* modal_title = nullptr

Definition at line 34 of file motorDashboard.cpp.

Referenced by init_motor_dashboard(), and motor_click_cb().

◆ motorList

std::vector<MotorDisplayData> motorList

Definition at line 27 of file motorDashboard.cpp.

Referenced by init_motor_dashboard(), and update_temps_cb().

◆ temp_chart

lv_obj_t* temp_chart = nullptr

Definition at line 32 of file motorDashboard.cpp.

Referenced by init_motor_dashboard(), motor_click_cb(), and update_temps_cb().

◆ temp_series

lv_chart_series_t* temp_series = nullptr

Definition at line 33 of file motorDashboard.cpp.

Referenced by init_motor_dashboard(), motor_click_cb(), and update_temps_cb().