Included running flag in struct.

This commit is contained in:
2025-08-18 17:28:16 +02:00
parent d17ef6c7ae
commit 044cfb069a
3 changed files with 10 additions and 7 deletions

View File

@@ -159,14 +159,14 @@ pub async fn set_green_led_handler(_context: &mut Context, _header: VarHeader, r
LED_FREQUENCY_SIGNAL.signal(rqst);
}
static RUNNING: Mutex<ThreadModeRawMutex, bool> = Mutex::new(false);
static STOP: Mutex<ThreadModeRawMutex, bool> = Mutex::new(false);
#[embassy_executor::task]
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);
*RUNNING.lock().await = true;
// Mark the impedance setup as running
context.impedance_setup.lock().await.running = true;
// Init the sequencer
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);
}
*RUNNING.lock().await = false;
context.impedance_setup.lock().await.running = false;
info!("Impedance measurement stopped.");
*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");
let was_busy = *RUNNING.lock().await;
let was_busy = context.impedance_setup.lock().await.running;
if was_busy {
*STOP.lock().await = true;
}

View File

@@ -20,11 +20,12 @@ pub static IMPEDANCE_SETUP: StaticCell<ImpedanceSetupType> = StaticCell::new();
pub struct ImpedanceSetup {
ad5940: AD5940,
dsp_config: Option<DspConfig>,
pub running: bool,
}
impl ImpedanceSetup {
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> {

View File

@@ -181,7 +181,9 @@ async fn impedance_setup_readout_task(mut pin: ExtiInput<'static>, impedance_set
let mut impedance_setup = impedance_setup.lock().await;
// Trigger the sequencer again
if impedance_setup.running {
impedance_setup.start_measurement().await;
}
// Read the FIFO count
let count = impedance_setup.get_fifo_count().await.unwrap();