mirror of
https://github.com/afska/gba-link-connection.git
synced 2026-09-08 00:47:13 -05:00
Adding signal levels to LinkUniversal_full example
This commit is contained in:
@@ -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("");
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user