summaryrefslogtreecommitdiff
path: root/app/src/hog.c
diff options
context:
space:
mode:
authorPete Johanson <peter@peterjohanson.com>2020-09-08 23:26:00 -0400
committerPete Johanson <peter@peterjohanson.com>2020-09-13 22:33:29 -0400
commit39f980a06dac1769e4f09abaf19d3ccbb4b34e67 (patch)
tree01ca7749443822591e62087bcade5d321974defd /app/src/hog.c
parente88d0833c5f8ddd2b8a9b93ab7b6d03c141f8463 (diff)
feat(bluetooth): Add back profiles, split fixes.
* Add back in profiles, not using Zephyr BT identity infrastructure. * Restore additional `&bt` commands for profile operations. * Fix for split pairing and subscriptions, since Zephyr persists subscriptions across connects. * Remove keymap from peripheral builds, reduces firmware size, and avoids unneeded attempts to send HID data.
Diffstat (limited to 'app/src/hog.c')
-rw-r--r--app/src/hog.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/app/src/hog.c b/app/src/hog.c
index 92858d5..93e6d9b 100644
--- a/app/src/hog.c
+++ b/app/src/hog.c
@@ -6,6 +6,10 @@
#include <settings/settings.h>
+#include <logging/log.h>
+
+LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
+
#include <bluetooth/bluetooth.h>
#include <bluetooth/gatt.h>
@@ -148,12 +152,40 @@ BT_GATT_SERVICE_DEFINE(hog_svc,
BT_GATT_PERM_WRITE,
NULL, write_ctrl_point, &ctrl_point));
+struct bt_conn *destination_connection() {
+ struct bt_conn *conn;
+ bt_addr_le_t *addr = zmk_ble_active_profile_addr();
+ LOG_DBG("Address pointer %p", addr);
+ if (!bt_addr_le_cmp(addr, BT_ADDR_LE_ANY)) {
+ LOG_WRN("Not sending, no active address for current profile");
+ return NULL;
+ } else if ((conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr)) == NULL) {
+ LOG_WRN("Not sending, not connected to active profile");
+ return NULL;
+ }
+
+ return conn;
+
+}
+
int zmk_hog_send_keypad_report(struct zmk_hid_keypad_report_body *report)
{
- return bt_gatt_notify(NULL, &hog_svc.attrs[5], report, sizeof(struct zmk_hid_keypad_report_body));
+ struct bt_conn *conn = destination_connection();
+ if (conn == NULL) {
+ return -ENOTCONN;
+ }
+
+ LOG_DBG("Sending to NULL? %s", conn == NULL ? "yes" : "no");
+
+ return bt_gatt_notify(conn, &hog_svc.attrs[5], report, sizeof(struct zmk_hid_keypad_report_body));
};
int zmk_hog_send_consumer_report(struct zmk_hid_consumer_report_body *report)
{
- return bt_gatt_notify(NULL, &hog_svc.attrs[10], report, sizeof(struct zmk_hid_consumer_report_body));
+ struct bt_conn *conn = destination_connection();
+ if (conn == NULL) {
+ return -ENOTCONN;
+ }
+
+ return bt_gatt_notify(conn, &hog_svc.attrs[10], report, sizeof(struct zmk_hid_consumer_report_body));
};