refactor(core): Extra position state change data struct.

* Separate header and data struct for the event.
* Remove duplicate struct in split code.
This commit is contained in:
Pete Johanson
2021-01-17 16:36:01 -05:00
parent 95acbd8859
commit 003db892ad
6 changed files with 31 additions and 34 deletions

View File

@@ -33,22 +33,14 @@ static struct bt_uuid_128 uuid = BT_UUID_INIT_128(ZMK_SPLIT_BT_SERVICE_UUID);
static struct bt_gatt_discover_params discover_params;
static struct bt_gatt_subscribe_params subscribe_params;
struct zmk_split_peripheral_event {
uint32_t position;
uint32_t state;
int32_t timestamp;
};
K_MSGQ_DEFINE(peripheral_event_msgq, sizeof(struct zmk_split_peripheral_event),
K_MSGQ_DEFINE(peripheral_event_msgq, sizeof(struct zmk_position_state_changed_data),
CONFIG_ZMK_SPLIT_BLE_CENTRAL_POSITION_QUEUE_SIZE, 4);
void peripheral_event_work_callback(struct k_work *work) {
struct zmk_split_peripheral_event ev;
struct zmk_position_state_changed_data ev;
while (k_msgq_get(&peripheral_event_msgq, &ev, K_NO_WAIT) == 0) {
struct position_state_changed *pos_ev = new_position_state_changed();
pos_ev->position = ev.position;
pos_ev->state = ev.state;
pos_ev->timestamp = ev.timestamp;
pos_ev->data = ev;
LOG_DBG("Trigger key position state change for %d", ev.position);
ZMK_EVENT_RAISE(pos_ev);
@@ -82,7 +74,7 @@ static uint8_t split_central_notify_func(struct bt_conn *conn,
if (changed_positions[i] & BIT(j)) {
uint32_t position = (i * 8) + j;
bool pressed = position_state[i] & BIT(j);
struct zmk_split_peripheral_event ev = {
struct zmk_position_state_changed_data ev = {
.position = position, .state = pressed, .timestamp = k_uptime_get()};
k_msgq_put(&peripheral_event_msgq, &ev, K_NO_WAIT);