Skip to content

Commit ebbd201

Browse files
committed
Support CIRCUITPY_DISPLAY_WIDTH environment variable
1 parent 9bcfe9f commit ebbd201

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/code.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import adafruit_imageload
2525
import adafruit_usb_host_descriptors
2626
from adafruit_anchored_group import AnchoredGroup
27-
from adafruit_fruitjam.peripherals import request_display_config
27+
from adafruit_fruitjam.peripherals import request_display_config, VALID_DISPLAY_SIZES
2828
from adafruit_argv_file import read_argv, write_argv
2929

3030
"""
@@ -53,14 +53,18 @@
5353
print(f"launching: {next_code_file}")
5454
supervisor.reload()
5555

56-
# read environment variables
57-
aspect_ratio_4x3 = os.getenv("FRUIT_JAM_OS_4x3", 0)
58-
59-
if aspect_ratio_4x3:
60-
request_display_config(640, 480)
61-
else:
62-
request_display_config(720, 400)
6356
display = supervisor.runtime.display
57+
if display is None:
58+
width_config = os.getenv("CIRCUITPY_DISPLAY_WIDTH")
59+
if width_config is None:
60+
request_display_config(720, 400)
61+
elif width_config in [x[0] for x in VALID_DISPLAY_SIZES]:
62+
for display_size in VALID_DISPLAY_SIZES:
63+
if display_size[0] == width_config:
64+
request_display_config(*display_size)
65+
break
66+
else:
67+
raise ValueError(f"Invalid display size. Must be one of: {VALID_DISPLAY_SIZES}")
6468

6569
scale = 1
6670
if display.width > 360:
@@ -142,12 +146,8 @@
142146

143147
mouse_buf = array.array("b", [0] * 8)
144148

145-
if aspect_ratio_4x3:
146-
WIDTH = 248
147-
HEIGHT = 218
148-
else:
149-
WIDTH = 280
150-
HEIGHT = 182
149+
WIDTH = int(280 / 360 * display.width // scale)
150+
HEIGHT = int(182 / 200 * display.height // scale)
151151

152152
config = {
153153
"menu_title": "Launcher Menu",

0 commit comments

Comments
 (0)