Files
g13-joystick/src/main.rs
2026-02-09 10:45:59 +01:00

54 lines
1.4 KiB
Rust

use std::time::Duration;
use embedded_graphics::{
mono_font::{MonoTextStyle, iso_8859_14::FONT_10X20},
pixelcolor::BinaryColor,
prelude::*,
text::{Alignment, Text, TextStyleBuilder},
};
use time::{OffsetDateTime, macros::offset};
use crate::g13::{G13, G13_LCD_COLUMNS, G13_LCD_ROWS};
mod g13;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut g13 = G13::new().await?;
g13.set_lcd_color(64, 0, 64).await?;
let mut _g13 = g13.clone();
tokio::spawn(async move {
let character_style = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
let textstyle = TextStyleBuilder::new()
.alignment(Alignment::Center)
.baseline(embedded_graphics::text::Baseline::Middle)
.build();
loop {
let now = OffsetDateTime::now_utc().to_offset(offset!(+1));
let string = format!("{:0>2}:{:0>2}:{:0>2}", now.hour(), now.minute(), now.second());
_g13.clear(BinaryColor::Off).unwrap();
Text::with_text_style(
&string,
Point::new(G13_LCD_COLUMNS / 2, G13_LCD_ROWS / 2),
character_style,
textstyle,
)
.draw(&mut _g13)
.unwrap();
_g13.render().unwrap();
tokio::time::sleep(Duration::from_secs(1)).await;
}
});
loop {
g13.read().await?;
}
}