Skip to content

change from using adafruit_sdcard to sdcardio #83

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 6 commits into from
Sep 10, 2020
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
37 changes: 22 additions & 15 deletions adafruit_pyportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,15 @@
import rtc
import supervisor
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
import adafruit_sdcard

try:
import sdcardio

NATIVE_SD = True
except ImportError:
import adafruit_sdcard as sdcardio

NATIVE_SD = False

if hasattr(board, "TOUCH_XL"):
import adafruit_touchscreen
Expand Down Expand Up @@ -328,10 +335,12 @@ def __init__(

if self._debug:
print("Init SD Card")
sd_cs = DigitalInOut(board.SD_CS)
sd_cs = board.SD_CS
if not NATIVE_SD:
sd_cs = DigitalInOut(sd_cs)
self._sdcard = None
try:
self._sdcard = adafruit_sdcard.SDCard(spi, sd_cs)
self._sdcard = sdcardio.SDCard(spi, sd_cs)
vfs = storage.VfsFat(self._sdcard)
storage.mount(vfs, "/sd")
except OSError as error:
Expand Down Expand Up @@ -660,10 +669,10 @@ def get_local_time(self, location=None):
try:
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]
except KeyError:
except KeyError as error:
raise KeyError(
"\n\nOur time service requires a login/password to rate-limit. Please register for a free adafruit.io account and place the user/key in your secrets file under 'aio_username' and 'aio_key'" # pylint: disable=line-too-long
)
) from error

location = secrets.get("timezone", location)
if location:
Expand All @@ -686,10 +695,10 @@ def get_local_time(self, location=None):
year_day = int(times[2])
week_day = int(times[3])
is_dst = None # no way to know yet
except KeyError:
except KeyError as error:
raise KeyError(
"Was unable to lookup the time, try setting secrets['timezone'] according to http://worldtimeapi.org/timezones" # pylint: disable=line-too-long
)
) from error
year, month, mday = [int(x) for x in the_date.split("-")]
the_time = the_time.split(".")[0]
hours, minutes, seconds = [int(x) for x in the_time.split(":")]
Expand Down Expand Up @@ -778,10 +787,10 @@ def image_converter_url(image_url, width, height, color_depth=16):
try:
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]
except KeyError:
except KeyError as error:
raise KeyError(
"\n\nOur image converter service require a login/password to rate-limit. Please register for a free adafruit.io account and place the user/key in your secrets file under 'aio_username' and 'aio_key'" # pylint: disable=line-too-long
)
) from error

return IMAGE_CONVERTER_SERVICE % (
aio_username,
Expand Down Expand Up @@ -813,10 +822,10 @@ def push_to_io(self, feed_key, data):
try:
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]
except KeyError:
except KeyError as error:
raise KeyError(
"Adafruit IO secrets are kept in secrets.py, please add them there!\n\n"
)
) from error

wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(
self._esp, secrets, None
Expand Down Expand Up @@ -970,13 +979,11 @@ def fetch(self, refresh_url=None, timeout=10):
try:
self.wget(image_url, filename, chunk_size=chunk_size)
except OSError as error:
print(error)
raise OSError(
"""\n\nNo writable filesystem found for saving datastream. Insert an SD card or set internal filesystem to be unsafe by setting 'disable_concurrent_write_protection' in the mount options in boot.py""" # pylint: disable=line-too-long
)
) from error
except RuntimeError as error:
print(error)
raise RuntimeError("wget didn't write a complete file")
raise RuntimeError("wget didn't write a complete file") from error
if iwidth < iheight:
pwidth = int(
self._image_resize[1]
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"secrets",
"adafruit_sdcard",
"storage",
"sdcardio",
"adafruit_io",
"adafruit_cursorcontrol",
"adafruit_requests",
Expand Down