Fix timing in draw routine
This commit is contained in:
@@ -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).
|
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
|
* 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=)
|
- [ ] Rewrite ascii conversion in Rust or Haskell (with an own implementation of =ascii-to-text=)
|
||||||
|
|||||||
20
src/main.rs
20
src/main.rs
@@ -77,6 +77,11 @@ fn main() -> ! {
|
|||||||
loop {
|
loop {
|
||||||
let monotimer_instant = monotimer.now();
|
let monotimer_instant = monotimer.now();
|
||||||
|
|
||||||
|
// reset
|
||||||
|
if button1.is_high().unwrap() {
|
||||||
|
index = 0
|
||||||
|
}
|
||||||
|
|
||||||
display.clear();
|
display.clear();
|
||||||
|
|
||||||
let text = Text::with_baseline(
|
let text = Text::with_baseline(
|
||||||
@@ -93,19 +98,14 @@ fn main() -> ! {
|
|||||||
index = (index + IMAGE_LEN) % IMAGE_END;
|
index = (index + IMAGE_LEN) % IMAGE_END;
|
||||||
|
|
||||||
// adjust for desired framerate
|
// adjust for desired framerate
|
||||||
// TODO: chip is too fast for some reason
|
// WARNING: don't do anything after elapsed() has been calculated,
|
||||||
let freq = monotimer.frequency().0;
|
// otherwise it will delay the frame being drawn, which will
|
||||||
// maybe use float calc here?
|
// knock it off sync
|
||||||
let ms_per_draw = 1000 / (freq / monotimer_instant.elapsed());
|
let freq: f64 = monotimer.frequency().0.into();
|
||||||
rprintln!("Draw took {}ms", ms_per_draw);
|
let ms_per_draw: f64 = f64::from(1000 ) / (freq / f64::from(monotimer_instant.elapsed()));
|
||||||
match DRAW_TIME.checked_sub(ms_per_draw as usize) {
|
match DRAW_TIME.checked_sub(ms_per_draw as usize) {
|
||||||
Some(result) => delay_provider.delay_ms(result as u32),
|
Some(result) => delay_provider.delay_ms(result as u32),
|
||||||
None => (),
|
None => (),
|
||||||
};
|
};
|
||||||
|
|
||||||
// reset
|
|
||||||
if button1.is_high().unwrap() {
|
|
||||||
index = 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user