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.
This commit is contained in:
DK 2024-04-18 17:59:27 +02:00 committed by GitHub
parent 16e92cf665
commit a626ae6d96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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();
}