2
2
#include <stdio.h>
3
3
#include <stdlib.h>
4
4
#include <string.h>
5
+ #include <time.h>
5
6
6
7
// Include the main libnx system header, for Switch development
7
8
#include <switch.h>
8
9
9
10
// 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.
10
12
11
13
/// Main program entrypoint
12
14
int main (int argc , char * argv [])
@@ -18,15 +20,23 @@ int main(int argc, char* argv[])
18
20
// take a look at the graphics/opengl set of examples, which uses EGL instead.
19
21
consoleInit (NULL );
20
22
21
- printf ("applet application play-stats example\n" );
23
+ printf ("application play-stats example\n" );
22
24
23
25
Result rc = 0 ;
24
26
PdmApplicationPlayStatistics stats [1 ];
27
+ PdmApplicationEvent events [1 ];
25
28
u64 titleIDs [1 ] = {0x010021B002EEA000 }; // Change this to the titleID of the current-process / the titleID you want to use.
26
29
s32 total_out ;
27
30
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;
28
37
29
38
printf ("Press A to get playstats.\n" );
39
+ if (initflag ) printf ("Press X to use pdmqry.\n" );
30
40
printf ("Press + to exit.\n" );
31
41
32
42
// Main loop
@@ -59,10 +69,31 @@ int main(int argc, char* argv[])
59
69
}
60
70
}
61
71
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
+
62
91
// Update the console, sending a new frame to the display
63
92
consoleUpdate (NULL );
64
93
}
65
94
95
+ if (initflag ) pdmqryExit ();
96
+
66
97
// Deinitialize and clean up resources used by the console (important!)
67
98
consoleExit (NULL );
68
99
return 0 ;
0 commit comments