Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow server initialisation to happen outside of begin() #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions BleKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,20 @@ BleKeyboard::BleKeyboard(std::string deviceName, std::string deviceManufacturer,
, deviceManufacturer(std::string(deviceManufacturer).substr(0,15))
, batteryLevel(batteryLevel) {}

void BleKeyboard::init(void)
{
if(!initialised) {
BLEDevice::init(deviceName);
BLEServer* pServer = BLEDevice::createServer();
pServer->setCallbacks(this);
initialised = true;
}
}

void BleKeyboard::begin(void)
{
BLEDevice::init(deviceName);
init();
BLEServer* pServer = BLEDevice::createServer();
pServer->setCallbacks(this);

hid = new BLEHIDDevice(pServer);
inputKeyboard = hid->inputReport(KEYBOARD_ID); // <-- input REPORTID from report map
Expand Down Expand Up @@ -543,4 +552,4 @@ void BleKeyboard::delay_ms(uint64_t ms) {
}
while(esp_timer_get_time() < e) {}
}
}
}
2 changes: 2 additions & 0 deletions BleKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class BleKeyboard : public Print, public BLEServerCallbacks, public BLECharacter
bool connected = false;
uint32_t _delay_ms = 7;
void delay_ms(uint64_t ms);
bool initialised = false;

uint16_t vid = 0x05ac;
uint16_t pid = 0x820a;
Expand All @@ -152,6 +153,7 @@ class BleKeyboard : public Print, public BLEServerCallbacks, public BLECharacter
public:
BleKeyboard(std::string deviceName = "ESP32 Keyboard", std::string deviceManufacturer = "Espressif", uint8_t batteryLevel = 100);
void begin(void);
void init(void);
void end(void);
void sendReport(KeyReport* keys);
void sendReport(MediaKeyReport* keys);
Expand Down