diff options
author | Pete Johanson <peter@peterjohanson.com> | 2020-06-29 00:37:11 -0400 |
---|---|---|
committer | Pete Johanson <peter@peterjohanson.com> | 2020-07-17 22:43:40 -0400 |
commit | 3796f76c56d42ca9b4fd36edae7f6bf6656009b9 (patch) | |
tree | 367eaa4b9c7b80c1e0d8a5f196668c2c911a4137 /app/src/split/bluetooth | |
parent | f6110a632d0ddbc0a9ebd7bfd4997366f95facfd (diff) |
Initial exploration of split BLE service.
* Service for split peripheral to report
position state to split central.
* Updated advertising info.
* Behavior for split BT until we have a proper
event system.
Diffstat (limited to 'app/src/split/bluetooth')
-rw-r--r-- | app/src/split/bluetooth/service.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/app/src/split/bluetooth/service.c b/app/src/split/bluetooth/service.c new file mode 100644 index 0000000..a669723 --- /dev/null +++ b/app/src/split/bluetooth/service.c @@ -0,0 +1,49 @@ + +#include <zephyr/types.h> +#include <sys/util.h> +#include <bluetooth/gatt.h> + +#include <zmk/matrix.h> +#include <zmk/split/bluetooth/service.h> + +static u8_t num_of_positions = ZMK_KEYMAP_LEN; +static u8_t position_state[16]; + +static ssize_t split_svc_pos_state(struct bt_conn *conn, const struct bt_gatt_attr *attrs, void *buf, u16_t len, u16_t offset) +{ + return bt_gatt_attr_read(conn, attrs, buf, len, offset, &position_state, sizeof(position_state)); +} + +static ssize_t split_svc_num_of_positions(struct bt_conn *conn, const struct bt_gatt_attr *attrs, void *buf, u16_t len, u16_t offset) +{ + return bt_gatt_attr_read(conn, attrs, buf, len, offset, attrs->user_data, sizeof(u8_t)); +} + +static void split_svc_pos_state_ccc(const struct bt_gatt_attr *attr, u16_t value) +{ +} + + +BT_GATT_SERVICE_DEFINE(split_svc, + BT_GATT_PRIMARY_SERVICE(ZMK_BT_UUID_SPLIT), + BT_GATT_CHARACTERISTIC(ZMK_BT_UUID_SPLIT_POS_STATE, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, + BT_GATT_PERM_READ_ENCRYPT, + split_svc_pos_state, NULL, &position_state), + BT_GATT_CCC(split_svc_pos_state_ccc, + BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT), + BT_GATT_DESCRIPTOR(BT_UUID_NUM_OF_DIGITALS, BT_GATT_PERM_READ, + split_svc_num_of_positions, NULL, &num_of_positions), +); + +int zmk_split_bt_position_pressed(u8_t position) +{ + WRITE_BIT(position_state[position / 8], position % 8, true); + return bt_gatt_notify(NULL, &split_svc.attrs[1], &position_state, sizeof(position_state)); +} + +int zmk_split_bt_position_released(u8_t position) +{ + WRITE_BIT(position_state[position / 8], position % 8, false); + // WRITE_BIT(position_state, position, false); + return bt_gatt_notify(NULL, &split_svc.attrs[1], &position_state, sizeof(position_state)); +}
\ No newline at end of file |