Skip to content

BLECharacteristic::setValue always echoes writes from Central back to Central #172

Open
@mlu

Description

@mlu

When playing around with MIDI characteristic I found that every note sent from a Central (iMac MIDI) was echoed back, that is not always what is wanted.

The reason is that the function setValue(const unsigned char value[], unsigned char length) that actually makes the change always invokes the listener callback. So when receiving a characteristic write from Central and we have writes without response the listener should not be invoked.

One possible way, that so far works for me is:

void BLECharacteristic::setValue(BLECentral& central, const unsigned char value[], unsigned char length) {
-- this->setValue(value, length);
++ if ( _properties & BLEWriteWithoutResponse ) {
++ this->_valueLength = min(length, this->_valueSize);
++ memcpy(this->_value, value, this->_valueLength);
++ }
++ else {
++ this->setValue(value, length);
++ }

this->_written = true;

BLECharacteristicEventHandler eventHandler = this->_eventHandlers[BLEWritten];
if (eventHandler) {
eventHandler(central, *this);
}
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions