Browse Source

Initial passkey entry support.

xmkb
Pete Johanson 5 years ago
parent
commit
b3babe2505
  1. 8
      README.md
  2. 58
      src/ble.c
  3. 3
      src/ble.h
  4. 6
      src/handlers.c
  5. 1
      src/keys.h

8
README.md

@ -19,6 +19,14 @@ with a less restritive license and better BLE support, built on top of the [Zeph @@ -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?

58
src/ble.c

@ -1,4 +1,6 @@ @@ -1,4 +1,6 @@
#include <math.h>
#include <settings/settings.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/conn.h>
@ -6,6 +8,12 @@ @@ -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) @@ -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) @@ -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() @@ -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;
}

3
src/ble.h

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
#pragma once
int zmk_ble_init();
int zmk_ble_init();
bool zmk_ble_handle_key_user(struct zmk_key_event *key_event);

6
src/handlers.c

@ -1,6 +1,7 @@ @@ -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) @@ -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
src/keys.h

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
#pragma once
#include <zephyr.h>
#include <dt-bindings/zmk/keys.h>
typedef u64_t zmk_key;

Loading…
Cancel
Save