From 2171364d385eb9eea3b9f9c1fe725a8b3863b3e8 Mon Sep 17 00:00:00 2001 From: Chuck <33324927+ChuckBuilds@users.noreply.github.com> Date: Mon, 7 Apr 2025 21:19:46 -0500 Subject: [PATCH] Display changes display manager changes --- src/clock.py | 13 +++++++++++-- src/display_controller.py | 13 ++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/clock.py b/src/clock.py index 72b84177..5011ee6f 100644 --- a/src/clock.py +++ b/src/clock.py @@ -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) diff --git a/src/display_controller.py b/src/display_controller.py index c354ef60..7c03e732 100644 --- a/src/display_controller.py +++ b/src/display_controller.py @@ -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