diff --git a/adafruit_pycamera.py b/adafruit_pycamera/__init__.py similarity index 97% rename from adafruit_pycamera.py rename to adafruit_pycamera/__init__.py index d71b8e2..d5abdab 100644 --- a/adafruit_pycamera.py +++ b/adafruit_pycamera/__init__.py @@ -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", @@ -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 @@ -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": @@ -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 @@ -531,7 +532,7 @@ 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() @@ -539,7 +540,7 @@ def init_display(self): 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 @@ -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 @@ -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) @@ -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 diff --git a/ov5640_autofocus.bin b/adafruit_pycamera/ov5640_autofocus.bin similarity index 100% rename from ov5640_autofocus.bin rename to adafruit_pycamera/ov5640_autofocus.bin diff --git a/ov5640_autofocus.bin.license b/adafruit_pycamera/ov5640_autofocus.bin.license similarity index 100% rename from ov5640_autofocus.bin.license rename to adafruit_pycamera/ov5640_autofocus.bin.license diff --git a/examples/camera/code.py b/examples/camera/code.py index 75b2996..de10475 100644 --- a/examples/camera/code.py +++ b/examples/camera/code.py @@ -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) @@ -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") diff --git a/pyproject.toml b/pyproject.toml index a7d0666..5fbf4d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"]}