Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a current_standby() method when the pin implements StatefulOututPin #26

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- next-header -->
## [Unreleased] - ReleaseDate
### Added
* Add a `current_standby()` method to check if the driver is currently in standby mode.

### Changed

* `Motor::new()` and `Driver::new()` methods now set the outputs upon their
Expand Down
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#[cfg(feature = "defmt")]
use defmt::Format;
use embedded_hal::digital::OutputPin;
use embedded_hal::digital::{OutputPin, StatefulOutputPin};
use embedded_hal::pwm::SetDutyCycle;

/// Defines errors which can happen when calling [`Motor::drive()`].
Expand Down Expand Up @@ -197,6 +197,16 @@ where
pub fn disable_standby(&mut self) -> Result<(), STBY::Error> {
self.standby.set_high()
}

/// Returns whether the standby mode is enabled.
///
/// *NOTE* this does *not* read the electrical state of the pin, see [`StatefulOutputPin`]
pub fn current_standby(&mut self) -> Result<bool, STBY::Error>
where
STBY: StatefulOutputPin,
{
self.standby.is_set_high()
}
}

/// Represents a single motor (either motor A or motor B) hooked up to a TB6612FNG controller.
Expand Down