diff --git a/README.md b/README.md index 6010f14..6ed1632 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ You can also change these compile-time constants: | `read(playerId)` | **u16** | Dequeues and returns the next message from player #`playerId`. If there's no data from that player, a `0` will be returned. | | `peek(playerId)` | **u16** | Returns the next message from player #`playerId` without dequeuing it. If there's no data from that player, a `0` will be returned. | | `send(data)` | - | Sends `data` to all connected players. If `data` is invalid or the send queue is full, a `false` will be returned. | -| `didQueueOverflow()` | **bool** | Returns whether the internal receive queue lost messages at some point due to being full. This can happen if your queue size is too low, if you receive too much data without calling `sync(...)` enough times, or if you don't `read(...)` enough messages before the next `sync()` call. The flag is cleared on each call. | +| `didQueueOverflow()` | **bool** | Returns whether the internal receive queue lost messages at some point due to being full. This can happen if your queue size is too low, if you receive too much data without calling `sync(...)` enough times, or if you don't `read(...)` enough messages before the next `sync()` call. After this call, the overflow flag is cleared if `clear` is `true` (default behavior). | | `resetTimer()` | - | Restarts the send timer without disconnecting. Call this if you changed `config.interval` | ⚠️ `0xFFFF` and `0x0` are reserved values, so don't send them! @@ -262,7 +262,7 @@ You can also change these compile-time constants: | `isServerClosed()` | **bool** | Returns `true` if the server was closed with `closeServer()`. | | `playerCount()` | **u8** _(1~5)_ | Returns the number of connected players. | | `currentPlayerId()` | **u8** _(0~4)_ | Returns the current player ID. | -| `didQueueOverflow()` | **bool** | Returns whether the internal receive queue lost messages at some point due to being full. This can happen if your queue size is too low, if you receive too much data without calling `receive(...)` enough times, or if excessive `receive(...)` calls prevent the ISR from copying data. The flag is cleared on each call. | +| `didQueueOverflow()` | **bool** | Returns whether the internal receive queue lost messages at some point due to being full. This can happen if your queue size is too low, if you receive too much data without calling `receive(...)` enough times, or if excessive `receive(...)` calls prevent the ISR from copying data. After this call, the overflow flag is cleared if `clear` is `true` (default behavior). | | `getLastError([clear])` | **LinkWireless::Error** | If one of the other methods returns `false`, you can inspect this to know the cause. After this call, the last error is cleared if `clear` is `true` (default behavior). | | `resetTimer()` | - | Restarts the send timer without disconnecting. Call this if you changed `config.interval`. | @@ -530,7 +530,7 @@ You can change these compile-time constants: | `peek()` | **u32** | Returns the next received value without dequeuing it. If there's no received data, a `0` will be returned. | | `send(data)` | - | Sends 32-bit `data`. If the other end asks for data at the same time you call this method, a `0x00000000` will be sent. | | `pendingCount()` | **u32** | Returns the number of pending outgoing transfers. | -| `didQueueOverflow()` | **bool** | Returns whether the internal receive queue lost messages at some point due to being full. This can happen if your queue size is too low, if you receive too much data without calling `read(...)` enough times, or if excessive `read(...)` calls prevent the ISR from copying data. The flag is cleared on each call. | +| `didQueueOverflow([clear])` | **bool** | Returns whether the internal receive queue lost messages at some point due to being full. This can happen if your queue size is too low, if you receive too much data without calling `read(...)` enough times, or if excessive `read(...)` calls prevent the ISR from copying data. After this call, the overflow flag is cleared if `clear` is `true` (default behavior). | | `didReset([clear])` | **bool** | Returns whether a JOYBUS reset was requested or not. After this call, the reset flag is cleared if `clear` is `true` (default behavior). | # 📱 LinkMobile diff --git a/lib/LinkCable.hpp b/lib/LinkCable.hpp index 2b273ab..d260d29 100644 --- a/lib/LinkCable.hpp +++ b/lib/LinkCable.hpp @@ -263,20 +263,23 @@ class LinkCable { * @brief Returns whether the internal receive queue lost messages at some * point due to being full. This can happen if your queue size is too low, if * you receive too much data without calling `sync(...)` enough times, or if - * you don't `read(...)` enough messages before the next `sync()` call. - * \warning The flag is cleared on each call. + * you don't `read(...)` enough messages before the next `sync()` call. After + * this call, the overflow flag is cleared if `clear` is `true` (default + * behavior). */ - [[nodiscard]] bool didQueueOverflow() { - bool flag = false; + [[nodiscard]] bool didQueueOverflow(bool clear = true) { + bool overflow = false; for (u32 i = 0; i < LINK_CABLE_MAX_PLAYERS; i++) { - flag = flag || _state.newMessages[i].overflow || - _state.readyToSyncMessages[i].overflow; - _state.newMessages[i].overflow = false; - state.syncedIncomingMessages[i].overflow = false; + overflow = overflow || _state.newMessages[i].overflow || + _state.readyToSyncMessages[i].overflow; + if (clear) { + _state.newMessages[i].overflow = false; + state.syncedIncomingMessages[i].overflow = false; + } } - return flag; + return overflow; } /** diff --git a/lib/LinkCube.hpp b/lib/LinkCube.hpp index 1076c94..23cbff7 100644 --- a/lib/LinkCube.hpp +++ b/lib/LinkCube.hpp @@ -156,13 +156,15 @@ class LinkCube { * @brief Returns whether the internal receive queue lost messages at some * point due to being full. This can happen if your queue size is too low, if * you receive too much data without calling `read(...)` enough times, or - * if excessive `read(...)` calls prevent the ISR from copying data. - * \warning The flag is cleared on each call. + * if excessive `read(...)` calls prevent the ISR from copying data. After + * this call, the overflow flag is cleared if `clear` is `true` (default + * behavior). */ - [[nodiscard]] bool didQueueOverflow() { - bool flag = newIncomingQueue.overflow; - newIncomingQueue.overflow = false; - return flag; + [[nodiscard]] bool didQueueOverflow(bool clear = true) { + bool overflow = newIncomingQueue.overflow; + if (clear) + newIncomingQueue.overflow = false; + return overflow; } /** diff --git a/lib/LinkUniversal.hpp b/lib/LinkUniversal.hpp index 276511e..ddf9769 100644 --- a/lib/LinkUniversal.hpp +++ b/lib/LinkUniversal.hpp @@ -364,19 +364,21 @@ class LinkUniversal { * @brief Returns whether the internal receive queue lost messages at some * point due to being full. This can happen if your queue size is too low, if * you receive too much data without calling `sync(...)` enough times, or if - * you don't `read(...)` enough messages before the next `sync()` call. - * \warning The flag is cleared on each call. + * you don't `read(...)` enough messages before the next `sync()` call. After + * this call, the overflow flag is cleared if `clear` is `true` (default + * behavior). */ - [[nodiscard]] bool didQueueOverflow() { - bool flag = mode == LINK_CABLE ? linkCable.didQueueOverflow() - : linkWireless.didQueueOverflow(); + [[nodiscard]] bool didQueueOverflow(bool clear = true) { + bool overflow = mode == LINK_CABLE ? linkCable.didQueueOverflow() + : linkWireless.didQueueOverflow(); for (u32 i = 0; i < LINK_UNIVERSAL_MAX_PLAYERS; i++) { - flag = flag || incomingMessages[i].overflow; - incomingMessages[i].overflow = false; + overflow = overflow || incomingMessages[i].overflow; + if (clear) + incomingMessages[i].overflow = false; } - return flag; + return overflow; } /** diff --git a/lib/LinkWireless.hpp b/lib/LinkWireless.hpp index 550481d..b0aab62 100644 --- a/lib/LinkWireless.hpp +++ b/lib/LinkWireless.hpp @@ -686,13 +686,15 @@ class LinkWireless { * @brief Returns whether the internal receive queue lost messages at some * point due to being full. This can happen if your queue size is too low, if * you receive too much data without calling `receive(...)` enough times, or - * if excessive `receive(...)` calls prevent the ISR from copying data. - * \warning The flag is cleared on each call. + * if excessive `receive(...)` calls prevent the ISR from copying data. After + * this call, the overflow flag is cleared if `clear` is `true` (default + * behavior). */ - [[nodiscard]] bool didQueueOverflow() { - bool flag = sessionState.newIncomingMessages.overflow; - sessionState.newIncomingMessages.overflow = false; - return flag; + [[nodiscard]] bool didQueueOverflow(bool clear = true) { + bool overflow = sessionState.newIncomingMessages.overflow; + if (clear) + sessionState.newIncomingMessages.overflow = false; + return overflow; } /** diff --git a/lib/c_bindings/C_LinkCable.cpp b/lib/c_bindings/C_LinkCable.cpp index 8c3d069..3f43bd9 100644 --- a/lib/c_bindings/C_LinkCable.cpp +++ b/lib/c_bindings/C_LinkCable.cpp @@ -73,8 +73,8 @@ bool C_LinkCable_send(C_LinkCableHandle handle, u16 data) { return static_cast(handle)->send(data); } -bool C_LinkCable_didQueueOverflow(C_LinkCableHandle handle) { - static_cast(handle)->didQueueOverflow(); +bool C_LinkCable_didQueueOverflow(C_LinkCableHandle handle, bool clear) { + static_cast(handle)->didQueueOverflow(clear); } void C_LinkCable_resetTimer(C_LinkCableHandle handle) { diff --git a/lib/c_bindings/C_LinkCable.h b/lib/c_bindings/C_LinkCable.h index f47ce1d..070bdbe 100644 --- a/lib/c_bindings/C_LinkCable.h +++ b/lib/c_bindings/C_LinkCable.h @@ -57,7 +57,7 @@ u16 C_LinkCable_peek(C_LinkCableHandle handle, u8 playerId); bool C_LinkCable_send(C_LinkCableHandle handle, u16 data); -bool C_LinkCable_didQueueOverflow(C_LinkCableHandle handle); +bool C_LinkCable_didQueueOverflow(C_LinkCableHandle handle, bool clear); void C_LinkCable_resetTimer(C_LinkCableHandle handle); C_LinkCable_Config C_LinkCable_getConfig(C_LinkCableHandle handle); diff --git a/lib/c_bindings/C_LinkCube.cpp b/lib/c_bindings/C_LinkCube.cpp index d0209e5..883fd18 100644 --- a/lib/c_bindings/C_LinkCube.cpp +++ b/lib/c_bindings/C_LinkCube.cpp @@ -51,8 +51,8 @@ u32 C_LinkCube_pendingCount(C_LinkCubeHandle handle) { return static_cast(handle)->pendingCount(); } -bool C_LinkCube_didQueueOverflow(C_LinkCubeHandle handle) { - return static_cast(handle)->didQueueOverflow(); +bool C_LinkCube_didQueueOverflow(C_LinkCubeHandle handle, bool clear) { + return static_cast(handle)->didQueueOverflow(clear); } bool C_LinkCube_didReset(C_LinkCubeHandle handle, bool clear) { diff --git a/lib/c_bindings/C_LinkCube.h b/lib/c_bindings/C_LinkCube.h index d9c95c1..7b5d0f5 100644 --- a/lib/c_bindings/C_LinkCube.h +++ b/lib/c_bindings/C_LinkCube.h @@ -25,8 +25,8 @@ u32 C_LinkCube_peek(C_LinkCubeHandle handle); void C_LinkCube_send(C_LinkCubeHandle handle, u32 data); u32 C_LinkCube_pendingCount(C_LinkCubeHandle handle); -bool C_LinkCube_didQueueOverflow(C_LinkCubeHandle handle); +bool C_LinkCube_didQueueOverflow(C_LinkCubeHandle handle, bool clear); bool C_LinkCube_didReset(C_LinkCubeHandle handle, bool clear); void C_LinkCube_onSerial(C_LinkCubeHandle handle); diff --git a/lib/c_bindings/C_LinkUniversal.cpp b/lib/c_bindings/C_LinkUniversal.cpp index b0e5d4b..2043c8f 100644 --- a/lib/c_bindings/C_LinkUniversal.cpp +++ b/lib/c_bindings/C_LinkUniversal.cpp @@ -88,6 +88,11 @@ bool C_LinkUniversal_send(C_LinkUniversalHandle handle, u16 data) { return static_cast(handle)->send(data); } +bool C_LinkUniversal_didQueueOverflow(C_LinkUniversalHandle handle, + bool clear) { + return static_cast(handle)->didQueueOverflow(clear); +} + void C_LinkUniversal_resetTimer(C_LinkUniversalHandle handle) { return static_cast(handle)->resetTimer(); } diff --git a/lib/c_bindings/C_LinkUniversal.h b/lib/c_bindings/C_LinkUniversal.h index 03371c9..a0e1fc6 100644 --- a/lib/c_bindings/C_LinkUniversal.h +++ b/lib/c_bindings/C_LinkUniversal.h @@ -79,6 +79,7 @@ u16 C_LinkUniversal_peek(C_LinkUniversalHandle handle, u8 playerId); bool C_LinkUniversal_send(C_LinkUniversalHandle handle, u16 data); +bool C_LinkUniversal_didQueueOverflow(C_LinkUniversalHandle handle, bool clear); void C_LinkUniversal_resetTimer(C_LinkUniversalHandle handle); C_LinkUniversal_State C_LinkUniversal_getState(C_LinkUniversalHandle handle); diff --git a/lib/c_bindings/C_LinkWireless.cpp b/lib/c_bindings/C_LinkWireless.cpp index 2341987..6e98161 100644 --- a/lib/c_bindings/C_LinkWireless.cpp +++ b/lib/c_bindings/C_LinkWireless.cpp @@ -151,8 +151,8 @@ u8 C_LinkWireless_currentPlayerId(C_LinkWirelessHandle handle) { return static_cast(handle)->currentPlayerId(); } -bool C_LinkWireless_didQueueOverflow(C_LinkWirelessHandle handle) { - return static_cast(handle)->didQueueOverflow(); +bool C_LinkWireless_didQueueOverflow(C_LinkWirelessHandle handle, bool clear) { + return static_cast(handle)->didQueueOverflow(clear); } C_LinkWireless_Error C_LinkWireless_getLastError(C_LinkWirelessHandle handle, diff --git a/lib/c_bindings/C_LinkWireless.h b/lib/c_bindings/C_LinkWireless.h index 6e1f807..b88b112 100644 --- a/lib/c_bindings/C_LinkWireless.h +++ b/lib/c_bindings/C_LinkWireless.h @@ -123,7 +123,7 @@ bool C_LinkWireless_isSessionActive(C_LinkWirelessHandle handle); bool C_LinkWireless_isServerClosed(C_LinkWirelessHandle handle); u8 C_LinkWireless_playerCount(C_LinkWirelessHandle handle); u8 C_LinkWireless_currentPlayerId(C_LinkWirelessHandle handle); -bool C_LinkWireless_didQueueOverflow(C_LinkWirelessHandle handle); +bool C_LinkWireless_didQueueOverflow(C_LinkWirelessHandle handle, bool clear); C_LinkWireless_Error C_LinkWireless_getLastError(C_LinkWirelessHandle handle, bool clear);