[PR #12] [MERGED] feat: USB remote wakeup (wake PC from sleep via controller button press) #158

Closed
opened 2026-10-22 05:06:49 +00:00 by roman · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/safijari/openpuck/pull/12
Author: @Copilot
Created: 6/7/2026
Status: ✅ Merged
Merged: 6/7/2026
Merged by: @safijari

Base: main ← Head: copilot/11


📝 Commits (4)

  • 516830e feat: implement USB remote wakeup for PC wake-from-sleep (#11)
  • 265b669 feat: wake on Steam short press, RF connection, and mode change
  • 3eab2dc feat: block mode change when USB host is suspended
  • 0a65010 refactor: split long CDC mode-change line for readability

📊 Changes

1 file changed (+25 additions, -3 deletions)

View changed files

📝 OpenPuck/OpenPuck.ino (+25 -3)

📄 Description

The puck never advertised remote wakeup support in its USB config descriptor, so the host never granted the feature and pressing a controller button while the PC was sleeping had no effect.

Changes

  • Arm remote wakeup in config descriptor — sets REMOTE_WAKEUP bit (bit 5) in bmAttributes before USBDevice.attach() across all three USB modes (Steam/Xbox/Switch). This surfaces the "Allow this device to wake the computer" option in the host OS.
USBDevice.setConfigurationAttribute(0x80 | 0x20);  // required(0x80) | remote_wakeup(0x20)
USBDevice.attach();
  • Send wakeup signal on Steam button short press — in the F1 report path (shared by all modes), tracks the TB_STEAM button's rising and falling edges. A press-and-release cycle completing in under 1 second fires remoteWakeup() while the USB bus is suspended. Longer holds (likely a controller power-off intent) are ignored.
// rising edge: record press time
if (steamNow && !steamWasDown) steamDownMs = millis();
// falling edge within 1 s -> short press -> wake
if (!steamNow && steamWasDown && millis() - steamDownMs < 1000u && USBDevice.suspended())
    USBDevice.remoteWakeup();
  • Send wakeup signal on new RF controller connection — in loop(), a static wasRfConn variable tracks the connected state (connSlot >= 0 && reply < 300 ms). The false→true transition fires remoteWakeup() if the host is suspended, so connecting a controller wakes a sleeping PC.

  • Send wakeup signal on USB re-attach / mode change — in setup(), immediately after the mount-wait loop, calls remoteWakeup() if USBDevice.suspended() is true. This covers the case where the host was sleeping when the device re-enumerated following a mode change.

  • Block mode changes while host is suspended — all three mode-change paths (controller button chord, WebUSB 0x03 command, CDC x<n> command) now check USBDevice.suspended() before proceeding with saveMode() + NVIC_SystemReset(). A mode switch while the PC is asleep is silently ignored for the chord and WebUSB paths; the CDC path prints # mode change blocked: host suspended.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/safijari/openpuck/pull/12 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 6/7/2026 **Status:** ✅ Merged **Merged:** 6/7/2026 **Merged by:** [@safijari](https://github.com/safijari) **Base:** `main` ← **Head:** `copilot/11` --- ### 📝 Commits (4) - [`516830e`](https://github.com/safijari/openpuck/commit/516830e5e96262b8bc82cc052a1c1510d4d1e20a) feat: implement USB remote wakeup for PC wake-from-sleep (#11) - [`265b669`](https://github.com/safijari/openpuck/commit/265b6699ca129e94abdf1c64712b37100b7e5c45) feat: wake on Steam short press, RF connection, and mode change - [`3eab2dc`](https://github.com/safijari/openpuck/commit/3eab2dcbf74f0ad027af1d7be0f6578c3b7859b1) feat: block mode change when USB host is suspended - [`0a65010`](https://github.com/safijari/openpuck/commit/0a65010cd1b39b34787f1879f0e3636e4428a0d1) refactor: split long CDC mode-change line for readability ### 📊 Changes **1 file changed** (+25 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `OpenPuck/OpenPuck.ino` (+25 -3) </details> ### 📄 Description The puck never advertised remote wakeup support in its USB config descriptor, so the host never granted the feature and pressing a controller button while the PC was sleeping had no effect. ## Changes - **Arm remote wakeup in config descriptor** — sets `REMOTE_WAKEUP` bit (bit 5) in `bmAttributes` before `USBDevice.attach()` across all three USB modes (Steam/Xbox/Switch). This surfaces the "Allow this device to wake the computer" option in the host OS. ```cpp USBDevice.setConfigurationAttribute(0x80 | 0x20); // required(0x80) | remote_wakeup(0x20) USBDevice.attach(); ``` - **Send wakeup signal on Steam button short press** — in the F1 report path (shared by all modes), tracks the `TB_STEAM` button's rising and falling edges. A press-and-release cycle completing in under 1 second fires `remoteWakeup()` while the USB bus is suspended. Longer holds (likely a controller power-off intent) are ignored. ```cpp // rising edge: record press time if (steamNow && !steamWasDown) steamDownMs = millis(); // falling edge within 1 s -> short press -> wake if (!steamNow && steamWasDown && millis() - steamDownMs < 1000u && USBDevice.suspended()) USBDevice.remoteWakeup(); ``` - **Send wakeup signal on new RF controller connection** — in `loop()`, a static `wasRfConn` variable tracks the connected state (`connSlot >= 0 && reply < 300 ms`). The false→true transition fires `remoteWakeup()` if the host is suspended, so connecting a controller wakes a sleeping PC. - **Send wakeup signal on USB re-attach / mode change** — in `setup()`, immediately after the mount-wait loop, calls `remoteWakeup()` if `USBDevice.suspended()` is true. This covers the case where the host was sleeping when the device re-enumerated following a mode change. - **Block mode changes while host is suspended** — all three mode-change paths (controller button chord, WebUSB `0x03` command, CDC `x<n>` command) now check `USBDevice.suspended()` before proceeding with `saveMode()` + `NVIC_SystemReset()`. A mode switch while the PC is asleep is silently ignored for the chord and WebUSB paths; the CDC path prints `# mode change blocked: host suspended`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
roman 2026-10-22 05:06:49 +00:00
Sign in to join this conversation.
No labels
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
safijari/openpuck#158
No description provided.