h2zero / NimBLE-Arduino

A fork of the NimBLE library structured for compilation with Arduino, for use with ESP32, nRF5x.
https://h2zero.github.io/NimBLE-Arduino/
Apache License 2.0
734 stars 153 forks source link

Using ``NimBLERemoteCharacteristic::getValue()`` in callbacks for ``NimBLERemoteCharacteristic::subscribe()`` #778

Closed Laxilef closed 15 hours ago

Laxilef commented 16 hours ago

Hi,

I looked at PR #49 but couldn't figure out if I can use method NimBLERemoteCharacteristic::getValue() in callbacks? The PR says that we should pass a timestamp to prevent re-reading, but is this relevant now?

Or can we just use such an expression now?

pChar->subscribe(true, [](NimBLERemoteCharacteristic* pChar, uint8_t* pData, size_t length, bool isNotify) {
  // ...
  auto value = pChar->getValue<short>();
  // ...
});
h2zero commented 16 hours ago

@Laxilef you can freely call this function, it just returns the internally stored value, does not trigger a read.

Laxilef commented 15 hours ago

Awesome! Thanks