refactor(split): move central sensor handling out of Bluetooth directory
This commit is contained in:
parent
785c1e4a4a
commit
264bdfbe14
3 changed files with 26 additions and 15 deletions
|
@ -7,5 +7,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <zmk/events/position_state_changed.h>
|
||||
#include <zmk/events/sensor_event.h>
|
||||
|
||||
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
|
||||
|
|
|
@ -168,19 +168,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) {
|
||||
|
@ -206,8 +193,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;
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Add table
Reference in a new issue