[FL-2204] Bluetooth forget devices (#967)

* bt: update connection parameters
* bt: set correct connection latency and timeout
* gui popup: add clean method
* furi_hal_bt: add connection parameters request, clear database
* bt: add forget bonded devices API
* bt_settings: add forget bonded devices GUI
* bt: rework pin code show with view port to hide view
* bt: support conn parameters for different profiles
* furi_hal_bt: sync f6 target
* target f6: fix build
* bt: format sources
* furi_hal_bt: update connection parameters
* bt: update connection params, fix GUI
* FuriHal: fix spelling
* Refactoring: rename _clean to _reset

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
gornekich
2022-01-21 20:32:03 +03:00
committed by GitHub
parent d4787e859e
commit 23ff6723cf
82 changed files with 471 additions and 116 deletions

View File

@@ -1 +1,3 @@
ADD_SCENE(bt_settings, start, Start)
ADD_SCENE(bt_settings, forget_dev_confirm, ForgetDevConfirm)
ADD_SCENE(bt_settings, forget_dev_success, ForgetDevSuccess)

View File

@@ -0,0 +1,44 @@
#include "../bt_settings_app.h"
#include "furi_hal_bt.h"
void bt_settings_scene_forget_dev_confirm_dialog_callback(DialogExResult result, void* context) {
furi_assert(context);
BtSettingsApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, result);
}
void bt_settings_scene_forget_dev_confirm_on_enter(void* context) {
BtSettingsApp* app = context;
DialogEx* dialog = app->dialog;
dialog_ex_set_header(dialog, "Unpair all devices?", 64, 3, AlignCenter, AlignTop);
dialog_ex_set_text(
dialog, "All previous pairings\nwill be lost.", 64, 22, AlignCenter, AlignTop);
dialog_ex_set_left_button_text(dialog, "Back");
dialog_ex_set_right_button_text(dialog, "Unpair");
dialog_ex_set_context(dialog, app);
dialog_ex_set_result_callback(dialog, bt_settings_scene_forget_dev_confirm_dialog_callback);
view_dispatcher_switch_to_view(app->view_dispatcher, BtSettingsAppViewDialog);
}
bool bt_settings_scene_forget_dev_confirm_on_event(void* context, SceneManagerEvent event) {
BtSettingsApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == DialogExResultLeft) {
consumed = scene_manager_previous_scene(app->scene_manager);
} else if(event.event == DialogExResultRight) {
bt_forget_bonded_devices(app->bt);
scene_manager_next_scene(app->scene_manager, BtSettingsAppSceneForgetDevSuccess);
consumed = true;
}
}
return consumed;
}
void bt_settings_scene_forget_dev_confirm_on_exit(void* context) {
BtSettingsApp* app = context;
dialog_ex_reset(app->dialog);
}

View File

@@ -0,0 +1,43 @@
#include "../bt_settings_app.h"
#include "furi_hal_bt.h"
#define SCENE_FORGET_DEV_SUCCESS_CUSTOM_EVENT (0UL)
void bt_settings_app_scene_forget_dev_success_popup_callback(void* context) {
BtSettingsApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, SCENE_FORGET_DEV_SUCCESS_CUSTOM_EVENT);
}
void bt_settings_scene_forget_dev_success_on_enter(void* context) {
BtSettingsApp* app = context;
Popup* popup = app->popup;
popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59);
popup_set_header(popup, "Done", 14, 15, AlignLeft, AlignTop);
popup_set_timeout(popup, 1500);
popup_set_context(popup, app);
popup_set_callback(popup, bt_settings_app_scene_forget_dev_success_popup_callback);
popup_enable_timeout(popup);
view_dispatcher_switch_to_view(app->view_dispatcher, BtSettingsAppViewPopup);
}
bool bt_settings_scene_forget_dev_success_on_event(void* context, SceneManagerEvent event) {
BtSettingsApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SCENE_FORGET_DEV_SUCCESS_CUSTOM_EVENT) {
if(scene_manager_has_previous_scene(app->scene_manager, BtSettingsAppSceneStart)) {
consumed = scene_manager_search_and_switch_to_previous_scene(
app->scene_manager, BtSettingsAppSceneStart);
}
}
}
return consumed;
}
void bt_settings_scene_forget_dev_success_on_exit(void* context) {
BtSettingsApp* app = context;
popup_reset(app->popup);
}

View File

@@ -1,6 +1,8 @@
#include "../bt_settings_app.h"
#include "furi_hal_bt.h"
#define SCENE_START_FORGET_DEV_SELECTED_EVENT (10UL)
enum BtSetting {
BtSettingOff,
BtSettingOn,
@@ -8,8 +10,8 @@ enum BtSetting {
};
const char* const bt_settings_text[BtSettingNum] = {
"Off",
"On",
"OFF",
"ON",
};
static void bt_settings_scene_start_var_list_change_callback(VariableItem* item) {
@@ -20,6 +22,12 @@ static void bt_settings_scene_start_var_list_change_callback(VariableItem* item)
view_dispatcher_send_custom_event(app->view_dispatcher, index);
}
static void bt_settings_scene_start_var_list_enter_callback(void* context, uint32_t index) {
furi_assert(context);
BtSettingsApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, SCENE_START_FORGET_DEV_SELECTED_EVENT);
}
void bt_settings_scene_start_on_enter(void* context) {
BtSettingsApp* app = context;
VariableItemList* var_item_list = app->var_item_list;
@@ -40,6 +48,9 @@ void bt_settings_scene_start_on_enter(void* context) {
variable_item_set_current_value_index(item, BtSettingOff);
variable_item_set_current_value_text(item, bt_settings_text[BtSettingOff]);
}
variable_item_list_add(var_item_list, "Forget all paired devices", 1, NULL, NULL);
variable_item_list_set_enter_callback(
var_item_list, bt_settings_scene_start_var_list_enter_callback, app);
} else {
item = variable_item_list_add(var_item_list, "Bluetooth", 1, NULL, NULL);
variable_item_set_current_value_text(item, "Broken");
@@ -56,16 +67,20 @@ bool bt_settings_scene_start_on_event(void* context, SceneManagerEvent event) {
if(event.event == BtSettingOn) {
furi_hal_bt_start_advertising();
app->settings.enabled = true;
consumed = true;
} else if(event.event == BtSettingOff) {
app->settings.enabled = false;
furi_hal_bt_stop_advertising();
consumed = true;
} else if(event.event == SCENE_START_FORGET_DEV_SELECTED_EVENT) {
scene_manager_next_scene(app->scene_manager, BtSettingsAppSceneForgetDevConfirm);
consumed = true;
}
consumed = true;
}
return consumed;
}
void bt_settings_scene_start_on_exit(void* context) {
BtSettingsApp* app = context;
variable_item_list_clean(app->var_item_list);
variable_item_list_reset(app->var_item_list);
}