Fix timing in draw routine

This commit is contained in:
Marco Thomas
2022-04-18 13:57:52 +02:00
parent 89dbe4adca
commit 7727f01fd2
2 changed files with 11 additions and 11 deletions

View File

@@ -25,5 +25,5 @@ The =video-to-ascii.py= conversion script uses [[https://github.com/ivanl-exe/im
It is assumed to be located on the same height as this project and that it is build in release-mode (due to performance).
* TODO
- [ ] Fix timing in draw
- [X] Fix timing in draw
- [ ] Rewrite ascii conversion in Rust or Haskell (with an own implementation of =ascii-to-text=)

View File

@@ -77,6 +77,11 @@ fn main() -> ! {
loop {
let monotimer_instant = monotimer.now();
// reset
if button1.is_high().unwrap() {
index = 0
}
display.clear();
let text = Text::with_baseline(
@@ -93,19 +98,14 @@ fn main() -> ! {
index = (index + IMAGE_LEN) % IMAGE_END;
// adjust for desired framerate
// TODO: chip is too fast for some reason
let freq = monotimer.frequency().0;
// maybe use float calc here?
let ms_per_draw = 1000 / (freq / monotimer_instant.elapsed());
rprintln!("Draw took {}ms", ms_per_draw);
// WARNING: don't do anything after elapsed() has been calculated,
// otherwise it will delay the frame being drawn, which will
// knock it off sync
let freq: f64 = monotimer.frequency().0.into();
let ms_per_draw: f64 = f64::from(1000 ) / (freq / f64::from(monotimer_instant.elapsed()));
match DRAW_TIME.checked_sub(ms_per_draw as usize) {
Some(result) => delay_provider.delay_ms(result as u32),
None => (),
};
// reset
if button1.is_high().unwrap() {
index = 0
}
}
}