Skip to content

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