Fix formatting, add some classes

This commit is contained in:
n07070 2023-12-20 11:47:56 +01:00
parent 6e936007c1
commit b9557be16c

View File

@ -9,12 +9,39 @@ import captouch
import json import json
import math import math
# class Bluetooth():
# def __init__(self) -> None:
# class Social():
# def
class Movements:
def orientation(self) -> int:
# Get current orientation
return 0
def update(self) -> None:
# Read from the gyroscope and accelerometers
print("Updating movements")
def last_movement(self) -> int:
# Time since last movement
return 1
def is_moving(self) -> bool:
# Is the badge currently in movement
return False
def is_shaking(self) -> bool:
# Active when the badge has been shaked
return False
class Configuration: class Configuration:
def __init__(self) -> None: def __init__(self) -> None:
# Add up to 5 items with custom header # Add up to 5 items with custom header
self.hdrs: list = ['name', 'handel', 'lang', 'pronouns', 'empty'] self.hdrs: list = ["name", "handel", "lang", "pronouns", "phone"]
self.strs: list = ['flow3r', '', 'noLang', '', ''] self.strs: list = ["flow3r", "", "noLang", "", ""]
self.size: int = 75 self.size: int = 75
self.font: int = 5 self.font: int = 5
self.colour: int = (1.0, 1.0, 1.0) self.colour: int = (1.0, 1.0, 1.0)
@ -43,16 +70,26 @@ class Configuration:
res.size = data["size"] res.size = data["size"]
if "font" in data and type(data["font"]) == int: if "font" in data and type(data["font"]) == int:
res.font = data["font"] res.font = data["font"]
if "color" in data and type(data["color"]) == str and len(data["color"]) == 7 and data["color"][0] == '#': if (
"color" in data
and type(data["color"]) == str
and len(data["color"]) == 7
and data["color"][0] == "#"
):
res.colour = ( res.colour = (
int(data["color"][1:3], 16) / 256.0, int(data["color"][1:3], 16) / 256.0,
int(data["color"][3:5], 16) / 256.0, int(data["color"][3:5], 16) / 256.0,
int(data["color"][5:], 16)/256.0 int(data["color"][5:], 16) / 256.0,
) )
return res return res
def save(self, path: str) -> None: def save(self, path: str) -> None:
colourstr: str = '#' + hex(int(255*self.colour[0]))[2:4] + hex(int(255*self.colour[1]))[2:4] + hex(int(255*self.colour[2]))[2:4] colourstr: str = (
"#"
+ hex(int(255 * self.colour[0]))[2:4]
+ hex(int(255 * self.colour[1]))[2:4]
+ hex(int(255 * self.colour[2]))[2:4]
)
d = { d = {
"size": self.size, "size": self.size,
"font": self.font, "font": self.font,
@ -67,7 +104,7 @@ class Configuration:
f.close() f.close()
class SensibleNickApp(Application): class BetterNickApp(Application):
state: int = 0 state: int = 0
since_state_change: int = 0 since_state_change: int = 0
@ -86,8 +123,13 @@ class SensibleNickApp(Application):
self._colours: list = [GO_GREEN, PUSH_RED, self._config.colour] self._colours: list = [GO_GREEN, PUSH_RED, self._config.colour]
self._en_colour = 2 self._en_colour = 2
self.varprint: list(str) = [str for str in self._config.strs if len(str) > 0] self.varprint: list(str) = [str for str in self._config.strs if len(str) > 0]
self.movement_state = Movements()
def draw(self, ctx: Context) -> None: def draw(self, ctx: Context) -> None:
if not self.movement_state.is_moving():
ctx.rgb(*BLACK).rectangle(-120, -120, 240, 240).fill()
return
ctx.text_align = ctx.CENTER ctx.text_align = ctx.CENTER
ctx.text_baseline = ctx.MIDDLE ctx.text_baseline = ctx.MIDDLE
# ctx.font_size = self._config.size # ctx.font_size = self._config.size
@ -122,6 +164,10 @@ class SensibleNickApp(Application):
def think(self, ins: InputState, delta_ms: int) -> None: def think(self, ins: InputState, delta_ms: int) -> None:
super().think(ins, delta_ms) super().think(ins, delta_ms)
self.movement_state.update()
self.ins.imu
self._phase += delta_ms / 900 self._phase += delta_ms / 900
self._scale = math.sin(self._phase) self._scale = math.sin(self._phase)
self._led += delta_ms / 100 self._led += delta_ms / 100
@ -159,8 +205,9 @@ class SensibleNickApp(Application):
self._en_iter_pressed = petals[1].pressed self._en_iter_pressed = petals[1].pressed
self._en_scale_pressed = petals[9].pressed self._en_scale_pressed = petals[9].pressed
# For running with `mpremote run`: # For running with `mpremote run`:
if __name__ == "__main__": if __name__ == "__main__":
import st3m.run import st3m.run
st3m.run.run_view(SensibleNickApp(ApplicationContext())) st3m.run.run_view(BetterNickApp(ApplicationContext()))