mirror of
https://github.com/hubaldv/bioz-firmware-rs.git
synced 2025-12-06 05:01:18 +00:00
Created basic sinus output via postcard rpc.
This commit is contained in:
@@ -163,7 +163,7 @@ static STOP: Mutex<ThreadModeRawMutex, bool> = Mutex::new(false);
|
|||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
pub async fn start_impedance_handler(context: SpawnCtx, header: VarHeader, rqst: StartImpedance, sender: Sender<AppTx>) {
|
pub async fn start_impedance_handler(context: SpawnCtx, header: VarHeader, rqst: StartImpedance, sender: Sender<AppTx>) {
|
||||||
info!("Start impedance measurement with interval {:?} ms.", rqst.interval_ms);
|
info!("Start impedance measurement with rate {:?} Hz.", rqst.update_frequency);
|
||||||
|
|
||||||
let mut impedance = context.impedance.lock().await;
|
let mut impedance = context.impedance.lock().await;
|
||||||
|
|
||||||
@@ -176,12 +176,12 @@ pub async fn start_impedance_handler(context: SpawnCtx, header: VarHeader, rqst:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut ticker = Ticker::every(Duration::from_millis(rqst.interval_ms.into()));
|
let mut ticker = Ticker::every(Duration::from_hz(rqst.update_frequency.into()));
|
||||||
let mut seq: u8 = 0;
|
let mut seq: u8 = 0;
|
||||||
while !*STOP.lock().await {
|
while !*STOP.lock().await {
|
||||||
ticker.next().await;
|
ticker.next().await;
|
||||||
|
|
||||||
impedance.update();
|
impedance.update(rqst.sinus_frequency);
|
||||||
|
|
||||||
let msg = Impedance {
|
let msg = Impedance {
|
||||||
magnitude: impedance.magnitude,
|
magnitude: impedance.magnitude,
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ impl ImpedanceTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self) {
|
pub fn update(&mut self, frequency: f32) {
|
||||||
let frequency = 1.0; // Hz, adjust as needed
|
// let frequency = 1.0; // Hz, adjust as needed
|
||||||
|
|
||||||
let current_time = self.time.elapsed().as_millis() as f32 / 1000.0; // Convert to seconds
|
let current_time = self.time.elapsed().as_millis() as f32 / 1000.0; // Convert to seconds
|
||||||
self.magnitude = cosf(2.0 * PI * frequency * current_time);
|
self.magnitude = cosf(2.0 * PI * frequency * current_time);
|
||||||
|
|||||||
Reference in New Issue
Block a user