mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 13:02:59 +00:00
adjust display controller
to run single threaded instead of multithreaded
This commit is contained in:
32
README.md
32
README.md
@@ -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.
|
||||
@@ -94,3 +95,4 @@ To stop the clock, press Ctrl+C.
|
||||
- `display_manager.py` - LED matrix display handling
|
||||
- `config/`
|
||||
- `config.json` - Configuration settings
|
||||
- `config_secrets.json` - Private settings (not in git)
|
||||
@@ -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]):
|
||||
# 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)
|
||||
|
||||
@@ -37,3 +61,6 @@ class DisplayManager:
|
||||
def cleanup(self):
|
||||
"""Clean up resources."""
|
||||
self.matrix.Clear()
|
||||
# Reset the singleton state when cleaning up
|
||||
DisplayManager._instance = None
|
||||
DisplayManager._initialized = False
|
||||
Reference in New Issue
Block a user