diff --git a/example-config.toml b/example-config.toml new file mode 100644 index 0000000..013fcb6 --- /dev/null +++ b/example-config.toml @@ -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" diff --git a/src/groovylight/config.py b/src/groovylight/config.py new file mode 100644 index 0000000..f23443e --- /dev/null +++ b/src/groovylight/config.py @@ -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. diff --git a/src/groovylight/geom.py b/src/groovylight/geom.py index 901cab4..8dbcb7f 100644 --- a/src/groovylight/geom.py +++ b/src/groovylight/geom.py @@ -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)