test goal celebration

This commit is contained in:
2026-05-02 20:56:33 -04:00
parent 6867679ca5
commit fced480e86
+110 -30
View File
@@ -24,12 +24,22 @@ font.LoadFont("/usr/local/share/7x13.bdf")
font_small = graphics.Font() font_small = graphics.Font()
font_small.LoadFont("/usr/local/share/5x7.bdf") font_small.LoadFont("/usr/local/share/5x7.bdf")
white = graphics.Color(255, 255, 255) # try to load a big font for GOAL!, fall back to regular if not available
yellow = graphics.Color(255, 200, 0) font_big = graphics.Font()
red = graphics.Color(255, 50, 50) try:
grey = graphics.Color(180, 180, 180) font_big.LoadFont("/usr/local/share/9x18.bdf")
except:
font_big = font
LOGO_DIR = "/usr/local/share/logos" white = graphics.Color(255, 255, 255)
yellow = graphics.Color(255, 200, 0)
red = graphics.Color(255, 50, 50)
grey = graphics.Color(180, 180, 180)
sabres_blue = graphics.Color(0, 48, 135)
sabres_gold = graphics.Color(252, 181, 20)
LOGO_DIR = "/home/alex/logos"
SABRES_ABBR = "BUF"
# --- Logo cache --- # --- Logo cache ---
logo_cache = {} logo_cache = {}
@@ -82,6 +92,7 @@ def get_scores(sport, league):
"home": home["team"]["abbreviation"].upper(), "home": home["team"]["abbreviation"].upper(),
"home_score": home["score"], "home_score": home["score"],
"status": status, "status": status,
"id": event["id"],
}) })
return games return games
except Exception as e: except Exception as e:
@@ -95,30 +106,83 @@ def get_all_scores():
games += get_scores("basketball", "nba") games += get_scores("basketball", "nba")
return games return games
def sabres_scored(games, prev_scores):
for game in games:
if game["away"] != SABRES_ABBR and game["home"] != SABRES_ABBR:
continue
gid = game["id"]
try:
away = int(game["away_score"])
home = int(game["home_score"])
except ValueError:
continue
if gid not in prev_scores:
continue
prev_away, prev_home = prev_scores[gid]
if game["away"] == SABRES_ABBR and away > prev_away:
return True
if game["home"] == SABRES_ABBR and home > prev_home:
return True
return False
# --- Goal celebration ---
def fill_background(canvas, color):
for x in range(256):
for y in range(32):
canvas.SetPixel(x, y, *color)
def play_goal_celebration():
global canvas
colors = [
(0, 48, 135), # sabres blue
(252, 181, 20), # sabres gold
]
flashes = 6
for i in range(flashes):
bg = colors[i % 2]
text_color = sabres_gold if i % 2 == 0 else sabres_blue
canvas.Clear()
# fill background
for x in range(256):
for y in range(32):
canvas.SetPixel(x, y, bg[0], bg[1], bg[2])
# draw GOAL! centered across full 256px width
text = "GOAL!"
# draw it twice across the display for that arena feel
graphics.DrawText(canvas, font_big, 20, 22, text_color, text)
graphics.DrawText(canvas, font_big, 140, 22, text_color, text)
canvas = matrix.SwapOnVSync(canvas)
time.sleep(0.3)
# hold final frame briefly
time.sleep(1.0)
# --- Draw all games across all panels --- # --- Draw all games across all panels ---
def draw_all_games(canvas, games, start_index): def draw_all_games(canvas, games, start_index):
for i in range(4): # one per panel for i in range(4):
game_index = (start_index + i) % len(games) game_index = (start_index + i) % len(games)
game = games[game_index] game = games[game_index]
offset = i * 64 # each panel is 64px wide offset = i * 64
league = game["league"] league = game["league"]
away_logo = load_logo(league, game["away"]) away_logo = load_logo(league, game["away"])
home_logo = load_logo(league, game["home"]) home_logo = load_logo(league, game["home"])
# Draw logos
draw_logo(canvas, away_logo, offset + 0, 0) draw_logo(canvas, away_logo, offset + 0, 0)
draw_logo(canvas, home_logo, offset + 0, 16) draw_logo(canvas, home_logo, offset + 0, 16)
# Draw team abbreviations
graphics.DrawText(canvas, font_small, offset + 18, 11, white, game["away"]) graphics.DrawText(canvas, font_small, offset + 18, 11, white, game["away"])
graphics.DrawText(canvas, font_small, offset + 18, 27, white, game["home"]) graphics.DrawText(canvas, font_small, offset + 18, 27, white, game["home"])
# Draw scores
graphics.DrawText(canvas, font, offset + 40, 13, yellow, str(game["away_score"])) graphics.DrawText(canvas, font, offset + 40, 13, yellow, str(game["away_score"]))
graphics.DrawText(canvas, font, offset + 40, 29, yellow, str(game["home_score"])) graphics.DrawText(canvas, font, offset + 40, 29, yellow, str(game["home_score"]))
# Draw a subtle divider between panels
if i < 3: if i < 3:
for row in range(32): for row in range(32):
canvas.SetPixel(offset + 63, row, 40, 40, 40) canvas.SetPixel(offset + 63, row, 40, 40, 40)
@@ -127,35 +191,51 @@ def draw_all_games(canvas, games, start_index):
def run(): def run():
global canvas global canvas
games = [] games = []
prev_scores = {}
last_fetch = 0 last_fetch = 0
current_page = 0 current_page = 0
page_display_time = 8 # seconds per page page_display_time = 8
last_switch = time.time() last_switch = time.time()
while True: while True:
now = time.time() play_goal_celebration()
# Re-fetch every 30 seconds # while True:
if now - last_fetch > 30: # now = time.time()
games = get_all_scores()
last_fetch = now
if not games:
current_page = 0
# Switch page every N seconds # if now - last_fetch > 30:
if games and now - last_switch > page_display_time: # new_games = get_all_scores()
current_page = (current_page + 4) % max(len(games), 1)
last_switch = now
canvas.Clear() # # check for sabres goal before updating prev_scores
# if prev_scores and sabres_scored(new_games, prev_scores):
# play_goal_celebration()
if games: # # update prev_scores
draw_all_games(canvas, games, current_page) # for game in new_games:
else: # gid = game["id"]
graphics.DrawText(canvas, font, 10, 22, red, "No games today") # try:
# prev_scores[gid] = (int(game["away_score"]), int(game["home_score"]))
# except ValueError:
# pass
canvas = matrix.SwapOnVSync(canvas) # games = new_games
time.sleep(0.03) # last_fetch = now
# if not games:
# current_page = 0
# if games and now - last_switch > page_display_time:
# current_page = (current_page + 4) % max(len(games), 1)
# last_switch = now
# canvas.Clear()
# if games:
# draw_all_games(canvas, games, current_page)
# else:
# graphics.DrawText(canvas, font, 10, 22, red, "No games today")
# canvas = matrix.SwapOnVSync(canvas)
# time.sleep(0.03)
if __name__ == "__main__": if __name__ == "__main__":
run() run()