#include "streamdeck.h" #include struct Image { void* data; size_t size; }; struct Key { bool isFolder; void* command; image* key; }; struct Screen { key* keys; }; struct Handler { hid_device* handler; }; struct Streamdeck { handler* hid_handle; }; 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; } streamdeck* connect(handler* deck) { streamdeck* res = malloc(sizeof(streamdeck)); res->hid_handle = deck; if (hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)) {} if (resetkeystream(res->hid_handle) != 0) {} return res; } int close() {} int createreadthread() { return 0; } int resetkeystream(handler* deck) { unsigned char data[IMAGE_REPORT_LENGTH]; if (!memset(data, 0x00, IMAGE_REPORT_LENGTH)) return -2; data[0] = 0x02; if (hid_write(deck->handler, data, IMAGE_REPORT_LENGTH) == -1) return -1; return 0; } int reset(handler* deck) { unsigned char data[17]; if (!memset(data, 0x00, 17)) return -2; data[0] = 0x0B; data[1] = 0x63; if (hid_send_feature_report(deck->handler, data, 17) == -1) return -1; return 0; }