Skip to content
Merged
Changes from 3 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
17 changes: 14 additions & 3 deletions adafruit_fruitjam/peripherals.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
}


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
Expand All @@ -72,9 +72,20 @@ def request_display_config(width, height, color_depth=None):
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 +213,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