Skip to content

Commit c2caea2

Browse files
committed
add more flight data to UI
1 parent df98efe commit c2caea2

5 files changed

Lines changed: 52 additions & 2 deletions

File tree

UI/include/flight_data.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ struct flight_history_t {
5252
float target_pos_west;
5353
float target_pos_up;
5454

55+
float elapsed_time;
56+
bool GND_flag;
57+
bool flight_armed;
58+
float thrust_perc;
59+
float diffy_perc;
60+
5561
// points to the oldest stored data
5662
int read_start_pos;
5763
// points to the most recently written data
@@ -97,6 +103,12 @@ struct flight_packet_t {
97103
float target_pos_north;
98104
float target_pos_west;
99105
float target_pos_up;
106+
107+
float elapsed_time;
108+
bool GND_flag;
109+
bool flight_armed;
110+
float thrust_perc;
111+
float diffy_perc;
100112
};
101113

102114
extern flight_history_t FlightHistory; // public interface

UI/include/ui_components.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ extern ImFont *large_font;
88

99
void centered_text(const char *text);
1010
bool rounded_button(const char *label, const ImVec2 &size, ImU32 color, float rounding = 10.0f);
11+
void colored_flag(char *text, bool state, ImVec4 on_color, ImVec4 off_color, char *imgui_id);
1112

1213
#endif

UI/src/flight_data.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ void commit_packet() {
7171
FlightHistory.target_pos_west = active_packet.target_pos_west;
7272
FlightHistory.target_pos_up = active_packet.target_pos_up;
7373

74+
FlightHistory.elapsed_time = active_packet.elapsed_time;
75+
FlightHistory.GND_flag = active_packet.GND_flag;
76+
FlightHistory.flight_armed = active_packet.flight_armed;
77+
FlightHistory.thrust_perc = active_packet.thrust_perc;
78+
FlightHistory.diffy_perc = active_packet.diffy_perc;
79+
7480
FlightHistory.write_pos += 1;
7581
FlightHistory.write_pos %= FLIGHT_HISTORY_LENGTH;
7682
FlightHistory.read_start_pos = FlightHistory.write_pos;

UI/src/ui.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,19 @@ void controller_output_panel() {
177177
centered_text("Controller Output");
178178
ImGui::Text(" Target Thrust: %5.2f N", FlightHistory.thrust_N);
179179
ImGui::Text(" Target Roll: %5.2f rad/s^2", FlightHistory.roll_roll_rad_sec_squared);
180-
ImGui::Text(" Thrust: %5.2f %%", 0); // TODO - these
181-
ImGui::Text(" Differential: %5.2f %%", 0);
180+
ImGui::Text(" Thrust: %5.2f %%", FlightHistory.thrust_perc);
181+
ImGui::Text(" Differential: %5.2f %%", FlightHistory.diffy_perc);
182+
183+
ImGui::Dummy(ImVec2(0, 100));
184+
185+
ImGui::Text("Elasped Time: %5.2f s", FlightHistory.elapsed_time);
186+
colored_flag(" GND Flag", FlightHistory.GND_flag, ImVec4(0.0f, 153.0 / 255.0, 0.0f, 1.0f), ImVec4(204.0 / 255.0, 0.0f, 0.0f, 1.0f), "##gnd_flag");
187+
ImGui::TableSetColumnIndex(1);
188+
if (FlightHistory.flight_armed) {
189+
colored_flag(" Armed", FlightHistory.flight_armed, ImVec4(204.0 / 255.0, 0.0f, 0.0f, 1.0f), ImVec4(0.0f, 153.0 / 255.0, 0.0f, 1.0f), "##armed_flag");
190+
} else {
191+
colored_flag(" Not Armed", FlightHistory.flight_armed, ImVec4(204.0 / 255.0, 0.0f, 0.0f, 1.0f), ImVec4(0.0f, 153.0 / 255.0, 0.0f, 1.0f), "##armed_flag");
192+
}
182193

183194
ImGui::End();
184195
}

UI/src/ui_components.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,24 @@ bool rounded_button(const char *label, const ImVec2 &size, ImU32 color, float ro
3838
ImGui::PopStyleColor(3);
3939

4040
return clicked;
41+
}
42+
43+
void colored_flag(char *text, bool state, ImVec4 on_color, ImVec4 off_color, char *imgui_id) {
44+
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 8.0f);
45+
if (state) {
46+
ImGui::PushStyleColor(ImGuiCol_FrameBg, on_color);
47+
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, on_color);
48+
ImGui::PushStyleColor(ImGuiCol_FrameBgActive, on_color);
49+
} else {
50+
ImGui::PushStyleColor(ImGuiCol_FrameBg, off_color);
51+
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, off_color);
52+
ImGui::PushStyleColor(ImGuiCol_FrameBgActive, off_color);
53+
}
54+
55+
ImGui::SetNextItemWidth(200.0f); // pixels
56+
ImGui::BeginDisabled(); // prevent editing
57+
ImGui::InputText(imgui_id, text, ImGuiInputTextFlags_ReadOnly);
58+
ImGui::EndDisabled();
59+
ImGui::PopStyleColor(3);
60+
ImGui::PopStyleVar();
4161
}

0 commit comments

Comments
 (0)