From ee17749635996704c1e3c0c1744390ef2b631d03 Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 18 Sep 2023 01:40:04 +0200 Subject: [PATCH] fix: reference lines, limit trigger opts, Esc key --- src/app.rs | 4 ++++ src/display/mod.rs | 12 +++--------- src/display/oscilloscope.rs | 19 ++++++++++++++----- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/app.rs b/src/app.rs index 5b19bd9..c24b33f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -177,6 +177,10 @@ impl App { CurrentDisplayMode::Spectroscope => self.mode = CurrentDisplayMode::Oscilloscope, } }, + KeyCode::Esc => { + self.graph.samples = self.graph.width; + self.graph.scale = 20000; + }, _ => {}, } }; diff --git a/src/display/mod.rs b/src/display/mod.rs index 4f7373b..867aa92 100644 --- a/src/display/mod.rs +++ b/src/display/mod.rs @@ -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; + 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 { - 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 { vec![] } + fn handle(&mut self, _event: Event) {} } pub struct DataSet { diff --git a/src/display/oscilloscope.rs b/src/display/oscilloscope.rs index 615be7a..472c83e 100644 --- a/src/display/oscilloscope.rs +++ b/src/display/oscilloscope.rs @@ -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 { + 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 { 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; + }, _ => {} } }