Skip to content

Commit 1e75869

Browse files
authored
Merge branch 'main' into overlays
2 parents 30544c7 + 491e88e commit 1e75869

File tree

7 files changed

+44
-6
lines changed

7 files changed

+44
-6
lines changed

adafruit_pycamera/__init__.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44
# SPDX-License-Identifier: MIT
55
"""Library for the Adafruit PyCamera with OV5640 autofocus module"""
6+
67
# pylint: disable=too-many-lines
78
import gc
89
import os
@@ -283,6 +284,32 @@ def make_debounced_expander_pin(pin_no):
283284

284285
self.mute = make_expander_output(_AW_MUTE, False)
285286

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

688-
def display_message(self, message, color=0xFF0000, scale=3):
715+
def display_message(self, message, color=0xFF0000, scale=3, full_screen=False):
689716
"""Display a message on the TFT"""
690717
text_area = label.Label(terminalio.FONT, text=message, color=color, scale=scale)
691-
text_area.anchor_point = (0.5, 0.5)
718+
text_area.anchor_point = (0, 0) if full_screen else (0.5, 0.5)
692719
if not self.display:
693720
self.init_display()
694-
text_area.anchored_position = (self.display.width / 2, self.display.height / 2)
721+
text_area.anchored_position = (
722+
(0, 0) if full_screen else (self.display.width / 2, self.display.height / 2)
723+
)
695724

696725
# Show it
697726
self.splash.append(text_area)
@@ -1101,6 +1130,7 @@ def __init__(self, init_autofocus=True):
11011130
self.init_neopixel()
11021131
self.init_display()
11031132
self.init_camera(init_autofocus)
1133+
11041134
try:
11051135
self.mount_sd_card()
11061136
except Exception as exc: # pylint: disable=broad-exception-caught

examples/ipcam/code.py renamed to examples/web_camera/code.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@
2222
pycam.camera.quality = 6
2323

2424
server = Server(socketpool.SocketPool(wifi.radio))
25-
PORT = 81
25+
if wifi.radio.ipv4_address:
26+
# use alt port if web workflow enabled
27+
port = 8080
28+
else:
29+
# connect to wifi and use standard http port otherwise
30+
wifi.radio.connect(os.getenv("WIFI_SSID"), os.getenv("WIFI_PASSWORD"))
31+
port = 80
32+
2633
BOUNDARY = b"FRAME" + binascii.hexlify(os.urandom(8))
2734

2835

@@ -51,7 +58,7 @@ def body():
5158

5259

5360
async def poll(interval):
54-
server.start(str(wifi.radio.ipv4_address), port=PORT)
61+
server.start(str(wifi.radio.ipv4_address), port=port)
5562
while True:
5663
try:
5764
server.poll()
@@ -65,6 +72,6 @@ async def main():
6572
await asyncio.gather(poll_task)
6673

6774

68-
pycam.display_message(f"{wifi.radio.ipv4_address}:{PORT}/", scale=2)
75+
pycam.display_message(f"{wifi.radio.ipv4_address}:{port}/", scale=2)
6976

7077
asyncio.run(main())

examples/ipcam2/code.py renamed to examples/web_settings_explorer/code.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,5 @@ def property_common(obj, request):
119119
return JSONResponse(request, {"error": str(exc)}, status=BAD_REQUEST_400)
120120

121121

122+
pycam.display_message(f"{wifi.radio.ipv4_address}:{port}/", scale=2)
122123
server.serve_forever(str(wifi.radio.ipv4_address), port)

0 commit comments

Comments
 (0)