Skip to content

Commit

Permalink
Remove BLE related code
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyhuangyc committed Jun 30, 2018
1 parent 478b0b4 commit 216b7e3
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 398 deletions.
79 changes: 2 additions & 77 deletions libraries/FreematicsPlus/FreematicsPlus.cpp
Expand Up @@ -14,12 +14,6 @@
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_pm.h"
#include "esp_bt.h"
#include "esp_gatt_defs.h"
#include "esp_gap_ble_api.h"
#include "esp_gatts_api.h"
#include "esp_bt_defs.h"
#include "esp_bt_main.h"
#include "esp_task_wdt.h"
#include "nvs_flash.h"
#include "driver/uart.h"
Expand Down Expand Up @@ -65,12 +59,12 @@ void gps_decode_task(void* inst)
while (readRxPin());
uint32_t start = getCycleCount();
taskYIELD();
taskENTER_CRITICAL(&mux);
portENTER_CRITICAL(&mux);
for (uint32_t i = 1; i <= 7; i++) {
while (getCycleCount() - start < i * F_CPU / GPS_BAUDRATE + F_CPU / GPS_BAUDRATE / 3);
c = (c | readRxPin()) >> 1;
}
taskEXIT_CRITICAL(&mux);
portEXIT_CRITICAL(&mux);
#else
int len = uart_read_bytes(GPS_UART_NUM, &c, 1, 60000 / portTICK_RATE_MS);
if (len != 1) continue;
Expand Down Expand Up @@ -424,72 +418,3 @@ void FreematicsESP32::xbTogglePower()
digitalWrite(PIN_BEE_PWR, LOW);
#endif
}

extern "C" {
void gatts_init(const char* device_name);
int gatts_send(uint8_t* data, size_t len);
}

bool GATTServer::initBLE()
{
btStart();
esp_err_t ret = esp_bluedroid_init();
if (ret) {
Serial.println("Bluetooth failed");
return false;
}
ret = esp_bluedroid_enable();
if (ret) {
Serial.println("Error enabling bluetooth");
return false;
}
return true;
}

static GATTServer* gatts_inst;

bool GATTServer::begin(const char* deviceName)
{
gatts_inst = this;
if (!initBLE()) return false;
gatts_init(deviceName);
return true;
}

bool GATTServer::send(uint8_t* data, size_t len)
{
return gatts_send(data, len);
}

size_t GATTServer::write(uint8_t c)
{
bool success = false;
if (sendbuf.length() >= MAX_BLE_MSG_LEN) {
success = send((uint8_t*)sendbuf.c_str(), sendbuf.length());
sendbuf = "";
}
sendbuf += (char)c;
if (c == '\n') {
success = send((uint8_t*)sendbuf.c_str(), sendbuf.length());
sendbuf = "";
}
return success ? sendbuf.length() : 0;
}

extern "C" {

size_t gatts_read_callback(uint8_t* buffer, size_t len)
{
if (gatts_inst) {
return gatts_inst->onRequest(buffer, len);
} else {
return 0;
}
}

void gatts_write_callback(uint8_t* data, size_t len)
{
if (gatts_inst) gatts_inst->onReceive(data, len);
}

}
24 changes: 0 additions & 24 deletions libraries/FreematicsPlus/FreematicsPlus.h
Expand Up @@ -114,27 +114,3 @@ class FreematicsESP32 : public CFreematics
// toggle xBee module power
void xbTogglePower();
};

#define MAX_BLE_MSG_LEN 160

class GATTServer : public Print
{
public:
bool begin(const char* deviceName = 0);
bool send(uint8_t* data, size_t len);
size_t write(uint8_t c);
virtual size_t onRequest(uint8_t* buffer, size_t len)
{
// being requested for data
buffer[0] = 'O';
buffer[1] = 'K';
return 2;
}
virtual void onReceive(uint8_t* buffer, size_t len)
{
// data received is in buffer
}
private:
static bool initBLE();
String sendbuf;
};

0 comments on commit 216b7e3

Please sign in to comment.