diff options
Diffstat (limited to 'hex33board')
| -rw-r--r-- | hex33board/__init__.py | 14 | ||||
| -rw-r--r-- | hex33board/i2c.py | 17 | ||||
| -rw-r--r-- | hex33board/menu.py | 3 |
3 files changed, 19 insertions, 15 deletions
diff --git a/hex33board/__init__.py b/hex33board/__init__.py index 3448d4d..a33ad92 100644 --- a/hex33board/__init__.py +++ b/hex33board/__init__.py @@ -111,12 +111,8 @@ class Keyboard: "i2c_addr": SliderSetting( "I2C ADDRESS", 127, default=0x33, fmt="0x{0:02x} ({0:d})" ), - "i2c_xo": SliderSetting( - "I2C X OFFSET", 12 * 6, default=0 - ), - "i2c_yo": SliderSetting( - "I2C Y OFFSET", 16, default=0 - ), + "i2c_xo": SliderSetting("I2C X OFFSET", 12 * 6, default=0), + "i2c_yo": SliderSetting("I2C Y OFFSET", 16, default=0), # SYNTH "synth_vol": SliderSetting( "SYNTH VOLUME", @@ -320,9 +316,11 @@ class Keyboard: self.on_layout(None, None) - def on_change(self, id, val, last): - if not (id.startswith('rgb') or id.startswith('layout') or id.startswith('scale')): return + if not ( + id.startswith("rgb") or id.startswith("layout") or id.startswith("scale") + ): + return if isinstance(self.i2c, I2CLeader): self.i2c.broadcast_chunked("S", json.dumps({id: val}).encode()) diff --git a/hex33board/i2c.py b/hex33board/i2c.py index 8370b41..955d86a 100644 --- a/hex33board/i2c.py +++ b/hex33board/i2c.py @@ -19,10 +19,11 @@ def i2c_decode(msg): def u16tob(v): - return bytes([ v >> 8, v & 0xff ]) + return bytes([v >> 8, v & 0xFF]) + def btou16(b): - return b[0] << 8 | b[1] + return b[0] << 8 | b[1] class I2CModule: @@ -51,7 +52,7 @@ class I2CModule: elif msg[0] == ord(b"C") or msg[0] == ord(b"S"): total_len = btou16(msg[1:]) assert not self.chunked - self.chunked = (total_len, bytes()) # TODO: preallocate full buffer + self.chunked = (total_len, bytes()) # TODO: preallocate full buffer elif msg[0] == ord(b"c") or msg[0] == ord(b"s"): assert self.chunked @@ -61,7 +62,9 @@ class I2CModule: if total_len == len(data): self.chunked = None - self.keyboard.settings.loadstring(data.decode(), restore=False) # msg[0] == ord(b"c") + self.keyboard.settings.loadstring( + data.decode(), restore=False + ) # msg[0] == ord(b"c") elif total_len < len(data): raise ValueError("chunked message longer than size in header") else: @@ -84,7 +87,9 @@ class I2CLeader(I2CModule): self.i2c.try_lock() self.devices = self.i2c.scan() - config = self.keyboard.settings.storestring(only=['rgb', 'layout', 'scale']).encode() + config = self.keyboard.settings.storestring( + only=["rgb", "layout", "scale"] + ).encode() self.broadcast_chunked("C", config) def broadcast(self, prefix: buffer, data: buffer, except_addr=None): @@ -110,7 +115,7 @@ class I2CLeader(I2CModule): # lower case: data buffers prefix = prefix.lower().encode() for i in range(0, total_len, CHUNK_SIZE): - self.broadcast(prefix, data[i:i+CHUNK_SIZE]) + self.broadcast(prefix, data[i : i + CHUNK_SIZE]) def tick(self): msg = bytearray(2) diff --git a/hex33board/menu.py b/hex33board/menu.py index 0cbd404..df0766b 100644 --- a/hex33board/menu.py +++ b/hex33board/menu.py @@ -242,7 +242,7 @@ class Settings: def dispatch(self, id: str, last_val=None): self.change_handlers[id](self.settings[id].value, last_val) - self.change_handlers['*'](id, self.settings[id].value, last_val) + self.change_handlers["*"](id, self.settings[id].value, last_val) def get(self, id: str) -> Setting: return self.settings[id] @@ -319,6 +319,7 @@ class Settings: for id in self.settings: yield id, self.settings[id].value + class MenuMode(Mode): color = (1.0, 1.0, 0.5) |
