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:
parent
81ef241e87
commit
ee17749635
3 changed files with 21 additions and 14 deletions
|
@ -177,6 +177,10 @@ impl App {
|
|||
CurrentDisplayMode::Spectroscope => self.mode = CurrentDisplayMode::Oscilloscope,
|
||||
}
|
||||
},
|
||||
KeyCode::Esc => {
|
||||
self.graph.samples = self.graph.width;
|
||||
self.graph.scale = 20000;
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
};
|
||||
|
|
|
@ -34,19 +34,13 @@ pub trait DisplayMode {
|
|||
// MUST define
|
||||
fn axis(&self, cfg: &GraphConfig, dimension: Dimension) -> Axis; // TODO simplify this
|
||||
fn process(&mut self, cfg: &GraphConfig, data: &Vec<Vec<f64>>) -> Vec<DataSet>;
|
||||
fn mode_str(&self) -> &'static str;
|
||||
|
||||
// SHOULD override
|
||||
fn handle(&mut self, _event: Event) {}
|
||||
fn channel_name(&self, index: usize) -> String { format!("{}", index) }
|
||||
fn header(&self, _cfg: &GraphConfig) -> String { "".into() }
|
||||
fn references(&self, cfg: &GraphConfig) -> Vec<DataSet> {
|
||||
let half_width = cfg.samples as f64 / 2.0;
|
||||
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),
|
||||
|
||||
]
|
||||
}
|
||||
fn references(&self, _cfg: &GraphConfig) -> Vec<DataSet> { vec![] }
|
||||
fn handle(&mut self, _event: Event) {}
|
||||
}
|
||||
|
||||
pub struct DataSet {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crossterm::event::{Event, KeyModifiers, KeyCode};
|
||||
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};
|
||||
|
||||
|
@ -52,6 +52,12 @@ impl DisplayMode for Oscilloscope {
|
|||
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> {
|
||||
let mut out = Vec::new();
|
||||
|
||||
|
@ -117,10 +123,13 @@ impl DisplayMode for Oscilloscope {
|
|||
KeyCode::Char('t') => self.triggering = !self.triggering,
|
||||
KeyCode::Char('e') => self.falling_edge = !self.falling_edge,
|
||||
KeyCode::Char('p') => self.peaks = !self.peaks,
|
||||
KeyCode::Char('=') => self.depth += 1,
|
||||
KeyCode::Char('-') => self.depth -= 1,
|
||||
KeyCode::Char('+') => self.depth += 10,
|
||||
KeyCode::Char('_') => self.depth -= 10,
|
||||
KeyCode::Char('=') => update_value_i(&mut self.depth, true, 1, 1.0, 0..65535),
|
||||
KeyCode::Char('-') => update_value_i(&mut self.depth, false, 1, 1.0, 0..65535),
|
||||
KeyCode::Char('+') => update_value_i(&mut self.depth, true, 10, 1.0, 0..65535),
|
||||
KeyCode::Char('_') => update_value_i(&mut self.depth, false, 10, 1.0, 0..65535),
|
||||
KeyCode::Esc => {
|
||||
self.triggering = false;
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue