I/O
This commit is contained in:
28
src/main.rs
28
src/main.rs
@@ -7,6 +7,7 @@ use embedded_graphics::{
|
||||
text::{Alignment, Text, TextStyleBuilder},
|
||||
};
|
||||
use time::{OffsetDateTime, macros::offset};
|
||||
use tokio::time::Instant;
|
||||
|
||||
use crate::g13::{G13, G13_LCD_COLUMNS, G13_LCD_ROWS};
|
||||
|
||||
@@ -26,24 +27,33 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.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(G13_LCD_COLUMNS / 2, G13_LCD_ROWS / 2),
|
||||
character_style,
|
||||
textstyle,
|
||||
)
|
||||
.draw(&mut _g13)
|
||||
.unwrap();
|
||||
Text::with_text_style(&string, Point::new(x as i32, y as i32), character_style, textstyle)
|
||||
.draw(&mut _g13)
|
||||
.unwrap();
|
||||
|
||||
_g13.render().unwrap();
|
||||
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
// Calculate delta time
|
||||
let delta = Instant::now() - start;
|
||||
tokio::time::sleep(Duration::from_millis(33) - delta).await;
|
||||
dt = (Instant::now() - start).as_secs_f64();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user