Button feedback, HDD colors, improved animation

This commit is contained in:
Joan
2025-12-31 13:24:01 +01:00
parent 5f35315f5f
commit f1dd6d5c49

View File

@@ -39,6 +39,13 @@ except:
# Number of views # Number of views
NUM_VIEWS = 3 NUM_VIEWS = 3
# View names (Spanish)
VIEW_NAMES = {
0: "Principal",
1: "Discos",
2: "Fecha",
}
# Spanish day names fallback # Spanish day names fallback
SPANISH_DAYS = { SPANISH_DAYS = {
'Monday': 'Lunes', 'Tuesday': 'Martes', 'Wednesday': 'Miércoles', 'Monday': 'Lunes', 'Tuesday': 'Martes', 'Wednesday': 'Miércoles',
@@ -84,6 +91,20 @@ def get_temperature_color(temp):
return graphics.Color(255, 255, 255) return graphics.Color(255, 255, 255)
def get_hdd_color(temp):
"""Color for HDD temps: green <32, yellow 32-40, red >40."""
try:
temp_value = int(temp)
if temp_value < 32:
return graphics.Color(0, 255, 80) # Green
elif temp_value <= 40:
return graphics.Color(255, 200, 0) # Yellow
else:
return graphics.Color(255, 50, 50) # Red
except:
return graphics.Color(255, 255, 255)
def get_spanish_day(now): def get_spanish_day(now):
"""Get day name in Spanish.""" """Get day name in Spanish."""
day_en = now.strftime("%A") day_en = now.strftime("%A")
@@ -145,6 +166,7 @@ class Matrix64Display(SampleBase):
if not self.button1.is_held: if not self.button1.is_held:
self.current_view = (self.current_view + 1) % NUM_VIEWS self.current_view = (self.current_view + 1) % NUM_VIEWS
self.last_view_change = time.time() self.last_view_change = time.time()
self.show_feedback(VIEW_NAMES[self.current_view], 1.5)
print(f"View: {self.current_view}") print(f"View: {self.current_view}")
def on_button2_press(self): def on_button2_press(self):
@@ -152,6 +174,7 @@ class Matrix64Display(SampleBase):
if not self.button2.is_held: if not self.button2.is_held:
self.current_view = (self.current_view - 1) % NUM_VIEWS self.current_view = (self.current_view - 1) % NUM_VIEWS
self.last_view_change = time.time() self.last_view_change = time.time()
self.show_feedback(VIEW_NAMES[self.current_view], 1.5)
print(f"View: {self.current_view}") print(f"View: {self.current_view}")
def on_button_held(self): def on_button_held(self):
@@ -212,8 +235,9 @@ class Matrix64Display(SampleBase):
now = datetime.datetime.now() now = datetime.datetime.now()
time_str = f"{now.hour:02d}:{now.minute:02d}:{now.second:02d}" time_str = f"{now.hour:02d}:{now.minute:02d}:{now.second:02d}"
# Weather Icon (with animation offset) # Weather Icon (with smooth sine wave animation)
anim_offset = (self.animation_frame % 4) - 2 # -2 to 1 import math
anim_offset = int(math.sin(self.animation_frame * 0.3) * 2)
draw_weather_icon(canvas, anim_offset, 0, self.weather_desc) draw_weather_icon(canvas, anim_offset, 0, self.weather_desc)
# Vertical separator # Vertical separator
@@ -257,26 +281,26 @@ class Matrix64Display(SampleBase):
time_color, humidity_color, hdd_color, label_color, line_color = colors time_color, humidity_color, hdd_color, label_color, line_color = colors
# Title # Title
graphics.DrawText(canvas, data_font, 4, 8, time_color, "HDD Temps") graphics.DrawText(canvas, data_font, 4, 8, time_color, "Discos")
graphics.DrawLine(canvas, 0, 10, 63, 10, line_color) graphics.DrawLine(canvas, 0, 10, 63, 10, line_color)
if self.hdd_temps and len(self.hdd_temps) > 1: if self.hdd_temps and len(self.hdd_temps) > 1:
temps = [(i+1, int(t[0])) for i, t in enumerate(self.hdd_temps[1:7]) if t] temps = [(i+1, int(t[0])) for i, t in enumerate(self.hdd_temps[1:7]) if t]
# Two columns: left (1-3), right (4-6) # Two columns: left (1-3), right (4-6) with bigger font
y = 20 y = 20
for idx, (num, temp_val) in enumerate(temps[:3]): for idx, (num, temp_val) in enumerate(temps[:3]):
temp_color = get_temperature_color(temp_val) temp_color = get_hdd_color(temp_val)
graphics.DrawText(canvas, small_font, 2, y, label_color, f"{num}:") graphics.DrawText(canvas, data_font, 0, y, label_color, f"{num}:")
graphics.DrawText(canvas, small_font, 12, y, temp_color, f"{temp_val}C") graphics.DrawText(canvas, data_font, 14, y, temp_color, f"{temp_val}C")
y += 9 y += 10
y = 20 y = 20
for idx, (num, temp_val) in enumerate(temps[3:6]): for idx, (num, temp_val) in enumerate(temps[3:6]):
temp_color = get_temperature_color(temp_val) temp_color = get_hdd_color(temp_val)
graphics.DrawText(canvas, small_font, 34, y, label_color, f"{num}:") graphics.DrawText(canvas, data_font, 34, y, label_color, f"{num}:")
graphics.DrawText(canvas, small_font, 44, y, temp_color, f"{temp_val}C") graphics.DrawText(canvas, data_font, 48, y, temp_color, f"{temp_val}C")
y += 9 y += 10
# Auto-cycle indicator # Auto-cycle indicator
if self.auto_cycle: if self.auto_cycle:
@@ -299,8 +323,9 @@ class Matrix64Display(SampleBase):
graphics.DrawLine(canvas, 0, 28, 63, 28, line_color) graphics.DrawLine(canvas, 0, 28, 63, 28, line_color)
# Weather icon with animation # Weather icon with smooth animation
anim_offset = (self.animation_frame % 4) - 2 import math
anim_offset = int(math.sin(self.animation_frame * 0.3) * 2)
draw_weather_icon(canvas, 4 + anim_offset, 32, self.weather_desc) draw_weather_icon(canvas, 4 + anim_offset, 32, self.weather_desc)
# Temperature # Temperature