[FL-1720] BLE GUI refactoring (#678)
* dialog_ex: add clean method, fix documentation * application: add bt debug and settings application * bt: add debug application * bt: add settings application * bt: rework bt service * bt debug: fix carrier debug app * assets: add debug animation to main menu * bt debug: fix bt packet test * bt service: rework bt service * bt: cleanup * Assets: fix spelling * Ble: wait for core 2 startup complete before initializing radio stack. * Accessor: remove dead code, switch port PA6 to PA4, because interrupt line 6 is used by down button. * FuriHal: assert interrupt line on add_int_callback. * Bt: update icon on core2 startup complete. Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
67
applications/bt/bt_settings_app/bt_settings_app.c
Executable file
67
applications/bt/bt_settings_app/bt_settings_app.c
Executable file
@@ -0,0 +1,67 @@
|
||||
#include "bt_settings_app.h"
|
||||
|
||||
static bool bt_settings_custom_event_callback(void* context, uint32_t event) {
|
||||
furi_assert(context);
|
||||
BtSettingsApp* app = context;
|
||||
return scene_manager_handle_custom_event(app->scene_manager, event);
|
||||
}
|
||||
|
||||
static bool bt_settings_back_event_callback(void* context) {
|
||||
furi_assert(context);
|
||||
BtSettingsApp* app = context;
|
||||
return scene_manager_handle_back_event(app->scene_manager);
|
||||
}
|
||||
|
||||
BtSettingsApp* bt_settings_app_alloc() {
|
||||
BtSettingsApp* app = furi_alloc(sizeof(BtSettingsApp));
|
||||
|
||||
// Load settings
|
||||
bt_settings_load(&app->settings);
|
||||
app->gui = furi_record_open("gui");
|
||||
|
||||
app->view_dispatcher = view_dispatcher_alloc();
|
||||
app->scene_manager = scene_manager_alloc(&bt_settings_scene_handlers, app);
|
||||
view_dispatcher_enable_queue(app->view_dispatcher);
|
||||
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
|
||||
|
||||
view_dispatcher_set_custom_event_callback(
|
||||
app->view_dispatcher, bt_settings_custom_event_callback);
|
||||
view_dispatcher_set_navigation_event_callback(
|
||||
app->view_dispatcher, bt_settings_back_event_callback);
|
||||
|
||||
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
||||
|
||||
app->submenu = submenu_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, BtSettingsAppViewSubmenu, submenu_get_view(app->submenu));
|
||||
app->dialog_ex = dialog_ex_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, BtSettingsAppViewDialogEx, dialog_ex_get_view(app->dialog_ex));
|
||||
|
||||
scene_manager_next_scene(app->scene_manager, BtSettingsAppSceneStart);
|
||||
return app;
|
||||
}
|
||||
|
||||
void bt_settings_app_free(BtSettingsApp* app) {
|
||||
furi_assert(app);
|
||||
// Submenu
|
||||
view_dispatcher_remove_view(app->view_dispatcher, BtSettingsAppViewSubmenu);
|
||||
submenu_free(app->submenu);
|
||||
// Dialog
|
||||
view_dispatcher_remove_view(app->view_dispatcher, BtSettingsAppViewDialogEx);
|
||||
dialog_ex_free(app->dialog_ex);
|
||||
// View dispatcher
|
||||
view_dispatcher_free(app->view_dispatcher);
|
||||
scene_manager_free(app->scene_manager);
|
||||
// Records
|
||||
furi_record_close("gui");
|
||||
free(app);
|
||||
}
|
||||
|
||||
extern int32_t bt_settings_app(void* p) {
|
||||
BtSettingsApp* app = bt_settings_app_alloc();
|
||||
view_dispatcher_run(app->view_dispatcher);
|
||||
bt_settings_save(&app->settings);
|
||||
bt_settings_app_free(app);
|
||||
return 0;
|
||||
}
|
27
applications/bt/bt_settings_app/bt_settings_app.h
Normal file
27
applications/bt/bt_settings_app/bt_settings_app.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
|
||||
#include "../bt_settings.h"
|
||||
#include "scenes/bt_settings_scene.h"
|
||||
|
||||
typedef struct {
|
||||
BtSettings settings;
|
||||
Gui* gui;
|
||||
SceneManager* scene_manager;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
Submenu* submenu;
|
||||
DialogEx* dialog_ex;
|
||||
} BtSettingsApp;
|
||||
|
||||
typedef enum {
|
||||
BtSettingsAppViewSubmenu,
|
||||
BtSettingsAppViewDialogEx,
|
||||
} BtSettingsAppView;
|
30
applications/bt/bt_settings_app/scenes/bt_settings_scene.c
Normal file
30
applications/bt/bt_settings_app/scenes/bt_settings_scene.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "bt_settings_scene.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const bt_settings_on_enter_handlers[])(void*) = {
|
||||
#include "bt_settings_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||
bool (*const bt_settings_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "bt_settings_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||
void (*const bt_settings_on_exit_handlers[])(void* context) = {
|
||||
#include "bt_settings_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers bt_settings_scene_handlers = {
|
||||
.on_enter_handlers = bt_settings_on_enter_handlers,
|
||||
.on_event_handlers = bt_settings_on_event_handlers,
|
||||
.on_exit_handlers = bt_settings_on_exit_handlers,
|
||||
.scene_num = BtSettingsAppSceneNum,
|
||||
};
|
29
applications/bt/bt_settings_app/scenes/bt_settings_scene.h
Normal file
29
applications/bt/bt_settings_app/scenes/bt_settings_scene.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) BtSettingsAppScene##id,
|
||||
typedef enum {
|
||||
#include "bt_settings_scene_config.h"
|
||||
BtSettingsAppSceneNum,
|
||||
} BtSettingsAppScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers bt_settings_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "bt_settings_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) \
|
||||
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
|
||||
#include "bt_settings_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
|
||||
#include "bt_settings_scene_config.h"
|
||||
#undef ADD_SCENE
|
@@ -0,0 +1,2 @@
|
||||
ADD_SCENE(bt_settings, start, Start)
|
||||
ADD_SCENE(bt_settings, disable_dialog, DisableDialog)
|
44
applications/bt/bt_settings_app/scenes/bt_settings_scene_disable_dialog.c
Executable file
44
applications/bt/bt_settings_app/scenes/bt_settings_scene_disable_dialog.c
Executable file
@@ -0,0 +1,44 @@
|
||||
#include "../bt_settings_app.h"
|
||||
#include <furi-hal-boot.h>
|
||||
#include <furi-hal-power.h>
|
||||
|
||||
static void bt_setting_disable_dialog_callback(DialogExResult result, void* context) {
|
||||
BtSettingsApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, result);
|
||||
}
|
||||
|
||||
void bt_settings_scene_disable_dialog_on_enter(void* context) {
|
||||
BtSettingsApp* app = context;
|
||||
DialogEx* dialog_ex = app->dialog_ex;
|
||||
dialog_ex_set_text(
|
||||
dialog_ex, "Reboot device\nto disable Bluetooth", 64, 32, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Back");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "Reboot");
|
||||
dialog_ex_set_result_callback(dialog_ex, bt_setting_disable_dialog_callback);
|
||||
dialog_ex_set_context(dialog_ex, app);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, BtSettingsAppViewDialogEx);
|
||||
}
|
||||
|
||||
bool bt_settings_scene_disable_dialog_on_event(void* context, SceneManagerEvent event) {
|
||||
BtSettingsApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == DialogExResultLeft) {
|
||||
scene_manager_previous_scene(app->scene_manager);
|
||||
consumed = true;
|
||||
} else if(event.event == DialogExResultRight) {
|
||||
app->settings.enabled = false;
|
||||
bt_settings_save(&app->settings);
|
||||
furi_hal_boot_set_mode(FuriHalBootModeNormal);
|
||||
furi_hal_power_reset();
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void bt_settings_scene_disable_dialog_on_exit(void* context) {
|
||||
BtSettingsApp* app = context;
|
||||
dialog_ex_clean(app->dialog_ex);
|
||||
}
|
56
applications/bt/bt_settings_app/scenes/bt_settings_scene_start.c
Executable file
56
applications/bt/bt_settings_app/scenes/bt_settings_scene_start.c
Executable file
@@ -0,0 +1,56 @@
|
||||
#include "../bt_settings_app.h"
|
||||
#include "furi-hal-bt.h"
|
||||
|
||||
enum BtSettingsAppStartSubmenuIndex {
|
||||
BtSettingsAppStartSubmenuIndexEnable,
|
||||
};
|
||||
|
||||
static void bt_settings_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||
BtSettingsApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void bt_settings_scene_start_on_enter(void* context) {
|
||||
BtSettingsApp* app = context;
|
||||
Submenu* submenu = app->submenu;
|
||||
|
||||
const char* submenu_label = app->settings.enabled ? "Disable" : "Enable";
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
submenu_label,
|
||||
BtSettingsAppStartSubmenuIndexEnable,
|
||||
bt_settings_scene_start_submenu_callback,
|
||||
app);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, BtSettingsAppViewSubmenu);
|
||||
}
|
||||
|
||||
bool bt_settings_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
BtSettingsApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == BtSettingsAppStartSubmenuIndexEnable) {
|
||||
if(!app->settings.enabled) {
|
||||
app->settings.enabled = true;
|
||||
furi_hal_bt_start_app();
|
||||
submenu_clean(app->submenu);
|
||||
submenu_add_item(
|
||||
app->submenu,
|
||||
"Disable",
|
||||
BtSettingsAppStartSubmenuIndexEnable,
|
||||
bt_settings_scene_start_submenu_callback,
|
||||
app);
|
||||
} else {
|
||||
scene_manager_next_scene(app->scene_manager, BtSettingsAppSceneDisableDialog);
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void bt_settings_scene_start_on_exit(void* context) {
|
||||
BtSettingsApp* app = context;
|
||||
submenu_clean(app->submenu);
|
||||
}
|
Reference in New Issue
Block a user