Skip to content

Commit a23ad9b

Browse files
committed
Avoid off-by-one error by not using C-style logic
My own fault for running into this bug... Signed-off-by: Daniel Schaefer <[email protected]>
1 parent d24822f commit a23ad9b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

ledmatrix/src/main.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ fn main() -> ! {
215215
let mut prev_timer = timer.get_counter().ticks();
216216
let mut game_timer = timer.get_counter().ticks();
217217

218-
let mut startup_percentage = 0;
218+
let mut startup_percentage = Some(0);
219219

220220
loop {
221221
// TODO: Current hardware revision does not have the sleep pin wired up :(
@@ -226,9 +226,12 @@ fn main() -> ! {
226226
// Handle period display updates. Don't do it too often
227227
if timer.get_counter().ticks() > prev_timer + 20_000 {
228228
// On startup slowly turn the screen on - it's a pretty effect :)
229-
if startup_percentage <= 100 {
230-
state.grid = percentage(startup_percentage);
231-
startup_percentage += 5;
229+
match startup_percentage {
230+
Some(p) if p <= 100 => {
231+
state.grid = percentage(p);
232+
startup_percentage = Some(p + 5);
233+
}
234+
_ => {}
232235
}
233236

234237
fill_grid_pixels(&state.grid, &mut matrix);
@@ -288,7 +291,7 @@ fn main() -> ! {
288291
}
289292
(Some(command), SleepState::Awake) => {
290293
// If there's a very early command, cancel the startup animation
291-
startup_percentage = 101;
294+
startup_percentage = None;
292295

293296
// While sleeping no command is handled, except waking up
294297
if let Some(response) =

0 commit comments

Comments
 (0)