Skip to content

Commit 335ba26

Browse files
authored
Merge pull request #34 from FoamyGuy/adding_pewpewm4_support
Adding PyPortal and Pew Pew M4 support
2 parents 978488a + 2b09d30 commit 335ba26

11 files changed

+302
-6
lines changed

adafruit_pybadger/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@
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+
elif "PyPortal" in os.uname().machine:
37+
from .pyportal import pyportal as pybadger

adafruit_pybadger/clue.py

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import audiopwmio
4949
from gamepad import GamePad
5050
import adafruit_lsm6ds
51+
import neopixel
5152
from adafruit_pybadger.pybadger_base import PyBadgerBase
5253

5354
__version__ = "0.0.0-auto.0"
@@ -70,6 +71,11 @@ def __init__(self):
7071
if i2c is not None:
7172
self._accelerometer = adafruit_lsm6ds.LSM6DS33(i2c)
7273

74+
# NeoPixels
75+
self._neopixels = neopixel.NeoPixel(
76+
board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB
77+
)
78+
7379
self._buttons = GamePad(
7480
digitalio.DigitalInOut(board.BUTTON_A),
7581
digitalio.DigitalInOut(board.BUTTON_B),

adafruit_pybadger/pewpewm4.py

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+
from adafruit_pybadger.pybadger_base import PyBadgerBase
51+
52+
__version__ = "0.0.0-auto.0"
53+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyBadger.git"
54+
55+
Buttons = namedtuple("Buttons", ("o", "x", "z", "right", "down", "up", "left"))
56+
57+
58+
class PewPewM4(PyBadgerBase):
59+
"""Class that represents a single Pew Pew M4."""
60+
61+
_audio_out = audioio.AudioOut
62+
_neopixel_count = 0
63+
64+
def __init__(self):
65+
super().__init__()
66+
67+
self._buttons = GamePad(
68+
digitalio.DigitalInOut(board.BUTTON_O),
69+
digitalio.DigitalInOut(board.BUTTON_X),
70+
digitalio.DigitalInOut(board.BUTTON_Z),
71+
digitalio.DigitalInOut(board.BUTTON_RIGHT),
72+
digitalio.DigitalInOut(board.BUTTON_DOWN),
73+
digitalio.DigitalInOut(board.BUTTON_UP),
74+
digitalio.DigitalInOut(board.BUTTON_LEFT),
75+
)
76+
77+
@property
78+
def button(self):
79+
"""The buttons on the board.
80+
81+
Example use:
82+
83+
.. code-block:: python
84+
85+
from adafruit_pybadger import pybadger
86+
87+
while True:
88+
if pybadger.button.x:
89+
print("Button X")
90+
elif pybadger.button.o:
91+
print("Button O")
92+
"""
93+
button_values = self._buttons.get_pressed()
94+
return Buttons(
95+
*[
96+
button_values & button
97+
for button in (
98+
PyBadgerBase.BUTTON_B,
99+
PyBadgerBase.BUTTON_A,
100+
PyBadgerBase.BUTTON_START,
101+
PyBadgerBase.BUTTON_SELECT,
102+
PyBadgerBase.BUTTON_RIGHT,
103+
PyBadgerBase.BUTTON_DOWN,
104+
PyBadgerBase.BUTTON_UP,
105+
)
106+
]
107+
)
108+
109+
@property
110+
def _unsupported(self):
111+
"""This feature is not supported on PewPew M4."""
112+
raise NotImplementedError("This feature is not supported on PewPew M4.")
113+
114+
# The following is a list of the features available in other PyBadger modules but
115+
# not available for CLUE. If called while using a CLUE, they will result in the
116+
# NotImplementedError raised in the property above.
117+
light = _unsupported
118+
acceleration = _unsupported
119+
pixels = _unsupported
120+
121+
122+
pewpewm4 = PewPewM4() # pylint: disable=invalid-name
123+
"""Object that is automatically created on import."""

adafruit_pybadger/pybadge.py

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import audioio
5555
from gamepadshift import GamePadShift
5656
import adafruit_lis3dh
57+
import neopixel
5758
from adafruit_pybadger.pybadger_base import PyBadgerBase
5859

5960
__version__ = "0.0.0-auto.0"
@@ -88,6 +89,11 @@ def __init__(self):
8889
except ValueError:
8990
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
9091

92+
# NeoPixels
93+
self._neopixels = neopixel.NeoPixel(
94+
board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB
95+
)
96+
9197
self._buttons = GamePadShift(
9298
digitalio.DigitalInOut(board.BUTTON_CLOCK),
9399
digitalio.DigitalInOut(board.BUTTON_OUT),

adafruit_pybadger/pybadger_base.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@
5555
import audiocore
5656
except ImportError:
5757
import audioio as audiocore
58+
from adafruit_bitmap_font import bitmap_font
5859
import displayio
59-
import neopixel
6060
from adafruit_display_shapes.rect import Rect
6161
from adafruit_display_text import label
62-
from adafruit_bitmap_font import bitmap_font
6362
import terminalio
6463
import adafruit_miniqr
6564

@@ -136,10 +135,7 @@ def __init__(self):
136135
self.display = board.DISPLAY
137136
self._display_brightness = 1.0
138137

139-
# NeoPixels
140-
self._neopixels = neopixel.NeoPixel(
141-
board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB
142-
)
138+
self._neopixels = None
143139

144140
# Auto dim display based on movement
145141
self._last_accelerometer = None

adafruit_pybadger/pygamer.py

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import analogio
4848
import digitalio
4949
import audioio
50+
import neopixel
5051
from gamepadshift import GamePadShift
5152
import adafruit_lis3dh
5253
from adafruit_pybadger.pybadger_base import PyBadgerBase
@@ -76,6 +77,11 @@ def __init__(self):
7677
except ValueError:
7778
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
7879

80+
# NeoPixels
81+
self._neopixels = neopixel.NeoPixel(
82+
board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB
83+
)
84+
7985
self._buttons = GamePadShift(
8086
digitalio.DigitalInOut(board.BUTTON_CLOCK),
8187
digitalio.DigitalInOut(board.BUTTON_OUT),

adafruit_pybadger/pyportal.py

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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.pyportal`
24+
================================================================================
25+
26+
Badge-focused CircuitPython helper library for PyPortal.
27+
28+
29+
* Author(s): Kattni Rembor
30+
31+
Implementation Notes
32+
--------------------
33+
34+
**Hardware:**
35+
36+
* `Adafruit PyPortal <https://www.adafruit.com/product/4116>`_
37+
38+
**Software and Dependencies:**
39+
40+
* Adafruit CircuitPython firmware for the supported boards:
41+
https://github.com/adafruit/circuitpython/releases
42+
43+
"""
44+
import board
45+
import analogio
46+
import audioio
47+
import neopixel
48+
from adafruit_pybadger.pybadger_base import PyBadgerBase
49+
50+
__version__ = "0.0.0-auto.0"
51+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyBadger.git"
52+
53+
54+
class PyPortal(PyBadgerBase):
55+
"""Class that represents a single PyPortal."""
56+
57+
_audio_out = audioio.AudioOut
58+
_neopixel_count = 1
59+
60+
def __init__(self):
61+
super().__init__()
62+
63+
# NeoPixels
64+
self._neopixels = neopixel.NeoPixel(
65+
board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB
66+
)
67+
self._light_sensor = analogio.AnalogIn(board.LIGHT)
68+
69+
@property
70+
def _unsupported(self):
71+
"""This feature is not supported on PyPortal."""
72+
raise NotImplementedError("This feature is not supported on PyPortal.")
73+
74+
# The following is a list of the features available in other PyBadger modules but
75+
# not available for PyPortal. If called while using a PyPortal, they will result in the
76+
# NotImplementedError raised in the property above.
77+
button = _unsupported
78+
acceleration = _unsupported
79+
auto_dim_display = _unsupported
80+
81+
82+
pyportal = PyPortal() # pylint: disable=invalid-name
83+
"""Object that is automatically created on import."""

examples/Blinka_PewPewM4.bmp

11.1 KB
Binary file not shown.

examples/Blinka_PyPortal.bmp

41.1 KB
Binary file not shown.
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Simpletest example using the Pew Pew M4.
2+
Use the O, X, and Z buttons to change between examples."""
3+
from adafruit_pybadger import pybadger
4+
5+
pybadger.show_badge(
6+
name_string="Blinka", hello_scale=3, my_name_is_scale=3, name_scale=4
7+
)
8+
9+
while True:
10+
if pybadger.button.o:
11+
pybadger.show_business_card(
12+
image_name="Blinka_PewPewM4.bmp",
13+
name_string="Blinka",
14+
name_scale=4,
15+
email_string_one="blinka@",
16+
email_string_two="adafruit.com",
17+
email_scale_one=2,
18+
email_scale_two=2,
19+
)
20+
elif pybadger.button.x:
21+
pybadger.show_qr_code(data="https://circuitpython.org")
22+
elif pybadger.button.z:
23+
pybadger.show_badge(
24+
name_string="Blinka", hello_scale=3, my_name_is_scale=3, name_scale=4
25+
)
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""Simpletest example using Adafruit PyPortal. Uses the touchscreen to advance between examples."""
2+
import board
3+
from adafruit_pybadger import pybadger
4+
import adafruit_touchscreen
5+
6+
# pylint: disable=invalid-name
7+
8+
# These pins are used as both analog and digital! XL, XR and YU must be analog
9+
# and digital capable. YD just need to be digital
10+
ts = adafruit_touchscreen.Touchscreen(
11+
board.TOUCH_XL,
12+
board.TOUCH_XR,
13+
board.TOUCH_YD,
14+
board.TOUCH_YU,
15+
calibration=((5200, 59000), (5800, 57000)),
16+
size=(320, 240),
17+
)
18+
19+
pybadger.show_badge(
20+
name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3
21+
)
22+
23+
cur_example = 0
24+
prev_touch = None
25+
while True:
26+
p = ts.touch_point
27+
if p and not prev_touch:
28+
cur_example += 1
29+
if cur_example >= 3:
30+
cur_example = 0
31+
print(cur_example)
32+
prev_touch = p
33+
34+
if cur_example == 0:
35+
pybadger.show_business_card(
36+
image_name="Blinka_PyPortal.bmp",
37+
name_string="Blinka",
38+
name_scale=2,
39+
email_string_one="blinka@",
40+
email_string_two="adafruit.com",
41+
)
42+
elif cur_example == 1:
43+
pybadger.show_qr_code(data="https://circuitpython.org")
44+
elif cur_example == 2:
45+
pybadger.show_badge(
46+
name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3
47+
)

0 commit comments

Comments
 (0)