Skip to content

Commit

Permalink
support of multiple BLE devices
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausMu committed Nov 2, 2024
1 parent 823381b commit 9ea3c03
Show file tree
Hide file tree
Showing 22 changed files with 1,182 additions and 194 deletions.
62 changes: 62 additions & 0 deletions Platformio/hardware/ESP32/keyboard_ble_hal_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,78 @@

#include "lib/ESP32-BLE-Keyboard/BleKeyboard.h"
#include "battery_hal_esp32.h"
#include "keyboard_ble_hal_esp32.h"

BleKeyboard bleKeyboard("OMOTE Keyboard", "CoretechR");

void keyboardBLE_startAdvertisingForAll_HAL() {
bleKeyboard.startAdvertisingForAll();
}

void keyboardBLE_startAdvertisingWithWhitelist_HAL(std::string peersAllowed) {
bleKeyboard.startAdvertisingWithWhitelist(peersAllowed);
}

void keyboardBLE_startAdvertisingDirected_HAL(std::string peerAddress, bool isRandomAddress) {
bleKeyboard.startAdvertisingDirected(peerAddress, isRandomAddress);
}

void keyboardBLE_stopAdvertising_HAL() {
bleKeyboard.stopAdvertising();
}

void keyboardBLE_printConnectedClients_HAL() {
bleKeyboard.printConnectedClients();
}

void keyboardBLE_disconnectAllClients_HAL() {
bleKeyboard.disconnectAllClients();
}

void keyboardBLE_printBonds_HAL() {
bleKeyboard.printBonds();
}

std::string keyboardBLE_getBonds_HAL() {
return bleKeyboard.getBonds();
}

void keyboardBLE_deleteBonds_HAL() {
bleKeyboard.deleteBonds();
}

bool keyboardBLE_forceConnectionToAddress_HAL(std::string peerAddress) {
return bleKeyboard.forceConnectionToAddress(peerAddress);
}

tAnnounceBLEmessage_cb thisAnnounceBLEmessage_cb = NULL;
void set_announceBLEmessage_cb_HAL(tAnnounceBLEmessage_cb pAnnounceBLEmessage_cb) {
// this is the callback in the commandHandler that we call from here
thisAnnounceBLEmessage_cb = pAnnounceBLEmessage_cb;
}

void keyboardBLE_BLEkeyboardMessage_cb(std::string message) {
// this callback is called from BLEKeyboard.cpp
if (thisAnnounceBLEmessage_cb != NULL) {
thisAnnounceBLEmessage_cb(message);
}
}

void init_keyboardBLE_HAL() {
int battery_voltage;
int battery_percentage;
boolean battery_ischarging;
get_battery_status_HAL(&battery_voltage, &battery_percentage, &battery_ischarging);

bleKeyboard.set_BLEKeyboardMessage_cb(&keyboardBLE_BLEkeyboardMessage_cb);
bleKeyboard.setBatteryLevel(battery_percentage);
bleKeyboard.begin();
// In case only one peer is bonded, startAdvertisingForAll() is called on initialisation
bleKeyboard.startAdvertisingIfExactlyOneBondExists();
}

bool keyboardBLE_isAdvertising_HAL() {
return bleKeyboard.isAdvertising();
}

bool keyboardBLE_isConnected_HAL() {
Expand Down
15 changes: 15 additions & 0 deletions Platformio/hardware/ESP32/keyboard_ble_hal_esp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@

#include "lib/ESP32-BLE-Keyboard/BleKeyboard.h"

void keyboardBLE_startAdvertisingForAll_HAL();
void keyboardBLE_startAdvertisingWithWhitelist_HAL(std::string peersAllowed);
void keyboardBLE_startAdvertisingDirected_HAL(std::string peerAddress, bool isRandomAddress);
void keyboardBLE_stopAdvertising_HAL();
void keyboardBLE_printConnectedClients_HAL();
void keyboardBLE_disconnectAllClients_HAL();
void keyboardBLE_printBonds_HAL();
std::string keyboardBLE_getBonds_HAL();
void keyboardBLE_deleteBonds_HAL();
bool keyboardBLE_forceConnectionToAddress_HAL(std::string peerAddress);
typedef void (*tAnnounceBLEmessage_cb)(std::string message);
extern tAnnounceBLEmessage_cb thisAnnounceBLEmessage_cb;
void set_announceBLEmessage_cb_HAL(tAnnounceBLEmessage_cb pAnnounceBLEmessage_cb);

void init_keyboardBLE_HAL();
bool keyboardBLE_isAdvertising_HAL();
bool keyboardBLE_isConnected_HAL();
void keyboardBLE_end_HAL();
void keyboardBLE_write_HAL(uint8_t c);
Expand Down
Loading

0 comments on commit 9ea3c03

Please sign in to comment.