1
0
Fork 0
mirror of https://github.com/alemidev/scope-tui.git synced 2024-11-23 14:14:48 +01:00

fix: reference lines, limit trigger opts, Esc key

This commit is contained in:
əlemi 2023-09-18 01:40:04 +02:00
parent 81ef241e87
commit ee17749635
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 21 additions and 14 deletions

View file

@ -177,6 +177,10 @@ impl App {
CurrentDisplayMode::Spectroscope => self.mode = CurrentDisplayMode::Oscilloscope, CurrentDisplayMode::Spectroscope => self.mode = CurrentDisplayMode::Oscilloscope,
} }
}, },
KeyCode::Esc => {
self.graph.samples = self.graph.width;
self.graph.scale = 20000;
},
_ => {}, _ => {},
} }
}; };

View file

@ -34,19 +34,13 @@ pub trait DisplayMode {
// MUST define // MUST define
fn axis(&self, cfg: &GraphConfig, dimension: Dimension) -> Axis; // TODO simplify this fn axis(&self, cfg: &GraphConfig, dimension: Dimension) -> Axis; // TODO simplify this
fn process(&mut self, cfg: &GraphConfig, data: &Vec<Vec<f64>>) -> Vec<DataSet>; fn process(&mut self, cfg: &GraphConfig, data: &Vec<Vec<f64>>) -> Vec<DataSet>;
fn mode_str(&self) -> &'static str;
// SHOULD override // SHOULD override
fn handle(&mut self, _event: Event) {}
fn channel_name(&self, index: usize) -> String { format!("{}", index) } fn channel_name(&self, index: usize) -> String { format!("{}", index) }
fn header(&self, _cfg: &GraphConfig) -> String { "".into() } fn header(&self, _cfg: &GraphConfig) -> String { "".into() }
fn references(&self, cfg: &GraphConfig) -> Vec<DataSet> { fn references(&self, _cfg: &GraphConfig) -> Vec<DataSet> { vec![] }
let half_width = cfg.samples as f64 / 2.0; fn handle(&mut self, _event: Event) {}
vec![
DataSet::new("".into(), vec![(0.0, 0.0), (cfg.width as f64, 0.0)], cfg.marker_type, GraphType::Line, cfg.axis_color),
DataSet::new("".into(), vec![(half_width, -(cfg.scale as f64)), (half_width, cfg.scale as f64)], cfg.marker_type, GraphType::Line, cfg.axis_color),
]
}
} }
pub struct DataSet { pub struct DataSet {

View file

@ -1,7 +1,7 @@
use crossterm::event::{Event, KeyModifiers, KeyCode}; use crossterm::event::{Event, KeyModifiers, KeyCode};
use ratatui::{widgets::{Axis, GraphType}, style::Style, text::Span}; use ratatui::{widgets::{Axis, GraphType}, style::Style, text::Span};
use crate::app::update_value_f; use crate::app::{update_value_f, update_value_i};
use super::{DisplayMode, GraphConfig, DataSet, Dimension}; use super::{DisplayMode, GraphConfig, DataSet, Dimension};
@ -52,6 +52,12 @@ impl DisplayMode for Oscilloscope {
a.style(Style::default().fg(cfg.axis_color)).bounds(bounds) a.style(Style::default().fg(cfg.axis_color)).bounds(bounds)
} }
fn references(&self, cfg: &GraphConfig) -> Vec<DataSet> {
vec![
DataSet::new("".into(), vec![(0.0, 0.0), (cfg.samples as f64, 0.0)], cfg.marker_type, GraphType::Line, cfg.axis_color),
]
}
fn process(&mut self, cfg: &GraphConfig, data: &Vec<Vec<f64>>) -> Vec<DataSet> { fn process(&mut self, cfg: &GraphConfig, data: &Vec<Vec<f64>>) -> Vec<DataSet> {
let mut out = Vec::new(); let mut out = Vec::new();
@ -117,10 +123,13 @@ impl DisplayMode for Oscilloscope {
KeyCode::Char('t') => self.triggering = !self.triggering, KeyCode::Char('t') => self.triggering = !self.triggering,
KeyCode::Char('e') => self.falling_edge = !self.falling_edge, KeyCode::Char('e') => self.falling_edge = !self.falling_edge,
KeyCode::Char('p') => self.peaks = !self.peaks, KeyCode::Char('p') => self.peaks = !self.peaks,
KeyCode::Char('=') => self.depth += 1, KeyCode::Char('=') => update_value_i(&mut self.depth, true, 1, 1.0, 0..65535),
KeyCode::Char('-') => self.depth -= 1, KeyCode::Char('-') => update_value_i(&mut self.depth, false, 1, 1.0, 0..65535),
KeyCode::Char('+') => self.depth += 10, KeyCode::Char('+') => update_value_i(&mut self.depth, true, 10, 1.0, 0..65535),
KeyCode::Char('_') => self.depth -= 10, KeyCode::Char('_') => update_value_i(&mut self.depth, false, 10, 1.0, 0..65535),
KeyCode::Esc => {
self.triggering = false;
},
_ => {} _ => {}
} }
} }