From 00d327b8671e62fa7b4e9a6125008416376fcf4c Mon Sep 17 00:00:00 2001 From: Rodrigo Alfonso Date: Thu, 23 Jan 2025 05:51:25 -0300 Subject: [PATCH] Fixing stop method and other stuff --- README.md | 2 +- lib/LinkCableMultiboot.hpp | 5 ++++- lib/LinkRawWireless.hpp | 7 +++---- lib/LinkUniversal.hpp | 2 +- lib/LinkWireless.hpp | 4 ++-- lib/LinkWirelessMultiboot.hpp | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f9379bd..24386ee 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ This version (`LinkCableMultiboot::Async`) allows more advanced use cases like p | `reset()` | - | Deactivates the library, canceling the in-progress transfer, if any. | | `getState()` | **LinkCableMultiboot::Async::State** | Returns the current state. | | `getResult([clear])` | **LinkCableMultiboot::Async::Result** | Returns the result of the last operation.

After this call, the result is cleared if `clear` is `true` (default behavior). | -| `playerCount()` | **u8** | Returns the number of connected players (`1~4`). | +| `playerCount()` | **u8** _(1~4)_ | Returns the number of connected players. | | `getPercentage()` | **u32** | Returns the completion percentage. | | `isReady()` | **bool** | Returns whether the ready mark is active or not.

This is only useful when using the `waitForReadySignal` parameter. | | `markReady()` | **bool** | Marks the transfer as ready.

This is only useful when using the `waitForReadySignal` parameter. | diff --git a/lib/LinkCableMultiboot.hpp b/lib/LinkCableMultiboot.hpp index 1a7928a..d847bcf 100644 --- a/lib/LinkCableMultiboot.hpp +++ b/lib/LinkCableMultiboot.hpp @@ -1015,8 +1015,11 @@ class LinkCableMultiboot { } void stop(Result newResult = NONE) { + auto mode = fixedData.transferMode; + resetState(newResult); - if (fixedData.transferMode == TransferMode::MULTI_PLAY) + + if (mode == TransferMode::MULTI_PLAY) linkRawCable.deactivate(); else linkSPI.deactivate(); diff --git a/lib/LinkRawWireless.hpp b/lib/LinkRawWireless.hpp index 38a242a..cdde92c 100644 --- a/lib/LinkRawWireless.hpp +++ b/lib/LinkRawWireless.hpp @@ -724,9 +724,9 @@ class LinkRawWireless { rawData[0] = header; for (u32 i = 0; i < dataSize; i++) rawData[i + 1] = data[i]; - dataSize++; - bool success = sendCommand(COMMAND_SEND_DATA, rawData, dataSize).success; + bool success = + sendCommand(COMMAND_SEND_DATA, rawData, 1 + dataSize).success; if (!success) { _resetState(); @@ -757,9 +757,8 @@ class LinkRawWireless { rawData[0] = header; for (u32 i = 0; i < dataSize; i++) rawData[i + 1] = data[i]; - dataSize++; - if (!sendCommand(COMMAND_SEND_DATA_AND_WAIT, rawData, dataSize, true) + if (!sendCommand(COMMAND_SEND_DATA_AND_WAIT, rawData, 1 + dataSize, true) .success) { _resetState(); return false; diff --git a/lib/LinkUniversal.hpp b/lib/LinkUniversal.hpp index 5b972de..7eab14c 100644 --- a/lib/LinkUniversal.hpp +++ b/lib/LinkUniversal.hpp @@ -194,7 +194,7 @@ class LinkUniversal { [[nodiscard]] bool isConnected() { return state == CONNECTED; } /** - * @brief Returns the number of connected players (`0~5`). + * @brief Returns the number of connected players (`1~5`). */ [[nodiscard]] u8 playerCount() { return mode == LINK_CABLE ? linkCable.playerCount() diff --git a/lib/LinkWireless.hpp b/lib/LinkWireless.hpp index 35c7d03..d2ef6b3 100644 --- a/lib/LinkWireless.hpp +++ b/lib/LinkWireless.hpp @@ -670,14 +670,14 @@ class LinkWireless { } /** - * @brief Returns the number of connected players. + * @brief Returns the number of connected players (`1~5`). */ [[nodiscard]] u8 playerCount() { return linkRawWireless.sessionState.playerCount; } /** - * @brief Returns the current player ID. + * @brief Returns the current player ID (`0~4`). */ [[nodiscard]] u8 currentPlayerId() { return linkRawWireless.sessionState.currentPlayerId; diff --git a/lib/LinkWirelessMultiboot.hpp b/lib/LinkWirelessMultiboot.hpp index bc76158..0e456ab 100644 --- a/lib/LinkWirelessMultiboot.hpp +++ b/lib/LinkWirelessMultiboot.hpp @@ -526,7 +526,7 @@ class LinkWirelessMultiboot { u32 _bytes, LinkRawWireless::ReceiveDataResponse& response) { LinkRawWireless::CommandResult remoteCommand; - volatile bool success = false; + bool success = false; success = linkRawWireless.sendDataAndWait(data, dataSize, remoteCommand, _bytes);