Skip to content

Commit

Permalink
refactor(split): move central sensor handling out of Bluetooth directory
Browse files Browse the repository at this point in the history
  • Loading branch information
xudongzheng committed Dec 11, 2024
1 parent d9bed67 commit b0c0341
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
5 changes: 5 additions & 0 deletions app/include/zmk/split/central.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 1 addition & 15 deletions app/src/split/bluetooth/central.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
20 changes: 20 additions & 0 deletions app/src/split/central.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit b0c0341

Please sign in to comment.