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:
|
||||
""" Repaint the screen with the new arrival times """
|
||||
try:
|
||||
updates = updates[0:LINE_COUNT] # take the first X lines
|
||||
for line_num, update in enumerate(updates):
|
||||
# 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
|
||||
datetime_text = "Current time: " + datetime.today().strftime("%d/%m/%Y %H:%M")
|
||||
write_line(5, datetime_text)
|
||||
except Exception as e:
|
||||
print("Error updating screen: ", str(e))
|
||||
|
||||
def clear_screen() -> None:
|
||||
""" Clear screen """
|
||||
|
|
@ -148,6 +151,7 @@ def main():
|
|||
# Main event loop
|
||||
running = True
|
||||
while running:
|
||||
try:
|
||||
# Pygame event handling begins
|
||||
if pygame.event.peek():
|
||||
for e in pygame.event.get():
|
||||
|
|
@ -171,6 +175,8 @@ def main():
|
|||
# Display update ends
|
||||
|
||||
sleep(0.2)
|
||||
except Exception as e:
|
||||
print("Exception in main loop: ", str(e))
|
||||
pygame.quit()
|
||||
exit(0)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue