From c8eb002e339bb6ba265a574b35f253f651578b4c Mon Sep 17 00:00:00 2001 From: ripytide Date: Mon, 11 Dec 2023 11:41:47 +0000 Subject: [PATCH] add the `Tb6612fng::current_standby()` method --- CHANGELOG.md | 3 +++ src/lib.rs | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e71a91..24f6097 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [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 diff --git a/src/lib.rs b/src/lib.rs index da2db27..6b0d781 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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()`]. @@ -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 + where + STBY: StatefulOutputPin, + { + self.standby.is_set_high() + } } /// Represents a single motor (either motor A or motor B) hooked up to a TB6612FNG controller.