The ETA is shown in green, yellow or red depending on how much time is left to walk to the stop.

This commit is contained in:
Nahuel Lofeudo 2022-10-09 16:51:21 +01:00
parent 0ff9dcbd56
commit 2d791cb08b
1 changed files with 26 additions and 5 deletions

31
main.py
View File

@ -1,4 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from curses import COLOR_GREEN, COLOR_RED
import os import os
from glob import glob from glob import glob
import pygame import pygame
@ -12,8 +13,11 @@ from arrival_times import ArrivalTime
# The font is JD LCD Rounded by Jecko Development # The font is JD LCD Rounded by Jecko Development
# https://fontstruct.com/fontstructions/show/459792/jd_lcd_rounded # https://fontstruct.com/fontstructions/show/459792/jd_lcd_rounded
TEXT_FONT = 'jd_lcd_rounded.ttf' TEXT_FONT = 'jd_lcd_rounded.ttf'
LINE_COUNT = 5 LINE_COUNT = 6
COLOR_LCD : pygame.Color = pygame.Color(244, 203, 96) COLOR_LCD_AMBER : pygame.Color = pygame.Color(0xf4, 0xcb, 0x60)
COLOR_LCD_GREEN: pygame.Color = pygame.Color(0xb3, 0xff, 0x00)
COLOR_LCD_RED: pygame.Color = pygame.Color(0xff, 0x3a, 0x4a)
COLOR_BACKGROUND = pygame.Color(0, 0, 0) COLOR_BACKGROUND = pygame.Color(0, 0, 0)
UPDATE_INTERVAL_SECONDS = 30 UPDATE_INTERVAL_SECONDS = 30
TEXT_SIZE = 160 # Size of the font in pixels TEXT_SIZE = 160 # Size of the font in pixels
@ -22,11 +26,17 @@ STOPS = [
1114 # Priory Walk 1114 # Priory Walk
] ]
# Define how long it takes to walk to a particular stop
MINUTES_TO_ROUTE = {
'15A': 15,
'54A': 9
}
# Offsets of each part within a line # Offsets of each part within a line
XOFFSET_ROUTE = 24 XOFFSET_ROUTE = 24
XOFFSET_DESTINATION = 300 XOFFSET_DESTINATION = 300
XOFFSEET_TIME_LEFT = 1606 XOFFSEET_TIME_LEFT = 1606
INTER_LINE_SPACE = 0 # 1920x720 -> 0 INTER_LINE_SPACE = -20 # 1920x720 -> 0
# Some global variables # Some global variables
window : pygame.Surface = None window : pygame.Surface = None
@ -43,7 +53,7 @@ def get_line_offset(line: int) -> int:
def write_entry(line: int, def write_entry(line: int,
route: str = '', destination: str = '', time_left: str = '', route: str = '', destination: str = '', time_left: str = '',
time_color: Color = COLOR_LCD, text_color: Color = COLOR_LCD): time_color: Color = COLOR_LCD_AMBER, text_color: Color = COLOR_LCD_AMBER):
""" Draws on the screen buffer an entry corresponding to an arrival time. """ """ Draws on the screen buffer an entry corresponding to an arrival time. """
# Step 1: Render the fragments # Step 1: Render the fragments
@ -62,12 +72,23 @@ def update_screen(updates: list[ArrivalTime]) -> None:
""" Repaint the screen with the new arrival times """ """ Repaint the screen with the new arrival times """
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
time_to_walk = update.due_in_minutes - (MINUTES_TO_ROUTE.get(update.route_id) or 0)
lcd_color = None
if time_to_walk > 5:
lcd_color = COLOR_LCD_GREEN
elif time_to_walk > 1:
lcd_color = COLOR_LCD_AMBER
else:
lcd_color = COLOR_LCD_RED
# Draw the line
write_entry( write_entry(
line=line_num, line=line_num,
route=update.route_id, route=update.route_id,
destination=update.destination, destination=update.destination,
time_left='Due' if update.isDue() else f'{update.due_in_minutes}min', time_left='Due' if update.isDue() else f'{update.due_in_minutes}min',
time_color=COLOR_LCD time_color=lcd_color
) )