26
26
//! use std::thread::sleep;
27
27
//! use std::time::Duration;
28
28
//!
29
- //! fn main() {
30
- //! let my_led = Pin::new(127); // number depends on chip, etc.
31
- //! my_led.with_exported(|| {
32
- //! my_led.set_direction(Direction::Out).unwrap();
33
- //! loop {
34
- //! my_led.set_value(0).unwrap();
35
- //! sleep(Duration::from_millis(200));
36
- //! my_led.set_value(1).unwrap();
37
- //! sleep(Duration::from_millis(200));
38
- //! }
39
- //! }).unwrap();
40
- //! }
29
+ //! let my_led = Pin::new(127); // number depends on chip, etc.
30
+ //! my_led.with_exported(|| {
31
+ //! my_led.set_direction(Direction::Out).unwrap();
32
+ //! loop {
33
+ //! my_led.set_value(0).unwrap();
34
+ //! sleep(Duration::from_millis(200));
35
+ //! my_led.set_value(1).unwrap();
36
+ //! sleep(Duration::from_millis(200));
37
+ //! }
38
+ //! }).unwrap();
41
39
//! ```
42
40
43
41
#![ cfg_attr( feature = "async-tokio" , allow( deprecated) ) ]
@@ -247,7 +245,7 @@ impl Pin {
247
245
/// This function will error out if the kernel does not support the GPIO
248
246
/// sysfs interface (i.e. `/sys/class/gpio` does not exist).
249
247
pub fn is_exported ( & self ) -> bool {
250
- fs:: metadata ( & format ! ( "/sys/class/gpio/gpio{}" , self . pin_num) ) . is_ok ( )
248
+ fs:: metadata ( format ! ( "/sys/class/gpio/gpio{}" , self . pin_num) ) . is_ok ( )
251
249
}
252
250
253
251
/// Export the GPIO
@@ -276,7 +274,7 @@ impl Pin {
276
274
/// }
277
275
/// ```
278
276
pub fn export ( & self ) -> Result < ( ) > {
279
- if fs:: metadata ( & format ! ( "/sys/class/gpio/gpio{}" , self . pin_num) ) . is_err ( ) {
277
+ if fs:: metadata ( format ! ( "/sys/class/gpio/gpio{}" , self . pin_num) ) . is_err ( ) {
280
278
let mut export_file = File :: create ( "/sys/class/gpio/export" ) ?;
281
279
export_file. write_all ( format ! ( "{}" , self . pin_num) . as_bytes ( ) ) ?;
282
280
}
@@ -290,7 +288,7 @@ impl Pin {
290
288
/// exported, it will return without error. That is, whenever
291
289
/// this function returns Ok, the GPIO is not exported.
292
290
pub fn unexport ( & self ) -> Result < ( ) > {
293
- if fs:: metadata ( & format ! ( "/sys/class/gpio/gpio{}" , self . pin_num) ) . is_ok ( ) {
291
+ if fs:: metadata ( format ! ( "/sys/class/gpio/gpio{}" , self . pin_num) ) . is_ok ( ) {
294
292
let mut unexport_file = File :: create ( "/sys/class/gpio/unexport" ) ?;
295
293
unexport_file. write_all ( format ! ( "{}" , self . pin_num) . as_bytes ( ) ) ?;
296
294
}
@@ -501,15 +499,15 @@ impl Pin {
501
499
502
500
#[ test]
503
501
fn extract_pin_fom_path_test ( ) {
504
- let tok1 = Pin :: extract_pin_from_path ( & "/sys/class/gpio/gpio951" ) ;
502
+ let tok1 = Pin :: extract_pin_from_path ( "/sys/class/gpio/gpio951" ) ;
505
503
assert_eq ! ( 951 , tok1. unwrap( ) ) ;
506
- let tok2 = Pin :: extract_pin_from_path ( & "/sys/CLASS/gpio/gpio951/" ) ;
504
+ let tok2 = Pin :: extract_pin_from_path ( "/sys/CLASS/gpio/gpio951/" ) ;
507
505
assert_eq ! ( 951 , tok2. unwrap( ) ) ;
508
- let tok3 = Pin :: extract_pin_from_path ( & "../../devices/soc0/gpiochip3/gpio/gpio124" ) ;
506
+ let tok3 = Pin :: extract_pin_from_path ( "../../devices/soc0/gpiochip3/gpio/gpio124" ) ;
509
507
assert_eq ! ( 124 , tok3. unwrap( ) ) ;
510
- let err1 = Pin :: extract_pin_from_path ( & "/sys/CLASS/gpio/gpio" ) ;
508
+ let err1 = Pin :: extract_pin_from_path ( "/sys/CLASS/gpio/gpio" ) ;
511
509
assert ! ( err1. is_err( ) ) ;
512
- let err2 = Pin :: extract_pin_from_path ( & "/sys/class/gpio/gpioSDS" ) ;
510
+ let err2 = Pin :: extract_pin_from_path ( "/sys/class/gpio/gpioSDS" ) ;
513
511
assert ! ( err2. is_err( ) ) ;
514
512
}
515
513
#[ cfg( not( target_os = "wasi" ) ) ]
@@ -532,7 +530,7 @@ impl PinPoller {
532
530
/// Create a new PinPoller for the provided pin number
533
531
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
534
532
pub fn new ( pin_num : u64 ) -> Result < PinPoller > {
535
- let devfile: File = File :: open ( & format ! ( "/sys/class/gpio/gpio{}/value" , pin_num) ) ?;
533
+ let devfile: File = File :: open ( format ! ( "/sys/class/gpio/gpio{}/value" , pin_num) ) ?;
536
534
let devfile_fd = devfile. as_raw_fd ( ) ;
537
535
let epoll_fd = epoll_create ( ) ?;
538
536
let mut event = EpollEvent :: new ( EpollFlags :: EPOLLPRI | EpollFlags :: EPOLLET , 0u64 ) ;
@@ -609,7 +607,7 @@ pub struct AsyncPinPoller {
609
607
#[ cfg( feature = "mio-evented" ) ]
610
608
impl AsyncPinPoller {
611
609
fn new ( pin_num : u64 ) -> Result < Self > {
612
- let devfile = File :: open ( & format ! ( "/sys/class/gpio/gpio{}/value" , pin_num) ) ?;
610
+ let devfile = File :: open ( format ! ( "/sys/class/gpio/gpio{}/value" , pin_num) ) ?;
613
611
Ok ( AsyncPinPoller { devfile } )
614
612
}
615
613
}
0 commit comments