Add .env support for transport and sound device configuration
- Add python-dotenv support to control_server.py and sound.py - Load TRANSPORT from environment variable (default: spi) - Load AUDIO_INPUT_DEVICE from environment variable (default: 7) - Load all port configurations from environment variables - Update .env.example with comprehensive configuration options - Create .env file with sensible defaults for Pi - Transport, sound device, and network settings now configurable via .env
This commit is contained in:
@@ -13,17 +13,22 @@ import socket
|
||||
import threading
|
||||
import time
|
||||
import argparse
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
from bar_config import LED_BAR_NAMES, DEFAULT_BAR_SETTINGS
|
||||
from color_utils import adjust_brightness
|
||||
from networking import SPIClient, WebSocketClient
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
# Configuration
|
||||
CONTROL_SERVER_PORT = 8765
|
||||
SOUND_CONTROL_HOST = "127.0.0.1"
|
||||
SOUND_CONTROL_PORT = 65433
|
||||
CONTROL_SERVER_PORT = int(os.getenv("CONTROL_SERVER_PORT", "8765"))
|
||||
SOUND_CONTROL_HOST = os.getenv("SOUND_CONTROL_HOST", "127.0.0.1")
|
||||
SOUND_CONTROL_PORT = int(os.getenv("SOUND_CONTROL_PORT", "65433"))
|
||||
|
||||
# Pattern name mapping for shorter JSON payloads
|
||||
PATTERN_NAMES = {
|
||||
@@ -463,11 +468,12 @@ def parse_arguments():
|
||||
|
||||
# Transport selection
|
||||
transport_group = parser.add_argument_group("Transport Options")
|
||||
default_transport = os.getenv("TRANSPORT", "spi")
|
||||
transport_group.add_argument(
|
||||
"--transport",
|
||||
choices=["spi", "websocket"],
|
||||
default="spi",
|
||||
help="Transport method for LED communication (default: spi)"
|
||||
default=default_transport,
|
||||
help=f"Transport method for LED communication (default from .env or {default_transport})"
|
||||
)
|
||||
|
||||
# Control options
|
||||
|
Reference in New Issue
Block a user