64 lines
1.8 KiB
Rust
64 lines
1.8 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 tokio::time::Instant;
|
|
|
|
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();
|
|
|
|
let mut x = G13_LCD_COLUMNS as f64 / 2.0;
|
|
let mut y = G13_LCD_ROWS as f64 / 2.0;
|
|
|
|
// 30 fps render loop
|
|
let mut dt = 0.0;
|
|
loop {
|
|
let start = Instant::now();
|
|
let now = OffsetDateTime::now_utc().to_offset(offset!(+1));
|
|
|
|
// Update Logic
|
|
x += _g13.state.get_x().await * dt * 25.0;
|
|
y += _g13.state.get_y().await * dt * 25.0;
|
|
|
|
// Render
|
|
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(x as i32, y as i32), character_style, textstyle)
|
|
.draw(&mut _g13)
|
|
.unwrap();
|
|
|
|
_g13.render().unwrap();
|
|
|
|
// Calculate delta time
|
|
let delta = Instant::now() - start;
|
|
tokio::time::sleep(Duration::from_millis(33) - delta).await;
|
|
dt = (Instant::now() - start).as_secs_f64();
|
|
}
|
|
});
|
|
|
|
loop {
|
|
g13.read().await?;
|
|
}
|
|
}
|