-
Notifications
You must be signed in to change notification settings - Fork 29
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
Support hot-plugging microSD cards for better UX #157
Comments
I've made a simple test to see if it was possible, and it is! See the gist for a simple loop implementation: The idea came from the MaixPy wiki docs here: https://wiki.sipeed.com/soft/maixpy/en/others/maixpy_faq.html#TF-card-format-is-right%2C-but-can%27t-read-tf-card-anf-failed-mount |
Awesome, thanks for finding and testing this! Did you happen to check if this worked with the selfcustody fork of MaixPy that Krux uses? I ask because we're about a year or more out of date with the MaixPy upstream repo right now, so I'm not sure if this will work or not without updating it. But we should probably try to update our fork regardless. |
Yes! I've tested and it is working on the current MaixPy from selfcustody, the one Krux uses. It freezes a little when trying to mount the SD (~1 sec), so I don't think it is good to put on the While loops, but instead I think we should check every time right before the usage (when click on PSBT or message for example) |
@tadeubas Sounds good to me. Are you working on a PR for this? |
Not yet... I would need to know more about all the functionalities that Krux enables the use of a SD card |
The easiest way to find all uses of the SD card would be to look for the string
In terms of implementing this, maybe we could streamline this mounting process by adding a
So, for example, you could convert this: if self.ctx.sd_card is not None:
self.ctx.display.clear()
if self.prompt(
t("Save signature to SD card?"), self.ctx.display.height() // 2
):
sig_filename = "signed-message.sig"
with open("/sd/%s" % sig_filename, "wb") as sig_file:
sig_file.write(sig)
self.ctx.display.flash_text(
t("Saved signature to SD card:\n%s") % sig_filename
) to this: with mount_sdcard() as sd:
self.ctx.display.clear()
if self.prompt(
t("Save signature to SD card?"), self.ctx.display.height() // 2
):
sig_filename = "signed-message.sig"
sd.write_binary(sig_filename, sig)
self.ctx.display.flash_text(
t("Saved signature to SD card:\n%s") % sig_filename
) The idea being that this new Alternatively, we could add a contextmanager function similar to I think either would suffice, but the latter might be more standard/pythonic and simpler, since you wouldn't need to add an |
Awesome idea! I can't think of a better alternative. Will do this |
The only problem is that micropython doesn't have the Should we add this lib in the vendor folder? For Python 3.11 version? https://github.com/python/cpython/blob/3.11/Lib/contextlib.py EDIT: |
Forget what I've said, it is possible to customize a class |
Hi @jreesun this issue is finished in the PR. Only 2 tests are broken, but the feature is working fine on the device |
Krux can only detect a microSD card at boot which makes the PSBT signing flow awkward and cumbersome if you're reading and writing the files to the card. It would be better if you could remove and insert a card at any point during runtime.
To solve this, I think we should update our MaixPy fork to no longer mount an SD card on startup in
maixpy_main.c
, but rather add support for the Micropython machine.SDCard module which should, in theory, let us mount (and re-mount) an SD card from our "userspace" Krux python code.See here for how we could do it:
https://github.com/loboris/MicroPython_K210_LoBo/blob/master/k210-freertos/mpy_support/standard_lib/uos/vfs_sdcard.c
The text was updated successfully, but these errors were encountered: