mirror of
https://github.com/hubaldv/bioz-firmware-rs.git
synced 2026-07-24 00:57:43 +00:00
Changed SweepPoints names, included KTO frequency set. Use matches! macro.
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -292,7 +292,7 @@ pub async fn start_sweep_impedance_handler(context: SpawnCtx, header: VarHeader,
|
|||||||
|
|
||||||
// Init the sequencer
|
// Init the sequencer
|
||||||
let response = match (rqst.lead_mode, rqst.points) {
|
let response = match (rqst.lead_mode, rqst.points) {
|
||||||
(BioImpedanceLeadMode::TwoLead, SweepPoints::Eight) => {
|
(BioImpedanceLeadMode::TwoLead, SweepPoints::Partial) => {
|
||||||
context.impedance_setup.lock().await.running_mode = RunningMode::SweepFrequency2Lead(rqst.points);
|
context.impedance_setup.lock().await.running_mode = RunningMode::SweepFrequency2Lead(rqst.points);
|
||||||
const SIZE: usize = 8;
|
const SIZE: usize = 8;
|
||||||
context
|
context
|
||||||
@@ -307,7 +307,7 @@ pub async fn start_sweep_impedance_handler(context: SpawnCtx, header: VarHeader,
|
|||||||
periods_per_dft_18: Vec::new(),
|
periods_per_dft_18: Vec::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
(BioImpedanceLeadMode::TwoLead, SweepPoints::Eighteen) => {
|
(BioImpedanceLeadMode::TwoLead, SweepPoints::Full | SweepPoints::KTO) => {
|
||||||
context.impedance_setup.lock().await.running_mode = RunningMode::SweepFrequency2Lead(rqst.points);
|
context.impedance_setup.lock().await.running_mode = RunningMode::SweepFrequency2Lead(rqst.points);
|
||||||
const SIZE: usize = 18;
|
const SIZE: usize = 18;
|
||||||
context
|
context
|
||||||
@@ -322,7 +322,7 @@ pub async fn start_sweep_impedance_handler(context: SpawnCtx, header: VarHeader,
|
|||||||
periods_per_dft_18: periods,
|
periods_per_dft_18: periods,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
(BioImpedanceLeadMode::FourLead, SweepPoints::Eight) => {
|
(BioImpedanceLeadMode::FourLead, SweepPoints::Partial) => {
|
||||||
info!("Start impedance spectroscopy 4-lead with 8 points");
|
info!("Start impedance spectroscopy 4-lead with 8 points");
|
||||||
context.impedance_setup.lock().await.running_mode = RunningMode::SweepFrequency4Lead(rqst.points);
|
context.impedance_setup.lock().await.running_mode = RunningMode::SweepFrequency4Lead(rqst.points);
|
||||||
const SIZE: usize = 8;
|
const SIZE: usize = 8;
|
||||||
@@ -338,7 +338,7 @@ pub async fn start_sweep_impedance_handler(context: SpawnCtx, header: VarHeader,
|
|||||||
periods_per_dft_18: Vec::new(),
|
periods_per_dft_18: Vec::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
(BioImpedanceLeadMode::FourLead, SweepPoints::Eighteen) => {
|
(BioImpedanceLeadMode::FourLead, SweepPoints::Full | SweepPoints::KTO) => {
|
||||||
info!("Start impedance spectroscopy 4-lead with 18 points");
|
info!("Start impedance spectroscopy 4-lead with 18 points");
|
||||||
context.impedance_setup.lock().await.running_mode = RunningMode::SweepFrequency4Lead(rqst.points);
|
context.impedance_setup.lock().await.running_mode = RunningMode::SweepFrequency4Lead(rqst.points);
|
||||||
const SIZE: usize = 18;
|
const SIZE: usize = 18;
|
||||||
@@ -400,8 +400,17 @@ pub async fn start_sweep_impedance_handler(context: SpawnCtx, header: VarHeader,
|
|||||||
pub async fn stop_impedance_handler(context: &mut Context, _header: VarHeader, _rqst: ()) -> bool {
|
pub async fn stop_impedance_handler(context: &mut Context, _header: VarHeader, _rqst: ()) -> bool {
|
||||||
info!("Stop impedance measurement");
|
info!("Stop impedance measurement");
|
||||||
let was_busy = context.impedance_setup.lock().await.running_mode;
|
let was_busy = context.impedance_setup.lock().await.running_mode;
|
||||||
if was_busy == RunningMode::SingleFrequency2Lead || was_busy == RunningMode::SingleFrequency4Lead || was_busy == RunningMode::SweepFrequency2Lead(SweepPoints::Eight) || was_busy == RunningMode::SweepFrequency2Lead(SweepPoints::Eighteen) || was_busy == RunningMode::SweepFrequency4Lead(SweepPoints::Eight) || was_busy == RunningMode::SweepFrequency4Lead(SweepPoints::Eighteen) {
|
|
||||||
|
let is_impedance_running = matches!(
|
||||||
|
was_busy,
|
||||||
|
RunningMode::SingleFrequency2Lead |
|
||||||
|
RunningMode::SingleFrequency4Lead |
|
||||||
|
RunningMode::SweepFrequency2Lead(_) |
|
||||||
|
RunningMode::SweepFrequency4Lead(_)
|
||||||
|
);
|
||||||
|
|
||||||
|
if is_impedance_running {
|
||||||
STOP.signal(());
|
STOP.signal(());
|
||||||
}
|
}
|
||||||
was_busy == RunningMode::SingleFrequency2Lead || was_busy == RunningMode::SingleFrequency4Lead || was_busy == RunningMode::SweepFrequency2Lead(SweepPoints::Eight) || was_busy == RunningMode::SweepFrequency2Lead(SweepPoints::Eighteen) || was_busy == RunningMode::SweepFrequency4Lead(SweepPoints::Eight) || was_busy == RunningMode::SweepFrequency4Lead(SweepPoints::Eighteen)
|
is_impedance_running
|
||||||
}
|
}
|
||||||
@@ -609,11 +609,11 @@ impl ImpedanceSetup {
|
|||||||
|
|
||||||
// Calibrate Rtia
|
// Calibrate Rtia
|
||||||
match number_of_points {
|
match number_of_points {
|
||||||
SweepPoints::Eight => {
|
SweepPoints::Partial => {
|
||||||
let results = self.calibrate_rtia_multiple::<8>(number_of_points).await.unwrap();
|
let results = self.calibrate_rtia_multiple::<8>(number_of_points).await.unwrap();
|
||||||
self.rtia_calibrated = RtiaCalibrated::Vec8(results);
|
self.rtia_calibrated = RtiaCalibrated::Vec8(results);
|
||||||
},
|
},
|
||||||
SweepPoints::Eighteen => {
|
SweepPoints::Full | SweepPoints::KTO => {
|
||||||
let results = self.calibrate_rtia_multiple::<18>(number_of_points).await.unwrap();
|
let results = self.calibrate_rtia_multiple::<18>(number_of_points).await.unwrap();
|
||||||
self.rtia_calibrated = RtiaCalibrated::Vec18(results);
|
self.rtia_calibrated = RtiaCalibrated::Vec18(results);
|
||||||
},
|
},
|
||||||
@@ -772,7 +772,14 @@ pub async fn impedance_setup_readout_task(mut pin: ExtiInput<'static>, impedance
|
|||||||
let mut impedance_setup = impedance_setup.lock().await;
|
let mut impedance_setup = impedance_setup.lock().await;
|
||||||
|
|
||||||
// Trigger the sequencer again
|
// Trigger the sequencer again
|
||||||
if impedance_setup.running_mode == RunningMode::SingleFrequency2Lead || impedance_setup.running_mode == RunningMode::SingleFrequency4Lead || impedance_setup.running_mode == RunningMode::SweepFrequency2Lead(SweepPoints::Eight) || impedance_setup.running_mode == RunningMode::SweepFrequency2Lead(SweepPoints::Eighteen) || impedance_setup.running_mode == RunningMode::SweepFrequency4Lead(SweepPoints::Eight) || impedance_setup.running_mode == RunningMode::SweepFrequency4Lead(SweepPoints::Eighteen) {
|
let is_impedance_running = matches! {
|
||||||
|
impedance_setup.running_mode,
|
||||||
|
RunningMode::SingleFrequency2Lead |
|
||||||
|
RunningMode::SingleFrequency4Lead |
|
||||||
|
RunningMode::SweepFrequency2Lead(_) |
|
||||||
|
RunningMode::SweepFrequency4Lead(_)
|
||||||
|
};
|
||||||
|
if is_impedance_running {
|
||||||
impedance_setup.start_measurement().await;
|
impedance_setup.start_measurement().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -850,11 +857,11 @@ pub async fn impedance_setup_readout_task(mut pin: ExtiInput<'static>, impedance
|
|||||||
let result = calculate_impedance_2_lead(chunk.try_into().unwrap());
|
let result = calculate_impedance_2_lead(chunk.try_into().unwrap());
|
||||||
|
|
||||||
match points {
|
match points {
|
||||||
SweepPoints::Eight => {
|
SweepPoints::Partial => {
|
||||||
impedance_output.magnitudes_8.push(result.magnitude).ok();
|
impedance_output.magnitudes_8.push(result.magnitude).ok();
|
||||||
impedance_output.phases_8.push(result.phase).ok();
|
impedance_output.phases_8.push(result.phase).ok();
|
||||||
}
|
}
|
||||||
SweepPoints::Eighteen => {
|
SweepPoints::Full | SweepPoints::KTO => {
|
||||||
impedance_output.magnitudes_18.push(result.magnitude).ok();
|
impedance_output.magnitudes_18.push(result.magnitude).ok();
|
||||||
impedance_output.phases_18.push(result.phase).ok();
|
impedance_output.phases_18.push(result.phase).ok();
|
||||||
}
|
}
|
||||||
@@ -885,7 +892,7 @@ pub async fn impedance_setup_readout_task(mut pin: ExtiInput<'static>, impedance
|
|||||||
};
|
};
|
||||||
|
|
||||||
match (&points, &impedance_setup.rtia_calibrated) {
|
match (&points, &impedance_setup.rtia_calibrated) {
|
||||||
(SweepPoints::Eight, RtiaCalibrated::Vec8(cal_vec)) => {
|
(SweepPoints::Partial, RtiaCalibrated::Vec8(cal_vec)) => {
|
||||||
// Take 4 samples per frequency point
|
// Take 4 samples per frequency point
|
||||||
for (i, chunk) in data_slice.chunks(4).enumerate() {
|
for (i, chunk) in data_slice.chunks(4).enumerate() {
|
||||||
let cal = &cal_vec[i];
|
let cal = &cal_vec[i];
|
||||||
@@ -895,7 +902,7 @@ pub async fn impedance_setup_readout_task(mut pin: ExtiInput<'static>, impedance
|
|||||||
impedance_output.phases_8.push(result.phase).ok();
|
impedance_output.phases_8.push(result.phase).ok();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(SweepPoints::Eighteen, RtiaCalibrated::Vec18(cal_vec)) => {
|
(SweepPoints::Full | SweepPoints::KTO, RtiaCalibrated::Vec18(cal_vec)) => {
|
||||||
// Take 4 samples per frequency point
|
// Take 4 samples per frequency point
|
||||||
for (i, chunk) in data_slice.chunks(4).enumerate() {
|
for (i, chunk) in data_slice.chunks(4).enumerate() {
|
||||||
let cal = &cal_vec[i];
|
let cal = &cal_vec[i];
|
||||||
|
|||||||
Reference in New Issue
Block a user