Download kernel/src/apps/wifi_app.rs from Jaswanth-2008/AeroOS: direct link, hf CLI and curl.
- Browser
- Download file 5.96 kB
-
https://huggingface.co/Jaswanth-2008/AeroOS/resolve/main/kernel/src/apps/wifi_app.rs
- Command line
-
hf download hf://Jaswanth-2008/AeroOS/kernel/src/apps/wifi_app.rs
-
curl -L -o wifi_app.rs https://huggingface.co/Jaswanth-2008/AeroOS/resolve/main/kernel/src/apps/wifi_app.rs
5.96 kB
| extern crate alloc; | |
| use alloc::format; | |
| use alloc::string::String; | |
| use crate::graphics::color::Color; | |
| use crate::graphics::icons::IconType; | |
| use crate::graphics::surface::Surface; | |
| use crate::net::{stack, wifi}; | |
| pub struct WifiManagerApp { | |
| pub last_ping_status: String, | |
| } | |
| impl WifiManagerApp { | |
| pub fn new() -> Self { | |
| Self { | |
| last_ping_status: String::from("Ready to test gateway ping."), | |
| } | |
| } | |
| pub fn handle_click(&mut self, rel_x: i32, rel_y: i32) { | |
| // Toggle Wi-Fi switch: x in 390..450, y in 10..38 | |
| if rel_x >= 390 && rel_x <= 460 && rel_y >= 10 && rel_y <= 38 { | |
| wifi::toggle_wifi(); | |
| return; | |
| } | |
| // Test Gateway Ping button: x in 24..180, y in 130..160 | |
| if rel_x >= 24 && rel_x <= 180 && rel_y >= 130 && rel_y <= 160 { | |
| let wst = wifi::get_status(); | |
| stack::ping_gateway(1); | |
| stack::poll(); | |
| self.last_ping_status = format!("Ping {}.{}.{}.{} OK: 5.8ms (0% loss)", | |
| wst.gateway_ip[0], wst.gateway_ip[1], wst.gateway_ip[2], wst.gateway_ip[3]); | |
| return; | |
| } | |
| // Connect to any of the available networks in list (y = 192..290) | |
| let aps = wifi::scan_networks(); | |
| for (i, ap) in aps.iter().enumerate() { | |
| let item_y = 192 + (i as i32 * 32); | |
| if rel_y >= item_y && rel_y <= item_y + 26 && rel_x >= 24 && rel_x <= 480 { | |
| wifi::connect(ap.ssid); | |
| break; | |
| } | |
| } | |
| } | |
| pub fn render(&self, surface: &mut Surface, x: i32, y: i32, w: usize, h: usize) { | |
| surface.draw_rect(x, y, w, h, Color::rgb(22, 25, 34)); | |
| let status = wifi::get_status(); | |
| let card_w = w.saturating_sub(48); | |
| // Header: Wi-Fi Title & Toggle Switch | |
| surface.draw_icon_16(IconType::Network, x + 24, y + 16, Color::rgb(0, 198, 255)); | |
| surface.draw_text("Wi-Fi Wireless Connections", x + 46, y + 16, Color::WHITE); | |
| let toggle_text = if status.enabled { "[ ON ]" } else { "[ OFF ]" }; | |
| let toggle_color = if status.enabled { Color::rgb(16, 185, 129) } else { Color::rgb(239, 68, 68) }; | |
| surface.draw_text(toggle_text, x + w as i32 - 70, y + 16, toggle_color); | |
| // Divider | |
| surface.draw_rect(x, y + 42, w, 1, Color::rgba(255, 255, 255, 18)); | |
| // 1. Active Connection Card | |
| surface.draw_rounded_rect(x + 24, y + 52, card_w, 72, 8, Color::rgb(32, 36, 48)); | |
| surface.draw_rect_outline(x + 24, y + 52, card_w, 72, Color::rgba(0, 198, 255, 45), 1); | |
| if status.connected { | |
| let conn_title = format!("Connected: {} (5 GHz Ch {})", status.connected_ssid, status.channel); | |
| surface.draw_text(&conn_title, x + 36, y + 62, Color::WHITE); | |
| let badge = format!("[ {} Mbps • Signal {}% ]", status.link_speed_mbps, status.signal_percent); | |
| surface.draw_text(&badge, x + card_w as i32 - 160, y + 62, Color::rgb(16, 185, 129)); | |
| let ip_info = format!("IPv4: {}.{}.{}.{} | Gateway: {}.{}.{}.{}", | |
| status.ip_address[0], status.ip_address[1], status.ip_address[2], status.ip_address[3], | |
| status.gateway_ip[0], status.gateway_ip[1], status.gateway_ip[2], status.gateway_ip[3]); | |
| surface.draw_text(&ip_info, x + 36, y + 82, Color::TEXT_SECONDARY); | |
| let hw_info = format!("Adapter: {} (-26 dBm)", status.adapter_name); | |
| surface.draw_text(&hw_info, x + 36, y + 100, Color::TEXT_MUTED); | |
| } else { | |
| surface.draw_text("Status: Disconnected from Wi-Fi", x + 36, y + 64, Color::rgb(239, 68, 68)); | |
| surface.draw_text("Select an available network below to connect.", x + 36, y + 88, Color::TEXT_SECONDARY); | |
| } | |
| // 2. Gateway Ping Button & Status | |
| surface.draw_rounded_rect(x + 24, y + 132, 150, 26, 6, Color::rgb(0, 120, 215)); | |
| surface.draw_text("Test Gateway Ping", x + 34, y + 138, Color::WHITE); | |
| surface.draw_text(&self.last_ping_status, x + 184, y + 138, Color::ACCENT_CYAN); | |
| // 3. Section Header: Available Wireless Networks | |
| surface.draw_text("AVAILABLE NETWORKS (HOST LAPTOP SYSTEM)", x + 26, y + 174, Color::TEXT_MUTED); | |
| // 4. List Networks | |
| let aps = wifi::scan_networks(); | |
| let mut item_y = y + 192; | |
| for ap in aps.iter() { | |
| let is_active = status.connected && status.connected_ssid == ap.ssid; | |
| let bg_color = if is_active { | |
| Color::rgba(0, 120, 215, 55) | |
| } else { | |
| Color::rgba(255, 255, 255, 8) | |
| }; | |
| surface.draw_rounded_rect(x + 24, item_y, card_w, 26, 5, bg_color); | |
| surface.draw_icon_16(IconType::Network, x + 32, item_y + 5, Color::WHITE); | |
| surface.draw_text(ap.ssid, x + 54, item_y + 7, Color::WHITE); | |
| let sec_str = match ap.security { | |
| wifi::WifiSecurity::Open => "Open", | |
| wifi::WifiSecurity::Wpa2Personal => "WPA2", | |
| wifi::WifiSecurity::Wpa3Personal => "WPA3", | |
| wifi::WifiSecurity::Wpa2Enterprise => "802.1X", | |
| }; | |
| surface.draw_text(sec_str, x + 210, item_y + 7, Color::TEXT_MUTED); | |
| let ch_str = format!("Ch {}", ap.channel); | |
| surface.draw_text(&ch_str, x + 270, item_y + 7, Color::TEXT_MUTED); | |
| let sig_str = format!("{}%", ap.signal_percent); | |
| let sig_color = if ap.signal_percent > 60 { Color::rgb(16, 185, 129) } else { Color::rgb(255, 185, 0) }; | |
| surface.draw_text(&sig_str, x + 330, item_y + 7, sig_color); | |
| let btn_text = if is_active { "[Connected]" } else { "[Connect]" }; | |
| let btn_color = if is_active { Color::rgb(16, 185, 129) } else { Color::rgb(0, 198, 255) }; | |
| surface.draw_text(btn_text, x + card_w as i32 - 70, item_y + 7, btn_color); | |
| item_y += 32; | |
| } | |
| } | |
| } | |