From dd58ddd94dfecbe378f3a0fc190a5f219321acc1 Mon Sep 17 00:00:00 2001 From: Joshua Liu Date: Wed, 30 Apr 2025 16:29:48 -0400 Subject: feat: inital commit, mostly moving files from old repository. streamdeck.c now contains basic HIDAPI implementations, util library is still mostly empty --- streamdeck.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 streamdeck.c (limited to 'streamdeck.c') diff --git a/streamdeck.c b/streamdeck.c new file mode 100644 index 0000000..e11d79d --- /dev/null +++ b/streamdeck.c @@ -0,0 +1,64 @@ +#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; +}; + +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; +} + -- cgit v1.2.3