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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions examples/bitmapsaver_screenshot_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-FileCopyrightText: 2019 Dave Astels for Adafruit Industries
# SPDX-License-Identifier: MIT


"""Example of taking a screenshot."""

# pylint:disable=invalid-name
Expand All @@ -12,13 +11,18 @@
import storage
from adafruit_bitmapsaver import save_pixels

TAKE_SCREENSHOT = False # Set to True to take a screenshot

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

print("Taking Screenshot...")
save_pixels("/sd/screenshot.bmp")
print("Screenshot taken")
print("Taking Screenshot... ")
save_pixels("/sd/screenshot.bmp")
print("Screenshot Saved")
storage.umount(vfs)
print("SD Card Unmounted") # Do not remove SD card until unmounted
33 changes: 19 additions & 14 deletions examples/bitmapsaver_screenshot_tft_featherwing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SPDX-FileCopyrightText: 2022 DJDevon3 for Adafruit Industries
# SPDX-FileCopyrightText: 2023 DJDevon3
# SPDX-License-Identifier: MIT
"""Screenshot on a 3.5" TFT Featherwing (integrated SD Card)"""
""" Screenshot on a 3.5" TFT Featherwing (integrated SD Card) """
# pylint:disable=invalid-name

import board
import digitalio
import displayio
Expand All @@ -16,23 +17,27 @@
DISPLAY_WIDTH = 480
DISPLAY_HEIGHT = 320

# Initialize Protocol Busses and SD Card
TAKE_SCREENSHOT = False # Set to True to take a screenshot

# Initialize SPI Bus
spi = board.SPI()
cs = digitalio.DigitalInOut(board.D5)
sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
displayio.release_displays()

# Setup Pinouts according to your feather board
# Initialize TFT Featherwing Display
tft_cs = board.D9
tft_dc = board.D10
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
display = HX8357(display_bus, width=DISPLAY_WIDTH, height=DISPLAY_HEIGHT)

# Mount Virtual File System
virtual_root = "/sd"
storage.mount(vfs, virtual_root)
if TAKE_SCREENSHOT:
# Initialize SD Card & Mount Virtual File System
cs = digitalio.DigitalInOut(board.D5)
sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
virtual_root = "/sd" # /sd is root dir of SD Card
storage.mount(vfs, virtual_root)

print("Taking Screenshot... ")
save_pixels("/sd/screenshot.bmp", display)
print("Screenshot taken")
print("Taking Screenshot... ")
save_pixels("/sd/screenshot.bmp", display)
print("Screenshot Saved")
storage.umount(vfs)
print("SD Card Unmounted") # Do not remove SD card until unmounted
28 changes: 16 additions & 12 deletions examples/bitmapsaver_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# SPDX-FileCopyrightText: 2019 Dave Astels for Adafruit Industries
# SPDX-License-Identifier: MIT


"""Example of using save_bitmap"""
# pylint:disable=invalid-name

import board
import busio
Expand All @@ -12,14 +11,7 @@
import storage
from adafruit_bitmapsaver import save_pixels

# pylint:disable=invalid-name

print("Setting up SD card")
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs = digitalio.DigitalInOut(board.SD_CS)
sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
TAKE_SCREENSHOT = False # Set True to take a screenshot

WHITE = 0xFFFFFF
BLACK = 0x000000
Expand Down Expand Up @@ -50,5 +42,17 @@
else:
bitmap[x, y] = 0

print("Saving bitmap")
save_pixels("/sd/test.bmp", bitmap, palette)
if TAKE_SCREENSHOT:
# Initialize SD Card & Mount Virtual File System
print("Setting up SD card")
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs = digitalio.DigitalInOut(board.SD_CS)
sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd") # /sd is root dir of SD Card

print("Taking Screenshot... ")
save_pixels("/sd/screenshot.bmp", bitmap, palette)
print("Screenshot Saved")
storage.umount(vfs)
print("SD Card Unmounted") # Do not remove SD card until unmounted