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

fix: updated limits on user-controlled settings

This commit is contained in:
əlemi 2023-09-21 03:27:43 +02:00
parent 1ebed14033
commit e99c9a4a3d
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 20 additions and 17 deletions

View file

@ -152,10 +152,10 @@ impl App {
_ => 1.0,
};
match key.code {
KeyCode::Up => update_value_i(&mut self.graph.scale, true, 250, magnitude, 0..32768), // inverted to act as zoom
KeyCode::Down => update_value_i(&mut self.graph.scale, false, 250, magnitude, 0..32768), // inverted to act as zoom
KeyCode::Right => update_value_i(&mut self.graph.samples, true, 25, magnitude, 0..self.graph.width*10),
KeyCode::Left => update_value_i(&mut self.graph.samples, false, 25, magnitude, 0..self.graph.width*10),
KeyCode::Up => update_value_i(&mut self.graph.scale, true, 250, magnitude, 0..65535), // inverted to act as zoom
KeyCode::Down => update_value_i(&mut self.graph.scale, false, 250, magnitude, 0..65535), // inverted to act as zoom
KeyCode::Right => update_value_i(&mut self.graph.samples, true, 25, magnitude, 0..self.graph.width*2),
KeyCode::Left => update_value_i(&mut self.graph.samples, false, 25, magnitude, 0..self.graph.width*2),
KeyCode::Char('q') => quit = true,
KeyCode::Char(' ') => self.pause = !self.pause,
KeyCode::Char('s') => self.graph.scatter = !self.graph.scatter,

View file

@ -66,6 +66,7 @@ impl DisplayMode for Oscilloscope {
let mut out = Vec::new();
let mut trigger_offset = 0;
if self.depth == 0 { self.depth = 1 }
if self.triggering {
for i in 0..data[0].len() {
if triggered(&data[0], i, self.threshold, self.depth, self.falling_edge) { // triggered
@ -127,10 +128,10 @@ 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('=') => 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::Char('=') => update_value_i(&mut self.depth, true, 1, 1.0, 1..65535),
KeyCode::Char('-') => update_value_i(&mut self.depth, false, 1, 1.0, 1..65535),
KeyCode::Char('+') => update_value_i(&mut self.depth, true, 10, 1.0, 1..65535),
KeyCode::Char('_') => update_value_i(&mut self.depth, false, 10, 1.0, 1..65535),
KeyCode::Esc => {
self.triggering = false;
},
@ -140,7 +141,7 @@ impl DisplayMode for Oscilloscope {
}
}
// TODO can this be made nicer?
#[allow(clippy::collapsible_else_if)] // TODO can this be made nicer?
fn triggered(data: &[f64], index: usize, threshold: f64, depth: u32, falling_edge:bool) -> bool {
if data.len() < index + (1+depth as usize) { return false; }
if falling_edge {
@ -154,7 +155,8 @@ fn triggered(data: &[f64], index: usize, threshold: f64, depth: u32, falling_edg
} else {
false
}
} else if data[index] <= threshold {
} else {
if data[index] <= threshold {
for i in 1..=depth as usize {
if data[index+i] <= threshold {
return false;
@ -164,4 +166,5 @@ fn triggered(data: &[f64], index: usize, threshold: f64, depth: u32, falling_edg
} else {
false
}
}
}