aboutsummaryrefslogtreecommitdiff
path: root/qmk/keyboards/sofle_choc/keymaps/custom/star_key.c
diff options
context:
space:
mode:
Diffstat (limited to 'qmk/keyboards/sofle_choc/keymaps/custom/star_key.c')
-rw-r--r--qmk/keyboards/sofle_choc/keymaps/custom/star_key.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/star_key.c b/qmk/keyboards/sofle_choc/keymaps/custom/star_key.c
new file mode 100644
index 0000000..8c04c00
--- /dev/null
+++ b/qmk/keyboards/sofle_choc/keymaps/custom/star_key.c
@@ -0,0 +1,37 @@
+#include QMK_KEYBOARD_H
+#include "transactions.h"
+#include "star_key.h"
+
+typedef struct _master_to_slave_t {
+ int is_star;
+} master_to_slave_t;
+
+
+bool is_star = 0;
+static bool is_synced = 1;
+
+// Handler for the slave, receive the star information
+void user_sync_a_slave_handler(uint8_t in_buflen, const void* in_data, uint8_t out_buflen, void* out_data) {
+ const master_to_slave_t *m2s = (const master_to_slave_t*)in_data;
+ is_star = m2s->is_star;
+}
+
+void star_key_init(void) {
+ if (!is_keyboard_master()) {
+ transaction_register_rpc(SET_STAR_KEY, user_sync_a_slave_handler);
+ }
+}
+
+void set_star_key(bool status) {
+ is_star = status;
+ is_synced = 0;
+}
+
+void sync_star_key(void) {
+ if (!is_synced) {
+ // Send the state to the other side of the keyboard
+ master_to_slave_t m2s = { is_star };
+ transaction_rpc_send(SET_STAR_KEY, sizeof(m2s), &m2s);
+ is_synced = 1;
+ }
+}