Skip to content

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