[FL-1722] BLE custom serial service (#685)
* 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 Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
11
applications/bt/bt_service/bt.c
Normal file → Executable file
11
applications/bt/bt_service/bt.c
Normal file → Executable file
@@ -1,4 +1,5 @@
|
||||
#include "bt_i.h"
|
||||
#include "battery_service.h"
|
||||
|
||||
#define BT_SERVICE_TAG "BT"
|
||||
|
||||
@@ -43,6 +44,12 @@ Bt* bt_alloc() {
|
||||
return bt;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int32_t bt_srv() {
|
||||
Bt* bt = bt_alloc();
|
||||
furi_record_create("bt", bt);
|
||||
@@ -68,6 +75,10 @@ int32_t bt_srv() {
|
||||
if(message.type == BtMessageTypeUpdateStatusbar) {
|
||||
// Update statusbar
|
||||
view_port_enabled_set(bt->statusbar_view_port, furi_hal_bt_is_alive());
|
||||
} else if(message.type == BtMessageTypeUpdateBatteryLevel) {
|
||||
if(furi_hal_bt_is_alive()) {
|
||||
battery_svc_update_level(message.data.battery_level);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@@ -1,3 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct Bt Bt;
|
||||
|
||||
bool bt_update_battery_level(Bt* bt, uint8_t battery_level);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -13,11 +13,16 @@
|
||||
|
||||
typedef enum {
|
||||
BtMessageTypeUpdateStatusbar,
|
||||
BtMessageTypeUpdateBatteryLevel,
|
||||
} BtMessageType;
|
||||
|
||||
typedef union {
|
||||
uint8_t battery_level;
|
||||
} BtMessageData;
|
||||
|
||||
typedef struct {
|
||||
BtMessageType type;
|
||||
void* param;
|
||||
BtMessageData data;
|
||||
} BtMessage;
|
||||
|
||||
struct Bt {
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#include <stm32wbxx.h>
|
||||
|
||||
#include <notification/notification-messages.h>
|
||||
#include <applications/bt/bt_service/bt.h>
|
||||
|
||||
#define POWER_OFF_TIMEOUT 30
|
||||
|
||||
@@ -39,6 +40,7 @@ struct Power {
|
||||
|
||||
ValueMutex* menu_vm;
|
||||
Cli* cli;
|
||||
Bt* bt;
|
||||
MenuItem* menu;
|
||||
|
||||
PowerState state;
|
||||
@@ -108,6 +110,8 @@ Power* power_alloc() {
|
||||
power->cli = furi_record_open("cli");
|
||||
power_cli_init(power->cli, power);
|
||||
|
||||
power->bt = furi_record_open("bt");
|
||||
|
||||
power->menu = menu_item_alloc_menu("Power", icon_animation_alloc(&A_Power_14));
|
||||
menu_item_subitem_add(
|
||||
power->menu, menu_item_alloc_function("Off", NULL, power_menu_off_callback, power));
|
||||
@@ -206,13 +210,15 @@ int32_t power_srv(void* p) {
|
||||
power->menu_vm, (Menu * menu) { menu_item_add(menu, power->menu); });
|
||||
|
||||
furi_record_create("power", power);
|
||||
|
||||
uint8_t battery_level = 0;
|
||||
uint8_t battery_level_prev = 0;
|
||||
while(1) {
|
||||
bool battery_low = false;
|
||||
|
||||
with_view_model(
|
||||
power->info_view, (PowerInfoModel * model) {
|
||||
model->charge = furi_hal_power_get_pct();
|
||||
battery_level = model->charge;
|
||||
model->health = furi_hal_power_get_bat_health_pct();
|
||||
model->capacity_remaining = furi_hal_power_get_battery_remaining_capacity();
|
||||
model->capacity_full = furi_hal_power_get_battery_full_capacity();
|
||||
@@ -258,6 +264,11 @@ int32_t power_srv(void* p) {
|
||||
|
||||
power_charging_indication_handler(power, notifications);
|
||||
|
||||
if(battery_level_prev != battery_level) {
|
||||
battery_level_prev = battery_level;
|
||||
bt_update_battery_level(power->bt, battery_level);
|
||||
}
|
||||
|
||||
view_port_update(power->battery_view_port);
|
||||
|
||||
osDelay(1024);
|
||||
|
Reference in New Issue
Block a user