Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 17bb8a3

Browse files
authoredDec 5, 2023
Merge pull request #4 from adafruit/gboy-mode
Gboy mode
2 parents ec67bde + e043a31 commit 17bb8a3

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed
 

‎adafruit_pycamera.py renamed to ‎adafruit_pycamera/__init__.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ class PyCamera: # pylint: disable=too-many-instance-attributes,too-many-public-
159159
# espcamera.FrameSize.P_FHD, # 1080x1920
160160
espcamera.FrameSize.QSXGA, # 2560x1920
161161
)
162-
combined_list = list(zip(resolutions, resolution_to_frame_size))
163-
print(combined_list)
164162

165163
effects = (
166164
"Normal",
@@ -172,7 +170,7 @@ class PyCamera: # pylint: disable=too-many-instance-attributes,too-many-public-
172170
"Sepia",
173171
"Solarize",
174172
)
175-
modes = ("JPEG", "GIF", "STOP")
173+
modes = ("JPEG", "GIF", "GBOY", "STOP")
176174

177175
_INIT_SEQUENCE = (
178176
b"\x01\x80\x78" # _SWRESET and Delay 120ms
@@ -451,7 +449,10 @@ def select_setting(self, setting_name):
451449
self._effect_label.background_color = 0x0
452450
self._res_label.color = 0xFFFFFF
453451
self._res_label.background_color = 0x0
454-
self._res_label.text = self.resolutions[self._resolution]
452+
if self.mode_text in ("GIF", "GBOY"):
453+
self._res_label.text = ""
454+
else:
455+
self._res_label.text = self.resolutions[self._resolution]
455456
self._mode_label.color = 0xFFFFFF
456457
self._mode_label.background_color = 0x0
457458
if setting_name == "effect":
@@ -490,7 +491,7 @@ def mode(self, setting):
490491
self._mode_label.text = self.modes[setting]
491492
if self.modes[setting] == "STOP":
492493
self.stop_motion_frame = 0
493-
if self.modes[setting] == "GIF":
494+
if self.modes[setting] in ("GIF", "GBOY"):
494495
self._res_label.text = ""
495496
else:
496497
self.resolution = self.resolution # kick it to reset the display
@@ -531,15 +532,15 @@ def resolution(self, res):
531532
self._res_label.text = self.resolutions[res]
532533
self.display.refresh()
533534

534-
def init_display(self):
535+
def init_display(self, reset=True):
535536
"""Initialize the TFT display"""
536537
# construct displayio by hand
537538
displayio.release_displays()
538539
self._display_bus = displayio.FourWire(
539540
self._spi,
540541
command=board.TFT_DC,
541542
chip_select=board.TFT_CS,
542-
reset=board.TFT_RESET,
543+
reset=board.TFT_RESET if reset else None,
543544
baudrate=60_000_000,
544545
)
545546
self.display = board.DISPLAY
@@ -567,7 +568,7 @@ def display_message(self, message, color=0xFF0000, scale=3):
567568
text_area = label.Label(terminalio.FONT, text=message, color=color, scale=scale)
568569
text_area.anchor_point = (0.5, 0.5)
569570
if not self.display:
570-
self.init_display()
571+
self.init_display(None)
571572
text_area.anchored_position = (self.display.width / 2, self.display.height / 2)
572573

573574
# Show it
@@ -587,7 +588,9 @@ def mount_sd_card(self):
587588
self._card_power.value = True
588589
card_cs = DigitalInOut(board.CARD_CS)
589590
card_cs.switch_to_output(False)
590-
# deinit display and SPI
591+
# deinit display and SPI bus because we need to drive all SD pins LOW
592+
# to ensure nothing, not even an I/O pin, could possibly power the SD
593+
# card
591594
self.deinit_display()
592595
self._spi.deinit()
593596
sckpin = DigitalInOut(board.SCK)
@@ -611,7 +614,7 @@ def mount_sd_card(self):
611614
vfs = storage.VfsFat(self.sdcard)
612615
print("mount vfs @", time.monotonic() - self._timestamp)
613616
storage.mount(vfs, "/sd")
614-
self.init_display()
617+
self.init_display(None)
615618
self._image_counter = 0
616619
self._sd_label.text = "SD OK"
617620
self._sd_label.color = 0x00FF00
File renamed without changes.

‎examples/camera/code.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
onionskin, last_frame, new_frame, displayio.Colorspace.RGB565_SWAPPED
3131
)
3232
pycam.blit(onionskin)
33+
elif pycam.mode_text == "GBOY":
34+
bitmaptools.dither(
35+
last_frame, pycam.continuous_capture(), displayio.Colorspace.RGB565_SWAPPED
36+
)
37+
pycam.blit(last_frame)
3338
else:
3439
pycam.blit(pycam.continuous_capture())
3540
# print("\t\t", capture_time, blit_time)
@@ -57,6 +62,23 @@
5762
time.sleep(0.5)
5863
pycam.live_preview_mode()
5964

65+
if pycam.mode_text == "GBOY":
66+
try:
67+
f = pycam.open_next_image("gif")
68+
except RuntimeError as e:
69+
pycam.display_message("Error\nNo SD Card", color=0xFF0000)
70+
time.sleep(0.5)
71+
continue
72+
73+
with gifio.GifWriter(
74+
f,
75+
pycam.camera.width,
76+
pycam.camera.height,
77+
displayio.Colorspace.RGB565_SWAPPED,
78+
dither=True,
79+
) as g:
80+
g.add_frame(last_frame, 1)
81+
6082
if pycam.mode_text == "GIF":
6183
try:
6284
f = pycam.open_next_image("gif")

‎pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ dynamic = ["dependencies", "optional-dependencies"]
4444
[tool.setuptools]
4545
# TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER,
4646
# CHANGE `py_modules = ['...']` TO `packages = ['...']`
47-
py-modules = ["adafruit_pycamera"]
47+
packages = ["adafruit_pycamera"]
4848

4949
[tool.setuptools.dynamic]
5050
dependencies = {file = ["requirements.txt"]}

0 commit comments

Comments
 (0)
Please sign in to comment.