Skip to content

Commit

Permalink
Merge pull request #4 from adafruit/gboy-mode
Browse files Browse the repository at this point in the history
Gboy mode
  • Loading branch information
jepler authored Dec 5, 2023
2 parents ec67bde + e043a31 commit 17bb8a3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
23 changes: 13 additions & 10 deletions adafruit_pycamera.py → adafruit_pycamera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ class PyCamera: # pylint: disable=too-many-instance-attributes,too-many-public-
# espcamera.FrameSize.P_FHD, # 1080x1920
espcamera.FrameSize.QSXGA, # 2560x1920
)
combined_list = list(zip(resolutions, resolution_to_frame_size))
print(combined_list)

effects = (
"Normal",
Expand All @@ -172,7 +170,7 @@ class PyCamera: # pylint: disable=too-many-instance-attributes,too-many-public-
"Sepia",
"Solarize",
)
modes = ("JPEG", "GIF", "STOP")
modes = ("JPEG", "GIF", "GBOY", "STOP")

_INIT_SEQUENCE = (
b"\x01\x80\x78" # _SWRESET and Delay 120ms
Expand Down Expand Up @@ -451,7 +449,10 @@ def select_setting(self, setting_name):
self._effect_label.background_color = 0x0
self._res_label.color = 0xFFFFFF
self._res_label.background_color = 0x0
self._res_label.text = self.resolutions[self._resolution]
if self.mode_text in ("GIF", "GBOY"):
self._res_label.text = ""
else:
self._res_label.text = self.resolutions[self._resolution]
self._mode_label.color = 0xFFFFFF
self._mode_label.background_color = 0x0
if setting_name == "effect":
Expand Down Expand Up @@ -490,7 +491,7 @@ def mode(self, setting):
self._mode_label.text = self.modes[setting]
if self.modes[setting] == "STOP":
self.stop_motion_frame = 0
if self.modes[setting] == "GIF":
if self.modes[setting] in ("GIF", "GBOY"):
self._res_label.text = ""
else:
self.resolution = self.resolution # kick it to reset the display
Expand Down Expand Up @@ -531,15 +532,15 @@ def resolution(self, res):
self._res_label.text = self.resolutions[res]
self.display.refresh()

def init_display(self):
def init_display(self, reset=True):
"""Initialize the TFT display"""
# construct displayio by hand
displayio.release_displays()
self._display_bus = displayio.FourWire(
self._spi,
command=board.TFT_DC,
chip_select=board.TFT_CS,
reset=board.TFT_RESET,
reset=board.TFT_RESET if reset else None,
baudrate=60_000_000,
)
self.display = board.DISPLAY
Expand Down Expand Up @@ -567,7 +568,7 @@ def display_message(self, message, color=0xFF0000, scale=3):
text_area = label.Label(terminalio.FONT, text=message, color=color, scale=scale)
text_area.anchor_point = (0.5, 0.5)
if not self.display:
self.init_display()
self.init_display(None)
text_area.anchored_position = (self.display.width / 2, self.display.height / 2)

# Show it
Expand All @@ -587,7 +588,9 @@ def mount_sd_card(self):
self._card_power.value = True
card_cs = DigitalInOut(board.CARD_CS)
card_cs.switch_to_output(False)
# deinit display and SPI
# deinit display and SPI bus because we need to drive all SD pins LOW
# to ensure nothing, not even an I/O pin, could possibly power the SD
# card
self.deinit_display()
self._spi.deinit()
sckpin = DigitalInOut(board.SCK)
Expand All @@ -611,7 +614,7 @@ def mount_sd_card(self):
vfs = storage.VfsFat(self.sdcard)
print("mount vfs @", time.monotonic() - self._timestamp)
storage.mount(vfs, "/sd")
self.init_display()
self.init_display(None)
self._image_counter = 0
self._sd_label.text = "SD OK"
self._sd_label.color = 0x00FF00
Expand Down
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions examples/camera/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
onionskin, last_frame, new_frame, displayio.Colorspace.RGB565_SWAPPED
)
pycam.blit(onionskin)
elif pycam.mode_text == "GBOY":
bitmaptools.dither(
last_frame, pycam.continuous_capture(), displayio.Colorspace.RGB565_SWAPPED
)
pycam.blit(last_frame)
else:
pycam.blit(pycam.continuous_capture())
# print("\t\t", capture_time, blit_time)
Expand Down Expand Up @@ -57,6 +62,23 @@
time.sleep(0.5)
pycam.live_preview_mode()

if pycam.mode_text == "GBOY":
try:
f = pycam.open_next_image("gif")
except RuntimeError as e:
pycam.display_message("Error\nNo SD Card", color=0xFF0000)
time.sleep(0.5)
continue

with gifio.GifWriter(
f,
pycam.camera.width,
pycam.camera.height,
displayio.Colorspace.RGB565_SWAPPED,
dither=True,
) as g:
g.add_frame(last_frame, 1)

if pycam.mode_text == "GIF":
try:
f = pycam.open_next_image("gif")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dynamic = ["dependencies", "optional-dependencies"]
[tool.setuptools]
# TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER,
# CHANGE `py_modules = ['...']` TO `packages = ['...']`
py-modules = ["adafruit_pycamera"]
packages = ["adafruit_pycamera"]

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}
Expand Down

0 comments on commit 17bb8a3

Please sign in to comment.