-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Check for duplicate pins in rows and columns #5123
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like very plausible code. Didn't test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have looked at the best way to fix this bug, and even started to code it a bit, but only very briefly. It was more complicated than I liked.
It could be done by using a Python set in shared-bindings,
adding all the pins to the set, and making sure the set length is correct. Or it might be done in the shared-module
implementation, but it's really something that should be done as arg validation in shared-bindings.
Right now the pin-claiming logic checks some actual hardware state, so you can't see if the pin is claimed until you go to allocate it.
All the keypad classes should check for duplicate pins in the pin lists, not just KeyMatrix,
so you might want to write a general duplicate object or duplicate pin checker which can be used in other cases as well. But KeyMatrix
is special because it has two lists of pins, not just one.
I was looking at this more tonight after the discussions on discord. I did implement a For test purposes I made a A couple of thoughts:
Let me know the thoughts. I can also try to be there on Monday and discuss this more during in the weeds, have to check if I am free at that time. Code for
|
I found a use for non-pin duplicate checking: in |
The build failed for one board on one translation, running out of space. Any thoughts on what to do here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks perfectly straightforward. No testing done.
mp_obj_t pin2_obj = mp_obj_subscr(seq2, MP_OBJ_NEW_SMALL_INT(pin_cnt_2), MP_OBJ_SENTINEL); | ||
mcu_pin_obj_t *pin2 = validate_obj_is_pin(pin2_obj); | ||
if (pin1 == pin2) { | ||
mp_raise_TypeError_varg(translate("%q and %q contain duplicate objects"), arg_name1, arg_name2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this only checks pins, we can say "pins" instead of "objects"
mp_raise_TypeError_varg(translate("%q and %q contain duplicate objects"), arg_name1, arg_name2); | |
mp_raise_TypeError_varg(translate("%q and %q contain duplicate pins"), arg_name1, arg_name2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, missed it the second time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, great, thanks for all the discussion and your patience with this!
Closes: #5034
KeyMatrix will check all the pins used for any duplicate against the rows and columns.