Files
P4-USB-transfer/main/BLE/ble.h
T
zhengxinandCursor 851e347cf5 初始提交卡包 USB 工程
纳入固件源码、屏幕组件、nand_xfer 工具和文档。忽略本机构建产物、sdkconfig,以及含本机路径的依赖锁。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-13 21:54:50 +08:00

87 lines
3.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef _BLE_H_
#define _BLE_H_
#include "esp_err.h"
#include <stdbool.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#ifdef __cplusplus
extern "C" {
#endif
/* NimBLE 在 ble_hs.c 中实现,公开 host/ble_hs.h 未导出 */
void ble_hs_lock(void);
void ble_hs_unlock(void);
extern const char *BLE_TAG;
extern bool notify_enabled;
extern volatile bool sentinel_mode_is_active;
extern char s_emoji_delete_target_pack;
extern TaskHandle_t notification_task_handle;
extern TaskHandle_t sentinel_task_handle;
// 设备名称
#define DEVICE_NAME "咔宝"
#define MAX_NOTIFY_LEN 256
// BLE 特征值
#define BLE_SERVICE_UUID 0xFFFF
#define BLE_CHAR_UUID_TX 0xFF01 // ESP32发送,APP接收
#define BLE_CHAR_UUID_RX 0xFF02 // APP发送,ESP32接收
#define BLE_CHAR_UUID_NOTIFY 0xFF03 // 通知特征
#define SENTINEL_TASK_PRIORITY 5
#define SENTINEL_TURN_ON 0x01
#define SENTINEL_TURN_OFF 0x02
#define SENTINEL_LISTEN_START_PULSE 0x04
#define SENTINEL_LISTEN_STOP_PULSE 0x08
#define SENTINEL_PULSE_TIMEOUT_MS 3000
#define SENTINEL_TOTAL_DURATION_MS (20 * 60 * 1000)
#define BLE_SEND_PROGRESS (1<<0)
#define BLE_SEND_VERSION (1<<1)
#define BLE_SEND_DL_EMOJI_FAILED (1<<2)
#define BLE_SEND_DL_EMOJI_SUCCESS (1<<3)
#define BLE_SEND_DOWNLOADED_PACKS (1<<4)
#define BLE_SEND_WIFI_STATE (1<<5)
#define BLE_SEND_EMOJI_USING (1<<6)
#define BLE_SEND_EMOJI_EXCHANGE_RESULT (1<<7)
#define BLE_SEND_OTA_RESULT (1<<8)
#define BLE_SEND_EMOJI_DELETE_RESULT (1<<9)
#define BLE_SEND_EMOJI_CLEAR_RESULT (1<<10)
/** 仅发送 Feedback 2.2A brightness 单帧(如设置页亮度滑条松手),由 notification_task 发送 */
#define BLE_SEND_BRIGHTNESS (1<<11)
/** 表情包下载成功后,等待首次切换指令做“收尾”(不重启,停留在目标包) */
extern volatile bool g_emoji_upgrade_pending_finalize;
/** 本次下载成功的 pack('A'/'B'/'C'/'D',或 '0') */
extern volatile char g_emoji_upgrade_downloaded_pack;
/** 最近一次收到的“切换表情包”目标 pack(供收尾逻辑判断) */
extern volatile char g_emoji_upgrade_last_switch_target;
/** 请求通过 BLE 发送 OTA 升级进度 1.11_B(0~100),由 notification_task 实际发送 */
void ble_send_ota_progress(uint8_t progress);
/** 请求通过 BLE 发送 OTA 升级结果 1.11_A(0=失败,1=成功),由 notification_task 实际发送 */
void ble_send_ota_result_request(uint8_t success);
/** 设置本次「切换表情包」指令的目标 Pack_id,供 notification_task 发送切换结果前执行保存 */
void set_emoji_exchange_target_pack(char pack_id);
/** 开始 BLE 广播(GAP 回调等 NimBLE 上下文可直接调用) */
void ble_app_advertise(void);
/** 整机初始化完成后首次起广播:从 app_main 等任务调用,内部持 ble_hs_lock */
void ble_app_advertise_after_system_init(void);
/** 设置本次「删除表情包」指令的目标 Pack_id,供 notification_task 发送删除结果前执行删除 */
void ble_set_emoji_delete_target(char pack_id);
void ble_main(void);
void send_notification_to_app(const char *message);
/** 请求通过 BLE 发送 WiFi 状态反馈(连接成功 0x01 / 断开 0x00),由 notification_task 实际发送 */
void ble_send_wifi_state_request(uint8_t connected);
void send_protocol_frame(const uint8_t *data, size_t len);
bool ble_is_connected(void);
#ifdef __cplusplus
}
#endif
#endif /* _BLE_H_ */