make basic config module

This commit is contained in:
Saji 2024-09-27 01:04:17 -05:00
parent 7e41e6e2f3
commit bcac3d0dcd
3 changed files with 82 additions and 4 deletions

52
example-config.toml Normal file
View file

@ -0,0 +1,52 @@
# Groovylight configuration base file.
# make your edits using this, at the moment the defaults are not stored
# in the program so every value must be specified.
[hardware]
# The target platform.
# Valid options: "cxxrtl", "colorlight"
type = "cxxrtl"
# hardware-specific options, these are gently parsed i.e extra options are ignored.
# colorlight options
# Maps the strings array onto the colorlight connectors.
# it's fine (but will raise a warning) if the list is longer than the number of strings.
stringmapping = [ "J1", "J2", "J3", "J4", "J5", "J6", "J7", "J8" ]
# cxxrtl options
[network]
# Network port to listen on for UDP datagrams.
port = 9999
# IPv4 address to use for the Ethernet port.
# This setting is ignored for CXXRTL.
# 'dhcp' will get the IP at runtime.
ip = "dhcp" # Can also be e.g. "192.168.0.123"
[display]
strict = true # allows some wacky configurations, like panels that overlap.
[[display.strings]]
position = { x = 31, y = 0 }
dimensions = { width = 256, height = 64 }
rotation = "UPDOWN"
[[display.strings]]
position = { x = 32, y = 0 }
dimensions = { width = 256, height = 64 }
rotation = "LEFTRIGHT"
[[display.strings]]
position = { x = 32, y = 64 }
dimensions = { width = 256, height = 64 }
rotation = "LEFTRIGHT"
[[display.strings]]
position = { x = 32, y = 128 }
dimensions = { width = 256, height = 64 }
rotation = "LEFTRIGHT"
[[display.strings]]
position = { x = 32, y = 192 }
dimensions = { width = 256, height = 64 }
rotation = "LEFTRIGHT"

25
src/groovylight/config.py Normal file
View file

@ -0,0 +1,25 @@
import tomllib
from pathlib import Path
from groovylight.geom import (
Coord,
DisplayDimensions,
DisplayGeometry,
DisplayRotation,
DisplayString,
)
class Config:
def __init__(self, file: Path) -> None:
with file.open("rb") as f:
self.conf = tomllib.load(f)
self.geom = DisplayGeometry(self.conf.display.strict)
for string in self.conf.display.strings:
pos = Coord(**string.position)
dims = DisplayDimensions(**string.dimensions)
rot = DisplayRotation[string.rotation]
disp = DisplayString(pos, dims, rot)
self.geom.add_string(disp)
self.network = self.conf.network # FIXME: parse this properly.

View file

@ -173,7 +173,8 @@ class DisplayGeometry:
will overlap with an existing string.
"""
for e in self._strings:
if e.intersects(s):
pass
if self.strict:
for e in self._strings:
if e.intersects(s):
raise RuntimeError(f"node {e} intersects with {s}")
self._strings.append(s)