5555}
5656
5757
58- def request_display_config (width , height , color_depth = None ):
58+ def request_display_config (width = None , height = None , color_depth = None ):
5959 """
6060 Request a display size configuration. If the display is un-initialized,
6161 or is currently using a different configuration it will be initialized
@@ -72,8 +72,22 @@ def request_display_config(width, height, color_depth=None):
7272 is 16.
7373 :return: None
7474 """
75- if (width , height ) not in VALID_DISPLAY_SIZES :
75+ # if user does not specify width, use default configuration
76+ if width is None and (width := os .getenv ("CIRCUITPY_DISPLAY_WIDTH" )) is None :
77+ raise ValueError ("No CIRCUITPY_DISPLAY_WIDTH specified in settings.toml." )
78+
79+ # check that we have a valid display size
80+ if (
81+ (height is not None and (width , height ) not in VALID_DISPLAY_SIZES ) or
82+ (height is None and width not in [size [0 ] for size in VALID_DISPLAY_SIZES ])
83+ ):
7684 raise ValueError (f"Invalid display size. Must be one of: { VALID_DISPLAY_SIZES } " )
85+
86+ # if user does not specify height, use matching height
87+ if height is None :
88+ for size in VALID_DISPLAY_SIZES :
89+ if width == size [0 ]:
90+ height = size [1 ]
7791
7892 # if user does not specify a requested color_depth
7993 if color_depth is None :
@@ -202,7 +216,7 @@ def any_button_pressed(self) -> bool:
202216 """
203217 Return whether any button is pressed
204218 """
205- return True in [button .value for (i , button ) in enumerate (self ._buttons )]
219+ return True in [not button .value for (i , button ) in enumerate (self ._buttons )]
206220
207221 @property
208222 def dac (self ):
0 commit comments