File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -182,10 +182,17 @@ impl GpioConfig {
182
182
GpioConfig :: from_str ( & contents[ ..] )
183
183
}
184
184
185
+ /// Get the pin with the provided name if present in this configuration
186
+ pub fn get_pin ( & self , name : & str ) -> Option < & PinConfig > {
187
+ self . pins . iter ( ) . find ( |p| p. names . iter ( ) . any ( |n| n == name) )
188
+ }
189
+
190
+ /// Get a reference to all the pins in this config
185
191
pub fn get_pins ( & self ) -> & [ PinConfig ] {
186
192
& self . pins [ ..]
187
193
}
188
194
195
+ /// Get the symlink root specified in the config (or the default)
189
196
pub fn get_symlink_root ( & self ) -> & str {
190
197
match self . symlink_root {
191
198
Some ( ref root) => & root,
@@ -302,6 +309,19 @@ names = ["wildcard"]
302
309
assert_eq ! ( status_led. export, true ) ;
303
310
}
304
311
312
+ #[ test]
313
+ fn test_get_pin_present ( ) {
314
+ let config = GpioConfig :: from_str ( BASIC_CFG ) . unwrap ( ) ;
315
+ let status_led = config. get_pin ( "status_led" ) . unwrap ( ) ;
316
+ assert_eq ! ( status_led. num, 37 ) ;
317
+ }
318
+
319
+ #[ test]
320
+ fn test_get_pin_not_present ( ) {
321
+ let config = GpioConfig :: from_str ( BASIC_CFG ) . unwrap ( ) ;
322
+ assert_eq ! ( config. get_pin( "missing" ) , None ) ;
323
+ }
324
+
305
325
#[ test]
306
326
fn test_parser_compact ( ) {
307
327
let config = GpioConfig :: from_str ( COMPACT_CFG ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments