Adds repeat

This commit is contained in:
Dandaedre 2024-09-26 01:39:10 -05:00
parent 7645e8e2c6
commit 3c4ec19600
4 changed files with 50 additions and 21 deletions

View File

@ -30,7 +30,7 @@ use chrono::Local;
#[packed_struct(endian = "lsb")]
pub struct DataPoint {
/// The alignement character 'x'
c: u8,
align: u8,
/// The value sent with as a u16
value: u16,
}
@ -50,7 +50,6 @@ pub(crate) fn scan_with_progress(
start: usize,
stop: usize,
points: usize,
// TODO: Add repeat to tui
repeat: usize,
) -> Result<(), TinyError> {
let mode = mode_from(start, stop)?;
@ -81,7 +80,7 @@ pub(crate) fn scan_with_progress(
*scan_message.lock().unwrap() = "Setting up repeat".to_string();
// TODO: Investigate this behaviour
send_cmd(&mut port, &format!("repeat {}\r", 5), SHORT_WAIT);
send_cmd(&mut port, &format!("repeat {}\r", repeat), SHORT_WAIT);
// TODO: Allow for user configuration
send_cmd(&mut port, "calc aver16\r", SHORT_WAIT);
@ -302,13 +301,13 @@ pub fn parse_data(
for (i, slice) in chunks_exact.enumerate() {
let s: &[u8; 3] = &[slice[0], slice[1], slice[2]];
let d = DataPoint::unpack(s)?;
if d.c == b'}' {
if d.align == b'}' {
// Found an end and the rest is garbage
end = i * 3;
// TODO: why doesn't it pop ?
info!("Found an end at {end}");
break;
} else if d.c != b'x' {
} else if d.align != b'x' {
// The alignment char is wrong
error!("Wrong alignment char");
return Err(TinyError::ParseEnd("Wrong alignement char".to_owned()));

View File

@ -113,6 +113,8 @@ pub(crate) struct SavedConfig {
pub(crate) stop_frequency: usize,
/// The default number of points
pub(crate) points: usize,
/// The default number of repeat per point
pub(crate) repeat: usize,
}
impl SavedConfig {
/// Create a config from file or returns an error
@ -140,6 +142,7 @@ impl SavedConfig {
start_frequency: arg.start_frequency.int_to_usize(),
stop_frequency: arg.stop_frequency.int_to_usize(),
points: arg.points.int_to_usize(),
repeat: arg.repeat.int_to_usize(),
})
.unwrap()
.as_bytes(),

View File

@ -51,18 +51,20 @@ impl<'a> AppInfo<'a> {
/// Create a new app with the port info available
pub(crate) fn new(info: Vec<SerialPortInfo>) -> Self {
let loaded_conf = SavedConfig::new();
let (start_frequency, stop_frequency, points) = {
let (start_frequency, stop_frequency, points, repeat) = {
if let Ok(c) = &loaded_conf {
(
UIUsize::new(c.start_frequency, 10, 960),
UIUsize::new(c.stop_frequency, 10, 960),
UIUsize::new(c.points, 100, 1000000),
UIUsize::new(c.repeat, 1, 1000),
)
} else {
(
UIUsize::new(240, 10, 960),
UIUsize::new(960, 10, 960),
UIUsize::new(10000, 100, 1000000),
UIUsize::new(1, 1, 1000),
)
}
};
@ -81,7 +83,7 @@ impl<'a> AppInfo<'a> {
scan_message: Arc::new(Mutex::new(String::new())),
return_data: Arc::new(Mutex::new(Vec::new())),
connection_status: Arc::new(Mutex::new(ConnectionStatus::Uninitialised)),
repeat: UIUsize::new(1, 1, 1000),
repeat,
error: None,
scan_error: Arc::new(Mutex::new(None)),
}
@ -172,25 +174,41 @@ impl<'a> AppInfo<'a> {
Constraint::Length(1),
])
.areas(frame.area());
let [_, area_minf, area_maxf, area_points, _] = Layout::horizontal([
let [_, area_minf, area_maxf, area_points, repeat, _] = Layout::horizontal([
Constraint::Min(7),
Constraint::Percentage(30),
Constraint::Percentage(30),
Constraint::Percentage(30),
Constraint::Percentage(25),
Constraint::Percentage(25),
Constraint::Percentage(25),
Constraint::Percentage(25),
Constraint::Min(7),
])
.areas(main_area);
// TODO: Move this in the color update
let (mif_color, maf_color, poi_color) = match self.flow_state {
AppState::FinalConfig(SelectedFinalConfig::StartFreq) => {
(SELECTED_COLOR, UNSELECTED_COLOR, UNSELECTED_COLOR)
}
AppState::FinalConfig(SelectedFinalConfig::FinalFreq) => {
(UNSELECTED_COLOR, SELECTED_COLOR, UNSELECTED_COLOR)
}
AppState::FinalConfig(SelectedFinalConfig::Points) => {
(UNSELECTED_COLOR, UNSELECTED_COLOR, SELECTED_COLOR)
}
let (mif_color, maf_color, poi_color, rpt_color) = match self.flow_state {
AppState::FinalConfig(SelectedFinalConfig::StartFreq) => (
SELECTED_COLOR,
UNSELECTED_COLOR,
UNSELECTED_COLOR,
UNSELECTED_COLOR,
),
AppState::FinalConfig(SelectedFinalConfig::FinalFreq) => (
UNSELECTED_COLOR,
SELECTED_COLOR,
UNSELECTED_COLOR,
UNSELECTED_COLOR,
),
AppState::FinalConfig(SelectedFinalConfig::Points) => (
UNSELECTED_COLOR,
UNSELECTED_COLOR,
SELECTED_COLOR,
UNSELECTED_COLOR,
),
AppState::FinalConfig(SelectedFinalConfig::Repeat) => (
UNSELECTED_COLOR,
UNSELECTED_COLOR,
UNSELECTED_COLOR,
SELECTED_COLOR,
),
_ => unreachable!(),
};
@ -213,6 +231,12 @@ impl<'a> AppInfo<'a> {
.style(poi_color),
area_points,
);
frame.render_widget(
Paragraph::new(self.repeat.int_to_string())
.block(Block::bordered().title("Repeat"))
.style(rpt_color),
repeat,
);
self.update_color()?;
frame.render_widget(Paragraph::new(self.status_message.clone()), title_area);
@ -523,6 +547,7 @@ impl<'a> AppInfo<'a> {
SelectedFinalConfig::StartFreq => self.start_frequency.change_value(direction),
SelectedFinalConfig::FinalFreq => self.stop_frequency.change_value(direction),
SelectedFinalConfig::Points => self.points.change_value(direction),
SelectedFinalConfig::Repeat => self.repeat.change_value(direction),
},
AppState::EndWindow => (),
AppState::Finished => (),

View File

@ -178,6 +178,8 @@ pub(crate) enum SelectedFinalConfig {
FinalFreq,
/// Selects the number of points
Points,
/// Selects the repeat
Repeat,
// /// Selects <Ok> to proceed
// Proceed,
}