Skip to content

Allow to add custom callback in BT Serial #2081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions libraries/BluetoothSerial/src/BluetoothSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static SemaphoreHandle_t _spp_tx_done = NULL;
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;

#define SPP_RUNNING 0x01
#define SPP_CONNECTED 0x02
Expand Down Expand Up @@ -231,6 +232,7 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
default:
break;
}
if(custom_spp_callback)(*custom_spp_callback)(event, param);
}

static bool _init_bt(const char *deviceName)
Expand Down Expand Up @@ -437,4 +439,10 @@ void BluetoothSerial::end()
_stop_bt();
}

esp_err_t BluetoothSerial::register_callback(esp_spp_cb_t * callback)
{
custom_spp_callback = callback;
return ESP_OK;
}

#endif
2 changes: 2 additions & 0 deletions libraries/BluetoothSerial/src/BluetoothSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "Arduino.h"
#include "Stream.h"
#include <esp_spp_api.h>

class BluetoothSerial: public Stream
{
Expand All @@ -38,6 +39,7 @@ class BluetoothSerial: public Stream
size_t write(const uint8_t *buffer, size_t size);
void flush();
void end(void);
esp_err_t register_callback(esp_spp_cb_t * callback);

private:
String local_name;
Expand Down