Last active
October 30, 2024 15:23
-
-
Save drashna/7c0d612223107b81ab2716f224559dab to your computer and use it in GitHub Desktop.
Caps word state sync
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#define SPLIT_TRANSACTION_IDS_USER USER_SYNC_A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct _master_to_slave_t { | |
bool is_caps_words_on :1; | |
} master_to_slave_t; | |
master_to_slave_t sync_data; | |
void user_config_sync(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, | |
uint8_t target2initiator_buffer_size, void* target2initiator_buffer) { | |
if (initiator2target_buffer_size == sizeof(master_to_slave_t)) { | |
memcpy(&sync_data, initiator2target_buffer, initiator2target_buffer_size); | |
} | |
} | |
void keyboard_post_init_user(void) { | |
transaction_register_rpc(USER_SYNC_A, user_sync_a_slave_handler); | |
} | |
void housekeeping_task_user(void) { | |
if (is_keyboard_master()) { | |
// Interact with slave every 500ms | |
static uint32_t last_sync = 0; | |
if (timer_elapsed32(last_sync) > 500) { | |
master_to_slave_t m2s = { .is_caps_words_on = is_caps_words_on() }; | |
if(transaction_rpc_send(USER_SYNC_A, sizeof(master_to_slave_t), &m2s) { | |
last_sync = timer_read32(); | |
} else { | |
dprint("Slave sync failed!\n"); | |
} | |
} | |
} else { // slave side | |
if (sync_data.is_caps_words_on) { | |
caps_word_on(); | |
} else { | |
caps_word_off(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment