forked from collabora/libsurvive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_example.c
71 lines (58 loc) · 2.03 KB
/
api_example.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <string.h>
#include <survive_api.h>
#include <os_generic.h>
static volatile int keepRunning = 1;
#ifdef __linux__
#include <assert.h>
#include <signal.h>
#include <stdlib.h>
void intHandler(int dummy) {
if (keepRunning == 0)
exit(-1);
keepRunning = 0;
}
#endif
static void log_fn(SurviveSimpleContext *actx, SurviveLogLevel logLevel, const char *msg) {
fprintf(stderr, "SimpleApi: %s\n", msg);
}
int main(int argc, char **argv) {
#ifdef __linux__
signal(SIGINT, intHandler);
signal(SIGTERM, intHandler);
signal(SIGKILL, intHandler);
#endif
SurviveSimpleContext *actx = survive_simple_init_with_logger(argc, argv, log_fn);
if (actx == 0) // implies -help or similiar
return 0;
survive_simple_start_thread(actx);
for (const SurviveSimpleObject *it = survive_simple_get_first_object(actx); it != 0;
it = survive_simple_get_next_object(actx, it)) {
printf("Found '%s'\n", survive_simple_object_name(it));
}
while (survive_simple_wait_for_update(actx) && keepRunning) {
for (const SurviveSimpleObject *it = survive_simple_get_next_updated(actx); it != 0;
it = survive_simple_get_next_updated(actx)) {
SurvivePose pose;
uint32_t timecode = survive_simple_object_get_latest_pose(it, &pose);
printf("%s %s (%u): %f %f %f %f %f %f %f\n", survive_simple_object_name(it),
survive_simple_serial_number(it), timecode, pose.Pos[0], pose.Pos[1], pose.Pos[2], pose.Rot[0],
pose.Rot[1], pose.Rot[2], pose.Rot[3]);
}
struct SurviveSimpleEvent event = {0};
while (survive_simple_next_event(actx, &event) != SurviveSimpleEventType_None) {
switch (event.event_type) {
case SurviveSimpleEventType_ButtonEvent: {
const struct SurviveSimpleButtonEvent *button_event = survive_simple_get_button_event(&event);
printf("%s button event %d %d\n", survive_simple_object_name(button_event->object),
(int)button_event->event_type, button_event->button_id);
}
case SurviveSimpleEventType_None:
break;
}
}
}
printf("Cleaning up\n");
survive_simple_close(actx);
return 0;
}