mirror of
https://github.com/alemidev/scope-tui.git
synced 2024-11-23 22:24:48 +01:00
feat: allow to set sample rate, show framerate
fps counter implementation is kind of scuffed but does the job
This commit is contained in:
parent
a25d9c3590
commit
d98f04ae1f
1 changed files with 20 additions and 4 deletions
24
src/main.rs
24
src/main.rs
|
@ -1,7 +1,7 @@
|
||||||
mod parser;
|
mod parser;
|
||||||
mod app;
|
mod app;
|
||||||
|
|
||||||
use std::{io::{self, ErrorKind}, time::Duration};
|
use std::{io::{self, ErrorKind}, time::{Duration, SystemTime}};
|
||||||
use tui::{
|
use tui::{
|
||||||
backend::{CrosstermBackend, Backend},
|
backend::{CrosstermBackend, Backend},
|
||||||
widgets::{Block, Chart, Axis, Dataset, GraphType},
|
widgets::{Block, Chart, Axis, Dataset, GraphType},
|
||||||
|
@ -38,6 +38,10 @@ struct Args {
|
||||||
#[arg(short, long, default_value_t = 20000)]
|
#[arg(short, long, default_value_t = 20000)]
|
||||||
range: u32,
|
range: u32,
|
||||||
|
|
||||||
|
/// Sample rate to use
|
||||||
|
#[arg(long, default_value_t = 44100)]
|
||||||
|
sample_rate: u32,
|
||||||
|
|
||||||
/// Don't draw reference line
|
/// Don't draw reference line
|
||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
no_reference: bool,
|
no_reference: bool,
|
||||||
|
@ -121,7 +125,7 @@ fn run_app<T : Backend>(args: Args, terminal: &mut Terminal<T>) -> Result<(), io
|
||||||
let spec = Spec {
|
let spec = Spec {
|
||||||
format: Format::S16NE,
|
format: Format::S16NE,
|
||||||
channels: 2,
|
channels: 2,
|
||||||
rate: 44100,
|
rate: args.sample_rate,
|
||||||
};
|
};
|
||||||
assert!(spec.is_valid());
|
assert!(spec.is_valid());
|
||||||
|
|
||||||
|
@ -151,6 +155,9 @@ fn run_app<T : Backend>(args: Args, terminal: &mut Terminal<T>) -> Result<(), io
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut fps = 0;
|
||||||
|
let mut framerate = 0;
|
||||||
|
let mut last_poll = SystemTime::now();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match s.read(&mut buffer) {
|
match s.read(&mut buffer) {
|
||||||
|
@ -196,6 +203,15 @@ fn run_app<T : Backend>(args: Args, terminal: &mut Terminal<T>) -> Result<(), io
|
||||||
(left, right) = fmt.oscilloscope(&mut buffer);
|
(left, right) = fmt.oscilloscope(&mut buffer);
|
||||||
datasets.push(data_set("R", &right, cfg.marker_type, cfg.graph_type(), cfg.secondary_color));
|
datasets.push(data_set("R", &right, cfg.marker_type, cfg.graph_type(), cfg.secondary_color));
|
||||||
datasets.push(data_set("L", &left, cfg.marker_type, cfg.graph_type(), cfg.primary_color));
|
datasets.push(data_set("L", &left, cfg.marker_type, cfg.graph_type(), cfg.primary_color));
|
||||||
|
|
||||||
|
fps += 1;
|
||||||
|
|
||||||
|
if let Ok(d) = last_poll.elapsed() {
|
||||||
|
if d.as_secs() >= 1 {
|
||||||
|
framerate = fps;
|
||||||
|
fps = 0;
|
||||||
|
last_poll = SystemTime::now();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
terminal.draw(|f| {
|
terminal.draw(|f| {
|
||||||
|
@ -204,10 +220,10 @@ fn run_app<T : Backend>(args: Args, terminal: &mut Terminal<T>) -> Result<(), io
|
||||||
.block(Block::default().title(
|
.block(Block::default().title(
|
||||||
Span::styled(
|
Span::styled(
|
||||||
format!(
|
format!(
|
||||||
"TUI {} <me@alemi.dev> -- {} mode -- range {} -- {} samples",
|
"TUI {} <me@alemi.dev> -- {} mode -- range {} -- {} samples -- {:.1} kHz -- {} fps",
|
||||||
if cfg.vectorscope() { "Vectorscope" } else { "Oscilloscope" },
|
if cfg.vectorscope() { "Vectorscope" } else { "Oscilloscope" },
|
||||||
if cfg.scatter() { "scatter" } else { "line" },
|
if cfg.scatter() { "scatter" } else { "line" },
|
||||||
cfg.scale(), cfg.width(),
|
cfg.scale(), cfg.width(), args.sample_rate as f32 / 1000.0, framerate,
|
||||||
),
|
),
|
||||||
Style::default().add_modifier(Modifier::BOLD).fg(Color::Yellow))
|
Style::default().add_modifier(Modifier::BOLD).fg(Color::Yellow))
|
||||||
))
|
))
|
||||||
|
|
Loading…
Reference in a new issue