From c066105510d76e4820536cab8b639425a84d47cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Thu, 28 Nov 2024 06:36:29 -0300 Subject: [PATCH] leak: Move to use new gpio_cdev over sysfs_gpio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- src/leak.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/leak.rs b/src/leak.rs index 1969f3f1c..f589ca00c 100644 --- a/src/leak.rs +++ b/src/leak.rs @@ -1,11 +1,11 @@ use std::{error::Error, thread::sleep, time::Duration}; -use linux_embedded_hal::sysfs_gpio::{Direction, Pin}; +use linux_embedded_hal::gpio_cdev::{Chip, LineHandle, LineRequestFlags}; use crate::peripherals::{AnyHardware, LeakSensor, PeripheralClass, PeripheralInfo, Peripherals}; pub struct LeakDetector { - pin: Pin, + pin: LineHandle, info: PeripheralInfo, } @@ -26,7 +26,7 @@ impl AnyHardware for LeakDetector { } pub struct LeakBuilder { - pin_number: u64, + pin_number: u32, info: PeripheralInfo, } @@ -46,7 +46,7 @@ impl LeakBuilder { /// # Arguments /// /// * `pin_number` - The GPIO pin number. - pub fn with_pin(mut self, pin_number: u64) -> Self { + pub fn with_pin(mut self, pin_number: u32) -> Self { self.pin_number = pin_number; self } @@ -57,10 +57,17 @@ impl LeakBuilder { } pub fn build(self) -> Result> { - let pin = Pin::new(self.pin_number); - pin.export()?; - sleep(Duration::from_millis(30)); - pin.set_direction(Direction::In)?; + let pin = { + let mut chip = Chip::new("/dev/gpiochip4")?; + let pin = chip + .get_line(self.pin_number) + .unwrap() + .request(LineRequestFlags::INPUT, 1, &format!("pin-leak")) + .expect("Failed to configure LEAK pin"); + sleep(Duration::from_millis(30)); + pin + }; + Ok(LeakDetector { pin, info: self.info,