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

Combine PAA5100 and PMW3901 into a single module for #301 #303

Merged
merged 3 commits into from
Mar 18, 2022

Conversation

Gadgetoid
Copy link
Member

@Gadgetoid Gadgetoid commented Mar 16, 2022

There were two sets of bindings which mapped onto one single driver class. This change cleans up that unnecessary bloat and maintenance burden by merging them into a single "module" exposing two modules to MicroPython sharing mostly the same code.

They diverge only with "make_new" which uses a wrapped constructor to set a chip type which we can refer to later if any special handling is needed for one device or the other:

mp_obj_t BreakoutPMW3901_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
    return make_new(ChipType::PMW3901, type, n_args, n_kw, all_args);
}

mp_obj_t BreakoutPAA5100_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
    return make_new(ChipType::PAA5100, type, n_args, n_kw, all_args);
}

mp_obj_t make_new(enum ChipType chip, const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
    breakout_pmw3901_BreakoutPMW3901_obj_t *self = nullptr;
    ...

This is demonstrated in the print magic method. IE, even though they are the same module, the following:

import breakout_paa5100
import breakout_pmw3901

paa = breakout_paa5100.BreakoutPAA5100()
pwm = breakout_pmw3901.BreakoutPMW3901()

print(paa)
print(pwm)

Will output:

>>> %Run -c $EDITOR_CONTENT
BreakoutPAA5100(spi = 0, cs = 17, sck = 18, mosi = 19, miso = 16, int = 20)
BreakoutPMW3901(spi = 0, cs = 17, sck = 18, mosi = 19, miso = 16, int = 20)

@Gadgetoid Gadgetoid force-pushed the patch-flowsensor-combined branch from 80cea40 to 887ae3d Compare March 16, 2022 17:57
@Gadgetoid Gadgetoid force-pushed the patch-flowsensor-combined branch from 8f95c84 to 8ca91f8 Compare March 18, 2022 13:35
@Gadgetoid Gadgetoid merged commit f8b6423 into main Mar 18, 2022
@Gadgetoid Gadgetoid deleted the patch-flowsensor-combined branch March 28, 2022 09:28
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

Successfully merging this pull request may close these issues.

1 participant