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

Made mappings default feature and added move_ascii_str function #25

Merged
merged 2 commits into from
Sep 21, 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
2 changes: 1 addition & 1 deletion tm1637/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["tm1637", "embedded-hal", "no-std", "embedded"]
readme = "../README.md"

[features]
default = ["async", "impl-debug"]
default = ["async", "impl-debug", "mappings"]
async = ["dep:embedded-hal", "dep:embedded-hal-async"]
blocking = ["dep:embedded-hal"]
mappings = []
Expand Down
37 changes: 37 additions & 0 deletions tm1637/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,43 @@ pub mod module {

Ok(())
}

/// Convert an `ASCII` string to a byte array using [`from_ascii_byte`](crate::mappings::from_ascii_byte) and move the segments across the display using [`TM1637::move_segments_raw`].
///
/// - `N` is the size of the internal window used to move the segments. See [`TM1637::move_segments_raw`] for more information.
/// - `M` is the maximum number of bytes that can be converted from the `ASCII` string.
///
/// # Example
///
/// Move the string `"HELLO "` across a `4-digit display`:
///
/// ```rust, ignore
/// let mut tm = TM1637::builder(clk_pin, dio_pin, delay)
/// .brightness(Brightness::L3)
/// .build();
///
/// tm.init().ok();
///
/// tm.move_ascii_str::<4, 6>(0, "HELLO ", 500).ok();
/// ```
#[cfg(feature = "mappings")]
pub async fn move_ascii_str<const N: usize, const M: usize>(
&mut self,
position: u8,
ascii_str: &str,
delay_ms: u32,
) -> Result<(), ERR> {
let mut bytes = [0u8; M];
ascii_str
.as_bytes()
.iter()
.take(M)
.enumerate()
.for_each(|(i, &byte)| bytes[i] = crate::mappings::from_ascii_byte(byte));

self.move_segments_raw::<N>(position, &bytes, delay_ms)
.await
}
}
}

Expand Down
Loading