mirror of
https://github.com/switchbrew/switch-examples.git
synced 2025-07-01 09:12:14 +02:00
Fix console updates
This commit is contained in:
parent
443e8201b8
commit
f97dcd6e22
@ -9,11 +9,6 @@
|
||||
|
||||
// See also libnx nfc.h.
|
||||
|
||||
#define PRINT_UPD(fmt, ...) ({ \
|
||||
printf(fmt, ## __VA_ARGS__); \
|
||||
consoleUpdate(NULL); \
|
||||
})
|
||||
|
||||
// Indefinitely wait for an event to be signaled
|
||||
// Break when + is pressed, or if the application should quit (in this case, return value will be non-zero)
|
||||
Result eventWaitLoop(Event *event) {
|
||||
@ -27,6 +22,7 @@ Result eventWaitLoop(Event *event) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
// Print raw data as hexadecimal numbers.
|
||||
void print_hex(void *buf, size_t size) {
|
||||
u8 *data = (u8 *)buf;
|
||||
for (size_t i=0; i<size; i++)
|
||||
@ -47,10 +43,10 @@ int main(int argc, char* argv[])
|
||||
// take a look at the graphics/opengl set of examples, which uses EGL instead.
|
||||
consoleInit(NULL);
|
||||
|
||||
PRINT_UPD("NFC example program.\n");
|
||||
|
||||
PRINT_UPD("Scan an amiibo tag to display its character.\n");
|
||||
PRINT_UPD("Press + to exit.\n\n");
|
||||
printf("NFC example program.\n");
|
||||
printf("Scan an amiibo tag to display its character.\n");
|
||||
printf("Press + to exit.\n\n");
|
||||
consoleUpdate(NULL);
|
||||
|
||||
// Initialize the nfp:user and nfc:user services.
|
||||
rc = nfpuInitialize();
|
||||
@ -67,7 +63,8 @@ int main(int argc, char* argv[])
|
||||
|
||||
// Wait for a change in availability.
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
PRINT_UPD("NFC is disabled. Please turn off plane mode via the quick settings to continue.\n");
|
||||
printf("NFC is disabled. Please turn off plane mode via the quick settings to continue.\n");
|
||||
consoleUpdate(NULL);
|
||||
rc = eventWaitLoop(&availability_change_event);
|
||||
}
|
||||
|
||||
@ -97,14 +94,18 @@ int main(int argc, char* argv[])
|
||||
|
||||
// Start the detection of tags.
|
||||
rc = nfpuStartDetection(controller);
|
||||
if (R_SUCCEEDED(rc))
|
||||
PRINT_UPD("Scanning for a tag...\n");
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
printf("Scanning for a tag...\n");
|
||||
consoleUpdate(NULL);
|
||||
}
|
||||
|
||||
// Wait until a tag is detected.
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
rc = eventWaitLoop(&activate_event);
|
||||
if (R_SUCCEEDED(rc))
|
||||
PRINT_UPD("A tag was detected, please do not remove it from the NFC spot.\n");
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
printf("A tag was detected, please do not remove it from the NFC spot.\n");
|
||||
consoleUpdate(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
// If a tag was successfully detected, load it into memory.
|
||||
@ -116,19 +117,22 @@ int main(int argc, char* argv[])
|
||||
NfpuModelInfo model_info = {0};
|
||||
rc = nfpuGetModelInfo(controller, &model_info);
|
||||
|
||||
if (R_SUCCEEDED(rc))
|
||||
PRINT_UPD("Amiibo ID: ");
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
printf("Amiibo ID: ");
|
||||
print_hex(model_info.amiibo_id, 8);
|
||||
consoleUpdate(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
PRINT_UPD("You can now remove the tag.\n");
|
||||
printf("You can now remove the tag.\n");
|
||||
consoleUpdate(NULL);
|
||||
eventWaitLoop(&deactivate_event);
|
||||
}
|
||||
|
||||
// If an error happened during detection/reading, print it.
|
||||
if (R_FAILED(rc))
|
||||
PRINT_UPD("Error: 0x%x.\n", rc);
|
||||
printf("Error: 0x%x.\n", rc);
|
||||
|
||||
// Unmount the tag.
|
||||
nfpuUnmount(controller);
|
||||
@ -137,11 +141,14 @@ int main(int argc, char* argv[])
|
||||
nfpuStopDetection(controller);
|
||||
|
||||
// Wait for the user to explicitely exit.
|
||||
PRINT_UPD("Press + to exit.\n");
|
||||
printf("Press + to exit.\n");
|
||||
while (appletMainLoop()) {
|
||||
hidScanInput();
|
||||
if (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_PLUS)
|
||||
break;
|
||||
|
||||
// Update the console, sending a new frame to the display
|
||||
consoleUpdate(NULL);
|
||||
}
|
||||
|
||||
// Cleanup.
|
||||
|
Loading…
Reference in New Issue
Block a user