Add some last-resort exception handling
This commit is contained in:
parent
35d0261682
commit
9f87527d9a
6
main.py
6
main.py
|
|
@ -72,6 +72,7 @@ def write_line(line: int, text: str, text_color: Color = COLOR_LCD_AMBER):
|
||||||
|
|
||||||
def update_screen(config: Config, updates: list[ArrivalTime]) -> None:
|
def update_screen(config: Config, updates: list[ArrivalTime]) -> None:
|
||||||
""" Repaint the screen with the new arrival times """
|
""" Repaint the screen with the new arrival times """
|
||||||
|
try:
|
||||||
updates = updates[0:LINE_COUNT] # take the first X lines
|
updates = updates[0:LINE_COUNT] # take the first X lines
|
||||||
for line_num, update in enumerate(updates):
|
for line_num, update in enumerate(updates):
|
||||||
# Find what color we need to use for the ETA
|
# Find what color we need to use for the ETA
|
||||||
|
|
@ -97,6 +98,8 @@ def update_screen(config: Config, updates: list[ArrivalTime]) -> None:
|
||||||
# Add the current time to the bottom line
|
# Add the current time to the bottom line
|
||||||
datetime_text = "Current time: " + datetime.today().strftime("%d/%m/%Y %H:%M")
|
datetime_text = "Current time: " + datetime.today().strftime("%d/%m/%Y %H:%M")
|
||||||
write_line(5, datetime_text)
|
write_line(5, datetime_text)
|
||||||
|
except Exception as e:
|
||||||
|
print("Error updating screen: ", str(e))
|
||||||
|
|
||||||
def clear_screen() -> None:
|
def clear_screen() -> None:
|
||||||
""" Clear screen """
|
""" Clear screen """
|
||||||
|
|
@ -148,6 +151,7 @@ def main():
|
||||||
# Main event loop
|
# Main event loop
|
||||||
running = True
|
running = True
|
||||||
while running:
|
while running:
|
||||||
|
try:
|
||||||
# Pygame event handling begins
|
# Pygame event handling begins
|
||||||
if pygame.event.peek():
|
if pygame.event.peek():
|
||||||
for e in pygame.event.get():
|
for e in pygame.event.get():
|
||||||
|
|
@ -171,6 +175,8 @@ def main():
|
||||||
# Display update ends
|
# Display update ends
|
||||||
|
|
||||||
sleep(0.2)
|
sleep(0.2)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception in main loop: ", str(e))
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue