Adding signal levels to LinkUniversal_full example

This commit is contained in:
Rodrigo Alfonso
2025-01-13 00:36:25 -03:00
parent 8021b391a8
commit 200f33bd97
2 changed files with 41 additions and 0 deletions

View File

@@ -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("");

View File

@@ -16,12 +16,16 @@ static std::unique_ptr<InputHandler> rHandler =
std::unique_ptr<InputHandler>(new InputHandler());
static std::unique_ptr<InputHandler> selectHandler =
std::unique_ptr<InputHandler>(new InputHandler());
static std::unique_ptr<InputHandler> rightHandler =
std::unique_ptr<InputHandler>(new InputHandler());
inline void send(u16 data) {
DEBULOG("-> " + std::to_string(data));
linkConnection->send(data);
}
void printWirelessSignalLevel();
std::vector<Background*> 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
}