use embassy_stm32::i2c; use embassy_stm32::peripherals; use embassy_stm32::time::Hertz; use embassy_time::{Duration, Timer}; use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; use embassy_util::channel::mpmc::Receiver; use embedded_graphics::{ mono_font::{ MonoTextStyle, {ascii::FONT_5X7, ascii::FONT_7X13}, }, pixelcolor::BinaryColor, prelude::*, primitives::{PrimitiveStyleBuilder, Rectangle}, text::Text, }; use core::fmt::Write; use heapless::String; use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; use crate::AzElPair; #[embassy_executor::task] pub async fn display_task( i2c1: peripherals::I2C1, sda: peripherals::PB6, scl: peripherals::PB7, cmd_receiver: Receiver<'static, ThreadModeRawMutex, AzElPair, 1>, ) { 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(&FONT_7X13, BinaryColor::On); let text_large_inv = MonoTextStyle::new(&FONT_7X13, BinaryColor::Off); let text_small = MonoTextStyle::new(&FONT_5X7, BinaryColor::On); let style_filled = PrimitiveStyleBuilder::new() .fill_color(BinaryColor::On) .build(); loop { let pair = cmd_receiver.recv().await; 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(); let mut tmp: String<16> = String::new(); write!(tmp, "AZ: {}", pair.az).unwrap(); Text::new(&tmp, Point::new(1, 30), text_large_inv) .draw(&mut display) .unwrap(); tmp.clear(); write!(tmp, "EL: {}", pair.el).unwrap(); Text::new(&tmp, Point::new(64, 30), text_large_inv) .draw(&mut display) .unwrap(); display.flush().unwrap(); Timer::after(Duration::from_millis(500)).await; } }