From b0c03418ba3092b9d83ff406e1f23b03c9b0f6e6 Mon Sep 17 00:00:00 2001 From: Xudong Zheng <7pkvm5aw@slicealias.com> Date: Sat, 23 Dec 2023 17:42:31 -0500 Subject: [PATCH] refactor(split): move central sensor handling out of Bluetooth directory --- app/include/zmk/split/central.h | 5 +++++ app/src/split/bluetooth/central.c | 16 +--------------- app/src/split/central.c | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/app/include/zmk/split/central.h b/app/include/zmk/split/central.h index da4ff7f3a9f..afdc9cd22ee 100644 --- a/app/include/zmk/split/central.h +++ b/app/include/zmk/split/central.h @@ -7,5 +7,10 @@ #pragma once #include +#include void zmk_position_state_change_handle(struct zmk_position_state_changed *ev); + +#if ZMK_KEYMAP_HAS_SENSORS +void zmk_sensor_event_handle(struct zmk_sensor_event *ev); +#endif diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index 1394b4f3ea2..c8b3bcb25df 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -237,19 +237,6 @@ int confirm_peripheral_slot_conn(struct bt_conn *conn) { } #if ZMK_KEYMAP_HAS_SENSORS -K_MSGQ_DEFINE(peripheral_sensor_event_msgq, sizeof(struct zmk_sensor_event), - CONFIG_ZMK_SPLIT_BLE_CENTRAL_POSITION_QUEUE_SIZE, 4); - -void peripheral_sensor_event_work_callback(struct k_work *work) { - struct zmk_sensor_event ev; - while (k_msgq_get(&peripheral_sensor_event_msgq, &ev, K_NO_WAIT) == 0) { - LOG_DBG("Trigger sensor change for %d", ev.sensor_index); - raise_zmk_sensor_event(ev); - } -} - -K_WORK_DEFINE(peripheral_sensor_event_work, peripheral_sensor_event_work_callback); - static uint8_t split_central_sensor_notify_func(struct bt_conn *conn, struct bt_gatt_subscribe_params *params, const void *data, uint16_t length) { @@ -275,8 +262,7 @@ static uint8_t split_central_sensor_notify_func(struct bt_conn *conn, memcpy(ev.channel_data, sensor_event.channel_data, sizeof(struct zmk_sensor_channel_data) * sensor_event.channel_data_size); - k_msgq_put(&peripheral_sensor_event_msgq, &ev, K_NO_WAIT); - k_work_submit(&peripheral_sensor_event_work); + zmk_sensor_event_handle(&ev); return BT_GATT_ITER_CONTINUE; } diff --git a/app/src/split/central.c b/app/src/split/central.c index d51c3e6c572..96f379a2e5f 100644 --- a/app/src/split/central.c +++ b/app/src/split/central.c @@ -31,3 +31,23 @@ void zmk_position_state_change_handle(struct zmk_position_state_changed *ev) { k_msgq_put(&peripheral_event_msgq, ev, K_NO_WAIT); k_work_submit(&peripheral_event_work); } + +#if ZMK_KEYMAP_HAS_SENSORS +K_MSGQ_DEFINE(peripheral_sensor_event_msgq, sizeof(struct zmk_sensor_event), + CONFIG_ZMK_SPLIT_BLE_CENTRAL_POSITION_QUEUE_SIZE, 4); + +void peripheral_sensor_event_work_callback(struct k_work *work) { + struct zmk_sensor_event ev; + while (k_msgq_get(&peripheral_sensor_event_msgq, &ev, K_NO_WAIT) == 0) { + LOG_DBG("Trigger sensor change for %d", ev.sensor_index); + raise_zmk_sensor_event(ev); + } +} + +K_WORK_DEFINE(peripheral_sensor_event_work, peripheral_sensor_event_work_callback); + +void zmk_sensor_event_handle(struct zmk_sensor_event *ev) { + k_msgq_put(&peripheral_sensor_event_msgq, ev, K_NO_WAIT); + k_work_submit(&peripheral_sensor_event_work); +} +#endif /* ZMK_KEYMAP_HAS_SENSORS */