blob: e11d79da41c8c98bdcd67ce6a7fd2a4a355a80a1 (
plain)
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
|
#include "streamdeck.h"
#include <hidapi/hidapi.h>
struct Image {
void* data;
size_t size;
};
struct Key {
bool isFolder;
void* command;
image* key;
};
struct Screen {
key* keys;
};
struct Handler {
hid_device* handler;
};
handler* create_hid_handler() {
handler* res = NULL;
res = malloc(sizeof(handler));
if (!res) {
return NULL;
}
/*
* Init the HIDAPI library
*/
if (hid_init() < 0) {
(void) fprintf(stderr, "Could not init the HID library\n");
free(res);
return NULL;
}
/*
* Create the device handler
*/
res->handler = hid_open(0x0fd9, 0x0063, NULL);
if (!res->handler) {
(void) fprintf(stderr, "Could not open Streamdeck!\n");
free(res);
hid_exit();
return NULL;
}
/*
* Set handler to be non-blocking
*/
if (hid_set_nonblocking(res->handler, 1) < 0) {
(void) fprintf(stderr, "Could not set HIDAPI handler to be non-blocking\n");
free(res);
hid_exit();
return NULL;
}
return res;
}
|