From a979cac843afbb87d63484168d66116b1e97ea94 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 22 May 2023 02:30:58 +0800 Subject: [PATCH] add is_plugged_in() convenience function for LLIO --- services/llio/src/llio_lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/llio/src/llio_lib.rs b/services/llio/src/llio_lib.rs index 4ee23b651..7e5324d06 100644 --- a/services/llio/src/llio_lib.rs +++ b/services/llio/src/llio_lib.rs @@ -46,6 +46,11 @@ impl Llio { ).map(|_| ()) } + pub fn is_plugged_in(&self) -> bool { + // 0.005033 * 100_000 against 1.50V * 100_000 + ((self.adc_vbus().unwrap() as u32) * 503) > 150_000 + } + pub fn adc_vbus(&self) -> Result { let response = send_message(self.conn, Message::new_blocking_scalar(Opcode::AdcVbus.to_usize().unwrap(), 0, 0, 0, 0))?;