Skip to content
Snippets Groups Projects

Add support for pronouns in nick

Merged ar requested to merge arachnist/flow3r-firmware:nick-pronouns into main
1 file
+ 31
4
Compare changes
  • Side-by-side
  • Inline
@@ -14,6 +14,8 @@ class Configuration:
self.name = "flow3r"
self.size: int = 75
self.font: int = 5
self.pronouns: list[str] = []
self.pronouns_size: int = 25
@classmethod
def load(cls, path: str) -> "Configuration":
@@ -33,6 +35,18 @@ class Configuration:
res.size = data["size"]
if "font" in data and type(data["font"]) == int:
res.font = data["font"]
# type checks don't look inside collections
if (
"pronouns" in data
and type(data["pronouns"]) == list
and set([type(x) for x in data["pronouns"]) == {str}
):
res.pronouns = data["pronouns"]
if "pronouns_size" in data:
if type(data["pronouns_size"]) == float:
res.pronouns_size = int(data["pronouns_size"])
if type(data["pronouns_size"]) == int:
res.pronouns_size = data["pronouns_size"]
return res
def save(self, path: str) -> None:
@@ -40,6 +54,8 @@ class Configuration:
"name": self.name,
"size": self.size,
"font": self.font,
"pronouns": self.pronouns,
"pronouns_size": self.pronouns_size,
}
jsondata = json.dumps(d)
with open(path, "w") as f:
@@ -50,11 +66,13 @@ class Configuration:
class NickApp(Application):
def __init__(self, app_ctx: ApplicationContext) -> None:
super().__init__(app_ctx)
self._scale = 1.0
self._scale_name = 1.0
self._scale_pronouns = 1.0
self._led = 0.0
self._phase = 0.0
self._filename = "/flash/nick.json"
self._config = Configuration.load(self._filename)
self._pronouns_serialized = " ".join(self._config.pronouns)
def draw(self, ctx: Context) -> None:
ctx.text_align = ctx.CENTER
@@ -67,11 +85,19 @@ class NickApp(Application):
ctx.move_to(0, 0)
ctx.save()
ctx.scale(self._scale, 1)
ctx.scale(self._scale_name, 1)
ctx.text(self._config.name)
ctx.restore()
leds.set_hsv(int(self._led), abs(self._scale) * 360, 1, 0.2)
if self._pronouns_serialized:
ctx.move_to(0, -60)
ctx.font_size = self._config.pronouns_size
ctx.save()
ctx.scale(1, self._scale_pronouns)
ctx.text(self._pronouns_serialized)
ctx.restore()
leds.set_hsv(int(self._led), abs(self._scale_name) * 360, 1, 0.2)
leds.update()
# ctx.fill()
@@ -83,7 +109,8 @@ class NickApp(Application):
super().think(ins, delta_ms)
self._phase += delta_ms / 1000
self._scale = math.sin(self._phase)
self._scale_name = math.sin(self._phase)
self._scale_pronouns = math.cos(self._phase)
self._led += delta_ms / 45
if self._led >= 40:
self._led = 0
Loading