Skip to content
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

Check for inconsistent CIRCUITPY and display CircuitPython update message #29

Merged
merged 1 commit into from
Feb 21, 2024
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: 34 additions & 3 deletions adafruit_pycamera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# SPDX-License-Identifier: MIT
"""Library for the Adafruit PyCamera with OV5640 autofocus module"""

# pylint: disable=too-many-lines

import os
import struct
import time
Expand Down Expand Up @@ -276,6 +278,32 @@ def make_debounced_expander_pin(pin_no):

self.mute = make_expander_output(_AW_MUTE, False)

self.check_for_update_needed()

def check_for_update_needed(self):
"""Check whether CIRCUITPY is too big, indicating it was created
by a version of CircuitPython older than 9.0.0 beta 2.
If so display and print a message and hang.
"""
circuitpy_stat = os.statvfs("/")
# CIRCUITPY should be 960KB or so. >1MB is too large
# and indicates an older version of CircuitPython
# created the filesystem.
if circuitpy_stat[1] * circuitpy_stat[2] > 1000000:
message = """\
CIRCUITPY problem.
Backup. Update CPy
to >= 9.0.0-beta.2.
Reformat:
import storage
storage.erase_
filesystem()
See Learn Guide."""
self.display_message(message, color=0xFFFFFF, scale=2, full_screen=True)
print(message)
while True:
pass

def make_camera_ui(self):
"""Create displayio widgets for the standard camera UI"""
self._sd_label = label.Label(
Expand Down Expand Up @@ -678,13 +706,15 @@ def deinit_display(self):
self._display_bus = None
self.display = None

def display_message(self, message, color=0xFF0000, scale=3):
def display_message(self, message, color=0xFF0000, scale=3, full_screen=False):
"""Display a message on the TFT"""
text_area = label.Label(terminalio.FONT, text=message, color=color, scale=scale)
text_area.anchor_point = (0.5, 0.5)
text_area.anchor_point = (0, 0) if full_screen else (0.5, 0.5)
if not self.display:
self.init_display()
text_area.anchored_position = (self.display.width / 2, self.display.height / 2)
text_area.anchored_position = (
(0, 0) if full_screen else (self.display.width / 2, self.display.height / 2)
)

# Show it
self.splash.append(text_area)
Expand Down Expand Up @@ -994,6 +1024,7 @@ def __init__(self, init_autofocus=True):
self.init_neopixel()
self.init_display()
self.init_camera(init_autofocus)

try:
self.mount_sd_card()
except Exception as exc: # pylint: disable=broad-exception-caught
Expand Down
6 changes: 3 additions & 3 deletions examples/basic_camera/code.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# SPDX-FileCopyrightText: Copyright (c) 2023 john park for Adafruit Industries
#
# SPDX-License-Identifier: MIT
''' simple point-and-shoot camera example. No bells! Zero whistles! '''
""" simple point-and-shoot camera example. No bells! Zero whistles! """

import time
import adafruit_pycamera # pylint: disable=import-error
import adafruit_pycamera # pylint: disable=import-error

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

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