Skip to content

Commit 182d51b

Browse files
authored
Merge pull request #4 from kofron/kofron-check-enabled-state
Check state of enable
2 parents 3874def + 80ea35e commit 182d51b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sysfs-pwm"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["Paul Osborne <osbpau@gmail.com>"]
55
license = "MIT/Apache-2.0"
66
homepage = "https://github.com/posborne/rust-sysfs-pwm"

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ impl Pwm {
146146
Ok(())
147147
}
148148

149+
/// Query the state of enable for a given PWM pin
150+
pub fn get_enabled(&self) -> Result<bool> {
151+
pwm_file_parse::<u32>(&self.chip, self.number, "enable").map(|enable_state| {
152+
match enable_state {
153+
1 => true,
154+
0 => false,
155+
_ => panic!("enable != 1|0 should be unreachable")
156+
}
157+
})
158+
}
159+
149160
/// Get the currently configured duty_cycle in nanoseconds
150161
pub fn get_duty_cycle_ns(&self) -> Result<u32> {
151162
pwm_file_parse::<u32>(&self.chip, self.number, "duty_cycle")

0 commit comments

Comments
 (0)