Save BadBT remember/forget device setting + fixes

This commit is contained in:
Willy-JL
2023-03-02 02:48:01 +00:00
parent 5544099cbe
commit cadf868030
8 changed files with 41 additions and 26 deletions
+1 -1
View File
@@ -107,7 +107,7 @@ BadKbApp* bad_kb_app_alloc(char* arg) {
Bt* bt = furi_record_open(RECORD_BT);
app->bt = bt;
app->is_bt = XTREME_SETTINGS()->bad_bt;
app->bonding = BondingForgetDevices;
app->bt_remember = XTREME_SETTINGS()->bad_bt_remember;
const char* adv_name = furi_hal_bt_get_profile_adv_name(FuriHalBtProfileHidKeyboard);
memcpy(app->name, adv_name, BAD_KB_ADV_NAME_MAX_LEN);
memcpy(app->bt_old_config.name, adv_name, BAD_KB_ADV_NAME_MAX_LEN);
+1 -5
View File
@@ -40,10 +40,6 @@ typedef enum BadKbCustomEvent {
BadKbCustomEventErrorBack
} BadKbCustomEvent;
#define BondingForgetDevices false
#define BondingRememberDevices true
typedef struct {
//uint8_t bounded_mac[BAD_KB_MAC_ADDRESS_LEN];
uint8_t mac[BAD_KB_MAC_ADDRESS_LEN];
@@ -65,7 +61,7 @@ struct BadKbApp {
ByteInput* byte_input;
uint8_t mac[BAD_KB_MAC_ADDRESS_LEN];
char name[BAD_KB_ADV_NAME_MAX_LEN + 1];
bool bonding; // weither we remember paired devices or not
bool bt_remember; // weither we remember paired devices or not
BadKbBtConfig bt_old_config;
BadKbAppError error;
+9 -7
View File
@@ -650,8 +650,8 @@ void bad_kb_config_switch_mode(BadKbApp* app) {
}
}
void bad_kb_config_switch_bonding_mode(BadKbApp *app) {
if (app->bonding) {
void bad_kb_config_switch_remember_mode(BadKbApp *app) {
if (app->bt_remember) {
// set bouding mac
uint8_t mac[6] = BAD_KB_BOUND_MAC_ADDRESS;
furi_hal_bt_set_profile_pairing_method(FuriHalBtProfileHidKeyboard, GapPairingPinCodeVerifyYesNo);
@@ -676,7 +676,7 @@ int32_t bad_kb_connection_init(BadKbApp* app) {
// furi_delay_ms(200);
bt_keys_storage_set_storage_path(app->bt, BAD_KB_APP_PATH_BOUND_KEYS_FILE);
app->bt_prev_mode = furi_hal_bt_get_profile_pairing_method(FuriHalBtProfileHidKeyboard);
if (app->bonding) { // usefull if bounding become an XTREME setting
if (app->bt_remember) {
uint8_t mac[6] = BAD_KB_BOUND_MAC_ADDRESS;
furi_hal_bt_set_profile_mac_addr(FuriHalBtProfileHidKeyboard, mac);
// using GapPairingNone breaks bounding between devices
@@ -688,8 +688,11 @@ int32_t bad_kb_connection_init(BadKbApp* app) {
bt_set_profile(app->bt, BtProfileHidKeyboard);
if(app->is_bt) {
furi_hal_bt_start_advertising();
if (!app->bonding)
if (app->bt_remember) {
bt_enable_peer_key_update(app->bt);
} else {
bt_disable_peer_key_update(app->bt); // disable peer key adding to bt SRAM storage
}
} else {
furi_hal_bt_stop_advertising();
}
@@ -708,12 +711,11 @@ void bad_kb_connection_deinit(BadKbApp* app) {
bt_disconnect(app->bt); // stop ble
// furi_delay_ms(200); // Wait 2nd core to update nvm storage
bt_keys_storage_set_default_path(app->bt);
if (app->bonding) {
if (app->bt_remember) {
// hal primitives doesn't restarts ble, that's what we want cuz we are shutting down
furi_hal_bt_set_profile_mac_addr(FuriHalBtProfileHidKeyboard, app->mac);
}else {
bt_enable_peer_key_update(app->bt); // starts saving peer keys (bounded devices)
}
bt_enable_peer_key_update(app->bt); // starts saving peer keys (bounded devices)
// fails if ble radio stack isn't ready when switching profile
// if it happens, maybe we should increase the delay after bt_disconnect
bt_set_profile(app->bt, BtProfileSerial);
+1 -1
View File
@@ -36,7 +36,7 @@ typedef struct {
void bad_kb_config_switch_mode(BadKbApp* app);
void bad_kb_config_switch_bonding_mode(BadKbApp *app);
void bad_kb_config_switch_remember_mode(BadKbApp *app);
int32_t bad_kb_connection_init(BadKbApp* app);
@@ -5,7 +5,7 @@
enum VarItemListIndex {
VarItemListIndexConnection,
VarItemListIndexBonding,
VarItemListIndexRemember,
VarItemListIndexKeyboardLayout,
VarItemListIndexAdvertisementName,
VarItemListIndexMacAddress,
@@ -22,9 +22,11 @@ void bad_kb_scene_config_bt_connection_callback(VariableItem* item) {
void bad_kb_scene_config_bt_bounding_callback(VariableItem* item) {
BadKbApp* bad_kb = variable_item_get_context(item);
bad_kb->bonding = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, bad_kb->bonding ? "Remember" : "Forget");
view_dispatcher_send_custom_event(bad_kb->view_dispatcher, VarItemListIndexBonding);
bad_kb->bt_remember = variable_item_get_current_value_index(item);
XTREME_SETTINGS()->bad_bt_remember = bad_kb->bt_remember;
XTREME_SETTINGS_SAVE();
variable_item_set_current_value_text(item, bad_kb->bt_remember ? "ON" : "OFF");
view_dispatcher_send_custom_event(bad_kb->view_dispatcher, VarItemListIndexRemember);
}
void bad_kb_scene_config_bt_var_item_list_callback(void* context, uint32_t index) {
@@ -43,16 +45,16 @@ void bad_kb_scene_config_bt_on_enter(void* context) {
variable_item_set_current_value_text(item, bad_kb->is_bt ? "BT" : "USB");
item = variable_item_list_add(
var_item_list, "Bonding", 2, bad_kb_scene_config_bt_bounding_callback, bad_kb);
variable_item_set_current_value_index(item, bad_kb->bonding);
variable_item_set_current_value_text(item, bad_kb->bonding ? "Remember" : "Forget");
var_item_list, "Remember", 2, bad_kb_scene_config_bt_bounding_callback, bad_kb);
variable_item_set_current_value_index(item, bad_kb->bt_remember);
variable_item_set_current_value_text(item, bad_kb->bt_remember ? "ON" : "OFF");
item = variable_item_list_add(var_item_list, "Keyboard layout", 0, NULL, bad_kb);
item = variable_item_list_add(var_item_list, "BT device name", 0, NULL, bad_kb);
// this doesn't update instantly when toggling between Bounding modes
if (!bad_kb->bonding) {
if (!bad_kb->bt_remember) {
item = variable_item_list_add(var_item_list, "BT MAC address", 0, NULL, bad_kb);
}
@@ -73,8 +75,8 @@ bool bad_kb_scene_config_bt_on_event(void* context, SceneManagerEvent event) {
scene_manager_next_scene(bad_kb->scene_manager, BadKbSceneConfigLayout);
} else if(event.event == VarItemListIndexConnection) {
bad_kb_config_switch_mode(bad_kb);
} else if (event.event == VarItemListIndexBonding) {
bad_kb_config_switch_bonding_mode(bad_kb);
} else if (event.event == VarItemListIndexRemember) {
bad_kb_config_switch_remember_mode(bad_kb);
scene_manager_previous_scene(bad_kb->scene_manager);
scene_manager_next_scene(bad_kb->scene_manager, BadKbSceneConfigBt);
} else if(event.event == VarItemListIndexAdvertisementName) {
@@ -8,6 +8,14 @@ static void xtreme_app_scene_protocols_bad_bk_mode_changed(VariableItem* item) {
app->save_settings = true;
}
static void xtreme_app_scene_protocols_bad_bt_remember_changed(VariableItem* item) {
XtremeApp* app = variable_item_get_context(item);
bool value = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, value ? "ON" : "OFF");
XTREME_SETTINGS()->bad_bt_remember = value;
app->save_settings = true;
}
static void xtreme_app_scene_protocols_subghz_extend_changed(VariableItem* item) {
XtremeApp* app = variable_item_get_context(item);
app->subghz_extend = variable_item_get_current_value_index(item);
@@ -33,6 +41,11 @@ void xtreme_app_scene_protocols_on_enter(void* context) {
variable_item_set_current_value_index(item, xtreme_settings->bad_bt);
variable_item_set_current_value_text(item, xtreme_settings->bad_bt ? "BT" : "USB");
item = variable_item_list_add(
var_item_list, "Bad BT Remember", 2, xtreme_app_scene_protocols_bad_bt_remember_changed, app);
variable_item_set_current_value_index(item, xtreme_settings->bad_bt_remember);
variable_item_set_current_value_text(item, xtreme_settings->bad_bt_remember ? "ON" : "OFF");
item = variable_item_list_add(
var_item_list, "SubGHz Extend", 2, xtreme_app_scene_protocols_subghz_extend_changed, app);
variable_item_set_current_value_index(item, app->subghz_extend);
+1
View File
@@ -39,6 +39,7 @@ void XTREME_SETTINGS_LOAD() {
xtreme_settings->bar_borders = true; // ON
xtreme_settings->bar_background = false; // OFF
xtreme_settings->bad_bt = false; // USB
xtreme_settings->bad_bt_remember = false; // OFF
xtreme_settings->butthurt_timer = 43200; // 12 H
xtreme_settings->sort_dirs_first = true; // ON
xtreme_settings->dark_mode = false; // OFF
+2 -1
View File
@@ -11,7 +11,7 @@
#define MAX_PACK_NAME_LEN 32
#define XTREME_SETTINGS_VERSION (4)
#define XTREME_SETTINGS_VERSION (5)
#define XTREME_SETTINGS_PATH INT_PATH(XTREME_SETTINGS_FILE_NAME)
#define XTREME_SETTINGS_MAGIC (0x69)
@@ -28,6 +28,7 @@ typedef struct {
bool bar_borders;
bool bar_background;
bool bad_bt;
bool bad_bt_remember;
int32_t butthurt_timer;
bool sort_dirs_first;
bool dark_mode;