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

core::fmt and ufmt support for writing to LCDs #59

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ColinTimBarndt
Copy link
Contributor

@ColinTimBarndt ColinTimBarndt commented Oct 3, 2024

This PR adds a new Writer struct that can be used to write formatted strings to the LCD. The writer is constrained to a rectangle, which also makes it usable for writing scrollable or multi-column text. It supports line breaks and inserts or promotes spaces to line breaks where needed. Closes #49.

I've added an Arduino example at examples/atmega328-nostd/src/bin/formatter-4bit.rs:

// Writing to the display using ufmt
{
	let mut writer = display.writer((0, 0), (5, 1), &mut delay).unwrap();
	const HELLO_TO: &str = "world";
	ufmt::uwrite!(writer, "Hello, {}!", HELLO_TO).unwrap();

	writer = display.writer((7, 0), (15, 1), &mut delay).unwrap();
	ufmt::uwrite!(writer, "max={}", core::u32::MAX).unwrap();
}

photo_2024-10-03_15-30-07

I can add examples for more MCUs later if needed, but it's the exact same code for everything.

Is this API okay?

@ColinTimBarndt ColinTimBarndt marked this pull request as draft October 3, 2024 13:32
@ColinTimBarndt
Copy link
Contributor Author

ColinTimBarndt commented Oct 3, 2024

I had to convert this to a draft because the code is already based on the change(s) of #58 (has rw pin specified, uses new names for traits). If that PR can be merged first, this would make things easier 😅. The disadvantage of opening multiple PRs at once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

impl core::format::Write to allow writing formatted strings
1 participant