Skip to content

Commit

Permalink
Initial implementation of ESP now replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
cvanelteren committed Feb 16, 2022
1 parent b9851dc commit 8f2126e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 41 deletions.
12 changes: 6 additions & 6 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ default_envs = ttgo-lora32-v2
[env:ttgo-lora32-v2]
; build_unflags = -std=gnu++11
build_flags =
-I src/ESP32-BLE-Keyboard
-I src/NimBLE-Arduino/src
-I src/FastLED/
; -I ESP32-BLE-Keyboard
; -I NimBLE-Arduino/src
; -I src/FastLED/
-D USE_NIMBLE
; -std=c++17
-std=c++11
-Wfatal-errors

platform = espressif32
Expand All @@ -29,8 +29,8 @@ lib_deps =
FastLED
; nkolban/ESP32 BLE Arduino @ ^1.0.4
; nkolban/ESP32 BLE Arduino
; t-vk/ESP32 BLE Keyboard
; NimBLE-Arduino
t-vk/ESP32 BLE Keyboard
NimBLE-Arduino

monitor_speed = 115200
board_build.partitions = part.csv
Expand Down
2 changes: 1 addition & 1 deletion src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ class Config { // see constructor in cpp file
uint8_t rot_encoder_steps = 4;
uint8_t rot_accel = 250;
// change this for your device
// uint8_t serv_add[6] = {0x80, 0x7D, 0x3A, 0xD4, 0x2C, 0x9C};
uint8_t serv_add[6] = {0x80, 0x7D, 0x3A, 0xD4, 0x2C, 0x9E};
// uint8_t serv_add[6] = {0x80, 0x7D, 0x3A, 0xD4, 0x2C, 0x9E};
// uint8_t serv_add[6] = {0x7C, 0x9E, 0xBD, 0xFB, 0xD9, 0x7A};
};
#endif
1 change: 1 addition & 0 deletions src/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ void Keyboard::update() {
printf("Bluetooth disconnected\n");
ble_connected = 0;
}
led->update();
}

void Keyboard::wakeup() {
Expand Down
3 changes: 1 addition & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,14 @@ void setup() {

// mesh.begin();
keyboard.begin();
// keyboard.led->active_keys = &(keyboard.matrix->active_keys);
keyboard.led->active_keys = &(keyboard.matrix->active_keys);

printf("------------SPLITBOARD------------\n");
// printf("layers size %d\n", keyboard.layers.size());
}

static bool is_connected;
void loop() {

// keyboard.mesh->update();
keyboard.update();
// while (!keyboard.mesh->is_connected()) {
Expand Down
36 changes: 12 additions & 24 deletions src/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Mesh::Mesh(Config *config) {
printf("Setting up mesh connection\n");
this->config = config;
has_connection = false;
host_dev = NULL;
}

void Mesh::begin() {
Expand Down Expand Up @@ -143,21 +144,6 @@ void Mesh::end() { BLEDevice::deinit(false); }

void Mesh::wakeup() { begin(); }

// void Mesh::send(const std::vector<keyswitch_t> &data,
// BLECharacteristic *characteristic) {
// if (data.size()) {
// characteristic->setValue((uint8_t *)&data, sizeof(data[0]) *
// data.size()); characteristic->notify(true);
// }
// }
// void Mesh::send(const std::vector<event_t> &data,
// BLECharacteristic *characteristic) {
// if (data.size()) {
// characteristic->setValue((uint8_t *)&data, sizeof(data[0]) *
// data.size()); characteristic->notify(true);
// }
// }

std::vector<keyswitch_t> Mesh::get_buffer() {
/**
* @brief Returns non-empty mesh keys
Expand Down Expand Up @@ -290,7 +276,7 @@ BLEClient *Mesh::create_client(BLEAdvertisedDevice *host_dev) {
bool Mesh::connectServer() {
NimBLEClient *client = nullptr;

printf("Attempting connection");
printf("Attempting connection\n");
if (host_dev == nullptr) {
printf("no host dev found\n");
return false;
Expand All @@ -316,7 +302,9 @@ bool Mesh::connectServer() {
return false;
}

printf("%d", host_dev == NULL);
printf("Creating client\n");
printf("%s \n", host_dev->getAddress().toString().c_str());
client = BLEDevice::createClient(host_dev->getAddress());
printf("New client created\n");

Expand Down Expand Up @@ -347,8 +335,6 @@ bool Mesh::connectServer() {
printf("Warning connection is not secure\n");
}

printf("Testing here");

printf("Connected to: %s\n", client->getPeerAddress().toString().c_str());
printf("SSRI: %d \n", client->getRssi());

Expand Down Expand Up @@ -456,12 +442,15 @@ void Mesh::retrieve_events(BLERemoteCharacteristic *remoteCharacteristic,

void Mesh::update() {
static size_t last_time;
if ((is_hub == false))
if (is_connected() == false) {
if (!connectServer()) {
scan();
if ((last_time - millis()) > 1000) {
last_time = millis();
if ((is_hub == false))
if (is_connected() == false) {
if (!connectServer()) {
scan();
}
}
}
}
}

void Mesh::onConnect(BLEClient *client) {
Expand Down Expand Up @@ -503,7 +492,6 @@ bool subscribe_to(std::string characteristic_uuid,
remote_service->getCharacteristic(characteristic_uuid);
// subscribe to remote characteristic
if (remote_characteristic->canNotify()) {
printf("REMOTE SERVICE CAN NOTIFY\n");
if (!remote_characteristic->subscribe(true, *cb)) {
printf("Cannot subscribe to characteristic \n");
client->disconnect();
Expand Down
17 changes: 9 additions & 8 deletions src/mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@
#include <cstdint>

#if defined(USE_NIMBLE)

#include "NimBLECharacteristic.h"
#include "NimBLEHIDDevice.h"
#include <NimBLEDevice.h>
#include <NimBLEHIDDevice.h>
#include <NimBLEServer.h>
#include <NimBLEUtils.h>

#define BLEDevice NimBLEDevice
#define BLEServerCallbacks NimBLEServerCallbacks
#define BLECharacteristicCallbacks NimBLECharacteristicCallbacks
#define BLEHIDDevice NimBLEHIDDevice
#define BLECharacteristic NimBLECharacteristic
#define BLEAdvertising NimBLEAdvertising
#define BLEServer NimBLEServer
#define BLAdvertisedDeviceCallbacks NimBLEAdvertisedDeviceCallbacks
// #define BLEDevice NimBLEDevice
// #define BLEServerCallbacks NimBLEServerCallbacks
// #define BLECharacteristicCallbacks NimBLECharacteristicCallbacks
// #define BLEHIDDevice NimBLEHIDDevice
// #define BLECharacteristic NimBLECharacteristic
// #define BLEAdvertising NimBLEAdvertising
// #define BLEServer NimBLEServer
// #define BLAdvertisedDeviceCallbacks NimBLEAdvertisedDeviceCallbacks

#define BLE_MAX_CONNECTIONS NIMBLE_MAX_CONNECTIONS

Expand Down

0 comments on commit 8f2126e

Please sign in to comment.