arduino / arduino/ArduinoCore-API

[Feature Request] Make Wire library methods virtual

Open
#31 6 comments 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
306
Forks
150
PR merge metrics
No merged PRs in 30d

Description

I suggest making the public methods of the TwoWire class virtual in order to allow polymorphism when subclassing it.

**Use case**: Have another library that utilizes the Wire library and takes a refrence to a TwoWire instance in constructor. Want to use it on pins without hardware I2C (or other reason for not wanting to use the standard Wire implementation). So I want to pass another class instance that inherits from TwoWire and implements the same methods (but uses software I2C). This does not work with current implementation because of early binding (the base class functions will be called instead of the ones in subclass).

Moved from: https://github.com/arduino/Arduino/issues/8734

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the TwoWire class declaration in ArduinoCore-API and reviewing its public methods and existing uses through references. Assess the API and compatibility implications of making those methods virtual, then verify that a subclass implementing the same methods can be passed where a TwoWire instance is expected and receives the calls.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.