mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-11 05:13:01 +00:00
Update weather display: Implement modern layout with detailed metrics
This commit is contained in:
@@ -196,7 +196,7 @@ class WeatherManager:
|
|||||||
]
|
]
|
||||||
|
|
||||||
def display_weather(self, force_clear: bool = False) -> None:
|
def display_weather(self, force_clear: bool = False) -> None:
|
||||||
"""Display current weather information using a static layout."""
|
"""Display current weather information using a modern layout."""
|
||||||
try:
|
try:
|
||||||
weather_data = self.get_weather()
|
weather_data = self.get_weather()
|
||||||
if not weather_data:
|
if not weather_data:
|
||||||
@@ -211,41 +211,98 @@ class WeatherManager:
|
|||||||
# Clear the display once at the start
|
# Clear the display once at the start
|
||||||
self.display_manager.clear()
|
self.display_manager.clear()
|
||||||
|
|
||||||
# Draw temperature (large, centered)
|
# Create a new image for drawing
|
||||||
temp_text = f"{current_state['temp']}°F"
|
image = Image.new('RGB', (self.display_manager.matrix.width, self.display_manager.matrix.height))
|
||||||
self.display_manager.draw_text(
|
draw = ImageDraw.Draw(image)
|
||||||
temp_text,
|
|
||||||
y=2,
|
|
||||||
color=self.COLORS['highlight'],
|
|
||||||
small_font=False
|
|
||||||
)
|
|
||||||
|
|
||||||
# Draw weather icon below temperature
|
# Draw weather condition icon and text at the top
|
||||||
icon_x = (self.display_manager.matrix.width - self.ICON_SIZE['large']) // 2
|
condition = weather_data['weather'][0]['main']
|
||||||
icon_y = self.display_manager.matrix.height // 2 - 4
|
icon_x = 2
|
||||||
|
icon_y = 2
|
||||||
self.display_manager.draw_weather_icon(
|
self.display_manager.draw_weather_icon(
|
||||||
current_state['condition'],
|
condition,
|
||||||
icon_x,
|
icon_x,
|
||||||
icon_y,
|
icon_y,
|
||||||
size=self.ICON_SIZE['large']
|
size=self.ICON_SIZE['large']
|
||||||
)
|
)
|
||||||
|
|
||||||
# Draw humidity at bottom
|
# Draw condition text next to icon
|
||||||
humidity_text = f"Humidity: {current_state['humidity']}%"
|
condition_text = condition
|
||||||
self.display_manager.draw_text(
|
draw.text((icon_x + self.ICON_SIZE['large'] + 2, icon_y),
|
||||||
humidity_text,
|
condition_text,
|
||||||
y=self.display_manager.matrix.height - 8,
|
font=self.display_manager.regular_font,
|
||||||
color=self.COLORS['text'],
|
fill=self.COLORS['text'])
|
||||||
small_font=True
|
|
||||||
)
|
|
||||||
|
|
||||||
# Update display once after all elements are drawn
|
# Draw "time ago" text below condition
|
||||||
|
time_since_update = int((time.time() - self.last_update) / 3600) # hours
|
||||||
|
time_text = f"{time_since_update} hours ago"
|
||||||
|
draw.text((icon_x + self.ICON_SIZE['large'] + 2, icon_y + 10),
|
||||||
|
time_text,
|
||||||
|
font=self.display_manager.small_font,
|
||||||
|
fill=self.COLORS['text'])
|
||||||
|
|
||||||
|
# Draw current temperature on the right
|
||||||
|
temp = round(weather_data['main']['temp'])
|
||||||
|
temp_text = f"{temp}°F"
|
||||||
|
temp_x = self.display_manager.matrix.width - 30 # Adjust position as needed
|
||||||
|
draw.text((temp_x, 2),
|
||||||
|
temp_text,
|
||||||
|
font=self.display_manager.regular_font,
|
||||||
|
fill=self.COLORS['highlight'])
|
||||||
|
|
||||||
|
# Draw high/low temperatures below current temp
|
||||||
|
temp_max = round(weather_data['main']['temp_max'])
|
||||||
|
temp_min = round(weather_data['main']['temp_min'])
|
||||||
|
high_low_text = f"{temp_max}°F / {temp_min}°F"
|
||||||
|
draw.text((temp_x - 5, 12),
|
||||||
|
high_low_text,
|
||||||
|
font=self.display_manager.small_font,
|
||||||
|
fill=self.COLORS['text'])
|
||||||
|
|
||||||
|
# Draw additional weather metrics
|
||||||
|
y_start = self.display_manager.matrix.height - 24
|
||||||
|
spacing = 8
|
||||||
|
|
||||||
|
# Air pressure
|
||||||
|
pressure = weather_data['main']['pressure'] * 0.02953 # Convert hPa to inHg
|
||||||
|
pressure_text = f"Air pressure {pressure:.2f} inHg"
|
||||||
|
draw.text((2, y_start),
|
||||||
|
pressure_text,
|
||||||
|
font=self.display_manager.small_font,
|
||||||
|
fill=self.COLORS['text'])
|
||||||
|
|
||||||
|
# Humidity
|
||||||
|
humidity = weather_data['main']['humidity']
|
||||||
|
humidity_text = f"Humidity {humidity}%"
|
||||||
|
draw.text((2, y_start + spacing),
|
||||||
|
humidity_text,
|
||||||
|
font=self.display_manager.small_font,
|
||||||
|
fill=self.COLORS['text'])
|
||||||
|
|
||||||
|
# Wind speed and direction
|
||||||
|
wind_speed = weather_data['wind']['speed']
|
||||||
|
wind_deg = weather_data.get('wind', {}).get('deg', 0)
|
||||||
|
wind_dir = self._get_wind_direction(wind_deg)
|
||||||
|
wind_text = f"Wind speed {wind_speed:.2f} mph ({wind_dir})"
|
||||||
|
draw.text((2, y_start + spacing * 2),
|
||||||
|
wind_text,
|
||||||
|
font=self.display_manager.small_font,
|
||||||
|
fill=self.COLORS['text'])
|
||||||
|
|
||||||
|
# Update the display
|
||||||
|
self.display_manager.image = image
|
||||||
self.display_manager.update_display()
|
self.display_manager.update_display()
|
||||||
self.last_weather_state = current_state
|
self.last_weather_state = current_state
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error displaying weather: {e}")
|
print(f"Error displaying weather: {e}")
|
||||||
|
|
||||||
|
def _get_wind_direction(self, degrees: float) -> str:
|
||||||
|
"""Convert wind degrees to cardinal direction."""
|
||||||
|
directions = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']
|
||||||
|
index = round(degrees / 45) % 8
|
||||||
|
return directions[index]
|
||||||
|
|
||||||
def display_hourly_forecast(self, force_clear: bool = False):
|
def display_hourly_forecast(self, force_clear: bool = False):
|
||||||
"""Display the next few hours of weather forecast."""
|
"""Display the next few hours of weather forecast."""
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user