Skip to content

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

Open
DenebTM wants to merge 1 commit intoarduino-libraries:masterfrom
DenebTM:master
Open

Use mbed::callback for BLE event handler typedefs on ARDUINO_ARCH_MBED#352
DenebTM wants to merge 1 commit intoarduino-libraries:masterfrom
DenebTM:master

Conversation

@DenebTM
Copy link
Copy Markdown

@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
Copy Markdown

CLAassistant commented Feb 12, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@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