feat(01-01): create package structure, Pydantic models, and device abstractions
- pyproject.toml with FastAPI, uvicorn, Pydantic v2, aiofiles, structlog deps - DeviceConfig Pydantic model with StripType, UUID, validation constraints - ShowModel with AudioRef, TrackModel, CueModel, AnalysisBlock, schema_version=1 - BaseDevice ABC with encode_frame, encode_animation_cmd, bytes_per_pixel - SK6812Device (4 bytes/pixel) and WS2801Device (3 bytes/pixel) implementations
This commit is contained in:
33
lightsync/devices/base.py
Normal file
33
lightsync/devices/base.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from lightsync.models.device import DeviceConfig
|
||||
|
||||
|
||||
class BaseDevice(ABC):
|
||||
def __init__(self, config: DeviceConfig):
|
||||
self.config = config
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.config.id
|
||||
|
||||
@property
|
||||
def led_count(self) -> int:
|
||||
return self.config.led_count
|
||||
|
||||
@abstractmethod
|
||||
def encode_frame(self, pixels: list[tuple]) -> bytes:
|
||||
"""Encode a full pixel frame to UDP payload bytes.
|
||||
pixels: list of (R, G, B) or (R, G, B, W) tuples.
|
||||
"""
|
||||
...
|
||||
|
||||
@abstractmethod
|
||||
def encode_animation_cmd(self, animation: str, params: dict) -> bytes:
|
||||
"""Encode an animation+params command packet."""
|
||||
...
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def bytes_per_pixel(self) -> int:
|
||||
"""Number of bytes per LED in frame mode (3 for RGB, 4 for RGBW)."""
|
||||
...
|
||||
Reference in New Issue
Block a user