forked from MiCkSoftware/ShockEmu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpad-daemon.c
More file actions
54 lines (41 loc) · 974 Bytes
/
gpad-daemon.c
File metadata and controls
54 lines (41 loc) · 974 Bytes
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
#include <IOKit/hid/IOHIDManager.h>
#include <unistd.h>
#include <stdio.h>
#include "zhelpers.h"
#include "gamepad.h"
void *zmq_ctx;
void *publisher;
static void callback(int type, int page, int usage, int value)
{
char data[50];
if (usage == 1)
return;
/* printf("type=%d, page=%d, usage=%d, value=%d\n", type, page, usage, value); */
char to_send[] =
{ usage,
value,
};
zmq_send(publisher, to_send, 2, 0);
}
int main()
{
void* ctx;
/* initialize gamepad */
ctx = gamepad_init(1, 0, 0);
if (!ctx) {
puts("init failed");
return -1;
}
zmq_ctx = zmq_ctx_new();
publisher = zmq_socket(zmq_ctx, ZMQ_PUB);
int rc = zmq_bind(publisher, "tcp://*:54321");
assert(rc == 0);
/* set callback */
gamepad_set_callback(ctx, callback);
CFRunLoopRun();
zmq_close(publisher);
zmq_ctx_destroy(zmq_ctx);
/* terminate gamepad */
gamepad_term(ctx);
return 0;
}