Implemented basic protocol parsing
This commit is contained in:
parent
7a4e4a89cb
commit
a7ae3731a4
3 changed files with 244 additions and 126 deletions
80
src/display.rs
Normal file
80
src/display.rs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
use core::fmt::Write;
|
||||
|
||||
use embassy_stm32::i2c;
|
||||
use embassy_stm32::peripherals;
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_time::{Duration, Timer};
|
||||
|
||||
use embedded_graphics::{
|
||||
mono_font::MonoTextStyle,
|
||||
pixelcolor::BinaryColor,
|
||||
prelude::*,
|
||||
primitives::{PrimitiveStyleBuilder, Rectangle},
|
||||
text::Text,
|
||||
};
|
||||
use profont::{PROFONT_12_POINT, PROFONT_7_POINT};
|
||||
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
|
||||
|
||||
use arrayvec::ArrayString;
|
||||
|
||||
#[embassy_executor::task]
|
||||
pub async fn display_task(i2c1: peripherals::I2C1, sda: peripherals::PB6, scl: peripherals::PB7) {
|
||||
let i2c = i2c::I2c::new(i2c1, sda, scl, Hertz::hz(100_000), i2c::Config::default());
|
||||
|
||||
let interface = I2CDisplayInterface::new(i2c);
|
||||
|
||||
let mut display = Ssd1306::new(interface, DisplaySize128x32, DisplayRotation::Rotate0)
|
||||
.into_buffered_graphics_mode();
|
||||
display.init().unwrap();
|
||||
|
||||
let text_large = MonoTextStyle::new(&PROFONT_12_POINT, BinaryColor::On);
|
||||
let text_large_inv = MonoTextStyle::new(&PROFONT_12_POINT, BinaryColor::Off);
|
||||
let text_small = MonoTextStyle::new(&PROFONT_7_POINT, BinaryColor::On);
|
||||
|
||||
let style_filled = PrimitiveStyleBuilder::new()
|
||||
.fill_color(BinaryColor::On)
|
||||
.build();
|
||||
|
||||
loop {
|
||||
display.clear();
|
||||
|
||||
Text::new("AFG rotor ctrl v0.1.0", Point::new(0, 6), text_small)
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
|
||||
Text::new("AZ: 23", Point::new(1, 17), text_large)
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
|
||||
Text::new("EL: 42", Point::new(64, 17), text_large)
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
|
||||
Rectangle::new(Point::new(0, 19), Size::new(128, 23))
|
||||
.into_styled(style_filled)
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
|
||||
Text::new("AZ: 23", Point::new(1, 30), text_large_inv)
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
|
||||
Text::new("EL: 42", Point::new(64, 30), text_large_inv)
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
|
||||
/*
|
||||
let now = Instant::now().as_millis();
|
||||
|
||||
|
||||
let mut buf = ArrayString::<20>::new();
|
||||
write!(&mut buf, "{}", now).expect("Can't write");
|
||||
Text::new(&buf, Point::new(0, 20), text_large)
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
*/
|
||||
display.flush().unwrap();
|
||||
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue