|
55 | 55 | } |
56 | 56 |
|
57 | 57 |
|
58 | | -def request_display_config(width, height, color_depth=None): |
| 58 | +def request_display_config(width=None, height=None, color_depth=None): |
59 | 59 | """ |
60 | 60 | Request a display size configuration. If the display is un-initialized, |
61 | 61 | or is currently using a different configuration it will be initialized |
62 | 62 | to the requested width and height. |
63 | 63 |
|
64 | 64 | This function will set the initialized display to ``supervisor.runtime.display`` |
65 | 65 |
|
66 | | - :param width: The width of the display in pixels. |
67 | | - :param height: The height of the display in pixels. |
| 66 | + :param width: The width of the display in pixels. Leave unspecified to default |
| 67 | + to the ``CIRCUITPY_DISPLAY_WIDTH`` environmental variable if provided. Otherwise, |
| 68 | + a ``ValueError`` exception will be thrown. |
| 69 | + :param height: The height of the display in pixels. Leave unspecified to default |
| 70 | + to the appropriate height for the provided width. |
68 | 71 | :param color_depth: The color depth of the display in bits. |
69 | 72 | Valid values are 1, 2, 4, 8, 16, 32. Larger resolutions must use |
70 | 73 | smaller color_depths due to RAM limitations. Default color_depth for |
71 | 74 | 720 and 640 width is 8, and default color_depth for 320 and 360 width |
72 | 75 | is 16. |
73 | 76 | :return: None |
74 | 77 | """ |
75 | | - if (width, height) not in VALID_DISPLAY_SIZES: |
| 78 | + # if user does not specify width, use default configuration |
| 79 | + if width is None and (width := os.getenv("CIRCUITPY_DISPLAY_WIDTH")) is None: |
| 80 | + raise ValueError("No CIRCUITPY_DISPLAY_WIDTH specified in settings.toml.") |
| 81 | + |
| 82 | + # check that we have a valid display size |
| 83 | + if (height is not None and (width, height) not in VALID_DISPLAY_SIZES) or ( |
| 84 | + height is None and width not in [size[0] for size in VALID_DISPLAY_SIZES] |
| 85 | + ): |
76 | 86 | raise ValueError(f"Invalid display size. Must be one of: {VALID_DISPLAY_SIZES}") |
77 | 87 |
|
| 88 | + # if user does not specify height, use matching height |
| 89 | + if height is None: |
| 90 | + height = next((h for w, h in VALID_DISPLAY_SIZES if width == w)) |
| 91 | + |
78 | 92 | # if user does not specify a requested color_depth |
79 | 93 | if color_depth is None: |
80 | 94 | # use the maximum color depth for given width |
|
0 commit comments