Skip to content

Commit

Permalink
prepare signal charts
Browse files Browse the repository at this point in the history
  • Loading branch information
Chleba committed Dec 10, 2023
1 parent 4680e02 commit 21f280a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 100 deletions.
5 changes: 2 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tokio::sync::mpsc;

use crate::{
action::Action,
components::{home::Home, fps::FpsCounter, wifiscan::WifiScan, Component},
components::{home::Home, wifiscan::WifiScan, Component},
config::Config,
mode::Mode,
tui,
Expand All @@ -26,15 +26,14 @@ pub struct App {
impl App {
pub fn new(tick_rate: f64, frame_rate: f64) -> Result<Self> {
let home = Home::new();
let fps = FpsCounter::default();
let wifiscan = WifiScan::default();
let config = Config::new()?;
let mode = Mode::Home;
Ok(Self {
tick_rate: 1.0,
// tick_rate,
frame_rate,
components: vec![Box::new(home), Box::new(fps), Box::new(wifiscan)],
components: vec![Box::new(home), Box::new(wifiscan)],
should_quit: false,
should_suspend: false,
config,
Expand Down
1 change: 0 additions & 1 deletion src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::{
tui::{Event, Frame},
};

pub mod fps;
pub mod home;
pub mod wifiscan;

Expand Down
90 changes: 0 additions & 90 deletions src/components/fps.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Component for Home {
}

fn draw(&mut self, f: &mut Frame<'_>, area: Rect) -> Result<()> {
f.render_widget(Paragraph::new("Network scanner"), area);
f.render_widget(Paragraph::new(" Network scanner"), area);
Ok(())
}
}
Expand Down
33 changes: 28 additions & 5 deletions src/components/wifiscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ pub struct WifiScan {
pub wifis: Vec<WifiInfo>,
}

pub struct WifiDataset {
ssid: String,
data: Vec<(f64, f64)>,
}

impl Default for WifiScan {
fn default() -> Self {
Self::new()
Expand All @@ -44,21 +49,21 @@ impl WifiScan {
fn make_table(&mut self) -> Table {
let header = Row::new(vec!["UTC", "ssid", "channel", "mac", "signal"])
.style(Style::default().fg(Color::Yellow))
.bottom_margin(0);
.bottom_margin(1);
let mut rows = Vec::new();
for w in &self.wifis {
// let gauge = Gauge::default()
// .block(Block::default())
// .gauge_style(Style::default().fg(Color::White).bg(Color::Black))
// .percent(20);

let max_dbm: f32 = -30.0;
let min_dbm: f32 = -90.0;
let s_clamp = w.signal.max(min_dbm).min(max_dbm);
let percent = ((s_clamp - min_dbm) / (max_dbm - min_dbm)).clamp(0.0, 1.0);

let p = (percent * 10.0) as usize;
let gauge: String = std::iter::repeat(char::from_u32(0x25a8).unwrap_or('#'))
let gauge: String = std::iter::repeat(char::from_u32(0x25a8)
.unwrap_or('#'))
.take(p)
.collect();

Expand All @@ -72,7 +77,7 @@ impl WifiScan {
Style::default().fg(Color::LightGreen),
Style::default().fg(Color::Green),
];
let color = (percent * ((colors.len() - 1) as f32)) as usize;
let color = (percent * ((colors.len()-1) as f32)) as usize;
let signal = format!("({}){}", w.signal, gauge);

rows.push(Row::new(vec![
Expand Down Expand Up @@ -102,6 +107,20 @@ impl WifiScan {
table
}

// pub fn make_chart(&mut self) -> Chart {
// let data = Vec::new();
// let dataset = Dataset::default()
// .name("data1")
// .marker(symbols::Marker::Dot)
// .style(Style::default().fg(Color::Red))
// .data(data);
// let chart = Chart::new(vec![dataset])
// .block(Block::default().title("Wifi signals").borders(Borders::ALL))
// .y_axis(Axis::default().title("signal").style(Style::default().fg(Color::Gray)))
// .x_axis(Axis::default().title("time").style(Style::default().fg(Color::Gray)));
// chart
// }

pub fn scan(&mut self) {
let tx = self.action_tx.clone().unwrap();
tokio::spawn(async move {
Expand Down Expand Up @@ -184,6 +203,10 @@ impl Component for WifiScan {
rect.y = 1;

let block = self.make_table();
f.render_widget(block, rect);

// let block = self.make_chart();
// f.render_widget(block, rects[1]);

// // -- LIST
// let mut logs: Vec<ListItem> = Vec::new();
Expand Down Expand Up @@ -221,7 +244,7 @@ impl Component for WifiScan {
// // println!("{:?}", items);
// let block = Table::new(items).block(Block::default().title("[Wifi Networks]").borders(Borders::ALL));

f.render_widget(block, rect);
// f.render_widget(block, rect);
Ok(())
}
}

0 comments on commit 21f280a

Please sign in to comment.