Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
  • Loading branch information
patrickelectric committed Feb 24, 2025
1 parent b996bb0 commit e56c1df
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/webpage/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ use crate::{
const MAVLINK_MESSAGES_WEBSOCKET_PATH: &str = "rest/ws";
const MAVLINK_HELPER: &str = "rest/helper";
const MAVLINK_POST: &str = "rest/mavlink";
const CONTROL_VEHICLES: &str = "rest/vehicles";
const HUB_MESSAGES_STATS_WEBSOCKET_PATH: &str = "stats/messages/ws";
const HUB_STATS_WEBSOCKET_PATH: &str = "stats/hub/ws";
const DRIVERS_STATS_WEBSOCKET_PATH: &str = "stats/drivers/ws";

enum Screens {
Main,
Helper,
Control,
}

#[derive(Clone, PartialEq)]
Expand Down Expand Up @@ -143,6 +145,10 @@ impl App {
if ui.button("Helper").clicked() {
self.show_screen = Screens::Helper;
}
ui.add_space(16.0);
if ui.button("Control").clicked() {
self.show_screen = Screens::Control;
}

ui.with_layout(
eframe::egui::Layout::right_to_left(eframe::egui::Align::RIGHT),
Expand Down Expand Up @@ -270,6 +276,34 @@ impl App {
});
}

fn show_control_screen(&mut self, ctx: &Context) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.label("Control");
if ui.button("Arm").clicked() {
let mut request = Request::post(format!("/{CONTROL_VEHICLES}/arm"), "{
\"system_id\": 1,
\"component_id\": 1,
\"force\": true
}".into());
request.headers.insert("Content-Type", "application/json");
ehttp::fetch(request, |res| {
log::info!("Arm response: {res:?}");
});
}
if ui.button("Disarm").clicked() {
let mut request = Request::post(format!("/{CONTROL_VEHICLES}/arm"), "{
\"system_id\": 1,
\"component_id\": 1,
\"force\": true
}".into());
request.headers.insert("Content-Type", "application/json");
ehttp::fetch(request, |res| {
log::info!("Disarm response: {res:?}");
});
}
});
}

fn deal_with_mavlink_message(&mut self, message: String) {
let Ok(message_json) = serde_json::from_str::<serde_json::Value>(&message) else {
return;
Expand Down Expand Up @@ -1007,6 +1041,7 @@ impl eframe::App for App {
match self.show_screen {
Screens::Main => self.show_main_screen(ctx),
Screens::Helper => self.show_helper_screen(ctx),
Screens::Control => self.show_control_screen(ctx),
}

ctx.request_repaint();
Expand Down

0 comments on commit e56c1df

Please sign in to comment.