Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions adafruit_fruitjam/peripherals.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,40 @@
}


def request_display_config(width, height, color_depth=None):
def request_display_config(width=None, height=None, color_depth=None):
"""
Request a display size configuration. If the display is un-initialized,
or is currently using a different configuration it will be initialized
to the requested width and height.

This function will set the initialized display to ``supervisor.runtime.display``

:param width: The width of the display in pixels.
:param height: The height of the display in pixels.
:param width: The width of the display in pixels. Leave unspecified to default
to the ``CIRCUITPY_DISPLAY_WIDTH`` environmental variable if provided. Otherwise,
a ``ValueError`` exception will be thrown.
:param height: The height of the display in pixels. Leave unspecified to default
to the appropriate height for the provided width.
:param color_depth: The color depth of the display in bits.
Valid values are 1, 2, 4, 8, 16, 32. Larger resolutions must use
smaller color_depths due to RAM limitations. Default color_depth for
720 and 640 width is 8, and default color_depth for 320 and 360 width
is 16.
:return: None
"""
if (width, height) not in VALID_DISPLAY_SIZES:
# if user does not specify width, use default configuration
if width is None and (width := os.getenv("CIRCUITPY_DISPLAY_WIDTH")) is None:
raise ValueError("No CIRCUITPY_DISPLAY_WIDTH specified in settings.toml.")

# check that we have a valid display size
if (height is not None and (width, height) not in VALID_DISPLAY_SIZES) or (
height is None and width not in [size[0] for size in VALID_DISPLAY_SIZES]
):
raise ValueError(f"Invalid display size. Must be one of: {VALID_DISPLAY_SIZES}")

# if user does not specify height, use matching height
if height is None:
height = next((h for w, h in VALID_DISPLAY_SIZES if width == w))

# if user does not specify a requested color_depth
if color_depth is None:
# use the maximum color depth for given width
Expand Down Expand Up @@ -202,7 +216,7 @@ def any_button_pressed(self) -> bool:
"""
Return whether any button is pressed
"""
return True in [button.value for (i, button) in enumerate(self._buttons)]
return True in [not button.value for (i, button) in enumerate(self._buttons)]

@property
def dac(self):
Expand Down