Skip to content

Commit b2e2143

Browse files
committed
Added pdmqry usage to the applet/app-playstats example.
1 parent d459edb commit b2e2143

File tree

1 file changed

+32
-1
lines changed
  • applet/app-playstats/source

1 file changed

+32
-1
lines changed

applet/app-playstats/source/main.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
#include <stdio.h>
33
#include <stdlib.h>
44
#include <string.h>
5+
#include <time.h>
56

67
// Include the main libnx system header, for Switch development
78
#include <switch.h>
89

910
// This example shows how to use applet to get playstats for applications. See also libnx applet.h. See applet.h for the requirements for using this.
11+
// This also shows how to use pdmqry, see also libnx pdm.h.
1012

1113
/// Main program entrypoint
1214
int main(int argc, char* argv[])
@@ -18,15 +20,23 @@ int main(int argc, char* argv[])
1820
// take a look at the graphics/opengl set of examples, which uses EGL instead.
1921
consoleInit(NULL);
2022

21-
printf("applet application play-stats example\n");
23+
printf("application play-stats example\n");
2224

2325
Result rc=0;
2426
PdmApplicationPlayStatistics stats[1];
27+
PdmApplicationEvent events[1];
2528
u64 titleIDs[1] = {0x010021B002EEA000}; // Change this to the titleID of the current-process / the titleID you want to use.
2629
s32 total_out;
2730
s32 i;
31+
bool initflag=0;
32+
33+
// Not needed if you just want to use the applet cmds.
34+
rc = pdmqryInitialize();
35+
if (R_FAILED(rc)) printf("pdmqryInitialize(): 0x%x\n", rc);
36+
if (R_SUCCEEDED(rc)) initflag = true;
2837

2938
printf("Press A to get playstats.\n");
39+
if (initflag) printf("Press X to use pdmqry.\n");
3040
printf("Press + to exit.\n");
3141

3242
// Main loop
@@ -59,10 +69,31 @@ int main(int argc, char* argv[])
5969
}
6070
}
6171

72+
if (initflag && (kDown & KEY_X)) {
73+
memset(events, 0, sizeof(events));
74+
total_out = 0;
75+
76+
rc = pdmqryQueryApplicationEvent(0, events, sizeof(events)/sizeof(PdmApplicationEvent), &total_out);
77+
printf("pdmqryQueryApplicationEvent(): 0x%x\n", rc);
78+
if (R_SUCCEEDED(rc)) {
79+
printf("total_out: %d\n", total_out);
80+
for (i=0; i<total_out; i++) {
81+
time_t tmptime = pdmPlayTimestampToPosix(events[i].timestampUser);
82+
83+
printf("%d: ", i);
84+
printf("titleID = 0x%08lX, entryindex = 0x%x, timestampUser = %u, timestampNetwork = %u, eventType = %u, timestampUser = %s\n", events[i].titleID, events[i].entryindex, events[i].timestampUser, events[i].timestampNetwork, events[i].eventType, ctime(&tmptime));
85+
}
86+
}
87+
88+
// For more pdmqry cmds see pdm.h.
89+
}
90+
6291
// Update the console, sending a new frame to the display
6392
consoleUpdate(NULL);
6493
}
6594

95+
if (initflag) pdmqryExit();
96+
6697
// Deinitialize and clean up resources used by the console (important!)
6798
consoleExit(NULL);
6899
return 0;

0 commit comments

Comments
 (0)