Skip to content

Commit b490831

Browse files
committed
Tighten up allocation excaption catching
1 parent 3357fef commit b490831

File tree

1 file changed

+6
-6
lines changed
  • PiCowbell_Camera_Demos/JPEG_Capture

1 file changed

+6
-6
lines changed

PiCowbell_Camera_Demos/JPEG_Capture/code.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ def open_next_image():
7878
cam.colorspace = adafruit_ov5640.OV5640_COLOR_JPEG
7979

8080
# Different platforms have different amounts of memory available.
81-
# Typically a Pico 2 can handle quality = 2 and a Pico can handle quality = 5.
82-
# Rather than detect and select sizes, let's try to detect the best dynamically
83-
# for broader platform support.
84-
# Start with the highest quality setting and attempt to allocate a buffer
81+
# Typically a Pico 2 can handle quality = 2 and a Pico can handle quality = 5.
82+
# Rather than detect and select sizes, let's try to detect the best dynamically
83+
# for broader platform support.
84+
# Start with the highest quality setting and attempt to allocate a buffer
8585
# of the necessary size. If it fails, try the next lowest.
8686
b = None
8787
for quality in range(2,55): #valid range is 2 to 54 inclusive
@@ -91,12 +91,12 @@ def open_next_image():
9191
b = bytearray(cam.capture_buffer_size)
9292
print(f"Quality {quality} successfully selected.")
9393
break
94-
except Exception:
94+
except MemoryError:
9595
print(f"Quality {quality} was too big. Trying next lowest.")
9696

9797
if b is None:
9898
print("There wasn't enough system memory to allocate the lowest quality buffer.")
99-
99+
100100
jpeg = cam.capture(b)
101101

102102
while True:

0 commit comments

Comments
 (0)