Skip to content

Commit f273135

Browse files
authored
Merge pull request #28 from DJDevon3/DJDevon3_WorkingBranch
Update examples with umount
2 parents 5bf93e4 + b05534e commit f273135

3 files changed

+48
-35
lines changed
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: 2019 Dave Astels for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33

4-
54
"""Example of taking a screenshot."""
65

76
# pylint:disable=invalid-name
@@ -12,13 +11,18 @@
1211
import storage
1312
from adafruit_bitmapsaver import save_pixels
1413

14+
TAKE_SCREENSHOT = False # Set to True to take a screenshot
1515

16-
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
17-
cs = digitalio.DigitalInOut(board.SD_CS)
18-
sdcard = adafruit_sdcard.SDCard(spi, cs)
19-
vfs = storage.VfsFat(sdcard)
20-
storage.mount(vfs, "/sd")
16+
if TAKE_SCREENSHOT:
17+
# Initialize SD Card & Mount Virtual File System
18+
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
19+
cs = digitalio.DigitalInOut(board.SD_CS)
20+
sdcard = adafruit_sdcard.SDCard(spi, cs)
21+
vfs = storage.VfsFat(sdcard)
22+
storage.mount(vfs, "/sd") # /sd is root dir of SD Card
2123

22-
print("Taking Screenshot...")
23-
save_pixels("/sd/screenshot.bmp")
24-
print("Screenshot taken")
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
Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# SPDX-FileCopyrightText: 2022 DJDevon3 for Adafruit Industries
1+
# SPDX-FileCopyrightText: 2023 DJDevon3
22
# SPDX-License-Identifier: MIT
3-
"""Screenshot on a 3.5" TFT Featherwing (integrated SD Card)"""
3+
""" Screenshot on a 3.5" TFT Featherwing (integrated SD Card) """
44
# pylint:disable=invalid-name
5+
56
import board
67
import digitalio
78
import displayio
@@ -16,23 +17,27 @@
1617
DISPLAY_WIDTH = 480
1718
DISPLAY_HEIGHT = 320
1819

19-
# Initialize Protocol Busses and SD Card
20+
TAKE_SCREENSHOT = False # Set to True to take a screenshot
21+
22+
# Initialize SPI Bus
2023
spi = board.SPI()
21-
cs = digitalio.DigitalInOut(board.D5)
22-
sdcard = adafruit_sdcard.SDCard(spi, cs)
23-
vfs = storage.VfsFat(sdcard)
24-
displayio.release_displays()
2524

26-
# Setup Pinouts according to your feather board
25+
# Initialize TFT Featherwing Display
2726
tft_cs = board.D9
2827
tft_dc = board.D10
2928
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
3029
display = HX8357(display_bus, width=DISPLAY_WIDTH, height=DISPLAY_HEIGHT)
3130

32-
# Mount Virtual File System
33-
virtual_root = "/sd"
34-
storage.mount(vfs, virtual_root)
31+
if TAKE_SCREENSHOT:
32+
# Initialize SD Card & Mount Virtual File System
33+
cs = digitalio.DigitalInOut(board.D5)
34+
sdcard = adafruit_sdcard.SDCard(spi, cs)
35+
vfs = storage.VfsFat(sdcard)
36+
virtual_root = "/sd" # /sd is root dir of SD Card
37+
storage.mount(vfs, virtual_root)
3538

36-
print("Taking Screenshot... ")
37-
save_pixels("/sd/screenshot.bmp", display)
38-
print("Screenshot taken")
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

examples/bitmapsaver_simpletest.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# SPDX-FileCopyrightText: 2019 Dave Astels for Adafruit Industries
22
# SPDX-License-Identifier: MIT
3-
4-
53
"""Example of using save_bitmap"""
4+
# pylint:disable=invalid-name
65

76
import board
87
import busio
@@ -12,14 +11,7 @@
1211
import storage
1312
from adafruit_bitmapsaver import save_pixels
1413

15-
# pylint:disable=invalid-name
16-
17-
print("Setting up SD card")
18-
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
19-
cs = digitalio.DigitalInOut(board.SD_CS)
20-
sdcard = adafruit_sdcard.SDCard(spi, cs)
21-
vfs = storage.VfsFat(sdcard)
22-
storage.mount(vfs, "/sd")
14+
TAKE_SCREENSHOT = False # Set True to take a screenshot
2315

2416
WHITE = 0xFFFFFF
2517
BLACK = 0x000000
@@ -50,5 +42,17 @@
5042
else:
5143
bitmap[x, y] = 0
5244

53-
print("Saving bitmap")
54-
save_pixels("/sd/test.bmp", bitmap, palette)
45+
if TAKE_SCREENSHOT:
46+
# Initialize SD Card & Mount Virtual File System
47+
print("Setting up SD card")
48+
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
49+
cs = digitalio.DigitalInOut(board.SD_CS)
50+
sdcard = adafruit_sdcard.SDCard(spi, cs)
51+
vfs = storage.VfsFat(sdcard)
52+
storage.mount(vfs, "/sd") # /sd is root dir of SD Card
53+
54+
print("Taking Screenshot... ")
55+
save_pixels("/sd/screenshot.bmp", bitmap, palette)
56+
print("Screenshot Saved")
57+
storage.umount(vfs)
58+
print("SD Card Unmounted") # Do not remove SD card until unmounted

0 commit comments

Comments
 (0)