From e56c1dfe3acf1f597daf8c942a0a7f8d40751a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Sun, 23 Feb 2025 21:57:16 -0300 Subject: [PATCH] wip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- src/webpage/src/app.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/webpage/src/app.rs b/src/webpage/src/app.rs index 7098c08..dc5bf79 100644 --- a/src/webpage/src/app.rs +++ b/src/webpage/src/app.rs @@ -28,6 +28,7 @@ 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"; @@ -35,6 +36,7 @@ const DRIVERS_STATS_WEBSOCKET_PATH: &str = "stats/drivers/ws"; enum Screens { Main, Helper, + Control, } #[derive(Clone, PartialEq)] @@ -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), @@ -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::(&message) else { return; @@ -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();