mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 21:18:35 -07:00
BadKB: Improve BT Remember handling
This commit is contained in:
@@ -47,8 +47,8 @@ void bad_kb_load_settings(BadKbApp* app) {
|
||||
flipper_format_rewind(file);
|
||||
}
|
||||
|
||||
if(!flipper_format_read_bool(file, "Bt_Remember", &app->bt_remember, 1)) {
|
||||
app->bt_remember = false;
|
||||
if(!flipper_format_read_bool(file, "Bt_Remember", &cfg->ble.bonding, 1)) {
|
||||
cfg->ble.bonding = false;
|
||||
flipper_format_rewind(file);
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ static void bad_kb_save_settings(BadKbApp* app) {
|
||||
if(flipper_format_file_open_always(file, BAD_KB_SETTINGS_PATH)) {
|
||||
flipper_format_write_string(file, "Keyboard_Layout", app->keyboard_layout);
|
||||
flipper_format_write_bool(file, "Is_Bt", &app->is_bt, 1);
|
||||
flipper_format_write_bool(file, "Bt_Remember", &app->bt_remember, 1);
|
||||
flipper_format_write_bool(file, "Bt_Remember", &cfg->ble.bonding, 1);
|
||||
flipper_format_write_string_cstr(file, "Bt_Name", cfg->ble.name);
|
||||
flipper_format_write_hex(file, "Bt_Mac", (uint8_t*)&cfg->ble.mac, sizeof(cfg->ble.mac));
|
||||
flipper_format_write_string_cstr(file, "Usb_Manuf", cfg->usb.manuf);
|
||||
@@ -143,23 +143,24 @@ void bad_kb_app_show_loading_popup(BadKbApp* app, bool show) {
|
||||
|
||||
int32_t bad_kb_conn_apply(BadKbApp* app) {
|
||||
if(app->is_bt) {
|
||||
bt_timeout = bt_hid_delays[LevelRssi39_0];
|
||||
bt_disconnect(app->bt);
|
||||
furi_delay_ms(200);
|
||||
bt_keys_storage_set_storage_path(app->bt, BAD_KB_KEYS_PATH);
|
||||
|
||||
// Setup new config
|
||||
// Setup profile config
|
||||
BadKbConfig* cfg = app->set_bt_id ? &app->id_config : &app->config;
|
||||
memcpy(&app->cur_ble_cfg, &cfg->ble, sizeof(cfg->ble));
|
||||
app->cur_ble_cfg.bonding = app->bt_remember;
|
||||
// TODO: Allow GapPairingNone with BT Remember ON
|
||||
if(app->bt_remember) {
|
||||
if(app->cur_ble_cfg.bonding) {
|
||||
app->cur_ble_cfg.pairing = GapPairingPinCodeVerifyYesNo;
|
||||
// Hardcode mac for remember mode
|
||||
// Change in config copy to preserve user choice for non-remember mode
|
||||
memcpy(app->cur_ble_cfg.mac, BAD_KB_BOUND_MAC, sizeof(BAD_KB_BOUND_MAC));
|
||||
} else {
|
||||
app->cur_ble_cfg.pairing = GapPairingNone;
|
||||
}
|
||||
|
||||
// Prepare for new profile
|
||||
bt_timeout = bt_hid_delays[LevelRssi39_0];
|
||||
bt_disconnect(app->bt);
|
||||
furi_delay_ms(200);
|
||||
bt_keys_storage_set_storage_path(app->bt, BAD_KB_KEYS_PATH);
|
||||
|
||||
// Set profile
|
||||
app->ble_hid = bt_profile_start(app->bt, ble_profile_hid, &app->cur_ble_cfg);
|
||||
furi_check(app->ble_hid);
|
||||
@@ -247,7 +248,7 @@ void bad_kb_config_refresh(BadKbApp* app) {
|
||||
bad_kb_conn_reset(app);
|
||||
} else {
|
||||
BleProfileHidParams* cur = &app->cur_ble_cfg;
|
||||
apply = apply || cfg->ble.bonding != app->bt_remember;
|
||||
apply = apply || cfg->ble.bonding != cur->bonding;
|
||||
apply = apply || strncmp(cfg->ble.name, cur->name, sizeof(cfg->ble.name));
|
||||
apply = apply || memcmp(cfg->ble.mac, cur->mac, sizeof(cfg->ble.mac));
|
||||
}
|
||||
|
||||
@@ -72,7 +72,6 @@ struct BadKbApp {
|
||||
|
||||
Bt* bt;
|
||||
bool is_bt;
|
||||
bool bt_remember;
|
||||
BadKbConfig config; // User options
|
||||
BadKbConfig id_config; // ID and BT_ID values
|
||||
|
||||
|
||||
@@ -344,6 +344,9 @@ static bool ducky_set_bt_id(BadKbScript* bad_kb, const char* line) {
|
||||
|
||||
strlcpy(cfg->ble.name, line + mac_len, sizeof(cfg->ble.name));
|
||||
FURI_LOG_D(WORKER_TAG, "set bt id: %s", line);
|
||||
|
||||
// Can't set bonding via BT_ID, sync with user choice instead
|
||||
cfg->ble.bonding = bad_kb->app->config.ble.bonding;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,14 @@ void bad_kb_scene_config_connection_callback(VariableItem* item) {
|
||||
|
||||
void bad_kb_scene_config_bt_remember_callback(VariableItem* item) {
|
||||
BadKbApp* bad_kb = variable_item_get_context(item);
|
||||
bad_kb->bt_remember = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, bad_kb->bt_remember ? "ON" : "OFF");
|
||||
bool value = variable_item_get_current_value_index(item);
|
||||
// Set user config and remember
|
||||
bad_kb->config.ble.bonding = value;
|
||||
// Apply to ID config so its temporarily overridden (currently can't set bonding with BT_ID anyway)
|
||||
if(bad_kb->set_bt_id) {
|
||||
bad_kb->id_config.ble.bonding = value;
|
||||
}
|
||||
variable_item_set_current_value_text(item, value ? "ON" : "OFF");
|
||||
view_dispatcher_send_custom_event(bad_kb->view_dispatcher, VarItemListIndexBtRemember);
|
||||
}
|
||||
|
||||
@@ -52,20 +58,22 @@ void bad_kb_scene_config_on_enter(void* context) {
|
||||
variable_item_set_current_value_text(item, bad_kb->is_bt ? "BT" : "USB");
|
||||
|
||||
if(bad_kb->is_bt) {
|
||||
BadKbConfig* cfg = bad_kb->set_bt_id ? &bad_kb->id_config : &bad_kb->config;
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list, "BT Remember", 2, bad_kb_scene_config_bt_remember_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");
|
||||
variable_item_set_current_value_index(item, cfg->ble.bonding);
|
||||
variable_item_set_current_value_text(item, cfg->ble.bonding ? "ON" : "OFF");
|
||||
|
||||
item = variable_item_list_add(var_item_list, "BT Device Name", 0, NULL, bad_kb);
|
||||
|
||||
item = variable_item_list_add(var_item_list, "BT MAC Address", 0, NULL, bad_kb);
|
||||
if(bad_kb->bt_remember) {
|
||||
if(cfg->ble.bonding) {
|
||||
variable_item_set_locked(item, true, "Remember\nmust be Off!");
|
||||
}
|
||||
|
||||
item = variable_item_list_add(var_item_list, "Randomize BT MAC", 0, NULL, bad_kb);
|
||||
if(bad_kb->bt_remember) {
|
||||
if(cfg->ble.bonding) {
|
||||
variable_item_set_locked(item, true, "Remember\nmust be Off!");
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user