@@ -54,6 +54,16 @@ static const struct bt_uuid_128 split_service_uuid = BT_UUID_INIT_128(ZMK_SPLIT_
54
54
K_MSGQ_DEFINE (peripheral_event_msgq , sizeof (struct zmk_position_state_changed ),
55
55
CONFIG_ZMK_SPLIT_BLE_CENTRAL_POSITION_QUEUE_SIZE , 4 );
56
56
57
+ void peripheral_event_work_callback (struct k_work * work ) {
58
+ struct zmk_position_state_changed ev ;
59
+ while (k_msgq_get (& peripheral_event_msgq , & ev , K_NO_WAIT ) == 0 ) {
60
+ LOG_DBG ("Trigger key position state change for %d" , ev .position );
61
+ ZMK_EVENT_RAISE (new_zmk_position_state_changed (ev ));
62
+ }
63
+ }
64
+
65
+ K_WORK_DEFINE (peripheral_event_work , peripheral_event_work_callback );
66
+
57
67
int peripheral_slot_index_for_conn (struct bt_conn * conn ) {
58
68
for (int i = 0 ; i < ZMK_BLE_SPLIT_PERIPHERAL_COUNT ; i ++ ) {
59
69
if (peripherals [i ].conn == conn ) {
@@ -92,6 +102,22 @@ int release_peripheral_slot(int index) {
92
102
}
93
103
slot -> state = PERIPHERAL_SLOT_STATE_OPEN ;
94
104
105
+ // Raise events releasing any active positions from this peripheral
106
+ for (int i = 0 ; i < POSITION_STATE_DATA_LEN ; i ++ ) {
107
+ for (int j = 0 ; j < 8 ; j ++ ) {
108
+ if (slot -> position_state [i ] & BIT (j )) {
109
+ uint32_t position = (i * 8 ) + j ;
110
+ struct zmk_position_state_changed ev = {.source = index ,
111
+ .position = position ,
112
+ .state = false,
113
+ .timestamp = k_uptime_get ()};
114
+
115
+ k_msgq_put (& peripheral_event_msgq , & ev , K_NO_WAIT );
116
+ k_work_submit (& peripheral_event_work );
117
+ }
118
+ }
119
+ }
120
+
95
121
for (int i = 0 ; i < POSITION_STATE_DATA_LEN ; i ++ ) {
96
122
slot -> position_state [i ] = 0U ;
97
123
slot -> changed_positions [i ] = 0U ;
@@ -136,16 +162,6 @@ int confirm_peripheral_slot_conn(struct bt_conn *conn) {
136
162
return 0 ;
137
163
}
138
164
139
- void peripheral_event_work_callback (struct k_work * work ) {
140
- struct zmk_position_state_changed ev ;
141
- while (k_msgq_get (& peripheral_event_msgq , & ev , K_NO_WAIT ) == 0 ) {
142
- LOG_DBG ("Trigger key position state change for %d" , ev .position );
143
- ZMK_EVENT_RAISE (new_zmk_position_state_changed (ev ));
144
- }
145
- }
146
-
147
- K_WORK_DEFINE (peripheral_event_work , peripheral_event_work_callback );
148
-
149
165
static uint8_t split_central_notify_func (struct bt_conn * conn ,
150
166
struct bt_gatt_subscribe_params * params , const void * data ,
151
167
uint16_t length ) {
0 commit comments