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
Request of setting notify_callback as class instance. #342
Comments
You can use void charaSubscribeNotification(NimBLERemoteCharacteristic* pChara) {
if (pChara->canNotify()) {
charaPrintId(pChara);
Serial.println(" canNotify ");
if (pChara->subscribe(true, std::bind(&Controller::notifyCB, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4), true)) {
Serial.println("set notifyCb");
} else {
Serial.println("failed to subscribe");
}
} |
@sivar2311 I tried calling scanEndCB with using the bind function but I cannot pass compilcation. class Controller {
void startScan() {
scanning = true;
auto pScan = NimBLEDevice::getScan();
pScan->setAdvertisedDeviceCallbacks(advDeviceCBs);
pScan->setInterval(45);
pScan->setWindow(15);
Serial.println("Start scan");
// pScan->start(scanTime, scanEndedCB);
pScan->start(scanTime,
std::bind(&Core::scanEndedCB, this, std::placeholders::_1)); // <<<<<<<<<< ======== Here
}
void scanEndedCB(NimBLEScanResults results) {
Serial.println("Scan Ended");
scanning = false;
}
}; I got the following error.
I triec casting but it did not solve the problem. pScan->start(scanTime,
(void (*)(NimBLEScanResults))std::bind(
&Core::scanEndedCB, this, std::placeholders::_1));
|
I found the reason because scanCompleteCB is not defined with std::function. |
Sorry, I was away for a few hours. For a "pure" function pointer std::bind does not work. |
Thank you for the information. if (pChara->subscribe(
true,
[this](NimBLERemoteCharacteristic* pRemoteCharacteristic,
uint8_t* pData, size_t length, bool isNotify) {
notifyCB(pRemoteCharacteristic, pData, length, isNotify);
},
true)) {
Serial.println("set notifyCb");
} else {
Serial.println("failed to subscribe");
}
|
I tried to set
notify_callback
with using class member method but could not. (scanCompleteCB
also)Could you support
CharacteristicCallbacks
class to set notify_callback likeAdvertisedDeviceCallbacks
orClientCallbacks
?Is there any way to do that current functions?
My use case:
Thank you for sharing an useful library.
The text was updated successfully, but these errors were encountered: