-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
M5Stack Cardputer keyboard handling improvements. #9529
M5Stack Cardputer keyboard handling improvements. #9529
Conversation
f75dd60
to
34ed9a3
Compare
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.
This is fine. Would you prefer to do this dynamically instead? We may be able to add functions to board
to do it.
This is how it is done for USB hosted keyboards: |
This is a reasonable idea. I didn't go for it immediately as I was not sure what would be the best interface for it and simply tried the simplest thing that came to mind first (and was easy enough to try even without deep knowledge of the codebase). Intuitively it currently seems to me that a reasonably clean solution would be to have some kind of a I'm not super-sure how this class would be best exposed to the python codebase and documented. Putting it into |
I think the ideal api would be booting with it as stdin, then whenever the user calls I don't think it's wise to try to get it under |
Given that for a few of the other boards that I've seen board.XXXXXX seems to always be either a pin or a display object, making board.KEYBOARD a function would feel rather inconsistent. I'd also find the behavior of detaching from stdin on object access pretty unintuitive (also, what if I want to use the object without detaching) and even more unintutiive if anything would happen to it automagically on scope expiration. Something like an explicit My suggestion about making a dedicated class is related to the fact that there is more to the keyboard than just being able to attach/detach it to stdin. Namely, the key ID to character mapping is a valuable thing and if not exposed from the built-in solution, most users would probably have to copy-paste-roll-their-own. To avoid this, we should expose this mapping somewhere. That "somewhere" could be the M5StackKeyboard class / module / variable, for example. I agree that putting this into shared-bindings feels unnecessary. However, if we have a class implementation hidden in the Is there a good place for documenting such a board-specific module / class / variable? |
You can put it in |
There isn't a great place. This is kinda the first board-specific functionality. I think bindings is fine. Other docs can live on Adafruit Playground: https://adafruit-playground.com/ |
34ed9a3
to
34c605e
Compare
... so I looked a bit into the directory structure and it feels to me that creating something like a espressif/bindings/m5stack_cardputer_keyboard, along with the need to introduce the pretty niche makefile variable and effectively require every build to indirectly be aware of this, is not nice at all. Things would then become especially ugly if the approach starts proliferating for any other boards that might want to implement a similar board-specific module. I'm therefore pretty convinced now that the code should go into I'll try to draft a new PR with a custom keyboard class implementation soon. |
Ya, that'd be a good idea. I think it'd help folks. |
* Exposed the DemuxKeyMatrix object as board.KEYBOARD. * Implemented the ability to not have the keyboard assigned as serial input (sys.stdin) by specifying M5STACK_CARDPUTER_KEYBOARD_SERIAL=0 in settings.toml. This enables custom handling of individual key up/key down events.
e0518b9
to
10beacf
Compare
... so I figured that making a subclass of DemuxKeyMatrix is a bit of a pain and instead just made a As previously, the board starts with the serial "attached". If the user does not need it, they can do something like:
which seems reasonable, at least for my personal purposes. As discussed above, the docs for this probably won't propagate anywhere so it will be a bit of a secret functionality for the time being (perhaps Google will do a good job pointing to this discussion when queried). WDYT? |
10beacf
to
7a99a70
Compare
- Move the keyboard-related code from board.c to cardputer_keyboard.c, exposed to python as cardputer_keyboard. - Remove board.KEYBOARD, provide cardputer_keyboard.KEYBOARD instead. - Provide additional methods in cardputer_keyboard: - detach_serial() - attach_serial() - key_to_char(key, shift)
7a99a70
to
4fb31c4
Compare
@tannewt ping |
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.
This is fine with me!
Want to try tweaking the make stubs
command to include this? https://github.com/adafruit/circuitpython/blob/main/Makefile#L266 Once it is in the stubs, then it should be made available in the API docs.
@konstantint Waiting for you to reply before merging. |
I took a quick peek at the I'd probably prefer merging this now as-is and looking into how to generate the documentation a bit later, to avoid this hanging for uncomfortably long (e.g. I'm probably too busy this weekend to take a look). |
Works for me! Thank you! |
For context, see discussion in 090f330