Description
Is your feature request/improvement related to a problem? Please describe.
The Wire methods onReceive and onRequest dont allow to pass a function via std::bind.
This would result to have to use a singleton to have access the hanlders if the I2C client code is an object like a library.
A solution similar to the attachInterrupt would solve the issue.
Describe the solution you'd like
Something like this (similar to what we do with attachInterrupt()
)
_i2bus->begin(address + baseAddress);
_i2bus->onReceive(std::bind(&I2CClient::onReceive, this));
_i2bus->onRequest(std::bind(&I2CClient::onRequest, this));
My current workaround is to have multiple definitions of the static handling methods
each pair call the right object handling methods.
This is not the best solution with callback_function_t
I could just pass the Wire object to class instanceand it will self manage.
Another solution would be to pass the object pointer to the registration method.
This approach is used by PacketSerial:
https://github.com/bakercp/PacketSerial/blob/master/src/PacketSerial.h#L372