Skip to content

Commit 3fa977c

Browse files
committed
Add support for Meowbit
1 parent 275c03e commit 3fa977c

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

meowbit/audioio.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class AudioOut:
2+
def __init__(self, pin):
3+
pass
4+
5+
def stop(self):
6+
pass
7+
8+
def play(self, what):
9+
pass
10+
11+
class WaveFile:
12+
def __init__(self, file, buffer=None):
13+
pass

meowbit/stage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../stage.py

meowbit/ugame.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import board
2+
import stage
3+
import busio
4+
import time
5+
import keypad
6+
7+
8+
K_X = 0x01
9+
K_O = 0x02
10+
K_DOWN = 0x04
11+
K_LEFT = 0x08
12+
K_RIGHT = 0x10
13+
K_UP = 0x20
14+
K_Z = 0x40
15+
16+
display = board.DISPLAY
17+
display.auto_brightness = True
18+
display.auto_refresh = False
19+
20+
21+
class _Buttons:
22+
def __init__(self):
23+
self.keys = keypad.Keys((board.BTNA, board.BTNB, board.DOWN,
24+
board.LEFT, board.RIGHT, board.UP),
25+
value_when_pressed=False, interval=0.05)
26+
self.last_state = 0
27+
self.event = keypad.Event(0, False)
28+
self.last_z_press = None
29+
30+
def get_pressed(self):
31+
buttons = self.last_state
32+
events = self.keys.events
33+
while events:
34+
if events.get_into(self.event):
35+
bit = 1 << self.event.key_number
36+
if self.event.pressed:
37+
buttons |= bit
38+
self.last_state |= bit
39+
else:
40+
self.last_state &= ~bit
41+
if buttons & K_Z:
42+
now = time.monotonic()
43+
if self.last_z_press:
44+
if now - self.last_z_press > 2:
45+
supervisor.set_next_code_file(None)
46+
supervisor.reload()
47+
else:
48+
self.last_z_press = now
49+
else:
50+
self.last_z_press = None
51+
return buttons
52+
53+
54+
class DummyAudio:
55+
def play(self, f, loop=False):
56+
pass
57+
58+
def stop(self):
59+
pass
60+
61+
def mute(self, mute):
62+
pass
63+
64+
audio = DummyAudio()
65+
buttons = _Buttons()

0 commit comments

Comments
 (0)