Skip to content

USB Wake Feature (port from DS5Dongle) - #93

Open
515orestis wants to merge 7 commits into
SundayMoments:mainfrom
515orestis:feature/enable-wake
Open

USB Wake Feature (port from DS5Dongle)#93
515orestis wants to merge 7 commits into
SundayMoments:mainfrom
515orestis:feature/enable-wake

Conversation

@515orestis

Copy link
Copy Markdown

No description provided.

515orestis and others added 7 commits July 6, 2026 01:16
…tons

Ports the wake feature from awalol/DS5Dongle into the DS5 Bridge companion
firmware. When built with ENABLE_WAKE_HID (default ON), the config descriptor
advertises USB REMOTE_WAKEUP (bmAttributes 0xE0) and a controller button press
during host suspend taps F15 on the existing HID keyboard interface to wake the PC.

- src/wake.{h,cpp}: wake FSM (button/reconnect detection -> tud_remote_wakeup ->
  F15 keystroke via HID instance 1), stripped of awalol's config/ps_shortcut and
  controller power-off (DS5 Bridge already power-manages in usb_pm_poll()).
- usb_descriptors.c: 0xE0 REMOTE_WAKEUP when ENABLE_WAKE_HID.
- usb.cpp: wake_note_suspend/resume() in the suspend/resume/mount callbacks.
- bt.cpp: wake_on_bt_connect() on HID interrupt channel open (pad reconnect).
- main.cpp: wake_on_bt_input() per BT report; wake_init()/wake_task() in main loop.
- CMakeLists.txt: build src/wake.cpp, add ENABLE_WAKE_HID option (default ON).
Firmware: add a runtime wake enable/disable flag gated in the wake FSM, exposed
via a new companion command CommandSetWakeEnabled (0x34). Default enabled.
- wake.{h,cpp}: wake_set_enabled()/wake_is_enabled(); request_host_wake() no-ops
  when disabled (still advertises remote-wakeup, just never wakes the host).
- companion.cpp: CommandSetWakeEnabled handler (mirrors SetSleepKeybindEnabled).

Companion app: 'Wake PC on PS Button' toggle in the device settings
'Power & Controller' section, wired end-to-end and re-applied on connect.
- protocol.ts: SET_WAKE_ENABLED (0x34) + wakeEnabled setting.
- types.ts / settings-store.ts: wakeEnabled setting (default true) + persistence.
- preload.ts / main.ts: setWakeEnabled IPC.
- bridge-service.ts: setWakeEnabled() + apply on connect.
- App.tsx: the toggle row + settings mapping.

Typecheck passes (tsc main+renderer); firmware builds clean (Pico SDK 2.2.0).
…umerate)

Previously the toggle only gated the firmware's wake action while the descriptor
statically advertised remote-wakeup, so Windows always saw the device as a wake
source. Now mirror awalol/DS5Dongle:

- usb_descriptors.c: bmAttributes REMOTE_WAKEUP bit (0xE0/0xC0) is set at runtime
  in tud_descriptor_configuration_cb from the wake flag (via C-linkage
  wake_remote_wakeup_enabled()); static image carries 0xC0. Keyboard interface
  stays present regardless (shared with shortcuts), unlike awalol which drops it.
- companion.cpp: CommandSetWakeEnabled calls usb_request_reconnect() so Windows
  re-reads the descriptor and adds/removes the device from its wake sources --
  but only when the value actually changes, else the app's connect-time settings
  re-apply would loop the reconnect.
- wake.cpp: wake_remote_wakeup_enabled() C accessor for the C-compiled descriptor.

Not persisted to flash (DS5 Bridge has no on-dongle config store; the companion
app re-applies on connect, like its other settings).
The reapply routine now sends SET_WAKE_ENABLED (0x34) during a full
settings re-apply, but the test's expected command-order constant was
not updated, failing the two reapply-order assertions. Insert the
command at the same position as in bridge-service.ts (after
SET_SLEEP_KEYBIND_ENABLED).
# Conflicts:
#	CMakeLists.txt
#	src/bt.cpp
#	src/main.cpp
The merge from up/main brought upstream's flash-nuke hash constant, but
our bundled pico-universal-flash-nuke.uf2 is built locally and differs
byte-for-byte. Rebuilt the flash-nuke and regenerated the constant so the
bundled binary matches the hash the companion verifies at runtime.
@SundayMoments

Copy link
Copy Markdown
Owner

Thanks for updating the PR. I'll be testing it later today.

@515orestis

Copy link
Copy Markdown
Author

it was based on 1.6.3 .i have updated from 1.6.4 but not tested , it has multiple changes from 1.6.3 ->1.6.4

gunCannoli added a commit to gunCannoli/DS5_Bridge that referenced this pull request Aug 10, 2026
…ntion

The controller was dropping its Bluetooth connection during a real
automatic WOL trigger, even though the manual WOL Test worked fine. Root
cause: wolwifi_on_controller_connect() fires at the exact BT-connection
Ready edge, and the very next wolwifi_task() tick immediately starts a
full WPA2 association + DHCP handshake on the CYW43439 -- a combo Wi-Fi/BT
chip that time-shares a single radio. That fresh Wi-Fi RF activity
contends with the still-stabilizing BT session for the shared radio and
was observed dropping it.

Researched how the existing "Wake PC on Controller" (USB persona-hold +
tud_remote_wakeup()) and upstream SundayMoments#93 handle this:
neither actually keeps the BT link itself connected -- both let BT drop
and reconnect fresh, so there's no existing pattern here to reuse.
Cross-checked awalol/DS5Dongle#207 (independent prior art on WOL-over-Wi-Fi
for the same combo chip): its Observe state incidentally imposes a ~3s
delay before starting Wi-Fi, and it confirmed cyw43_tcpip_link_status() as
the correct status call (already fixed here) plus two lwIP DHCP options
not yet set in this repo.

Fix: delay the *start* of the Wi-Fi connect sequence (not just the send)
by WIFI_CONNECT_START_DELAY_MS=2000 after a controller-connect edge, via
g_connect_start_not_before_ms checked in the Idle case of wolwifi_task().
Only applies when Wi-Fi isn't already connected -- if a prior session's
Wi-Fi link is already up, there's no new radio activity to contend with BT,
so the packet still sends immediately. Debug Ping/WOL Test triggers are
unaffected (user-initiated on demand, not tied to a BT connect event).

Also add DHCP_DOES_ARP_CHECK=0 / LWIP_DHCP_DOES_ACD_CHECK=0 to
lwipopts.h per the PR #207 finding: skips the DHCP client's post-lease ARP
conflict probe, shortening the handshake and further shrinking the
contention window.

Considered also skipping the send entirely if an ARP check shows the
target is already awake, but decided against it: a stray magic packet to
an already-on host is harmless, so the added latency/complexity isn't
worth it for the automatic trigger.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
gunCannoli added a commit to gunCannoli/DS5_Bridge that referenced this pull request Aug 10, 2026
Fourth bug in the WOL debugging arc: the controller dropped BT during a
real automatic WOL trigger due to CYW43 radio contention between a fresh
Wi-Fi connect and a still-stabilizing BT session. Documents the PR
research (SundayMoments#93, "Wake PC on Controller", DS5Dongle #207/#186/SundayMoments#136), root
cause, the 2s connect-start-delay fix, and the rejected ARP-liveness-check
alternative. Sets re-flashing the rebuilt debug firmware and re-testing
the real PC-off wake scenario as the current task.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
gunCannoli added a commit to gunCannoli/DS5_Bridge that referenced this pull request Aug 10, 2026
No in-the-room visual signal existed for whether an automatic WOL trigger
was actually doing anything -- especially relevant now that it can retry
for up to 15s (see the resend-until-confirmed fix). Added a 3-stage
lightbar sequence overlaid on the controller during a resend cycle:

- Pulsing dark<->light green (~1.5s breathing cycle) for as long as the
  cycle is actively resending/waiting.
- Solid light green for 2s once the target confirms it woke up (same ARP
  liveness signal the resend cycle already uses to know when to stop).
- Restore to whatever color was showing immediately before the indicator
  started -- a true restore, not the existing flash-then-refresh pattern
  PR SundayMoments#93 uses for controller-wake, since bt_set_lightbar_color() overwrites
  its own restore target (saved_lightbar_*) on every call and so can't
  itself remember "what was showing before".

New bt.cpp/bt.h API: bt_wol_indicator_begin/confirm/cancel/loop(), with a
dedicated snapshot (wol_indicator_pre_*) separate from the existing
saved_lightbar_*/lightbar_restore_pending mechanism, so the pulse's own
repeated bt_set_lightbar_color() calls during animation don't clobber the
color it needs to restore to. Wired into wolwifi.cpp's begin_resend_cycle()
(start pulsing), drive_resend_cycle()'s confirmation branch (solid + hold),
and its budget-exhausted branch (cancel, restore immediately -- kept as a
purely positive signal with no distinct failure color, consistent with
the earlier decision not to add complexity for the unconfirmed case).
Polled from main.cpp's existing Lightbar phase alongside bt_lightbar_loop().

Debug WOL Test button is unaffected -- it doesn't go through the resend
cycle, so no indicator fires for it.

Debug firmware rebuilt at build/waveshare/ds5-bridge.uf2.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants