Display changes

display manager changes
This commit is contained in:
Chuck
2025-04-07 21:19:46 -05:00
parent 27347b13d0
commit 2171364d38
2 changed files with 23 additions and 3 deletions

View File

@@ -1,15 +1,22 @@
import time
import logging
from datetime import datetime
import pytz
from typing import Dict, Any
from src.config_manager import ConfigManager
from src.display_manager import DisplayManager
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class Clock:
def __init__(self):
def __init__(self, display_manager: DisplayManager = None):
self.config_manager = ConfigManager()
self.config = self.config_manager.config
self.display_manager = DisplayManager(self.config.get('display', {}))
# Use the provided display_manager or create a new one if none provided
self.display_manager = display_manager or DisplayManager(self.config.get('display', {}))
logger.info("Clock initialized with display_manager: %s", id(self.display_manager))
self.location = self.config.get('location', {})
self.clock_config = self.config.get('clock', {})
# Use configured timezone if available, otherwise try to determine it
@@ -62,12 +69,14 @@ class Clock:
def display_time(self) -> None:
"""Display the current time."""
current_time = self.get_current_time()
logger.debug("Displaying time: %s", current_time)
# Center the text on the display
text_width = self.display_manager.font.getlength(current_time)
x = (self.display_manager.matrix.width - text_width) // 2
y = (self.display_manager.matrix.height - 24) // 2
logger.debug("Drawing time at position (%d, %d)", x, y)
self.display_manager.clear()
self.display_manager.draw_text(current_time, x, y)

View File

@@ -1,19 +1,25 @@
import time
import logging
from typing import Dict, Any
from src.clock import Clock
from src.weather_manager import WeatherManager
from src.display_manager import DisplayManager
from src.config_manager import ConfigManager
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class DisplayController:
def __init__(self):
self.config_manager = ConfigManager()
self.config = self.config_manager.config
self.display_manager = DisplayManager(self.config.get('display', {}))
self.clock = Clock()
self.clock = Clock(display_manager=self.display_manager)
self.weather = WeatherManager(self.config, self.display_manager)
self.current_display = 'clock'
self.last_switch = time.time()
logger.info("DisplayController initialized with display_manager: %s", id(self.display_manager))
def run(self):
"""Run the display controller, switching between displays."""
@@ -24,13 +30,18 @@ class DisplayController:
# Switch display if interval has passed
if current_time - self.last_switch > rotation_interval:
logger.info("Switching display from %s to %s",
self.current_display,
'weather' if self.current_display == 'clock' else 'clock')
self.current_display = 'weather' if self.current_display == 'clock' else 'clock'
self.last_switch = current_time
# Display current screen
if self.current_display == 'clock':
logger.debug("Updating clock display")
self.clock.display_time()
else:
logger.debug("Updating weather display")
self.weather.display_weather()
# Small delay to prevent CPU overload