Skip to content

Commit 51206ac

Browse files
committed
ledmatrix: Wake up upon receiving any command
It's annoying to use the wake up command. Any command should wake up the module. Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 9a0f48d commit 51206ac

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

ledmatrix/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,15 @@ What can change the sleep state
203203
- `SLEEP#` pin
204204
- USB Suspend
205205
- Software/Firmware Triggers
206-
- Sleep/Wake Command via USB Serial
206+
- Sleep/Wake or other command via USB Serial
207207
- Idle timer
208208

209209
Both of the hardware/OS triggers change the sleep state if the transition from one state to another.
210210
For example, if USB suspends, the LED matrix turns off. If it resumes, the LEDs come back on.
211211
Same for the `SLEEP#` pin.
212212

213213
The sleep/wake command always changes the state. But it can't be received when USB is suspended.
214+
Any other command will also wake up the device.
214215

215216
The idle timer will send the device to sleep after a configured timeout (default 60 seconds).
216217
The idle timer is reset once the device wakes up or once it receives a command.

ledmatrix/src/main.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -372,20 +372,21 @@ fn main() -> ! {
372372
&mut led_enable,
373373
);
374374
}
375-
(Some(c @ Command::BootloaderReset), _)
376-
| (Some(c @ Command::IsSleeping), _) => {
377-
if let Some(response) =
378-
handle_command(&c, &mut state, &mut matrix, random)
379-
{
380-
let _ = serial.write(&response);
381-
};
382-
}
383-
(Some(command), SleepState::Awake) => {
375+
(Some(command), _) => {
384376
// If there's a very early command, cancel the startup animation
385377
startup_percentage = None;
386378

387379
// Reset sleep timer when interacting with the device
388380
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+
);
389390

390391
if let Some(response) =
391392
handle_command(&command, &mut state, &mut matrix, random)
@@ -401,6 +402,7 @@ fn main() -> ! {
401402
buf[0], buf[1], buf[2], buf[3]
402403
)
403404
.unwrap();
405+
// let _ = serial.write(text.as_bytes());
404406
fill_grid_pixels(&state, &mut matrix);
405407
}
406408
_ => {}

0 commit comments

Comments
 (0)