Skip to content

Commit

Permalink
Merge branch 'release-candidate' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
skotopes committed Sep 28, 2021
2 parents fd29e19 + b3f1db8 commit 6c60c96
Show file tree
Hide file tree
Showing 140 changed files with 3,893 additions and 4,006 deletions.
4 changes: 4 additions & 0 deletions applications/applications.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern int32_t music_player_app(void* p);

// On system start hooks declaration
extern void bt_cli_init();
extern void crypto_cli_init();
extern void ibutton_cli_init();
extern void irda_cli_init();
extern void lfrfid_cli_init();
Expand Down Expand Up @@ -171,6 +172,9 @@ const size_t FLIPPER_APPS_COUNT = sizeof(FLIPPER_APPS) / sizeof(FlipperApplicati

// On system start hooks
const FlipperOnStartHook FLIPPER_ON_SYSTEM_START[] = {
#ifdef SRV_CLI
crypto_cli_init,
#endif
irda_cli_init,
#ifdef APP_NFC
nfc_cli_init,
Expand Down
13 changes: 13 additions & 0 deletions applications/bt/bt_debug_app/bt_debug_app.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "bt_debug_app.h"
#include <furi-hal-bt.h>

enum BtDebugSubmenuIndex {
BtDebugSubmenuIndexCarrierTest,
Expand All @@ -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");

Expand Down Expand Up @@ -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;
}
30 changes: 11 additions & 19 deletions applications/bt/bt_service/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand All @@ -67,25 +56,28 @@ 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_active());

BtMessage message;
while(1) {
furi_check(osMessageQueueGet(bt->message_queue, &message, NULL, osWaitForever) == osOK);
if(message.type == BtMessageTypeUpdateStatusbar) {
// Update statusbar
view_port_enabled_set(bt->statusbar_view_port, furi_hal_bt_is_alive());
view_port_enabled_set(bt->statusbar_view_port, furi_hal_bt_is_active());
} else if(message.type == BtMessageTypeUpdateBatteryLevel) {
// Update battery level
if(furi_hal_bt_is_alive()) {
if(furi_hal_bt_is_active()) {
battery_svc_update_level(message.data.battery_level);
}
} else if(message.type == BtMessageTypePinCodeShow) {
Expand Down
2 changes: 2 additions & 0 deletions applications/bt/bt_service/bt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions applications/bt/bt_service/bt_api.c
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
1 change: 0 additions & 1 deletion applications/bt/bt_service/bt_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 7 additions & 11 deletions applications/bt/bt_settings_app/bt_settings_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,21 @@ 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;
}

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);
Expand Down
11 changes: 3 additions & 8 deletions applications/bt/bt_settings_app/bt_settings_app.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
ADD_SCENE(bt_settings, start, Start)
ADD_SCENE(bt_settings, disable_dialog, DisableDialog)

This file was deleted.

67 changes: 38 additions & 29 deletions applications/bt/bt_settings_app/scenes/bt_settings_scene_start.c
Original file line number Diff line number Diff line change
@@ -1,56 +1,65 @@
#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) {
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;
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);
}
Loading

0 comments on commit 6c60c96

Please sign in to comment.