From abfa21ff018d7840ec149696bef53028e71fe4df Mon Sep 17 00:00:00 2001 From: Zachary Sunforge Date: Sun, 25 Jun 2023 17:33:03 -0700 Subject: [PATCH] Poll example --- examples/ads1256/src/bin/poll.rs | 26 ++++++++++++++++++- .../src/standard/multiplexer/sync/poll.rs | 3 ++- src/error.rs | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/examples/ads1256/src/bin/poll.rs b/examples/ads1256/src/bin/poll.rs index 6e5e225..917629d 100644 --- a/examples/ads1256/src/bin/poll.rs +++ b/examples/ads1256/src/bin/poll.rs @@ -38,6 +38,7 @@ use physical_ads1256::standard::multiplexer::poll::{ AutocalPoll, AutocalPollStatePub, ModInputOnly, }; use physical_node::transducer::{Publish, Publisher, StatefulPublisher}; +use physical_node::transducer::input::Poll; const AUTOCAL_CONF: Config = Config { status: Status::setting(Buffer::Enabled, AutoCal::Enabled, BitOrder::MostSigFirst), @@ -157,5 +158,28 @@ async fn main(spawner: Spawner) { state: Cell::new(f32::ElectricPotential::new::(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::(); + 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::(); + info!("Log task ai{}: {}", input_num, msg); + } } diff --git a/peripheral-components/ads1256/node/src/standard/multiplexer/sync/poll.rs b/peripheral-components/ads1256/node/src/standard/multiplexer/sync/poll.rs index 1038272..d5f0f1a 100644 --- a/peripheral-components/ads1256/node/src/standard/multiplexer/sync/poll.rs +++ b/peripheral-components/ads1256/node/src/standard/multiplexer/sync/poll.rs @@ -64,7 +64,8 @@ where async fn poll(&self) -> Result { let mut ads1256_guard = self.ads1256.lock().await; 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 .autocal_convert_m( diff --git a/src/error.rs b/src/error.rs index 99b3012..ca1d807 100644 --- a/src/error.rs +++ b/src/error.rs @@ -5,7 +5,7 @@ /// /// 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. -#[derive(Copy, Clone, Eq, PartialEq)] +#[derive(Copy, Clone, Eq, PartialEq, Debug)] pub enum CriticalError { /// Critical communication failed and retries are either impossible or also failed. Communication,