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

Use mbed::callback for BLE event handler typedefs on ARDUINO_ARCH_MBED #352

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DenebTM
Copy link

@DenebTM DenebTM commented Feb 12, 2024

This allows using capturing lambdas for BLE device and characteristic event handlers on Mbed OS-based devices, as required by a recent project of mine:

for (auto tup : senswarn_chars) {
  auto ble_char = std::get<BLEUnsignedCharCharacteristic*>(tup);
  auto val_ptr  = std::get<bool*>(tup);

  ble_char->setEventHandler(
      BLEWritten,
      [val_ptr](BLEDevice central, BLECharacteristic characteristic) {
        bool warning_active = *characteristic.value() != 0;

        if (*val_ptr != warning_active) { *val_ptr = warning_active; }

        if (warning_active) { ch_any_warning_active.writeValue(true); }
      });

  sv_senswarn.addCharacteristic(*ble_char);
}

Note: Perhaps a plain std::function type is permissible here in general. I no longer have access to the hardware to test this, unfortunately.

This allows using capturing lambdas for BLE handlers on mbed-based
devices.
@CLAassistant
Copy link

CLAassistant commented Feb 12, 2024

CLA assistant check
All committers have signed the CLA.

@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants