blob: 03ce6b55d2688459acbda807e9a2756bbc35e8cd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#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
}
}
|