use core::convert::Infallible;
use atm90e32_async::{Atm90e32, Config, LineFreq, PgaGain};
struct DummySpi;
impl embedded_hal_async::spi::ErrorType for DummySpi {
type Error = Infallible;
}
impl embedded_hal_async::spi::SpiDevice for DummySpi {
async fn transaction(
&mut self,
_ops: &mut [embedded_hal_async::spi::Operation<'_, u8>],
) -> Result<(), Self::Error> {
Ok(())
}
}
struct DummyDelay;
impl embedded_hal_async::delay::DelayNs for DummyDelay {
async fn delay_ns(&mut self, _ns: u32) {}
}
async fn run() -> Result<(), atm90e32_async::Error<Infallible>> {
let mut meter = Atm90e32::new(DummySpi, DummyDelay);
let _ = meter.probe().await;
let cfg = Config::default()
.with_voltage_gain([39470, 39470, 39470])
.with_current_gain([65327, 65327, 65327])
.with_line_freq(LineFreq::Hz50)
.with_pga_gain(PgaGain::X2);
let _ = meter.init(&cfg).await;
Ok(())
}
fn main() {
use core::future::Future;
use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
fn noop(_: *const ()) {}
fn clone(_: *const ()) -> RawWaker {
RawWaker::new(core::ptr::null(), &VTABLE)
}
static VTABLE: RawWakerVTable = RawWakerVTable::new(clone, noop, noop, noop);
#[allow(unsafe_code)]
let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
let mut cx = Context::from_waker(&waker);
let mut fut = core::pin::pin!(run());
match fut.as_mut().poll(&mut cx) {
Poll::Ready(res) => {
let ok: bool = res.is_ok();
println!("example finished ok={}", ok);
}
Poll::Pending => unreachable!("dummy stubs never yield"),
}
}