Skip to content

Commit 011e857

Browse files
committed
More responses to review comments.
1 parent e7a37e8 commit 011e857

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Scripts/Winwing/xplane_default_fmc.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ def fetch_dataref_mapping(device: CduDevice):
9999

100100

101101
def color_from_style(style):
102-
return COLOR_MAP[style & 7]
102+
# According to the documentation
103+
# (https://developer.x-plane.com/article/datarefs-for-the-cdu-screen/)
104+
# the four lowest bits encode color, but only color indexes 0 through 7
105+
# are defined at this point. We therefore look at only the lowest three
106+
# bits to avoid an out-of-bounds access on the `COLOR_MAP` list.
107+
return COLOR_MAP[style & 7]
103108

104109

105110
def size_from_style(style):
@@ -145,7 +150,7 @@ async def handle_device_update(queue: asyncio.Queue, device: CduDevice):
145150
values = await queue.get()
146151

147152
try:
148-
elapsed = asyncio.get_event_loop().time() - last_run_time
153+
elapsed = asyncio.get_running_loop().time() - last_run_time
149154

150155
# Weaker CPUs may experience performance issues when a websocket connection is saturated with requests, such as when pages are frequently changed.
151156
# This rate limits the number of active websocket requests to MobiFlight.
@@ -155,7 +160,7 @@ async def handle_device_update(queue: asyncio.Queue, device: CduDevice):
155160

156161
display_json = generate_display_json(device, values)
157162
await websocket.send(display_json)
158-
last_run_time = asyncio.get_event_loop().time()
163+
last_run_time = asyncio.get_running_loop().time()
159164

160165
except websockets.exceptions.ConnectionClosed:
161166
logging.error(

0 commit comments

Comments
 (0)