Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgornekich <n.gorbadey@gmail.com>2021-09-15 19:58:32 +0300
committerGitHub <noreply@github.com>2021-09-15 19:58:32 +0300
commit4768177cf5f84905e41bc1a73556a036281fe584 (patch)
treeb9a697a457a87e3589884f56480538536484be02 /applications/bt
parent8fd411097ec3cd96c5f744008d71529661eea732 (diff)
[FL-1796] Disable bluetooth (#703)
* bt: add authentication for all characteristics * bt: app_ble cleanup * bt: add start and stop advertising API * bt: rework application with start and stop advertising API * bt: support f7 target * bt: f7 target remove unused files * bt: stop advertising in bt debug application * bt: fix bt status bar update * bt: change bluetooth On Off order
Diffstat (limited to 'applications/bt')
-rwxr-xr-xapplications/bt/bt_debug_app/bt_debug_app.c13
-rwxr-xr-xapplications/bt/bt_service/bt.c26
-rw-r--r--applications/bt/bt_service/bt.h2
-rwxr-xr-xapplications/bt/bt_service/bt_api.c6
-rw-r--r--applications/bt/bt_service/bt_i.h1
-rwxr-xr-xapplications/bt/bt_settings_app/bt_settings_app.c18
-rwxr-xr-x[-rw-r--r--]applications/bt/bt_settings_app/bt_settings_app.h11
-rw-r--r--applications/bt/bt_settings_app/scenes/bt_settings_scene_config.h1
-rwxr-xr-xapplications/bt/bt_settings_app/scenes/bt_settings_scene_disable_dialog.c44
-rwxr-xr-xapplications/bt/bt_settings_app/scenes/bt_settings_scene_start.c67
10 files changed, 78 insertions, 111 deletions
diff --git a/applications/bt/bt_debug_app/bt_debug_app.c b/applications/bt/bt_debug_app/bt_debug_app.c
index 1511e84f..90333107 100755
--- a/applications/bt/bt_debug_app/bt_debug_app.c
+++ b/applications/bt/bt_debug_app/bt_debug_app.c
@@ -1,4 +1,5 @@
#include "bt_debug_app.h"
+#include <furi-hal-bt.h>
enum BtDebugSubmenuIndex {
BtDebugSubmenuIndexCarrierTest,
@@ -25,6 +26,10 @@ uint32_t bt_debug_start_view(void* context) {
BtDebugApp* bt_debug_app_alloc() {
BtDebugApp* app = furi_alloc(sizeof(BtDebugApp));
+
+ // Load settings
+ bt_settings_load(&app->settings);
+
// Gui
app->gui = furi_record_open("gui");
@@ -88,7 +93,15 @@ void bt_debug_app_free(BtDebugApp* app) {
int32_t bt_debug_app(void* p) {
BtDebugApp* app = bt_debug_app_alloc();
+ // Stop advertising
+ furi_hal_bt_stop_advertising();
+
view_dispatcher_run(app->view_dispatcher);
+
+ // Restart advertising
+ if(app->settings.enabled) {
+ furi_hal_bt_start_advertising();
+ }
bt_debug_app_free(app);
return 0;
}
diff --git a/applications/bt/bt_service/bt.c b/applications/bt/bt_service/bt.c
index 09094d17..672919fa 100755
--- a/applications/bt/bt_service/bt.c
+++ b/applications/bt/bt_service/bt.c
@@ -3,13 +3,6 @@
#define BT_SERVICE_TAG "BT"
-// static void bt_update_statusbar(void* arg) {
-// furi_assert(arg);
-// Bt* bt = arg;
-// BtMessage m = {.type = BtMessageTypeUpdateStatusbar};
-// furi_check(osMessageQueuePut(bt->message_queue, &m, 0, osWaitForever) == osOK);
-// }
-
static void bt_draw_statusbar_callback(Canvas* canvas, void* context) {
canvas_draw_icon(canvas, 0, 0, &I_Bluetooth_5x8);
}
@@ -42,10 +35,6 @@ Bt* bt_alloc() {
// Alloc queue
bt->message_queue = osMessageQueueNew(8, sizeof(BtMessage), NULL);
- // doesn't make sense if we waiting for transition on service start
- // bt->update_status_timer = osTimerNew(bt_update_statusbar, osTimerPeriodic, bt, NULL);
- // osTimerStart(bt->update_status_timer, 4000);
-
// Setup statusbar view port
bt->statusbar_view_port = bt_statusbar_view_port_alloc();
// Gui
@@ -67,15 +56,18 @@ int32_t bt_srv() {
FURI_LOG_E(BT_SERVICE_TAG, "Core2 startup failed");
} else {
view_port_enabled_set(bt->statusbar_view_port, true);
- if(bt->bt_settings.enabled) {
- bool bt_app_started = furi_hal_bt_start_app();
- if(!bt_app_started) {
- FURI_LOG_E(BT_SERVICE_TAG, "BT App start failed");
- } else {
- FURI_LOG_I(BT_SERVICE_TAG, "BT App started");
+ if(furi_hal_bt_init_app()) {
+ FURI_LOG_I(BT_SERVICE_TAG, "BLE stack started");
+ if(bt->bt_settings.enabled) {
+ furi_hal_bt_start_advertising();
+ FURI_LOG_I(BT_SERVICE_TAG, "Start advertising");
}
+ } else {
+ FURI_LOG_E(BT_SERVICE_TAG, "BT App start failed");
}
}
+ // Update statusbar
+ view_port_enabled_set(bt->statusbar_view_port, furi_hal_bt_is_alive());
BtMessage message;
while(1) {
diff --git a/applications/bt/bt_service/bt.h b/applications/bt/bt_service/bt.h
index 0bde59b8..ccf5e501 100644
--- a/applications/bt/bt_service/bt.h
+++ b/applications/bt/bt_service/bt.h
@@ -9,6 +9,8 @@ extern "C" {
typedef struct Bt Bt;
+void bt_update_statusbar(Bt* bt);
+
void bt_update_battery_level(Bt* bt, uint8_t battery_level);
bool bt_pin_code_show(Bt* bt, uint32_t pin_code);
diff --git a/applications/bt/bt_service/bt_api.c b/applications/bt/bt_service/bt_api.c
index a12ac268..db709871 100755
--- a/applications/bt/bt_service/bt_api.c
+++ b/applications/bt/bt_service/bt_api.c
@@ -1,6 +1,12 @@
#include "bt.h"
#include "bt_i.h"
+void bt_update_statusbar(Bt* bt) {
+ furi_assert(bt);
+ BtMessage message = {.type = BtMessageTypeUpdateStatusbar};
+ furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK);
+}
+
void bt_update_battery_level(Bt* bt, uint8_t battery_level) {
furi_assert(bt);
BtMessage message = {
diff --git a/applications/bt/bt_service/bt_i.h b/applications/bt/bt_service/bt_i.h
index fbc0f378..fa78811a 100644
--- a/applications/bt/bt_service/bt_i.h
+++ b/applications/bt/bt_service/bt_i.h
@@ -32,7 +32,6 @@ typedef struct {
struct Bt {
BtSettings bt_settings;
osMessageQueueId_t message_queue;
- osTimerId_t update_status_timer;
Gui* gui;
ViewPort* statusbar_view_port;
DialogsApp* dialogs;
diff --git a/applications/bt/bt_settings_app/bt_settings_app.c b/applications/bt/bt_settings_app/bt_settings_app.c
index 6eaf3761..f3e60937 100755
--- a/applications/bt/bt_settings_app/bt_settings_app.c
+++ b/applications/bt/bt_settings_app/bt_settings_app.c
@@ -31,12 +31,11 @@ BtSettingsApp* bt_settings_app_alloc() {
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
- app->submenu = submenu_alloc();
+ app->var_item_list = variable_item_list_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));
+ app->view_dispatcher,
+ BtSettingsAppViewVarItemList,
+ variable_item_list_get_view(app->var_item_list));
scene_manager_next_scene(app->scene_manager, BtSettingsAppSceneStart);
return app;
@@ -44,12 +43,9 @@ BtSettingsApp* bt_settings_app_alloc() {
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);
+ // Variable item list
+ view_dispatcher_remove_view(app->view_dispatcher, BtSettingsAppViewVarItemList);
+ variable_item_list_free(app->var_item_list);
// View dispatcher
view_dispatcher_free(app->view_dispatcher);
scene_manager_free(app->scene_manager);
diff --git a/applications/bt/bt_settings_app/bt_settings_app.h b/applications/bt/bt_settings_app/bt_settings_app.h
index cfbea1d0..0cb2b0be 100644..100755
--- a/applications/bt/bt_settings_app/bt_settings_app.h
+++ b/applications/bt/bt_settings_app/bt_settings_app.h
@@ -6,8 +6,7 @@
#include <gui/view_dispatcher.h>
#include <gui/scene_manager.h>
-#include <gui/modules/submenu.h>
-#include <gui/modules/dialog_ex.h>
+#include <gui/modules/variable-item-list.h>
#include "../bt_settings.h"
#include "scenes/bt_settings_scene.h"
@@ -17,11 +16,7 @@ typedef struct {
Gui* gui;
SceneManager* scene_manager;
ViewDispatcher* view_dispatcher;
- Submenu* submenu;
- DialogEx* dialog_ex;
+ VariableItemList* var_item_list;
} BtSettingsApp;
-typedef enum {
- BtSettingsAppViewSubmenu,
- BtSettingsAppViewDialogEx,
-} BtSettingsAppView;
+typedef enum { BtSettingsAppViewVarItemList } BtSettingsAppView;
diff --git a/applications/bt/bt_settings_app/scenes/bt_settings_scene_config.h b/applications/bt/bt_settings_app/scenes/bt_settings_scene_config.h
index e7d19b1a..6aa23850 100644
--- a/applications/bt/bt_settings_app/scenes/bt_settings_scene_config.h
+++ b/applications/bt/bt_settings_app/scenes/bt_settings_scene_config.h
@@ -1,2 +1 @@
ADD_SCENE(bt_settings, start, Start)
-ADD_SCENE(bt_settings, disable_dialog, DisableDialog)
diff --git a/applications/bt/bt_settings_app/scenes/bt_settings_scene_disable_dialog.c b/applications/bt/bt_settings_app/scenes/bt_settings_scene_disable_dialog.c
deleted file mode 100755
index ac2d5f44..00000000
--- a/applications/bt/bt_settings_app/scenes/bt_settings_scene_disable_dialog.c
+++ /dev/null
@@ -1,44 +0,0 @@
-#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);
-}
diff --git a/applications/bt/bt_settings_app/scenes/bt_settings_scene_start.c b/applications/bt/bt_settings_app/scenes/bt_settings_scene_start.c
index faf1d3a1..6e021148 100755
--- a/applications/bt/bt_settings_app/scenes/bt_settings_scene_start.c
+++ b/applications/bt/bt_settings_app/scenes/bt_settings_scene_start.c
@@ -1,28 +1,45 @@
#include "../bt_settings_app.h"
#include "furi-hal-bt.h"
-enum BtSettingsAppStartSubmenuIndex {
- BtSettingsAppStartSubmenuIndexEnable,
+enum BtSetting {
+ BtSettingOff,
+ BtSettingOn,
+ BtSettingNum,
};
-static void bt_settings_scene_start_submenu_callback(void* context, uint32_t index) {
- BtSettingsApp* app = context;
+const char* const bt_settings_text[BtSettingNum] = {
+ "Off",
+ "On",
+};
+
+static void bt_settings_scene_start_var_list_change_callback(VariableItem* item) {
+ BtSettingsApp* app = variable_item_get_context(item);
+ uint8_t index = variable_item_get_current_value_index(item);
+
+ variable_item_set_current_value_text(item, bt_settings_text[index]);
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,
+ VariableItemList* var_item_list = app->var_item_list;
+
+ VariableItem* item;
+ item = variable_item_list_add(
+ var_item_list,
+ "Bluetooth",
+ BtSettingNum,
+ bt_settings_scene_start_var_list_change_callback,
app);
+ if(app->settings.enabled) {
+ variable_item_set_current_value_index(item, BtSettingOn);
+ variable_item_set_current_value_text(item, bt_settings_text[BtSettingOn]);
+ } else {
+ variable_item_set_current_value_index(item, BtSettingOff);
+ variable_item_set_current_value_text(item, bt_settings_text[BtSettingOff]);
+ }
- view_dispatcher_switch_to_view(app->view_dispatcher, BtSettingsAppViewSubmenu);
+ view_dispatcher_switch_to_view(app->view_dispatcher, BtSettingsAppViewVarItemList);
}
bool bt_settings_scene_start_on_event(void* context, SceneManagerEvent event) {
@@ -30,27 +47,19 @@ bool bt_settings_scene_start_on_event(void* context, SceneManagerEvent event) {
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;
+ if(event.event == BtSettingOn) {
+ furi_hal_bt_start_advertising();
+ app->settings.enabled = true;
+ } else if(event.event == BtSettingOff) {
+ app->settings.enabled = false;
+ furi_hal_bt_stop_advertising();
}
+ consumed = true;
}
return consumed;
}
void bt_settings_scene_start_on_exit(void* context) {
BtSettingsApp* app = context;
- submenu_clean(app->submenu);
+ variable_item_list_clean(app->var_item_list);
}