device-os icon indicating copy to clipboard operation
device-os copied to clipboard

Allow for overriding TwoWire class's internal functions

Open Dan-Kouba opened this issue 4 years ago • 3 comments

submission notes
**Important:** Please sanitize/remove any confidential info like usernames, passwords, org names, product names/ids, access tokens, client ids/secrets, or anything else you don't wish to share.

Please Read and Sign the Contributor License Agreement ([Info here](https://github.com/spark/firmware/blob/develop/CONTRIBUTING.md)).

You may also delete this submission notes header if you'd like. Thank you for contributing!

Problem

The current implementation of the TwoWire class does not define its methods as virtual, therefore preventing any classes that inherit from TwoWire from overriding those functions.

Solution

This PR adds the virtual identifier to most internal functions allowing for override when deriving from this class.


Completeness

  • [x] User is totes amazing for contributing!
  • [ ] Contributor has signed CLA (Info here)
  • [ ] Problem and Solution clearly stated
  • [ ] Run unit/integration/application tests on device
  • [ ] Added documentation
  • [ ] Added to CHANGELOG.md after merging (add links to docs and issues)

Dan-Kouba avatar Dec 01 '20 18:12 Dan-Kouba

Perhaps make the I2C interface protected in the class as well

protected:
  hal_i2c_interface_t _i2c;

cc @avtolstoy

eberseth avatar Dec 10 '20 00:12 eberseth

@eberseth I'm good with that — would preclude the interface() function from being needed in derived classes. Shall I submit a new commit?

Dan-Kouba avatar Dec 16 '20 01:12 Dan-Kouba

@eberseth I'm good with that — would preclude the interface() function from being needed in derived classes. Shall I submit a new commit?

You can make changes, squash, and force push to overwrite the branch.

eberseth avatar Dec 17 '20 17:12 eberseth