Skip to content

Commit 7cb7bdc

Browse files
committed
starting work on pewpew m4 support
1 parent 8aca7b9 commit 7cb7bdc

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

adafruit_pybadger/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@
3131
from .pybadge import pybadge as pybadger
3232
elif "PyGamer" in os.uname().machine:
3333
from .pygamer import pygamer as pybadger
34+
elif "PewPew M4" in os.uname().machine:
35+
from .pewpewm4 import pewpewm4 as pybadger
36+

adafruit_pybadger/pewpewm4.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2020 Kattni Rembor for Adafruit Industries
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
"""
23+
`adafruit_pybadger.clue`
24+
================================================================================
25+
26+
Badge-focused CircuitPython helper library for Pew Pew M4.
27+
28+
29+
* Author(s): Kattni Rembor
30+
31+
Implementation Notes
32+
--------------------
33+
34+
**Hardware:**
35+
36+
* `Pew Pew M4 <https://hackaday.io/project/165032-pewpew-m4>`_
37+
38+
**Software and Dependencies:**
39+
40+
* Adafruit CircuitPython firmware for the supported boards:
41+
https://github.com/adafruit/circuitpython/releases
42+
43+
"""
44+
45+
from collections import namedtuple
46+
import board
47+
import digitalio
48+
import audioio
49+
from gamepad import GamePad
50+
import adafruit_lsm6ds
51+
from adafruit_pybadger.pybadger_base import PyBadgerBase
52+
53+
__version__ = "0.0.0-auto.0"
54+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyBadger.git"
55+
56+
Buttons = namedtuple("Buttons", "b a start right down up left")
57+
58+
59+
class PewPewM4(PyBadgerBase):
60+
"""Class that represents a single Pew Pew M4."""
61+
62+
_audio_out = audioio.AudioOut
63+
_neopixel_count = 0
64+
65+
def __init__(self):
66+
super().__init__()
67+
68+
69+
self._buttons = GamePad(
70+
digitalio.DigitalInOut(board.BUTTON_A),
71+
digitalio.DigitalInOut(board.BUTTON_B),
72+
)
73+
74+
@property
75+
def button(self):
76+
"""The buttons on the board.
77+
78+
Example use:
79+
80+
.. code-block:: python
81+
82+
from adafruit_pybadger import pybadger
83+
84+
while True:
85+
if pybadger.button.a:
86+
print("Button A")
87+
elif pybadger.button.b:
88+
print("Button B")
89+
"""
90+
button_values = self._buttons.get_pressed()
91+
return Buttons(
92+
button_values & PyBadgerBase.BUTTON_B, button_values & PyBadgerBase.BUTTON_A
93+
)
94+
95+
@property
96+
def _unsupported(self):
97+
"""This feature is not supported on CLUE."""
98+
raise NotImplementedError("This feature is not supported on CLUE.")
99+
100+
# The following is a list of the features available in other PyBadger modules but
101+
# not available for CLUE. If called while using a CLUE, they will result in the
102+
# NotImplementedError raised in the property above.
103+
light = _unsupported
104+
105+
106+
107+
clue = Clue() # pylint: disable=invalid-name
108+
"""Object that is automatically created on import."""

0 commit comments

Comments
 (0)