Skip to content

Add qrio.QRDecoder.find() to locate codes without decoding #8467

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

Merged
merged 1 commit into from
Oct 25, 2023

Conversation

deshipu
Copy link

@deshipu deshipu commented Oct 8, 2023

Fix #8452

@tannewt tannewt self-requested a review October 10, 2023 20:14
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple questions about your API design choices. Thanks for the PR!

if (quirc_decode(&self->code, &self->data) != QUIRC_SUCCESS) {
continue;
mp_obj_t code_obj;
if (decode) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit weird to me. Almost always there is a 1:1 relationship between Python functions and their C common_hal parts. Could you refactor this so that find() and decode() share code but have two separate common_hal functions that each include their piece of this branch?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way I can think of doing this cleanly is to rename this function, and then have two one-liner common_hal functions that call it, with true or false. Would that be better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a little better but not what I'm thinking. Ideally this code would be split apart. I bet you can factor out the start through quirc_end and return quirc_count(). You'll end up with a loop in each function that mirrors this one (but simpler without the if).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still have two functions identical except for what is inside that if, so I don't see much point? I will try to come up with something.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved as much as I could without passing too many variables around to a common function, but there is still a lot of duplication. I'm not happy with it, but I can't see how to improve it.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I was thinking. Thanks!

@tannewt tannewt merged commit 9354c92 into adafruit:main Oct 25, 2023
@jepler
Copy link

jepler commented Oct 26, 2023

Cool, thanks!

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.

qrio: add an option to also know the positions of the qr-codes found
3 participants