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 for additional services like logging #19

Merged
merged 2 commits into from
Apr 26, 2020
Merged

Allow for additional services like logging #19

merged 2 commits into from
Apr 26, 2020

Conversation

dvv
Copy link
Contributor

@dvv dvv commented Apr 22, 2020

Example below:

#include <BleKeyboard.h>

class Myshonok : public BleKeyboard {
private:
  BLEService *pLogService;
  BLECharacteristic *pTxCharacteristic;
public:
  Myshonok(const char *deviceName, const char *manufacturer) : BleKeyboard(deviceName, manufacturer) {
  }
  template <typename T> void log(T x) {
    if (!isConnected()) return;
    auto s = String(x);
    pTxCharacteristic->setValue((uint8_t *)s.c_str(), s.length());
    pTxCharacteristic->notify();
  }
protected:
  void onStarted(BLEServer *pServer) override {
    pLogService = pServer->createService("6E400001-B5A3-F393-E0A9-E50E24DCCA9E");
    pTxCharacteristic = pLogService->createCharacteristic("6E400003-B5A3-F393-E0A9-E50E24DCCA9E", BLECharacteristic::PROPERTY_NOTIFY);
    pTxCharacteristic->addDescriptor(new BLE2902());
    pLogService->start();
  }
};

static Myshonok kbd("Myshonok", "x670cm69");

void setup() {
  kbd.begin();
}

void loop() {
  if (SMTH) {
    kbd.log("SMTH");
  }
}

Please consider applying
TIA

@T-vK
Copy link
Owner

T-vK commented Apr 22, 2020

Sure, why not. What systems have you tested this with? Would you mind creating another PR for https://github.com/T-vK/ESP32-BLE-Mouse and maybe also for https://github.com/lemmingDev/ESP32-BLE-Gamepad which is maintained by lemmingDev?

@dvv
Copy link
Contributor Author

dvv commented Apr 22, 2020

It runs on my esp32 devkit steer keys reader and controls an android phone.
Sure, asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants