diff --git a/README.md b/README.md index 4f3349b..879f61e 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ Name | Type | Default | Description --- | --- | --- | --- `baudRate` | **BaudRate** | `BAUD_RATE_1` | Sets a specific baud rate. `timeout` | **u32** | `3` | Maximum number of *frames* without receiving data from other player before marking them as disconnected or resetting the connection. -`interval` | **u16** | `50` | Number of *1024-cycle ticks* (61.04μs) between transfers *(50 = 3.052ms)*. It's the interval of Timer #`sendTimerId`. Lower values will transfer faster but also consume more CPU. +`interval` | **u16** | `50` | Number of *1024-cycle ticks* (61.04μs) between transfers *(50 = 3.052ms)*. It's the interval of Timer #`sendTimerId`. Lower values will transfer faster but also consume more CPU. You can use `Link::perFrame(...)` to convert from *packets per frame* to *interval values*. `sendTimerId` | **u8** *(0~3)* | `3` | GBA Timer to use for sending. You can update these values at any time without creating a new instance: @@ -171,7 +171,7 @@ Name | Type | Default | Description `retransmission` | **bool** | `true` | If `true`, the library handles retransmission for you, so there should be no packet loss. `maxPlayers` | **u8** *(2~5)* | `5` | Maximum number of allowed players. If your game only supports -for example- two players, set this to `2` as it will make transfers faster. `timeout` | **u32** | `10` | Maximum number of *frames* without receiving data from other player before resetting the connection. -`interval` | **u16** | `50` | Number of *1024-cycle ticks* (61.04μs) between transfers *(50 = 3.052ms)*. It's the interval of Timer #`sendTimerId`. Lower values will transfer faster but also consume more CPU. +`interval` | **u16** | `50` | Number of *1024-cycle ticks* (61.04μs) between transfers *(50 = 3.052ms)*. It's the interval of Timer #`sendTimerId`. Lower values will transfer faster but also consume more CPU. You can use `Link::perFrame(...)` to convert from *packets per frame* to *interval values*. `sendTimerId` | **u8** *(0~3)* | `3` | GBA Timer to use for sending. `asyncACKTimerId` | **s8** *(0~3 or -1)* | `-1` | GBA Timer to use for ACKs. If you have free timers, use one here to reduce CPU usage. diff --git a/lib/LinkCable.hpp b/lib/LinkCable.hpp index c8a1d8f..80fcfeb 100644 --- a/lib/LinkCable.hpp +++ b/lib/LinkCable.hpp @@ -106,6 +106,8 @@ class LinkCable { * *(50 = 3.052ms)*. It's the interval of Timer #`sendTimerId`. Lower values * will transfer faster but also consume more CPU. * @param sendTimerId `(0~3)` GBA Timer to use for sending. + * \warning You can use `Link::perFrame(...)` to convert from *packets per + * frame* to *interval values*. */ explicit LinkCable(BaudRate baudRate = BAUD_RATE_1, u32 timeout = LINK_CABLE_DEFAULT_TIMEOUT, diff --git a/lib/LinkWireless.hpp b/lib/LinkWireless.hpp index 00e45e7..5fe40f6 100644 --- a/lib/LinkWireless.hpp +++ b/lib/LinkWireless.hpp @@ -258,6 +258,8 @@ class LinkWireless { * @param sendTimerId GBA Timer to use for sending. * @param asyncACKTimerId GBA Timer to use for ACKs. If you have free timers, * use one here to reduce CPU usage. + * \warning You can use `Link::perFrame(...)` to convert from *packets per + * frame* to *interval values*. */ explicit LinkWireless( bool forwarding = true, diff --git a/lib/_link_common.hpp b/lib/_link_common.hpp index c18051f..4c004d6 100644 --- a/lib/_link_common.hpp +++ b/lib/_link_common.hpp @@ -239,6 +239,11 @@ class Queue { volatile bool _needsClear = false; }; +// Packets per frame -> Timer interval +static inline u16 perFrame(u16 packets) { + return (1667 * 1024) / (packets * 6104); +} + // mGBA Logging #if LINK_ENABLE_DEBUG_LOGS != 0