Browse Source
* Especially for splits, we need the ability to unpair all paired devices as sledgehammer if we need to "reset things", and doing so via keymaps isn't suitable. * Allows shields to define a collection of key positions that if all held 2 seconds after startup, will unpair all existing pairs for the device.xmkb
Pete Johanson
4 years ago
22 changed files with 160 additions and 10 deletions
@ -1,2 +1,3 @@ |
|||||||
CONFIG_ZMK_SPLIT=y |
CONFIG_ZMK_SPLIT=y |
||||||
CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y |
CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y |
||||||
|
CONFIG_ZMK_BLE_UNPAIR_COMBO=y |
@ -1,2 +1,3 @@ |
|||||||
CONFIG_ZMK_SPLIT=y |
CONFIG_ZMK_SPLIT=y |
||||||
CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y |
CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y |
||||||
|
CONFIG_ZMK_BLE_UNPAIR_COMBO=y |
@ -1,2 +1,3 @@ |
|||||||
CONFIG_ZMK_SPLIT=y |
CONFIG_ZMK_SPLIT=y |
||||||
CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y |
CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y |
||||||
|
CONFIG_ZMK_BLE_UNPAIR_COMBO=y |
@ -1,2 +1,3 @@ |
|||||||
CONFIG_ZMK_SPLIT=y |
CONFIG_ZMK_SPLIT=y |
||||||
CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y |
CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y |
||||||
|
CONFIG_ZMK_BLE_UNPAIR_COMBO=y |
@ -1,2 +1,3 @@ |
|||||||
CONFIG_ZMK_SPLIT=y |
CONFIG_ZMK_SPLIT=y |
||||||
CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y |
CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y |
||||||
|
CONFIG_ZMK_BLE_UNPAIR_COMBO=y |
@ -1,2 +1,3 @@ |
|||||||
CONFIG_ZMK_SPLIT=y |
CONFIG_ZMK_SPLIT=y |
||||||
CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y |
CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y |
||||||
|
CONFIG_ZMK_BLE_UNPAIR_COMBO=y |
||||||
|
@ -0,0 +1,12 @@ |
|||||||
|
# Copyright (c) 2020, Pete Johanson |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
description: | |
||||||
|
Defines a set of key positions that will unpair all BT devices if held on startup. |
||||||
|
|
||||||
|
compatible: "zmk,bt-unpair-combo" |
||||||
|
|
||||||
|
properties: |
||||||
|
key-positions: |
||||||
|
type: array |
||||||
|
required: true |
@ -0,0 +1,80 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Peter Johanson |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <device.h> |
||||||
|
#include <init.h> |
||||||
|
|
||||||
|
#include <logging/log.h> |
||||||
|
|
||||||
|
#define DT_DRV_COMPAT zmk_bt_unpair_combo |
||||||
|
|
||||||
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
||||||
|
|
||||||
|
#include <zmk/ble.h> |
||||||
|
#include <zmk/event-manager.h> |
||||||
|
#include <zmk/events/position-state-changed.h> |
||||||
|
|
||||||
|
|
||||||
|
static u8_t combo_state; |
||||||
|
|
||||||
|
const u32_t key_positions[] = DT_INST_PROP(0, key_positions); |
||||||
|
#define KP_LEN DT_INST_PROP_LEN(0, key_positions) |
||||||
|
|
||||||
|
int index_for_key_position(u32_t kp) |
||||||
|
{ |
||||||
|
for (int i = 0; i < KP_LEN; i++) { |
||||||
|
if (key_positions[i] == kp) { |
||||||
|
return i; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
int unpair_combo_listener(const struct zmk_event_header *eh) |
||||||
|
{ |
||||||
|
if (is_position_state_changed(eh)) { |
||||||
|
const struct position_state_changed *psc = cast_position_state_changed(eh); |
||||||
|
|
||||||
|
int kp_index = index_for_key_position(psc->position); |
||||||
|
if (kp_index < 0) { |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
WRITE_BIT(combo_state, kp_index, psc->state); |
||||||
|
} |
||||||
|
|
||||||
|
return 0; |
||||||
|
}; |
||||||
|
|
||||||
|
void unpair_combo_work_handler(struct k_work *work) |
||||||
|
{ |
||||||
|
for (int i = 0; i < KP_LEN; i++) { |
||||||
|
if (!(combo_state & BIT(i))) { |
||||||
|
LOG_DBG("Key position %d not held, skipping unpair combo", key_positions[i]); |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
zmk_ble_unpair_all(); |
||||||
|
}; |
||||||
|
|
||||||
|
struct k_delayed_work unpair_combo_work; |
||||||
|
|
||||||
|
int zmk_ble_unpair_combo_init(struct device *_unused) |
||||||
|
{ |
||||||
|
k_delayed_work_init(&unpair_combo_work, unpair_combo_work_handler); |
||||||
|
k_delayed_work_submit(&unpair_combo_work, K_SECONDS(2)); |
||||||
|
|
||||||
|
return 0; |
||||||
|
}; |
||||||
|
|
||||||
|
ZMK_LISTENER(zmk_ble_unpair_combo, unpair_combo_listener); |
||||||
|
ZMK_SUBSCRIPTION(zmk_ble_unpair_combo, position_state_changed); |
||||||
|
|
||||||
|
SYS_INIT(zmk_ble_unpair_combo_init, |
||||||
|
APPLICATION, |
||||||
|
CONFIG_APPLICATION_INIT_PRIORITY); |
Loading…
Reference in new issue