Skip to content

Commit 516d9a6

Browse files
authored
Merge pull request #29 from dhalbert/circuitpython-update-check
Check for inconsistent CIRCUITPY and display CircuitPython update message
2 parents 00691dd + a6e2d38 commit 516d9a6

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

adafruit_pycamera/__init__.py

+34-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# SPDX-License-Identifier: MIT
55
"""Library for the Adafruit PyCamera with OV5640 autofocus module"""
66

7+
# pylint: disable=too-many-lines
8+
79
import os
810
import struct
911
import time
@@ -276,6 +278,32 @@ def make_debounced_expander_pin(pin_no):
276278

277279
self.mute = make_expander_output(_AW_MUTE, False)
278280

281+
self.check_for_update_needed()
282+
283+
def check_for_update_needed(self):
284+
"""Check whether CIRCUITPY is too big, indicating it was created
285+
by a version of CircuitPython older than 9.0.0 beta 2.
286+
If so display and print a message and hang.
287+
"""
288+
circuitpy_stat = os.statvfs("/")
289+
# CIRCUITPY should be 960KB or so. >1MB is too large
290+
# and indicates an older version of CircuitPython
291+
# created the filesystem.
292+
if circuitpy_stat[1] * circuitpy_stat[2] > 1000000:
293+
message = """\
294+
CIRCUITPY problem.
295+
Backup. Update CPy
296+
to >= 9.0.0-beta.2.
297+
Reformat:
298+
import storage
299+
storage.erase_
300+
filesystem()
301+
See Learn Guide."""
302+
self.display_message(message, color=0xFFFFFF, scale=2, full_screen=True)
303+
print(message)
304+
while True:
305+
pass
306+
279307
def make_camera_ui(self):
280308
"""Create displayio widgets for the standard camera UI"""
281309
self._sd_label = label.Label(
@@ -678,13 +706,15 @@ def deinit_display(self):
678706
self._display_bus = None
679707
self.display = None
680708

681-
def display_message(self, message, color=0xFF0000, scale=3):
709+
def display_message(self, message, color=0xFF0000, scale=3, full_screen=False):
682710
"""Display a message on the TFT"""
683711
text_area = label.Label(terminalio.FONT, text=message, color=color, scale=scale)
684-
text_area.anchor_point = (0.5, 0.5)
712+
text_area.anchor_point = (0, 0) if full_screen else (0.5, 0.5)
685713
if not self.display:
686714
self.init_display()
687-
text_area.anchored_position = (self.display.width / 2, self.display.height / 2)
715+
text_area.anchored_position = (
716+
(0, 0) if full_screen else (self.display.width / 2, self.display.height / 2)
717+
)
688718

689719
# Show it
690720
self.splash.append(text_area)
@@ -994,6 +1024,7 @@ def __init__(self, init_autofocus=True):
9941024
self.init_neopixel()
9951025
self.init_display()
9961026
self.init_camera(init_autofocus)
1027+
9971028
try:
9981029
self.mount_sd_card()
9991030
except Exception as exc: # pylint: disable=broad-exception-caught

examples/basic_camera/code.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2023 john park for Adafruit Industries
22
#
33
# SPDX-License-Identifier: MIT
4-
''' simple point-and-shoot camera example. No bells! Zero whistles! '''
4+
""" simple point-and-shoot camera example. No bells! Zero whistles! """
55

66
import time
7-
import adafruit_pycamera # pylint: disable=import-error
7+
import adafruit_pycamera # pylint: disable=import-error
88

99
pycam = adafruit_pycamera.PyCamera()
1010
pycam.mode = 0 # only mode 0 (JPEG) will work in this example
1111

1212
# User settings - try changing these:
13-
pycam.resolution = 8 # 0-12 preset resolutions:
13+
pycam.resolution = 8 # 0-12 preset resolutions:
1414
# 0: 240x240, 1: 320x240, 2: 640x480, 3: 800x600, 4: 1024x768,
1515
# 5: 1280x720, 6: 1280x1024, 7: 1600x1200, 8: 1920x1080, 9: 2048x1536,
1616
# 10: 2560x1440, 11: 2560x1600, 12: 2560x1920

0 commit comments

Comments
 (0)