Switched to using ufmt for formatting

This commit is contained in:
Sebastian 2022-08-24 17:45:38 +02:00
parent 275dea77e9
commit 4fb98ee9c5
4 changed files with 41 additions and 10 deletions

29
Cargo.lock generated
View file

@ -732,6 +732,7 @@ dependencies = [
"rustc_version 0.4.0",
"spin",
"stable_deref_trait",
"ufmt-write",
]
[[package]]
@ -1033,6 +1034,7 @@ dependencies = [
"nb 1.0.0",
"panic-probe",
"ssd1306",
"ufmt",
]
[[package]]
@ -1256,6 +1258,33 @@ dependencies = [
"syn",
]
[[package]]
name = "ufmt"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a64846ec02b57e9108d6469d98d1648782ad6bb150a95a9baac26900bbeab9d"
dependencies = [
"ufmt-macros",
"ufmt-write",
]
[[package]]
name = "ufmt-macros"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d337d3be617449165cb4633c8dece429afd83f84051024079f97ad32a9663716"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "ufmt-write"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69"
[[package]]
name = "unicode-ident"
version = "1.0.3"

View file

@ -21,8 +21,9 @@ cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7.0"
embedded-hal = "0.2.6"
futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
heapless = { version = "0.7.5", default-features = false }
heapless = { version = "0.7.5", default-features = false, features = ['ufmt-impl']}
nb = "1.0.0"
ufmt = "0.2.0"
ssd1306 = "0.7.1"
embedded-graphics = "0.7.1"

View file

@ -17,8 +17,8 @@ use embedded_graphics::{
text::Text,
};
use core::fmt::Write;
use heapless::String;
use ufmt::uwrite;
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
@ -61,13 +61,13 @@ pub async fn display_task(
.unwrap();
let mut tmp: String<16> = String::new();
write!(tmp, "AZ: {}", rotor_state.actual_pos.az).unwrap();
uwrite!(tmp, "AZ: {}", rotor_state.actual_pos.az).unwrap();
Text::new(&tmp, Point::new(1, 17), text_large)
.draw(&mut display)
.unwrap();
tmp.clear();
write!(tmp, "EL: {}", rotor_state.actual_pos.el).unwrap();
uwrite!(tmp, "EL: {}", rotor_state.actual_pos.el).unwrap();
Text::new(&tmp, Point::new(64, 17), text_large)
.draw(&mut display)
.unwrap();
@ -78,13 +78,13 @@ pub async fn display_task(
.unwrap();
tmp.clear();
write!(tmp, "AZ: {}", rotor_state.setpoint_pos.az).unwrap();
uwrite!(tmp, "AZ: {}", rotor_state.setpoint_pos.az).unwrap();
Text::new(&tmp, Point::new(1, 30), text_large_inv)
.draw(&mut display)
.unwrap();
tmp.clear();
write!(tmp, "EL: {}", rotor_state.setpoint_pos.el).unwrap();
uwrite!(tmp, "EL: {}", rotor_state.setpoint_pos.el).unwrap();
Text::new(&tmp, Point::new(64, 30), text_large_inv)
.draw(&mut display)
.unwrap();

View file

@ -1,6 +1,5 @@
use defmt::Format;
use core::fmt::Write;
use embassy_stm32::interrupt;
use embassy_stm32::peripherals;
use embassy_stm32::usb::Driver;
@ -11,7 +10,9 @@ use embassy_util::channel::mpmc::{Receiver, Sender};
use embassy_util::{select, Either};
use futures::future::join;
use heapless::String;
use ufmt::uwrite;
use crate::AzElPair;
@ -101,13 +102,13 @@ pub async fn usb_task(
let mut resp: String<16> = String::new();
match cmd {
Gs232Cmd::GetAl => {
write!(&mut resp, "AZ={}\r", current_pos.az).unwrap();
uwrite!(&mut resp, "AZ={}\r", current_pos.az).unwrap();
}
Gs232Cmd::GetEz => {
write!(&mut resp, "EL={}\r", current_pos.el).unwrap();
uwrite!(&mut resp, "EL={}\r", current_pos.el).unwrap();
}
Gs232Cmd::GetAlEz => {
write!(&mut resp, "AZ={} EL={}\r", current_pos.az, current_pos.el)
uwrite!(&mut resp, "AZ={} EL={}\r", current_pos.az, current_pos.el)
.unwrap();
}
Gs232Cmd::MoveTo(_) => {