adjust display controller

to run single threaded instead of multithreaded
This commit is contained in:
Chuck
2025-04-07 20:04:55 -05:00
parent 6ac83a2a8a
commit 35c3f6eae0
2 changed files with 53 additions and 24 deletions

View File

@@ -51,23 +51,19 @@ sudo apt-get install -y fonts-dejavu
## Performance Optimization ## Performance Optimization
To reduce flickering and improve display quality, you have two options: To reduce flickering and improve display quality:
1. Run the program with root privileges (quick solution): 1. Edit `/boot/firmware/cmdline.txt`:
```bash ```bash
sudo python3 clock.py sudo nano /boot/firmware/cmdline.txt
``` ```
2. For better performance (recommended): 2. Add `isolcpus=3` at the end of the line
- Edit `/boot/firmware/cmdline.txt`:
```bash 3. Save and reboot:
sudo nano /boot/firmware/cmdline.txt ```bash
``` sudo reboot
- Add `isolcpus=3` at the end of the line ```
- Save and reboot:
```bash
sudo reboot
```
## Configuration ## Configuration
@@ -76,12 +72,17 @@ Edit the `config/config.json` file to customize:
- Display settings (brightness, dimensions) - Display settings (brightness, dimensions)
- Clock format and update interval - Clock format and update interval
For sensitive settings like API keys:
1. Copy the template: `cp config/config_secrets.template.json config/config_secrets.json`
2. Edit `config/config_secrets.json` with your API keys
## Running the Clock ## Running the Clock
To start the clock with optimal performance: The program must be run with root privileges to access the LED matrix hardware:
```bash ```bash
cd src cd src
sudo python3 clock.py sudo python3 display_controller.py
``` ```
To stop the clock, press Ctrl+C. To stop the clock, press Ctrl+C.
@@ -94,3 +95,4 @@ To stop the clock, press Ctrl+C.
- `display_manager.py` - LED matrix display handling - `display_manager.py` - LED matrix display handling
- `config/` - `config/`
- `config.json` - Configuration settings - `config.json` - Configuration settings
- `config_secrets.json` - Private settings (not in git)

View File

@@ -4,22 +4,46 @@ import time
from typing import Dict, Any from typing import Dict, Any
class DisplayManager: class DisplayManager:
_instance = None
_initialized = False
def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super(DisplayManager, cls).__new__(cls)
return cls._instance
def __init__(self, config: Dict[str, Any]): def __init__(self, config: Dict[str, Any]):
self.config = config # Only initialize once
self.matrix = self._setup_matrix() if not DisplayManager._initialized:
self.font = ImageFont.truetype("DejaVuSans.ttf", 24) self.config = config
self.image = Image.new('RGB', (self.matrix.width, self.matrix.height)) self.matrix = self._setup_matrix()
self.draw = ImageDraw.Draw(self.image) self.font = ImageFont.truetype("DejaVuSans.ttf", 24)
self.image = Image.new('RGB', (self.matrix.width, self.matrix.height))
self.draw = ImageDraw.Draw(self.image)
DisplayManager._initialized = True
def _setup_matrix(self) -> RGBMatrix: def _setup_matrix(self) -> RGBMatrix:
"""Setup the RGB matrix with the provided configuration.""" """Setup the RGB matrix with the provided configuration."""
options = RGBMatrixOptions() options = RGBMatrixOptions()
# Hardware specific settings
options.hardware_mapping = 'adafruit-hat' # Set for Adafruit Bonnet/HAT
options.gpio_slowdown = 4 # Required for Pi 3
options.rows = self.config.get('rows', 32) options.rows = self.config.get('rows', 32)
options.cols = self.config.get('cols', 64) options.cols = self.config.get('cols', 64)
options.chain_length = self.config.get('chain_length', 2) options.chain_length = self.config.get('chain_length', 2)
options.hardware_mapping = 'adafruit-hat' options.parallel = 1
options.gpio_slowdown = 4 options.pwm_bits = 11
options.brightness = self.config.get('brightness', 50) options.brightness = self.config.get('brightness', 50)
options.pwm_lsb_nanoseconds = 130
options.led_rgb_sequence = "RGB"
options.pixel_mapper_config = ""
options.multiplexing = 0
# Additional options for stability
options.disable_hardware_pulsing = False
options.show_refresh_rate = 1
options.limit_refresh_rate_hz = 100
return RGBMatrix(options=options) return RGBMatrix(options=options)
@@ -37,3 +61,6 @@ class DisplayManager:
def cleanup(self): def cleanup(self):
"""Clean up resources.""" """Clean up resources."""
self.matrix.Clear() self.matrix.Clear()
# Reset the singleton state when cleaning up
DisplayManager._instance = None
DisplayManager._initialized = False