#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 sync_star_key(void) { if (!is_synced) { // Send the state to the other side of the keyboard master_to_slave_t m2s = { is_star }; is_synced = transaction_rpc_send(SET_STAR_KEY, sizeof(m2s), &m2s); } } static uint8_t star_number = 0; #define LY_SYMB TD(TD_LAYER_SYMB) void star_key_process_record(uint16_t keycode, keyrecord_t *record) { switch (keycode) { case KC_O: star_number = (star_number + 1) % 3; if (star_number != 0 && is_star == 0) { is_star = 1; is_synced = 0; } else if (star_number == 0) { is_star = 0; is_synced = 0; } return; case LY_SYMB: // Ignore the layer events return; default: if (star_number != 0) { star_number = 0; is_star = 0; is_synced = 0; } return; // Process all other keycodes normally } }