Skip to content

Commit

Permalink
Add hexpansion detection keychord
Browse files Browse the repository at this point in the history
Hold the boop button and press the button to the left of a hexpansion slot to trigger hexpansion detection.
When you're done with the hexpansion, press boop again to trigger hexpansion removal. This needs to be at least 5 seconds later.
  • Loading branch information
MatthewWilkes committed Jun 2, 2024
1 parent c819f9f commit 3994c6b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
37 changes: 30 additions & 7 deletions modules/frontboards/twentyfour.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import display
from events.input import Button, BUTTON_TYPES, ButtonDownEvent, ButtonUpEvent
import machine
from system.eventbus import eventbus
from tildagonos import tildagonos
from . import FrontBoard
from system.hexpansion.events import HexpansionInsertionEvent, HexpansionRemovalEvent
import time


BUTTONS = {
Expand All @@ -31,13 +34,33 @@ async def background_task(self):
display.gfx_init()

button_states = {button: False for button in self.BUTTON_PINS.keys()}
hexpansion_states = {1: None, 2: None, 3: None, 4: None, 5: None, 6: None}
while True:
booped = not machine.Pin(0, mode=machine.Pin.IN).value()
tildagonos.read_egpios()
for button, pin in self.BUTTON_PINS.items():
button_down = not tildagonos.check_egpio_state(pin, readgpios=False)
if button_down and not button_states[button]:
await eventbus.emit_async(ButtonDownEvent(button=button))
if not button_down and button_states[button]:
await eventbus.emit_async(ButtonUpEvent(button=button))
button_states[button] = button_down
print(booped)
if booped:
now = time.ticks_ms()
for i, gpio in enumerate(
map(lambda i: self.BUTTON_PINS[BUTTONS[i]], "ABCDEF")
):
state = hexpansion_states[i + 1]
button_down = not tildagonos.check_egpio_state(
gpio, readgpios=False
)
if button_down and state is None:
print(f"Down {i}")
hexpansion_states[i + 1] = now
await eventbus.emit_async(HexpansionInsertionEvent(port=i + 1))
elif state and time.ticks_diff(now, state) > 5000:
hexpansion_states[i + 1] = None
await eventbus.emit_async(HexpansionRemovalEvent(port=i + 1))
else:
for button, pin in self.BUTTON_PINS.items():
button_down = not tildagonos.check_egpio_state(pin, readgpios=False)
if button_down and not button_states[button]:
await eventbus.emit_async(ButtonDownEvent(button=button))
if not button_down and button_states[button]:
await eventbus.emit_async(ButtonUpEvent(button=button))
button_states[button] = button_down
await asyncio.sleep(0.01)
7 changes: 6 additions & 1 deletion modules/system/hexpansion/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ def _format_eeprom(self, eep):
def _mount_eeprom(self, eep, port):
mountpoint = f"/hexpansion_{port}"

print(mountpoint, os.listdir())
if mountpoint in os.listdir():
# This is mounted already, unmount first
vfs.umount(mountpoint)

try:
print(f"Attempting to mount i2c eeprom from hexpansion port {port}")
vfs.mount(eep, mountpoint)
Expand Down Expand Up @@ -232,7 +237,7 @@ async def background_task(self):
)
if hexpansion_present:
if settings.get("pattern_mirror_hexpansions", False):
tildagonos.leds[13 + i] = tildagonos.leds[1 + (i*2)]
tildagonos.leds[13 + i] = tildagonos.leds[1 + (i * 2)]
else:
tildagonos.leds[13 + i] = led_colours[i]
else:
Expand Down

0 comments on commit 3994c6b

Please sign in to comment.