Skip to content

Commit e65212c

Browse files
committed
Support active_low configuration
1 parent e105a41 commit e65212c

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## [master] - Unreleased
4+
5+
### Changed
6+
7+
- Add support for `active_low` configuration.
8+
39
## [0.5.1] - 2016-06-17
410

511
### Changed
@@ -148,7 +154,8 @@
148154
- Initial version of the library with basic functionality
149155
- Support for `export`/`unexport`/`get_value`/`set_value`/`set_direction`
150156

151-
[0.5.1]: https://github.com/posborne/rust-sysfs-gpio/compare/0.5.0...0.5.1`
157+
[master]: https://github.com/posborne/rust-sysfs-gpio/compare/0.5.1...master
158+
[0.5.1]: https://github.com/posborne/rust-sysfs-gpio/compare/0.5.0...0.5.1
152159
[0.5.0]: https://github.com/posborne/rust-sysfs-gpio/compare/0.4.4...0.5.0
153160
[0.4.4]: https://github.com/posborne/rust-sysfs-gpio/compare/0.4.3...0.4.4
154161
[0.4.3]: https://github.com/posborne/rust-sysfs-gpio/compare/0.4.2...0.4.3

src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,34 @@ impl Pin {
407407
Ok(())
408408
}
409409

410+
/// Get polarity of the Pin (`true` is active low)
411+
pub fn get_active_low(&self) -> Result<bool> {
412+
match self.read_from_device_file("active_low") {
413+
Ok(s) => {
414+
match s.trim() {
415+
"1" => Ok(true),
416+
"0" => Ok(false),
417+
other => Err(Error::Unexpected(format!("active_low file contents {}", other))),
418+
}
419+
}
420+
Err(e) => Err(::std::convert::From::from(e)),
421+
}
422+
}
423+
424+
/// Set the polarity of the Pin (`true` is active low)
425+
///
426+
/// This will affect "rising" and "falling" edge triggered
427+
/// configuration.
428+
pub fn set_active_low(&self, active_low: bool) -> Result<()> {
429+
self.write_to_device_file("active_low",
430+
match active_low {
431+
true => "1",
432+
false => "0",
433+
})?;
434+
435+
Ok(())
436+
}
437+
410438
/// Get a PinPoller object for this pin
411439
///
412440
/// This pin poller object will register an interrupt with the

0 commit comments

Comments
 (0)