Skip to content

Update examples with umount #28

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 4 commits into from
Jun 18, 2023
Merged

Conversation

DJDevon3
Copy link
Contributor

Help avoid data corruption by unmounting SD card after use

DJDevon3 added 2 commits May 19, 2023 21:37
Help avoid data corruption by unmounting SD card after use
ran black on directory
@tekktrik tekktrik requested a review from a team May 26, 2023 13:29
@tekktrik
Copy link
Member

This looks good to me, did you test these as well?

@DJDevon3
Copy link
Contributor Author

@tekktrik Only tested the TFT featherwing example and can confirm it works well. The other 2 I did just because I was in there. Should I not submit things I cannot explicitly test? It seemed like a shame to leave the other 2 examples alone without umount. I probably should have specified that in the original commit sorry.

@tekktrik
Copy link
Member

No, totally fine to PR things you haven't tested! Just wanted to check, definitely always makes me more confident when it is tested is all :)

@tekktrik
Copy link
Member

I'm out today but will look tomorrow!

Copy link
Member

@tekktrik tekktrik left a comment

Choose a reason for hiding this comment

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

Does it make sense to just take out TAKE_SCREENSHOT (assuming it's value would always be true) and always begin the block of taking the screenshot and then unmounting the SD card? Or is there a specific reason it would be helpful to toggle it, and why that default value is False?

@DJDevon3
Copy link
Contributor Author

DJDevon3 commented May 29, 2023

Take screenshot is False by default. Set to true to take a screenshot.

A good real world example is at the very end of my feather weather project. That's my old "YOLO version" as Anecdata puts it where I race a 120 second timer to remove the SD card, upload it to the PC, and put it back. Still have to update my own scripts.

I included the if statement because I believe its in everyone's best interest to become accustomed to using it in that way, especially beginners.

Technically it doesn't need to be there... but then neither does umount. It adds safety measures so you don't

  1. take a screenshot when you don't mean to. Depending on screen size and MCU power this can take up to 5 minutes and you cannot back out once started. Conversely, depending on the speed of your MCU (esp32-s3 or iMX) and a tiny display you might get into a loop of never ending screenshot taking and by attempting to stop it mid-stream you risk data corruption.
  2. possibly corrupt data because you're unaware how important umount is.

Stopping an SD write mid-stream won't just corrupt the file you're trying to write, it will create gibberish files that cannot be deleted and/or corrupt your entire SD card.

Between the if statement and umount the risk of data corruption and infinite screenshot taking loop is virtually eliminated. For advanced users with never ending scripts at some point you'll likely want to remount but that is unnecessary in the simpletest examples. umount however is definitely necessary.

They're features I wish would have been included in the examples from the beginning. I've used this library more than anyone else I know. I've used it on the NRF52840, M0's, M4's, and ESP32-S2 & S3. Beginners in particular will run into data corruption issues if those 2 features are not included. I learned the hard way, these features are necessary.

Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

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

Thank you @DJDevon3.

I tested all 3 examples, two on a PyPortal Titano, and the other with Feather RP2040 + TFT Featherwing.

I think it's okay to have the TAKE_SCREENSHOT variable even though it's not strictly necessary. It's convenient to a high level switch like this so that you can keep the code on your device but only enable it when specifically interested in writing the screenshots.

However I do think we should make one of two possible further changes:

Move the initialization of the SDCard to inside of the if TAKE_SCREENSHOT: block so that if the variable is false the SDCard won't get initialized or mounted.

Or

Move storage.umount(vfs) to outside / below the if statement.

Because as it is now, when TAKE_SCREENSHOT is False it means the SDCard will get initialized and mounted, but then not unmounted since that is currently inside the if block. Which is one of the things this change is intending to help guard against.

@DJDevon3
Copy link
Contributor Author

@FoamyGuy that's a great point and points out a flaw in the way I've been using it. Will take another shot at improving it. Thank you for the excellent guidance.

As requested by review. Unable to test the "bitmapsaver_simpletest" bitmap palette example on my featherwing since SCK is in use by other things.
@DJDevon3
Copy link
Contributor Author

DJDevon3 commented Jun 13, 2023

Moved SD Card initialization into take screenshot if statement. Works well.
Tested the bitmapsaver_screenshot_simpletest.py & bitmapsaver_screenshot_tft_featherwing.py. example successfully

screenshot

was unable to successfully test the bitmapsaver_simpletest.py example on my tft featherwing because sck in use. if a reviewer could test/confirm that works then push it. it just won't work by default on a 3.5" tft featherwing which is why we have a separate example for the tft featherwing. :) I'm not sure what hardware it's designed for so I don't want to mess with that one too much since I can't successfully test for it.

Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

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

The current version looks good to me. I tested the simpletest successfully on a PyPortal Titano.

@FoamyGuy FoamyGuy merged commit f273135 into adafruit:main Jun 18, 2023
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jun 19, 2023
Updating https://github.com/adafruit/Adafruit_CircuitPython_BitmapSaver to 1.2.10 from 1.2.9:
  > Merge pull request adafruit/Adafruit_CircuitPython_BitmapSaver#28 from DJDevon3/DJDevon3_WorkingBranch

Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 1.14.1 from 1.14.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Requests#133 from DJDevon3/WorkingBranch

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
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.

3 participants