mirror of
https://github.com/hubaldv/bioz-firmware-rs.git
synced 2025-12-06 05:01:18 +00:00
Included running flag in struct.
This commit is contained in:
@@ -159,14 +159,14 @@ pub async fn set_green_led_handler(_context: &mut Context, _header: VarHeader, r
|
|||||||
LED_FREQUENCY_SIGNAL.signal(rqst);
|
LED_FREQUENCY_SIGNAL.signal(rqst);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RUNNING: Mutex<ThreadModeRawMutex, bool> = Mutex::new(false);
|
|
||||||
static STOP: Mutex<ThreadModeRawMutex, bool> = Mutex::new(false);
|
static STOP: Mutex<ThreadModeRawMutex, bool> = Mutex::new(false);
|
||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
pub async fn start_single_impedance_handler(context: SpawnCtx, header: VarHeader, rqst: StartImpedance, sender: Sender<AppTx>) {
|
pub async fn start_single_impedance_handler(context: SpawnCtx, header: VarHeader, rqst: StartImpedance, sender: Sender<AppTx>) {
|
||||||
info!("Start impedance measurement at {:?} Hz.", rqst.sinus_frequency);
|
info!("Start impedance measurement at {:?} Hz.", rqst.sinus_frequency);
|
||||||
|
|
||||||
*RUNNING.lock().await = true;
|
// Mark the impedance setup as running
|
||||||
|
context.impedance_setup.lock().await.running = true;
|
||||||
|
|
||||||
// Init the sequencer
|
// Init the sequencer
|
||||||
context.impedance_setup.lock().await.init_single_frequency_measurement(rqst.sinus_frequency).await;
|
context.impedance_setup.lock().await.init_single_frequency_measurement(rqst.sinus_frequency).await;
|
||||||
@@ -198,14 +198,14 @@ pub async fn start_single_impedance_handler(context: SpawnCtx, header: VarHeader
|
|||||||
seq = seq.wrapping_add(1);
|
seq = seq.wrapping_add(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
*RUNNING.lock().await = false;
|
context.impedance_setup.lock().await.running = false;
|
||||||
info!("Impedance measurement stopped.");
|
info!("Impedance measurement stopped.");
|
||||||
*STOP.lock().await = false;
|
*STOP.lock().await = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn stop_single_impedance_handler(_context: &mut Context, _header: VarHeader, _rqst: ()) -> bool {
|
pub async fn stop_single_impedance_handler(context: &mut Context, _header: VarHeader, _rqst: ()) -> bool {
|
||||||
info!("Stop impedance measurement");
|
info!("Stop impedance measurement");
|
||||||
let was_busy = *RUNNING.lock().await;
|
let was_busy = context.impedance_setup.lock().await.running;
|
||||||
if was_busy {
|
if was_busy {
|
||||||
*STOP.lock().await = true;
|
*STOP.lock().await = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,12 @@ pub static IMPEDANCE_SETUP: StaticCell<ImpedanceSetupType> = StaticCell::new();
|
|||||||
pub struct ImpedanceSetup {
|
pub struct ImpedanceSetup {
|
||||||
ad5940: AD5940,
|
ad5940: AD5940,
|
||||||
dsp_config: Option<DspConfig>,
|
dsp_config: Option<DspConfig>,
|
||||||
|
pub running: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ImpedanceSetup {
|
impl ImpedanceSetup {
|
||||||
pub fn new(ad5940: AD5940) -> Self {
|
pub fn new(ad5940: AD5940) -> Self {
|
||||||
ImpedanceSetup { ad5940, dsp_config: None }
|
ImpedanceSetup { ad5940, dsp_config: None, running: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn init(&mut self) -> Result<(), Error> {
|
pub async fn init(&mut self) -> Result<(), Error> {
|
||||||
|
|||||||
@@ -181,7 +181,9 @@ async fn impedance_setup_readout_task(mut pin: ExtiInput<'static>, impedance_set
|
|||||||
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 {
|
||||||
impedance_setup.start_measurement().await;
|
impedance_setup.start_measurement().await;
|
||||||
|
}
|
||||||
|
|
||||||
// Read the FIFO count
|
// Read the FIFO count
|
||||||
let count = impedance_setup.get_fifo_count().await.unwrap();
|
let count = impedance_setup.get_fifo_count().await.unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user