PID controllers hierarchy revision
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "BluetoothDispatcher.hpp"
|
||||
|
||||
static DeviceConnectedCb deviceConnectedCallback = nullptr;
|
||||
|
||||
static void deviceConnectedStaticCallback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param);
|
||||
|
||||
BluetoothDispatcher::BluetoothDispatcher(BluetoothSerial *controller, const char *device_name) {
|
||||
@@ -26,12 +27,11 @@ bool BluetoothDispatcher::initialize(volatile bool loop_on_fail, int readTimeout
|
||||
deviceConnectedCallback = [this](BTAddress device) {
|
||||
_onDeviceConnected(device);
|
||||
};
|
||||
_controller->setTimeout(2);
|
||||
_controller->setTimeout(50);
|
||||
bool success = _controller->begin(_device_name, false);
|
||||
if (!success) {
|
||||
ESP_LOGI(_tag, "Failed to initialize Bluetooth controller!");
|
||||
while (loop_on_fail)
|
||||
;
|
||||
while (loop_on_fail);
|
||||
return false;
|
||||
} else {
|
||||
ESP_LOGI(_tag, "Bluetooth host initialized");
|
||||
@@ -43,12 +43,12 @@ void BluetoothDispatcher::onNewPackageReceived(NewPackageCallback newPackageRece
|
||||
_newPackageReceivedCb = newPackageReceivedCb;
|
||||
}
|
||||
|
||||
void BluetoothDispatcher::tick(const char *message_delimeter) {
|
||||
void BluetoothDispatcher::tick(const char message_delimeter) {
|
||||
/* Call the callback, if new package received */
|
||||
while (_controller->available()) { _buffer += (char)_controller->read(); }
|
||||
if (_buffer.endsWith(message_delimeter)) {
|
||||
while (_controller->available()) { _buffer += (char) _controller->read(); }
|
||||
if (_buffer.lastIndexOf(message_delimeter) != -1) {
|
||||
char buffer[_buffer_size];
|
||||
auto messageEnd = _buffer.lastIndexOf('}');
|
||||
auto messageEnd = _buffer.indexOf(message_delimeter) - 1;
|
||||
if (messageEnd == -1) {
|
||||
_buffer.clear();
|
||||
} else {
|
||||
@@ -71,7 +71,7 @@ BluetoothDispatcher::~BluetoothDispatcher() {
|
||||
}
|
||||
|
||||
void BluetoothDispatcher::_onConfirmRequest(uint16_t pin) {
|
||||
ESP_LOGI(_tag, "The Bluetooth PIN is: %06lu", (long unsigned int)pin);
|
||||
ESP_LOGI(_tag, "The Bluetooth PIN is: %06lu", (long unsigned int) pin);
|
||||
_controller->confirmReply(true);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ void BluetoothDispatcher::onNewDeviceConnected(DeviceConnectedCb deviceConnected
|
||||
}
|
||||
|
||||
void BluetoothDispatcher::sendPackage(const char *package, size_t size) {
|
||||
_controller->write((uint8_t *)package, size);
|
||||
_controller->write((uint8_t *) package, size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user