Poll example
This commit is contained in:
@ -38,6 +38,7 @@ use physical_ads1256::standard::multiplexer::poll::{
|
|||||||
AutocalPoll, AutocalPollStatePub, ModInputOnly,
|
AutocalPoll, AutocalPollStatePub, ModInputOnly,
|
||||||
};
|
};
|
||||||
use physical_node::transducer::{Publish, Publisher, StatefulPublisher};
|
use physical_node::transducer::{Publish, Publisher, StatefulPublisher};
|
||||||
|
use physical_node::transducer::input::Poll;
|
||||||
|
|
||||||
const AUTOCAL_CONF: Config = Config {
|
const AUTOCAL_CONF: Config = Config {
|
||||||
status: Status::setting(Buffer::Enabled, AutoCal::Enabled, BitOrder::MostSigFirst),
|
status: Status::setting(Buffer::Enabled, AutoCal::Enabled, BitOrder::MostSigFirst),
|
||||||
@ -157,5 +158,28 @@ async fn main(spawner: Spawner) {
|
|||||||
state: Cell::new(f32::ElectricPotential::new::<volt>(f32::NAN)).into(),
|
state: Cell::new(f32::ElectricPotential::new::<volt>(f32::NAN)).into(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
spawner.spawn(log_task(&inputs.ai1, 1)).unwrap();
|
||||||
|
spawner.spawn(log_task(&inputs.ai2, 2)).unwrap();
|
||||||
|
spawner.spawn(log_task(&inputs.ai3, 3)).unwrap();
|
||||||
|
spawner.spawn(poll_task(&inputs.ai1, 1, Duration::from_secs(5))).unwrap();
|
||||||
|
spawner.spawn(poll_task(&inputs.ai2, 2, Duration::from_secs(10))).unwrap();
|
||||||
|
spawner.spawn(poll_task(&inputs.ai3, 3, Duration::from_secs(20))).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[embassy_executor::task(pool_size = 3)]
|
||||||
|
async fn poll_task(input: &'static ExampleInput, input_num: u8, every: Duration,) {
|
||||||
|
loop {
|
||||||
|
Timer::after(every).await;
|
||||||
|
let result = input.poll().await.unwrap().get::<volt>();
|
||||||
|
info!("ai{} poll result: {} volts", input_num, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[embassy_executor::task(pool_size = 3)]
|
||||||
|
async fn log_task(input: &'static ExampleInput, input_num: u8) {
|
||||||
|
let mut subscriber = input.subscribe().unwrap();
|
||||||
|
loop {
|
||||||
|
let msg = subscriber.next_message_pure().await.get::<volt>();
|
||||||
|
info!("Log task ai{}: {}", input_num, msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,8 @@ where
|
|||||||
async fn poll(&self) -> Result<Self::Value, CriticalError> {
|
async fn poll(&self) -> Result<Self::Value, CriticalError> {
|
||||||
let mut ads1256_guard = self.ads1256.lock().await;
|
let mut ads1256_guard = self.ads1256.lock().await;
|
||||||
let ads1256 = ads1256_guard.deref_mut();
|
let ads1256 = ads1256_guard.deref_mut();
|
||||||
ads1256.data_ready.wait_for_low().await;
|
//TODO: ADS1256 documentation seems to say we should be waiting for drdy low after putting
|
||||||
|
// issuing standby command but it never goes low.
|
||||||
|
|
||||||
let result = ads1256
|
let result = ads1256
|
||||||
.autocal_convert_m(
|
.autocal_convert_m(
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
///
|
///
|
||||||
/// In many systems there can be a single function for handling any critical error as a critical
|
/// In many systems there can be a single function for handling any critical error as a critical
|
||||||
/// error always means everything needs to be stopped.
|
/// error always means everything needs to be stopped.
|
||||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||||
pub enum CriticalError {
|
pub enum CriticalError {
|
||||||
/// Critical communication failed and retries are either impossible or also failed.
|
/// Critical communication failed and retries are either impossible or also failed.
|
||||||
Communication,
|
Communication,
|
||||||
|
Reference in New Issue
Block a user