summaryrefslogtreecommitdiff
path: root/app/src/split/bluetooth/service.c
diff options
context:
space:
mode:
authorNick <nick.win999@gmail.com>2020-09-19 19:15:05 -0500
committerNick <nick.win999@gmail.com>2020-09-19 19:15:05 -0500
commitda0fb965f6b6a67154e20a3fddda48f5bc392d77 (patch)
treef7f9aa9a45b39bb4d943eb7d2ba6e71d516ab40c /app/src/split/bluetooth/service.c
parent844f2c76749cbc5ff611d8e69819af82b698089a (diff)
parentc0806d27f1d048db335ecc854eab61b59e23ea7a (diff)
Merge remote-tracking branch 'upstream/main' into bluetooth/battery-reporting
Diffstat (limited to 'app/src/split/bluetooth/service.c')
-rw-r--r--app/src/split/bluetooth/service.c50
1 files changed, 28 insertions, 22 deletions
diff --git a/app/src/split/bluetooth/service.c b/app/src/split/bluetooth/service.c
index e1d232a..86af685 100644
--- a/app/src/split/bluetooth/service.c
+++ b/app/src/split/bluetooth/service.c
@@ -1,6 +1,16 @@
+/*
+ * Copyright (c) 2020 The ZMK Contributors
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include <zephyr/types.h>
#include <sys/util.h>
+
+#include <logging/log.h>
+
+LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
+
#include <bluetooth/gatt.h>
#include <bluetooth/uuid.h>
@@ -11,40 +21,36 @@
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_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)
-{
+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)
-{
+static void split_svc_pos_state_ccc(const struct bt_gatt_attr *attr, u16_t value) {
+ LOG_DBG("value %d", value);
}
+BT_GATT_SERVICE_DEFINE(
+ split_svc, BT_GATT_PRIMARY_SERVICE(BT_UUID_DECLARE_128(ZMK_SPLIT_BT_SERVICE_UUID)),
+ BT_GATT_CHARACTERISTIC(BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_POSITION_STATE_UUID),
+ 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), );
-BT_GATT_SERVICE_DEFINE(split_svc,
- BT_GATT_PRIMARY_SERVICE(BT_UUID_DECLARE_128(ZMK_SPLIT_BT_SERVICE_UUID)),
- BT_GATT_CHARACTERISTIC(BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_POSITION_STATE_UUID), 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)
-{
+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)
-{
+int zmk_split_bt_position_released(u8_t position) {
WRITE_BIT(position_state[position / 8], position % 8, false);
return bt_gatt_notify(NULL, &split_svc.attrs[1], &position_state, sizeof(position_state));
} \ No newline at end of file