Skip to content

Commit

Permalink
refactor(split): move event listener out of Bluetooth directory
Browse files Browse the repository at this point in the history
  • Loading branch information
xudongzheng committed Dec 23, 2023
1 parent a593c72 commit eb64ea7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ struct zmk_split_run_behavior_payload {
char behavior_dev[ZMK_SPLIT_RUN_BEHAVIOR_DEV_LEN];
} __packed;

int zmk_split_bt_position_pressed(uint8_t position);
int zmk_split_bt_position_released(uint8_t position);
int zmk_split_bt_sensor_triggered(uint8_t sensor_index,
const struct zmk_sensor_channel_data channel_data[],
size_t channel_data_size);
int zmk_split_position_pressed(uint8_t position);
int zmk_split_position_released(uint8_t position);
int zmk_split_sensor_triggered(uint8_t sensor_index,
const struct zmk_sensor_channel_data channel_data[],
size_t channel_data_size);
4 changes: 4 additions & 0 deletions app/src/split/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Copyright (c) 2022 The ZMK Contributors
# SPDX-License-Identifier: MIT

if (NOT CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
target_sources(app PRIVATE listener.c)
endif()

if (CONFIG_ZMK_SPLIT_BLE)
add_subdirectory(bluetooth)
endif()
3 changes: 1 addition & 2 deletions app/src/split/bluetooth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# SPDX-License-Identifier: MIT

if (NOT CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
target_sources(app PRIVATE split_listener.c)
target_sources(app PRIVATE service.c)
target_sources(app PRIVATE peripheral.c)
endif()
if (CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
target_sources(app PRIVATE central.c)
endif()
endif()
2 changes: 1 addition & 1 deletion app/src/split/bluetooth/central.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/behavior.h>
#include <zmk/sensors.h>
#include <zmk/split/bluetooth/uuid.h>
#include <zmk/split/bluetooth/service.h>
#include <zmk/split/service.h>
#include <zmk/event_manager.h>
#include <zmk/events/position_state_changed.h>
#include <zmk/events/sensor_event.h>
Expand Down
12 changes: 6 additions & 6 deletions app/src/split/bluetooth/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/behavior.h>
#include <zmk/matrix.h>
#include <zmk/split/bluetooth/uuid.h>
#include <zmk/split/bluetooth/service.h>
#include <zmk/split/service.h>

#if IS_ENABLED(CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS)
#include <zmk/events/hid_indicators_changed.h>
Expand Down Expand Up @@ -203,12 +203,12 @@ int send_position_state() {
return 0;
}

int zmk_split_bt_position_pressed(uint8_t position) {
int zmk_split_position_pressed(uint8_t position) {
WRITE_BIT(position_state[position / 8], position % 8, true);
return send_position_state();
}

int zmk_split_bt_position_released(uint8_t position) {
int zmk_split_position_released(uint8_t position) {
WRITE_BIT(position_state[position / 8], position % 8, false);
return send_position_state();
}
Expand Down Expand Up @@ -250,9 +250,9 @@ int send_sensor_state(struct sensor_event ev) {
return 0;
}

int zmk_split_bt_sensor_triggered(uint8_t sensor_index,
const struct zmk_sensor_channel_data channel_data[],
size_t channel_data_size) {
int zmk_split_sensor_triggered(uint8_t sensor_index,
const struct zmk_sensor_channel_data channel_data[],
size_t channel_data_size) {
if (channel_data_size > ZMK_SENSOR_EVENT_MAX_CHANNELS) {
return -EINVAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <zephyr/device.h>
#include <zephyr/logging/log.h>

#include <zmk/split/bluetooth/service.h>
#include <zmk/split/service.h>

LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

Expand All @@ -23,17 +23,17 @@ int split_listener(const zmk_event_t *eh) {
const struct zmk_position_state_changed *pos_ev;
if ((pos_ev = as_zmk_position_state_changed(eh)) != NULL) {
if (pos_ev->state) {
return zmk_split_bt_position_pressed(pos_ev->position);
return zmk_split_position_pressed(pos_ev->position);
} else {
return zmk_split_bt_position_released(pos_ev->position);
return zmk_split_position_released(pos_ev->position);
}
}

#if ZMK_KEYMAP_HAS_SENSORS
const struct zmk_sensor_event *sensor_ev;
if ((sensor_ev = as_zmk_sensor_event(eh)) != NULL) {
return zmk_split_bt_sensor_triggered(sensor_ev->sensor_index, sensor_ev->channel_data,
sensor_ev->channel_data_size);
return zmk_split_sensor_triggered(sensor_ev->sensor_index, sensor_ev->channel_data,
sensor_ev->channel_data_size);
}
#endif /* ZMK_KEYMAP_HAS_SENSORS */
return ZMK_EV_EVENT_BUBBLE;
Expand Down

0 comments on commit eb64ea7

Please sign in to comment.