diff options
author | Pete Johanson <peter@peterjohanson.com> | 2020-09-13 22:43:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-13 22:43:45 -0400 |
commit | 160f296bfb562ca0596630f84c4121920ea3c304 (patch) | |
tree | 63218f4af1b20108af667de8e346d204076064bb /app/src/hog.c | |
parent | 304603240f7ba16f67912a0031c64fb9ae4e8279 (diff) | |
parent | 4658999e31865e54d02955c500c716385e6c69d8 (diff) |
Merge pull request #133 from petejohanson/bluetooth/ident-management
feat(bluetooth): Proper basic bond management, new `bt` behavior for resetting bond to host.
Diffstat (limited to 'app/src/hog.c')
-rw-r--r-- | app/src/hog.c | 36 |
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)); }; |