summaryrefslogtreecommitdiff
path: root/streamdeck.c
diff options
context:
space:
mode:
authorJoshua Liu <joshua.liu@sourceobby.com>2025-08-21 16:07:02 -0400
committerJoshua Liu <joshua.liu@sourceobby.com>2025-08-21 16:07:02 -0400
commitda525aae81d7b1221e73a4b1a9c048bfa832bf37 (patch)
treebdba8a5867ef52b06489a6ab46ef0ad387b15893 /streamdeck.c
parentfdf5c358291960327931f44d6b09f4fe892e1930 (diff)
feat: some changes that I made while testing that I am too lazy to remove, but also added infrastructure to support reading the keystream
Diffstat (limited to 'streamdeck.c')
-rw-r--r--streamdeck.c92
1 files changed, 46 insertions, 46 deletions
diff --git a/streamdeck.c b/streamdeck.c
index 739f5b9..4de63a3 100644
--- a/streamdeck.c
+++ b/streamdeck.c
@@ -1,50 +1,15 @@
#include "streamdeck.h"
#include <bits/pthreadtypes.h>
+#include <hidapi/hidapi.h>
#include <pthread.h>
-
-struct Image {
- void* data;
- size_t size;
-};
-
-struct Key {
- bool isFolder;
- void* command;
- image* key;
- pthread_mutex_t key_mutex;
-};
-
-/* How should we deal with invalid keys with nothing? Well we can use
- * a bitmask */
-/*
- * Keys are numbered left to right.
- * so in the mini streamdeck we have
- * 0 1 2
- * 3 4 5
- */
-struct Screen {
- key* keys;
-};
-
-struct Handler {
- hid_device* handler;
-};
-
-struct Streamdeck {
- handler* hid_handle;
- void* callback_funcs;
- screen* curr_screen;
- int numkeys;
- int devicetype;
-};
-
pthread_mutex_t inflate_lock;
int update_current_folder (screen* folder);
int load_folder ();
int load_key ();
-int createreadthread();
+int createreadthread (streamdeck* target);
+void read_deck_stream (void* target);
int
@@ -94,12 +59,13 @@ create_hid_handler ()
/*
* 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;
- }
+ /* We will likely only want to set this later, or maybe never. */
+ // 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;
}
@@ -120,6 +86,7 @@ connect()
/* Upon second thought, this may actually not be necessary */
pthread_mutex_init(&(startscreen->keys + i)->key_mutex , NULL);
}
+ res->curr_screen = startscreen;
}
/* We will either to this before or after we initialize the streamdeck struct */
if (resetkeystream(res->hid_handle) != 0)
@@ -130,8 +97,10 @@ connect()
}
int
-createreadthread()
+createreadthread(streamdeck* target)
{
+ if (pthread_create(pthread_t *restrict newthread, NULL, read_deck_stream, target))
+ return 1;
return 0;
}
@@ -142,8 +111,11 @@ resetkeystream(handler* deck)
if (!memset(data, 0x00, IMAGE_REPORT_LENGTH))
return -2;
data[0] = 0x02;
- if (hid_write(deck->handler, data, IMAGE_REPORT_LENGTH) == -1)
+ if (hid_write(deck->handler, data, IMAGE_REPORT_LENGTH) < 0)
+ {
+ printf("Unable to write()/2: %ls\n", hid_error(deck->handler));
return -1;
+ }
return 0;
}
@@ -235,3 +207,31 @@ clean_exit ()
hid_exit ();
}
+/* Eventually want to change this to return the old
+ * brightness level */
+int
+set_brightness (streamdeck* deck, int new_level)
+{
+ new_level = (new_level > 100) ? 100 : new_level;
+ unsigned char data[17];
+ if (set_data(data) == -1)
+ return -2;
+ data[0] = 0x05;
+ data[1] = 0x55;
+ data[2] = 0xaa;
+ data[3] = 0xd1;
+ data[4] = 0x01;
+ data[5] = new_level;
+ if (hid_send_feature_report(deck->hid_handle->handler, data, 17) == -1)
+ return -1;
+ return 0;
+}
+
+void
+read_deck_stream (void* target)
+{
+ streamdeck* deck = (streamdeck*) target;
+ if (!deck)
+ return;
+}
+