This example can be found in Development\examples\c\listener\listener.c
.
This example shows how to implement the PST SDK using the PstTracker struct and how to receive data by implementing with pst_tracker_add_tracker_listener(). The example initializes the PST Tracker and grabs 100 datapoints.
In order to be able to run this example, the PST Tracker has to be initialized first. This can be done by starting the PST-Server and the PST-Client applications and making sure the calibration files have been downloaded and a tracking target is available. The tracking target can be the default Reference target or a newly trained or imported target. For more information, please see the Initialization section or check the PST Manual.
When compiling and running this example, please make sure that the required dependencies can be found by the executable (e.g. by copying the Development\Redist
directory into the build directory).
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#include <sys/signal.h>
#endif
static void Exithandler(int sig);
#ifdef WIN32
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
Exithandler(CEvent);
return TRUE;
}
#endif
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
static inline void PrintMatrix(float mat[16])
{
for (int y = 0; y < 4; ++y)
{
for (int x = 0; x < 4; ++x)
{
printf("%f \t", mat[x + y * 4]);
}
printf("\n");
}
}
static bool running = true;
static const uint32_t numberOfSamplesToGrab = 100;
{
static uint32_t samplesGrabbed = 0;
if (samplesGrabbed++ >= numberOfSamplesToGrab)
{
running = false;
}
{
PrintMatrix(mat);
}
}
static void Exithandler(int sig)
{
running = false;
}
void PrintLastErrorMessage()
{
char* last_error_message = NULL;
{
last_error_message = "Failed to allocate memory error.";
}
printf("last error message: %s \n", last_error_message);
}
{
{
PrintLastErrorMessage();
exit(status);
}
}
int main(int argc, char *argv[])
{
#ifdef WIN32
SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE);
#else
signal(SIGTERM, Exithandler);
signal(SIGKILL, Exithandler);
signal(SIGQUIT, Exithandler);
signal(SIGINT, Exithandler);
#endif
#ifdef WIN32
#else
CheckErrorCode(
pst_tracker_init4(&ctracker,
"",
"config.cfg",
"models.db", argv[1]));
#endif
{
printf("\nNo calibration information could be found in the configuration directory. "
"Please use the PST Server and PST Client application to initialize the PST Tracker and create/import a tracking target. "
"More information can be found in the Initialization section of the PST SDK manual and the PST Manual.\n\n");
printf("Press enter to continue...\n");
getchar();
return 1;
}
char* version_string;
printf("Running PST Server version %s \n", version_string);
printf("Put the Reference card in front of the PST in order to see tracking results.\n\n");
double fps;
printf("Frame rate set to %f \n", fps);
while (running)
{
#ifdef WIN32
Sleep(100);
#else
usleep(100000);
#endif
}
return 0;
}