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

Enhancement: Abstract I2CBuilder and SPIBuilder #209

Open
EAGrahamJr opened this issue Jul 10, 2024 · 0 comments
Open

Enhancement: Abstract I2CBuilder and SPIBuilder #209

EAGrahamJr opened this issue Jul 10, 2024 · 0 comments

Comments

@EAGrahamJr
Copy link
Contributor

To ensure more consistency across devices, I would suggest that the I2CBuilder and SPIBuilder classes get some abstraction. For example:

public abstract class AbstractI2CBuilder<I2CThing> {
    protected int controller;
    protected int address;
    protected I2CDeviceInterface device;
    protected I2CThing thing;

    protected abstract I2CThing buildThing(I2CDeviceInterface i2CDeviceInterface);

    public I2CThing build() {
        if (thing == null) {
            if (device == null) device = I2CDevice.builder(address).setController(controller).build();
            thing = buildThing(device);
        }
        return thing;
    }
}

This would help ensure behavior across all the device classes using these builders, as there currently is some variation depending upon when the class was added to the code base (i.e. some builders throw exceptions when the device is already created and others do not)1.

I didn't find a whole lot of current devices that have "dual interfaces", so there may not be a lot of refactoring involved, but would likely help for future additions.

1Not a criticism by any means -- my own stuff gets out of date within days. 😏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant