summaryrefslogtreecommitdiff
path: root/streamdeck.c
diff options
context:
space:
mode:
Diffstat (limited to 'streamdeck.c')
-rw-r--r--streamdeck.c64
1 files changed, 64 insertions, 0 deletions
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 <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;
+}
+