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-13 14:25:37 +0300
committerGitHub <noreply@github.com>2021-09-13 14:25:37 +0300
commit95d9140d2458b1fd471627c49ef0ecc1faf9c68e (patch)
tree9ca229cbaf3517b22047313905ac3ae6f4cf5f72 /applications/bt
parent4456982e2767f6754587e5981bd87d28bfcded42 (diff)
[FL-1795] BLE GAP refactoring (#694)
* ble: remove heart rate profile * ble-glue: delete dead code * ble-glue: dis refactoring * ble-glue: add battery service * broken ble_common refactoring * ble-glue: advertise 128 bit service uid * ble-glue: remove dead code * ble: advertise service 16 bit uid depending on flipper color * ble-glue: remove debug * ble: intriduce serial service * ble: serial over ble * bt: serial echo server * bt: serial service process indicate acknowledge * bt: serial service event handler update * bt: refactore battery service * bt: add battery level apdate API * power: update battery level on change * bt: refactore device information service * app_ble: pairing configuration * bt: display pin code * bt: refactor battery service * bt: refactor device info service * bt: change advertise timer to freertos one * bt: separate app_ble to hci and gap * bt: increase max ble packet size * gap: refactoring * bt: refactor serial service * bt: support f7 target * bt: not blocking pin code show request Co-authored-by: Anna Prosvetova <anna@prosvetova.me> Co-authored-by: あく <alleteam@gmail.com>
Diffstat (limited to 'applications/bt')
-rwxr-xr-xapplications/bt/bt_service/bt.c25
-rw-r--r--applications/bt/bt_service/bt.h4
-rwxr-xr-xapplications/bt/bt_service/bt_api.c15
-rw-r--r--applications/bt/bt_service/bt_i.h6
4 files changed, 43 insertions, 7 deletions
diff --git a/applications/bt/bt_service/bt.c b/applications/bt/bt_service/bt.c
index ba292021..0c7dac90 100755
--- a/applications/bt/bt_service/bt.c
+++ b/applications/bt/bt_service/bt.c
@@ -22,6 +22,17 @@ static ViewPort* bt_statusbar_view_port_alloc() {
return statusbar_view_port;
}
+static void bt_pin_code_show_event_handler(Bt* bt, uint32_t pin) {
+ furi_assert(bt);
+ string_t pin_str;
+ string_init_printf(pin_str, "%06d", pin);
+ dialog_message_set_text(
+ bt->dialog_message, string_get_cstr(pin_str), 64, 32, AlignCenter, AlignCenter);
+ dialog_message_set_buttons(bt->dialog_message, "Back", NULL, NULL);
+ dialog_message_show(bt->dialogs, bt->dialog_message);
+ string_clear(pin_str);
+}
+
Bt* bt_alloc() {
Bt* bt = furi_alloc(sizeof(Bt));
// Load settings
@@ -41,13 +52,11 @@ Bt* bt_alloc() {
bt->gui = furi_record_open("gui");
gui_add_view_port(bt->gui, bt->statusbar_view_port, GuiLayerStatusBarLeft);
- return bt;
-}
+ // Dialogs
+ bt->dialogs = furi_record_open("dialogs");
+ bt->dialog_message = dialog_message_alloc();
-bool bt_update_battery_level(Bt* bt, uint8_t battery_level) {
- BtMessage message = {
- .type = BtMessageTypeUpdateBatteryLevel, .data.battery_level = battery_level};
- return osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK;
+ return bt;
}
int32_t bt_srv() {
@@ -76,9 +85,13 @@ int32_t bt_srv() {
// Update statusbar
view_port_enabled_set(bt->statusbar_view_port, furi_hal_bt_is_alive());
} else if(message.type == BtMessageTypeUpdateBatteryLevel) {
+ // Update battery level
if(furi_hal_bt_is_alive()) {
battery_svc_update_level(message.data.battery_level);
}
+ } else if(message.type == BtMessageTypePinCodeShow) {
+ // Display PIN code
+ bt_pin_code_show_event_handler(bt, message.data.pin_code);
}
}
return 0;
diff --git a/applications/bt/bt_service/bt.h b/applications/bt/bt_service/bt.h
index 4be69dae..0bde59b8 100644
--- a/applications/bt/bt_service/bt.h
+++ b/applications/bt/bt_service/bt.h
@@ -9,7 +9,9 @@ extern "C" {
typedef struct Bt Bt;
-bool bt_update_battery_level(Bt* bt, uint8_t battery_level);
+void bt_update_battery_level(Bt* bt, uint8_t battery_level);
+
+bool bt_pin_code_show(Bt* bt, uint32_t pin_code);
#ifdef __cplusplus
}
diff --git a/applications/bt/bt_service/bt_api.c b/applications/bt/bt_service/bt_api.c
new file mode 100755
index 00000000..a12ac268
--- /dev/null
+++ b/applications/bt/bt_service/bt_api.c
@@ -0,0 +1,15 @@
+#include "bt.h"
+#include "bt_i.h"
+
+void bt_update_battery_level(Bt* bt, uint8_t battery_level) {
+ furi_assert(bt);
+ BtMessage message = {
+ .type = BtMessageTypeUpdateBatteryLevel, .data.battery_level = battery_level};
+ furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK);
+}
+
+bool bt_pin_code_show(Bt* bt, uint32_t pin_code) {
+ furi_assert(bt);
+ BtMessage message = {.type = BtMessageTypePinCodeShow, .data.pin_code = pin_code};
+ return osMessageQueuePut(bt->message_queue, &message, 0, 0) == osOK;
+}
diff --git a/applications/bt/bt_service/bt_i.h b/applications/bt/bt_service/bt_i.h
index 6c0c2bf7..fbc0f378 100644
--- a/applications/bt/bt_service/bt_i.h
+++ b/applications/bt/bt_service/bt_i.h
@@ -9,14 +9,18 @@
#include <gui/view_port.h>
#include <gui/view.h>
+#include <applications/dialogs/dialogs.h>
+
#include "../bt_settings.h"
typedef enum {
BtMessageTypeUpdateStatusbar,
BtMessageTypeUpdateBatteryLevel,
+ BtMessageTypePinCodeShow,
} BtMessageType;
typedef union {
+ uint32_t pin_code;
uint8_t battery_level;
} BtMessageData;
@@ -31,4 +35,6 @@ struct Bt {
osTimerId_t update_status_timer;
Gui* gui;
ViewPort* statusbar_view_port;
+ DialogsApp* dialogs;
+ DialogMessage* dialog_message;
};