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

Allow BLECharacteristic::setValue() functions to accept temporaries #10191

Open
1 task done
ElCarl opened this issue Aug 18, 2024 · 0 comments
Open
1 task done

Allow BLECharacteristic::setValue() functions to accept temporaries #10191

ElCarl opened this issue Aug 18, 2024 · 0 comments
Assignees
Labels
Type: Feature request Feature request for Arduino ESP32

Comments

@ElCarl
Copy link

ElCarl commented Aug 18, 2024

Related area

BLE API

Hardware specification

Shouldn't depend on specific hardware

Is your feature request related to a problem?

API is harder to use than it needs to be. E.g. cannot write:

BLECharacteristic myCharacteristic(...);
// ...
myCharacteristic.setValue(2.5F);  // Error here

Error: no instance of overloaded function "BLECharacteristic::setValue" matches the argument list
This is because the function requires a reference to a value, which cannot be created from the temporary 2.5F value.

You instead have to do:

BLECharacteristic myCharacteristic(...);
// ...
float tempFloat = 2.5F;
myCharacteristic.setValue(tempFloat;  // OK

This is OK for a couple of calls, but if you're setting lots of values it gets very messy.

Describe the solution you'd like

Change the function signatures to either take arguments by value or by const reference:

// old
void setValue(uint32_t &data32);

// new - value
void setValue(uint32_t data32);

// new - const reference
void setValue(const uint32_t &data32);

This should apply to all the overloads: uint16_t, uint32_t, int, float, double.
Since the code already just immediately copies everything into a uint8_t[] or other temporary value I don't think this will affect how it works. It also shouldn't break any existing use of the API.
As such, cost of implementing this should be minimal.

Describe alternatives you've considered

Workaround with temporary variables. Works OK but gets messy as number of variables increases.

Additional context

No response

I have checked existing list of Feature requests and the Contribution Guide

  • I confirm I have checked existing list of Feature requests and Contribution Guide.
@ElCarl ElCarl added the Type: Feature request Feature request for Arduino ESP32 label Aug 18, 2024
@SuGlider SuGlider self-assigned this Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature request Feature request for Arduino ESP32
Projects
None yet
Development

No branches or pull requests

2 participants