@@ -361,32 +361,42 @@ fn main() -> ! {
361
361
Ok ( count) => {
362
362
let random = get_random_byte ( & rosc) ;
363
363
match ( parse_command ( count, & buf) , & state. sleeping ) {
364
- // While sleeping no command is handled, except waking up
365
- ( Some ( Command :: Sleep ( go_sleeping) ) , _) => {
366
- sleeping = go_sleeping;
364
+ // Handle bootloader command without any delay
365
+ // No need, it'll reset the device anyways
366
+ ( Some ( c @ Command :: BootloaderReset ) , _) => {
367
+ handle_command ( & c, & mut state, & mut matrix, random) ;
368
+ }
369
+ ( Some ( command) , _) => {
370
+ if let Command :: Sleep ( go_sleeping) = command {
371
+ sleeping = go_sleeping;
372
+ } else {
373
+ // If already sleeping, wake up.
374
+ // This means every command will wake the device up.
375
+ // Much more convenient than having to send the wakeup commmand.
376
+ sleeping = false ;
377
+ }
378
+ // Make sure sleep animation only goes up to newly set brightness,
379
+ // if setting the brightness causes wakeup
380
+ if let SleepState :: Sleeping ( ( ref grid, _) ) = state. sleeping {
381
+ if let Command :: SetBrightness ( new_brightness) = command {
382
+ state. sleeping =
383
+ SleepState :: Sleeping ( ( grid. clone ( ) , new_brightness) ) ;
384
+ }
385
+ }
367
386
handle_sleep (
368
- go_sleeping ,
387
+ sleeping ,
369
388
& mut state,
370
389
& mut matrix,
371
390
& mut delay,
372
391
& mut led_enable,
373
392
) ;
374
- }
375
- ( Some ( command) , _) => {
393
+
376
394
// If there's a very early command, cancel the startup animation
377
395
startup_percentage = None ;
378
396
379
397
// Reset sleep timer when interacting with the device
398
+ // Very easy way to keep the device from going to sleep
380
399
sleep_timer = timer. get_counter ( ) . ticks ( ) ;
381
- // If already sleeping, wake up
382
- sleeping = false ;
383
- handle_sleep (
384
- sleeping,
385
- & mut state,
386
- & mut matrix,
387
- & mut delay,
388
- & mut led_enable,
389
- ) ;
390
400
391
401
if let Some ( response) =
392
402
handle_command ( & command, & mut state, & mut matrix, random)
@@ -403,9 +413,10 @@ fn main() -> ! {
403
413
)
404
414
. unwrap ( ) ;
405
415
// let _ = serial.write(text.as_bytes());
416
+
406
417
fill_grid_pixels ( & state, & mut matrix) ;
407
418
}
408
- _ => { }
419
+ ( None , _ ) => { }
409
420
}
410
421
}
411
422
}
@@ -477,6 +488,7 @@ fn get_random_byte(rosc: &RingOscillator<Enabled>) -> u8 {
477
488
byte
478
489
}
479
490
491
+ // Will do nothing if already in the right state
480
492
fn handle_sleep (
481
493
go_sleeping : bool ,
482
494
state : & mut LedmatrixState ,
0 commit comments