All modules and core of the app was created

This commit is contained in:
2024-01-11 22:47:53 +07:00
parent 3c2889b8f7
commit 5dd404d44b
18 changed files with 647 additions and 128 deletions

View File

@@ -36,18 +36,23 @@ bool BluetoothDispatcher::initialize(bool loop_on_fail, int readTimeoutMS) {
}
}
void BluetoothDispatcher::tick(NewPackageCallback newPackageReceivedCb) {
void BluetoothDispatcher::onNewPackageReceived(NewPackageCallback newPackageReceivedCb) {
_newPackageReceivedCb = newPackageReceivedCb;
}
void BluetoothDispatcher::tick() {
/* Call the callback, if new package received */
while (_controller->available() and _buffer.length() <= _buffer_size) { _buffer += (char)_controller->read(); }
while (_controller->available() and _buffer.length() <= _buffer_size) {
_buffer += (char)_controller->read();
}
if (_buffer.endsWith("\r")) {
char buffer[_buffer_size];
_buffer.substring(0, _buffer.lastIndexOf('\r'), buffer);
ESP_LOGD(_tag, "Received new buffer %s", buffer);
if (newPackageReceivedCb) {
newPackageReceivedCb(buffer);
if (_newPackageReceivedCb) {
_newPackageReceivedCb(buffer);
}
_buffer.clear();
_controller->write((uint8_t *)"Hello, world!", strlen("Hello, world!"));
}
if (_buffer.length() > _available_buffer_size) {
_buffer.clear();
@@ -64,7 +69,7 @@ void BluetoothDispatcher::_onConfirmRequest(uint16_t pin) {
_controller->confirmReply(true);
}
void BluetoothDispatcher::_onAuthComplete(boolean success) {
void BluetoothDispatcher::_onAuthComplete(boolean success) const {
if (success) {
ESP_LOGI(_tag, "Pairing success!");
} else {
@@ -72,7 +77,7 @@ void BluetoothDispatcher::_onAuthComplete(boolean success) {
}
}
void BluetoothDispatcher::_onDeviceConnected(BTAddress device) {
void BluetoothDispatcher::_onDeviceConnected(BTAddress device) const {
ESP_LOGI(_tag, "New device connected: %s", device.toString(true).c_str());
if (_deviceConnectedCallback) {
_deviceConnectedCallback(device);
@@ -88,8 +93,10 @@ void BluetoothDispatcher::sendPackage(const char *package, size_t size) {
_controller->write((uint8_t *)package, size);
}
static void deviceConnectedStaticCallback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) {
if (event == ESP_SPP_SRV_OPEN_EVT and param->srv_open.status == ESP_SPP_SUCCESS and deviceConnectedCallback) {
if (event == ESP_SPP_SRV_OPEN_EVT and param->srv_open.status == ESP_SPP_SUCCESS
and deviceConnectedCallback) {
deviceConnectedCallback(BTAddress(param->srv_open.rem_bda));
}
}