diff --git a/src/app.rs b/src/app.rs index 6a8a22e..cfd814e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -47,6 +47,7 @@ pub struct AppConfig { width: u32, vectorscope: bool, pub references: bool, + pub triggering: bool, pub marker_type: symbols::Marker, pub graph_type: GraphType, @@ -161,6 +162,7 @@ impl From::<&crate::Args> for App { palette: vec![Color::Red, Color::Yellow], scale: args.range, width: args.buffer / 4, // TODO It's 4 because 2 channels and 2 bytes per sample! + triggering: args.triggering, vectorscope: args.vectorscope, references: !args.no_reference, marker_type, graph_type, diff --git a/src/main.rs b/src/main.rs index f47dca4..f16f59b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,6 +61,10 @@ struct Args { #[arg(long, value_name = "N", default_value_t = 32)] server_buffer: u32, + /// Start drawing at first rising edge + #[arg(long, default_value_t = false)] + triggering: bool, + /// Don't draw reference line #[arg(long, default_value_t = false)] no_reference: bool, @@ -171,6 +175,20 @@ fn run_app(args: Args, terminal: &mut Terminal) -> Result<(), io channels = fmt.oscilloscope(&mut buffer, 2); } + if app.cfg.triggering { + // TODO allow to customize channel to use for triggering and threshold + if let Some(ch) = channels.get(0) { + let mut discard = 0; + for i in 0..ch.len() { // seek to first sample rising through threshold + if i + 1 < ch.len() && ch[i] <= 0.0 && ch[i+1] > 0.0 { // triggered + break; + } else { + discard += 1; + } + } + for ch in channels.iter_mut() { + *ch = ch[discard..].to_vec(); + } } } @@ -246,6 +264,9 @@ fn run_app(args: Args, terminal: &mut Terminal) -> Result<(), io KeyCode::Char('v') => app.set_vectorscope(!app.vectorscope()), KeyCode::Char('s') => app.set_scatter(!app.scatter()), KeyCode::Char('h') => app.cfg.references = !app.cfg.references, + KeyCode::Char('t') => app.cfg.triggering = !app.cfg.triggering, + KeyCode::Up => {}, + KeyCode::Down => {}, _ => {}, } } @@ -298,8 +319,9 @@ fn block(app: &App, sample_rate: f32, framerate: u32) -> Block { b = b.title( Span::styled( format!( - "TUI {} -- {} mode -- range {} -- {} samples -- {:.1} kHz -- {} fps", + "TUI {} -- {}{} mode -- range {} -- {} samples -- {:.1} kHz -- {} fps", if app.vectorscope() { "Vectorscope" } else { "Oscilloscope" }, + if app.cfg.triggering { "triggered " } else { "" }, if app.scatter() { "scatter" } else { "line" }, app.scale(), app.width(), sample_rate / 1000.0, framerate, ),