Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_43676597
arduino-esp32
提交
307b1368
A
arduino-esp32
项目概览
weixin_43676597
/
arduino-esp32
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
arduino-esp32
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
307b1368
编写于
1月 20, 2020
作者:
M
Me No Dev
提交者:
GitHub
1月 20, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement BTSerial onData to dynamically receive packets from SPP (#3649)
上级
32d5654a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
17 addition
and
5 deletion
+17
-5
libraries/BluetoothSerial/src/BluetoothSerial.cpp
libraries/BluetoothSerial/src/BluetoothSerial.cpp
+13
-5
libraries/BluetoothSerial/src/BluetoothSerial.h
libraries/BluetoothSerial/src/BluetoothSerial.h
+4
-0
未找到文件。
libraries/BluetoothSerial/src/BluetoothSerial.cpp
浏览文件 @
307b1368
...
...
@@ -36,9 +36,7 @@
#include "esp_spp_api.h"
#include <esp_log.h>
#ifdef ARDUINO_ARCH_ESP32
#include "esp32-hal-log.h"
#endif
const
char
*
_spp_server_name
=
"ESP32SPP"
;
...
...
@@ -52,6 +50,7 @@ static TaskHandle_t _spp_task_handle = NULL;
static
EventGroupHandle_t
_spp_event_group
=
NULL
;
static
boolean
secondConnectionAttempt
;
static
esp_spp_cb_t
*
custom_spp_callback
=
NULL
;
static
BluetoothSerialDataCb
custom_data_callback
=
NULL
;
#define INQ_LEN 0x10
#define INQ_NUM_RSPS 20
...
...
@@ -218,7 +217,6 @@ static void _spp_tx_task(void * arg){
_spp_task_handle
=
NULL
;
}
static
void
esp_spp_cb
(
esp_spp_cb_event_t
event
,
esp_spp_cb_param_t
*
param
)
{
switch
(
event
)
...
...
@@ -278,7 +276,9 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
//esp_log_buffer_hex("",param->data_ind.data,param->data_ind.len); //for low level debug
//ets_printf("r:%u\n", param->data_ind.len);
if
(
_spp_rx_queue
!=
NULL
){
if
(
custom_data_callback
){
custom_data_callback
(
param
->
data_ind
.
data
,
param
->
data_ind
.
len
);
}
else
if
(
_spp_rx_queue
!=
NULL
){
for
(
int
i
=
0
;
i
<
param
->
data_ind
.
len
;
i
++
){
if
(
xQueueSend
(
_spp_rx_queue
,
param
->
data_ind
.
data
+
i
,
(
TickType_t
)
0
)
!=
pdTRUE
){
log_e
(
"RX Full! Discarding %u bytes"
,
param
->
data_ind
.
len
-
i
);
...
...
@@ -322,6 +322,10 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
if
(
custom_spp_callback
)(
*
custom_spp_callback
)(
event
,
param
);
}
void
BluetoothSerial
::
onData
(
BluetoothSerialDataCb
cb
){
custom_data_callback
=
cb
;
}
static
void
esp_bt_gap_cb
(
esp_bt_gap_cb_event_t
event
,
esp_bt_gap_cb_param_t
*
param
)
{
switch
(
event
){
...
...
@@ -469,7 +473,7 @@ static bool _init_bt(const char *deviceName)
}
if
(
!
_spp_task_handle
){
xTaskCreate
(
_spp_tx_task
,
"spp_tx"
,
4096
,
NULL
,
2
,
&
_spp_task_handle
);
xTaskCreate
PinnedToCore
(
_spp_tx_task
,
"spp_tx"
,
4096
,
NULL
,
2
,
&
_spp_task_handle
,
0
);
if
(
!
_spp_task_handle
){
log_e
(
"Network Event Task Start Failed!"
);
return
false
;
...
...
@@ -511,6 +515,10 @@ static bool _init_bt(const char *deviceName)
return
false
;
}
if
(
esp_bt_sleep_disable
()
!=
ESP_OK
){
log_e
(
"esp_bt_sleep_disable failed"
);
}
log_i
(
"device name set"
);
esp_bt_dev_set_device_name
(
deviceName
);
...
...
libraries/BluetoothSerial/src/BluetoothSerial.h
浏览文件 @
307b1368
...
...
@@ -22,6 +22,9 @@
#include "Arduino.h"
#include "Stream.h"
#include <esp_spp_api.h>
#include <functional>
typedef
std
::
function
<
void
(
const
uint8_t
*
buffer
,
size_t
size
)
>
BluetoothSerialDataCb
;
class
BluetoothSerial
:
public
Stream
{
...
...
@@ -39,6 +42,7 @@ class BluetoothSerial: public Stream
size_t
write
(
const
uint8_t
*
buffer
,
size_t
size
);
void
flush
();
void
end
(
void
);
void
onData
(
BluetoothSerialDataCb
cb
);
esp_err_t
register_callback
(
esp_spp_cb_t
*
callback
);
void
enableSSP
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录