summaryrefslogtreecommitdiff
path: root/streamdeck.c
diff options
context:
space:
mode:
authorJoshua Liu <joshua.liu@sourceobby.com>2025-04-30 16:29:48 -0400
committerJoshua Liu <joshua.liu@sourceobby.com>2025-04-30 16:29:48 -0400
commitdd58ddd94dfecbe378f3a0fc190a5f219321acc1 (patch)
tree81e6907aa0d24ce92fccc6a9ee9c180d72d9d260 /streamdeck.c
feat: inital commit, mostly moving files from old repository. streamdeck.c now contains basic HIDAPI implementations, util library is still mostly empty
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;
+}
+