diff --git a/docs/wireless_adapter.md b/docs/wireless_adapter.md index d272519..4ee906d 100644 --- a/docs/wireless_adapter.md +++ b/docs/wireless_adapter.md @@ -260,7 +260,7 @@ Whenever either side expects something to be sent from the other (as SPI is alwa ⚠️ IDs are randomly generated. Each time you broadcast or connect, the adapter assigns you a new id. -⚠️ Reading broadcasts is a two-step process: First, you send `0x1c`. Then, wait until the adapter retrieves data (games usually wait 1 full second). Lastly, send a `0x1e` and it will return what's described above. +⚠️ Reading broadcasts is a three-step process: First, you send `0x1c` (you will get an ACK instantly), and start waiting until the adapter retrieves data (games usually wait 1 full second). Then, send a `0x1d` and it will return what's described above. Lastly, send a `0x1e` to finish the process (you can ignore what the adapter returns here). If you don't send that last `0x1e`, the next command will fail. #### Setup - `0x17` diff --git a/lib/LinkWireless.h b/lib/LinkWireless.h index 2d8c9e7..ffb0216 100644 --- a/lib/LinkWireless.h +++ b/lib/LinkWireless.h @@ -78,6 +78,7 @@ #define LINK_WIRELESS_COMMAND_START_HOST 0x19 #define LINK_WIRELESS_COMMAND_ACCEPT_CONNECTIONS 0x1a #define LINK_WIRELESS_COMMAND_BROADCAST_READ_START 0x1c +#define LINK_WIRELESS_COMMAND_BROADCAST_READ_POLL 0x1d #define LINK_WIRELESS_COMMAND_BROADCAST_READ_END 0x1e #define LINK_WIRELESS_COMMAND_CONNECT 0x1f #define LINK_WIRELESS_COMMAND_IS_FINISHED_CONNECT 0x20 @@ -254,7 +255,7 @@ class LinkWireless { wait(LINK_WIRELESS_BROADCAST_SEARCH_WAIT); - auto result = sendCommand(LINK_WIRELESS_COMMAND_BROADCAST_READ_END); + auto result = sendCommand(LINK_WIRELESS_COMMAND_BROADCAST_READ_POLL); bool success2 = result.success && result.responses.size() % LINK_WIRELESS_BROADCAST_RESPONSE_LENGTH == 0; @@ -265,6 +266,15 @@ class LinkWireless { return false; } + bool success3 = + sendCommand(LINK_WIRELESS_COMMAND_BROADCAST_READ_END).success; + + if (!success3) { + reset(); + lastError = COMMAND_FAILED; + return false; + } + u32 totalBroadcasts = result.responses.size() / LINK_WIRELESS_BROADCAST_RESPONSE_LENGTH;