diff options
author | Pete Johanson <peter@peterjohanson.com> | 2020-05-16 23:26:26 -0400 |
---|---|---|
committer | Pete Johanson <peter@peterjohanson.com> | 2020-05-16 23:26:26 -0400 |
commit | b3babe2505fe4542e18967d90ccfc2783943243f (patch) | |
tree | 1df09d4abffbbfcc34510a8a6ad0a34104b9352c | |
parent | 3b10e00d276537a4f5b0e81b8117295057986041 (diff) |
Initial passkey entry support.
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | src/ble.c | 58 | ||||
-rw-r--r-- | src/ble.h | 3 | ||||
-rw-r--r-- | src/handlers.c | 6 | ||||
-rw-r--r-- | src/keys.h | 1 |
5 files changed, 67 insertions, 9 deletions
@@ -19,6 +19,14 @@ with a less restritive license and better BLE support, built on top of the [Zeph - Update the kscan GPIO driver to use interrupts. - Try disabling callbacks for the read pins temporarily when scanning, then re-enabling them. +# Missing Features + +- Mod Tap +- One Shot +- Shell over BLE? +- Split support + - custom kscan driver? that recieves events from other side over serial/BLE notifications? + ## Long Term - Tool to convert keymap `info.json` files into a DTS keymap file? @@ -1,4 +1,6 @@ +#include <math.h> + #include <settings/settings.h> #include <bluetooth/bluetooth.h> #include <bluetooth/conn.h> @@ -6,6 +8,12 @@ #include <bluetooth/uuid.h> #include <bluetooth/gatt.h> +#include "keys.h" + +static struct bt_conn *auth_passkey_entry_conn; +static u8_t passkey_entries[6] = {0, 0, 0, 0, 0, 0}; +static u8_t passkey_digit = 0; + static void connected(struct bt_conn *conn, u8_t err) { char addr[BT_ADDR_LE_STR_LEN]; @@ -75,7 +83,7 @@ static void auth_passkey_entry(struct bt_conn *conn) bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); printk("Passkey entry requested for %s\n", addr); - // bt_conn_auth_passkey_entry(conn, 1234); + auth_passkey_entry_conn = bt_conn_ref(conn); } static void auth_cancel(struct bt_conn *conn) @@ -84,6 +92,14 @@ static void auth_cancel(struct bt_conn *conn) bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + if (auth_passkey_entry_conn) + { + bt_conn_unref(auth_passkey_entry_conn); + auth_passkey_entry_conn = NULL; + } + + passkey_digit = 0; + printk("Pairing cancelled: %s\n", addr); } @@ -132,15 +148,41 @@ int zmk_ble_init() return err; } - // err = bt_passkey_set(1234); - if (err) - { - printk("Set passkey failed: %d\n", err); - return err; - } - bt_conn_cb_register(&conn_callbacks); bt_conn_auth_cb_register(&zmk_ble_auth_cb_display); return 0; } + +bool zmk_ble_handle_key_user(struct zmk_key_event *key_event) +{ + zmk_key key = key_event->key; + + if (!auth_passkey_entry_conn) + { + return true; + } + + if (key < KC_1 || key > KC_0) + { + return true; + } + + u32_t val = (key == KC_0) ? 0 : (key - KC_1 + 1); + + passkey_entries[passkey_digit++] = val; + + if (passkey_digit == 6) + { + u32_t passkey = 0; + for (int i = 5; i >= 0; i--) + { + passkey = (passkey * 10) + val; + } + bt_conn_auth_passkey_entry(auth_passkey_entry_conn, passkey); + bt_conn_unref(auth_passkey_entry_conn); + auth_passkey_entry_conn = NULL; + } + + return false; +} @@ -1,4 +1,5 @@ #pragma once -int zmk_ble_init();
\ No newline at end of file +int zmk_ble_init(); +bool zmk_ble_handle_key_user(struct zmk_key_event *key_event);
\ No newline at end of file diff --git a/src/handlers.c b/src/handlers.c index 9383e75..0ab93f6 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -1,6 +1,7 @@ #include "handlers.h" +#include "ble.h" #include "endpoints.h" __attribute__((weak)) bool zmk_handle_key_user(struct zmk_key_event *key_event) @@ -15,5 +16,10 @@ void zmk_handle_key(struct zmk_key_event key_event) return; } + if (!zmk_ble_handle_key_user(&key_event)) + { + return; + } + zmk_endpoints_send_key_event(key_event); }; @@ -1,6 +1,7 @@ #pragma once #include <zephyr.h> +#include <dt-bindings/zmk/keys.h> typedef u64_t zmk_key; |