From a626ae6d96e2dae1b434420e0605e2cb58f7aaf8 Mon Sep 17 00:00:00 2001 From: DK Date: Thu, 18 Apr 2024 17:59:27 +0200 Subject: [PATCH 1/3] Add non-persistent 'last_profile' variable for profile toggling (related to #767) Add functionality to revert to the last used BLE profile via special index This update introduces the ability to switch back to the previously active Bluetooth Low Energy (BLE) profile by passing index 255 to the profile selection function. This feature facilitates quick toggling between two frequently used profiles, enhancing user convenience and efficiency in scenarios requiring regular switching between different BLE configurations. --- app/src/ble.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/ble.c b/app/src/ble.c index 7e1ae7d4..bb8fa106 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -61,6 +61,7 @@ enum advertising_type { static struct zmk_ble_profile profiles[ZMK_BLE_PROFILE_COUNT]; static uint8_t active_profile; +static uint8_t last_profile; #define DEVICE_NAME CONFIG_BT_DEVICE_NAME #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1) @@ -265,6 +266,11 @@ static int ble_save_profile(void) { } int zmk_ble_prof_select(uint8_t index) { + if (index == 255) { + index = last_profile; + last_profile = active_profile; + } + if (index >= ZMK_BLE_PROFILE_COUNT) { return -ERANGE; } @@ -625,7 +631,7 @@ static void zmk_ble_ready(int err) { LOG_ERR("Bluetooth init failed (err %d)", err); return; } - + last_profile = active_profile; update_advertising(); } From cac692e9c384071d0033db8250a4dc8da0c180a0 Mon Sep 17 00:00:00 2001 From: DK Date: Thu, 18 Apr 2024 18:44:06 +0200 Subject: [PATCH 2/3] Update pre-commit.yml --- .github/workflows/pre-commit.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 7a4c211e..343ca65a 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -3,6 +3,7 @@ name: pre-commit on: pull_request: push: + workflow_dispatch: jobs: pre-commit: From d77c2e324b62fa9689285f617dbcaf54ea7556cc Mon Sep 17 00:00:00 2001 From: DK Date: Fri, 19 Apr 2024 08:41:10 +0200 Subject: [PATCH 3/3] fixed --- .github/workflows/pre-commit.yml | 1 - app/src/ble.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 343ca65a..7a4c211e 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -3,7 +3,6 @@ name: pre-commit on: pull_request: push: - workflow_dispatch: jobs: pre-commit: diff --git a/app/src/ble.c b/app/src/ble.c index bb8fa106..6168dffa 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -268,7 +268,6 @@ static int ble_save_profile(void) { int zmk_ble_prof_select(uint8_t index) { if (index == 255) { index = last_profile; - last_profile = active_profile; } if (index >= ZMK_BLE_PROFILE_COUNT) { @@ -280,6 +279,7 @@ int zmk_ble_prof_select(uint8_t index) { return 0; } + last_profile = active_profile; active_profile = index; ble_save_profile();