Skip to content

Commit 55cfdf3

Browse files
committed
Update examples with umount
Help avoid data corruption by unmounting SD card after use
1 parent 0229bfa commit 55cfdf3

3 files changed

+26
-8
lines changed

examples/bitmapsaver_screenshot_simpletest.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@
1212
import storage
1313
from adafruit_bitmapsaver import save_pixels
1414

15+
TAKE_SCREENSHOT = False # Set to True to take a screenshot
1516

1617
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
1718
cs = digitalio.DigitalInOut(board.SD_CS)
1819
sdcard = adafruit_sdcard.SDCard(spi, cs)
1920
vfs = storage.VfsFat(sdcard)
2021
storage.mount(vfs, "/sd")
2122

22-
print("Taking Screenshot...")
23-
save_pixels("/sd/screenshot.bmp")
24-
print("Screenshot taken")
23+
if TAKE_SCREENSHOT:
24+
print("Taking Screenshot... ")
25+
save_pixels("/sd/screenshot.bmp")
26+
print("Screenshot Saved")
27+
storage.umount(vfs)
28+
print("SD Card Unmounted") # Do not remove SD card until unmounted
29+

examples/bitmapsaver_screenshot_tft_featherwing.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
DISPLAY_WIDTH = 480
1717
DISPLAY_HEIGHT = 320
1818

19+
TAKE_SCREENSHOT = False # Set to True to take a screenshot
20+
1921
# Initialize Protocol Busses and SD Card
2022
spi = board.SPI()
2123
cs = digitalio.DigitalInOut(board.D5)
@@ -33,6 +35,10 @@
3335
virtual_root = "/sd"
3436
storage.mount(vfs, virtual_root)
3537

36-
print("Taking Screenshot... ")
37-
save_pixels("/sd/screenshot.bmp", display)
38-
print("Screenshot taken")
38+
if TAKE_SCREENSHOT:
39+
print("Taking Screenshot... ")
40+
save_pixels("/sd/screenshot.bmp", display)
41+
print("Screenshot Saved")
42+
storage.umount(vfs)
43+
print("SD Card Unmounted") # Do not remove SD card until unmounted
44+

examples/bitmapsaver_simpletest.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
# pylint:disable=invalid-name
1616

17+
TAKE_SCREENSHOT = False # Set to True to take a screenshot
18+
1719
print("Setting up SD card")
1820
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
1921
cs = digitalio.DigitalInOut(board.SD_CS)
@@ -50,5 +52,10 @@
5052
else:
5153
bitmap[x, y] = 0
5254

53-
print("Saving bitmap")
54-
save_pixels("/sd/test.bmp", bitmap, palette)
55+
if TAKE_SCREENSHOT:
56+
print("Taking Screenshot... ")
57+
save_pixels("/sd/screenshot.bmp", bitmap, palette)
58+
print("Screenshot Saved")
59+
storage.umount(vfs)
60+
print("SD Card Unmounted") # Do not remove SD card until unmounted
61+

0 commit comments

Comments
 (0)