From 200f33bd974dff3ec8264a16d0b69f4e358bb36c Mon Sep 17 00:00:00 2001 From: Rodrigo Alfonso Date: Mon, 13 Jan 2025 00:36:25 -0300 Subject: [PATCH] Adding signal levels to LinkUniversal_full example --- examples/LinkCable_full/src/main.cpp | 3 ++ .../LinkCable_full/src/scenes/TestScene.cpp | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/examples/LinkCable_full/src/main.cpp b/examples/LinkCable_full/src/main.cpp index a16ffce..38c2ab1 100644 --- a/examples/LinkCable_full/src/main.cpp +++ b/examples/LinkCable_full/src/main.cpp @@ -98,6 +98,9 @@ void printTutorial() { DEBULOG("A: send counter++ (cont)"); DEBULOG("L: send counter++ twice (once)"); DEBULOG("R: send counter++ twice (cont)"); +#ifdef USE_LINK_UNIVERSAL + DEBULOG("RIGHT: get signal level"); +#endif DEBULOG("SELECT: force lag (9k lines)"); DEBULOG("DOWN: turn off connection"); DEBULOG(""); diff --git a/examples/LinkCable_full/src/scenes/TestScene.cpp b/examples/LinkCable_full/src/scenes/TestScene.cpp index 4177097..a947cd1 100644 --- a/examples/LinkCable_full/src/scenes/TestScene.cpp +++ b/examples/LinkCable_full/src/scenes/TestScene.cpp @@ -16,12 +16,16 @@ static std::unique_ptr rHandler = std::unique_ptr(new InputHandler()); static std::unique_ptr selectHandler = std::unique_ptr(new InputHandler()); +static std::unique_ptr rightHandler = + std::unique_ptr(new InputHandler()); inline void send(u16 data) { DEBULOG("-> " + std::to_string(data)); linkConnection->send(data); } +void printWirelessSignalLevel(); + std::vector TestScene::backgrounds() { return {}; } @@ -51,6 +55,7 @@ void TestScene::tick(u16 keys) { lHandler->setIsPressed(keys & KEY_L); rHandler->setIsPressed(keys & KEY_R); selectHandler->setIsPressed(keys & KEY_SELECT); + rightHandler->setIsPressed(keys & KEY_RIGHT); // log events if (!isConnected && linkConnection->isConnected()) { @@ -63,10 +68,14 @@ void TestScene::tick(u16 keys) { isConnected = false; DEBULOG("! disconnected"); } + + // other buttons if (selectHandler->hasBeenPressedNow()) { DEBULOG("! lagging..."); Link::wait(9000); } + if (rightHandler->hasBeenReleasedNow()) + printWirelessSignalLevel(); // determine which value should be sent u16 value = LINK_CABLE_NO_DATA; @@ -102,3 +111,32 @@ void TestScene::tick(u16 keys) { } } } + +void printWirelessSignalLevel() { +#ifdef USE_LINK_UNIVERSAL + if (linkConnection->getMode() != LinkUniversal::Mode::LINK_WIRELESS) { + DEBULOG("! not in wireless mode"); + return; + } + + LinkWireless::SignalLevelResponse response; + if (!linkConnection->getLinkWireless()->getSignalLevel(response)) { + DEBULOG(linkConnection->getLinkWireless()->getLastError() == + LinkWireless::Error::BUSY_TRY_AGAIN + ? "! busy, try again" + : "! failed"); + return; + } + + if (linkConnection->getLinkWireless()->getState() == + LinkWireless::State::SERVING) { + for (u32 i = 1; i < linkConnection->playerCount(); i++) + DEBULOG("P" + std::to_string(i) + ": " + + std::to_string(response.signalLevels[i] * 100 / 255) + "%"); + } else { + auto playerId = linkConnection->currentPlayerId(); + DEBULOG("P" + std::to_string(playerId) + ": " + + std::to_string(response.signalLevels[playerId] * 100 / 255) + "%"); + } +#endif +}