[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:
@@ -18,7 +18,9 @@ BtSettingsApp* bt_settings_app_alloc() {
|
||||
// Load settings
|
||||
bt_settings_load(&app->settings);
|
||||
app->gui = furi_record_open("gui");
|
||||
app->bt = furi_record_open("bt");
|
||||
|
||||
// View Dispatcher and Scene Manager
|
||||
app->view_dispatcher = view_dispatcher_alloc();
|
||||
app->scene_manager = scene_manager_alloc(&bt_settings_scene_handlers, app);
|
||||
view_dispatcher_enable_queue(app->view_dispatcher);
|
||||
@@ -31,26 +33,45 @@ BtSettingsApp* bt_settings_app_alloc() {
|
||||
|
||||
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
||||
|
||||
// Gui Modules
|
||||
app->var_item_list = variable_item_list_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher,
|
||||
BtSettingsAppViewVarItemList,
|
||||
variable_item_list_get_view(app->var_item_list));
|
||||
|
||||
app->dialog = dialog_ex_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, BtSettingsAppViewDialog, dialog_ex_get_view(app->dialog));
|
||||
|
||||
app->popup = popup_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, BtSettingsAppViewPopup, popup_get_view(app->popup));
|
||||
|
||||
// Set first scene
|
||||
scene_manager_next_scene(app->scene_manager, BtSettingsAppSceneStart);
|
||||
return app;
|
||||
}
|
||||
|
||||
void bt_settings_app_free(BtSettingsApp* app) {
|
||||
furi_assert(app);
|
||||
// Variable item list
|
||||
// Gui modules
|
||||
view_dispatcher_remove_view(app->view_dispatcher, BtSettingsAppViewVarItemList);
|
||||
variable_item_list_free(app->var_item_list);
|
||||
// View dispatcher
|
||||
|
||||
view_dispatcher_remove_view(app->view_dispatcher, BtSettingsAppViewDialog);
|
||||
dialog_ex_free(app->dialog);
|
||||
|
||||
view_dispatcher_remove_view(app->view_dispatcher, BtSettingsAppViewPopup);
|
||||
popup_free(app->popup);
|
||||
|
||||
// View Dispatcher and Scene Manager
|
||||
view_dispatcher_free(app->view_dispatcher);
|
||||
scene_manager_free(app->scene_manager);
|
||||
|
||||
// Records
|
||||
furi_record_close("gui");
|
||||
furi_record_close("bt");
|
||||
free(app);
|
||||
}
|
||||
|
||||
|
@@ -1,22 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <furi.h>
|
||||
#include <bt/bt_service/bt.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
#include <gui/modules/variable_item_list.h>
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
#include <gui/modules/popup.h>
|
||||
|
||||
#include "../bt_settings.h"
|
||||
#include "scenes/bt_settings_scene.h"
|
||||
|
||||
typedef struct {
|
||||
BtSettings settings;
|
||||
Bt* bt;
|
||||
Gui* gui;
|
||||
SceneManager* scene_manager;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
|
||||
VariableItemList* var_item_list;
|
||||
DialogEx* dialog;
|
||||
Popup* popup;
|
||||
} BtSettingsApp;
|
||||
|
||||
typedef enum { BtSettingsAppViewVarItemList } BtSettingsAppView;
|
||||
typedef enum {
|
||||
BtSettingsAppViewVarItemList,
|
||||
BtSettingsAppViewDialog,
|
||||
BtSettingsAppViewPopup,
|
||||
} BtSettingsAppView;
|
||||
|
2
applications/bt/bt_settings_app/scenes/bt_settings_scene_config.h
Normal file → Executable file
2
applications/bt/bt_settings_app/scenes/bt_settings_scene_config.h
Normal file → Executable 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)
|
||||
|
@@ -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);
|
||||
}
|
@@ -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);
|
||||
}
|
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user