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
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
sudo python3 clock.py
sudo nano /boot/firmware/cmdline.txt
```
2. For better performance (recommended):
- Edit `/boot/firmware/cmdline.txt`:
```bash
sudo nano /boot/firmware/cmdline.txt
```
- Add `isolcpus=3` at the end of the line
- Save and reboot:
```bash
sudo reboot
```
2. Add `isolcpus=3` at the end of the line
3. Save and reboot:
```bash
sudo reboot
```
## Configuration
@@ -76,12 +72,17 @@ Edit the `config/config.json` file to customize:
- Display settings (brightness, dimensions)
- 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
To start the clock with optimal performance:
The program must be run with root privileges to access the LED matrix hardware:
```bash
cd src
sudo python3 clock.py
sudo python3 display_controller.py
```
To stop the clock, press Ctrl+C.
@@ -93,4 +94,5 @@ To stop the clock, press Ctrl+C.
- `config_manager.py` - Configuration management
- `display_manager.py` - LED matrix display handling
- `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
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]):
self.config = config
self.matrix = self._setup_matrix()
self.font = ImageFont.truetype("DejaVuSans.ttf", 24)
self.image = Image.new('RGB', (self.matrix.width, self.matrix.height))
self.draw = ImageDraw.Draw(self.image)
# Only initialize once
if not DisplayManager._initialized:
self.config = config
self.matrix = self._setup_matrix()
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:
"""Setup the RGB matrix with the provided configuration."""
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.cols = self.config.get('cols', 64)
options.chain_length = self.config.get('chain_length', 2)
options.hardware_mapping = 'adafruit-hat'
options.gpio_slowdown = 4
options.parallel = 1
options.pwm_bits = 11
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)
@@ -36,4 +60,7 @@ class DisplayManager:
def cleanup(self):
"""Clean up resources."""
self.matrix.Clear()
self.matrix.Clear()
# Reset the singleton state when cleaning up
DisplayManager._instance = None
DisplayManager._initialized = False