Skip to content

Commit c61bc37

Browse files
committed
starting magtag support and example
1 parent 8e4aec4 commit c61bc37

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

adafruit_pybadger/mag_tag.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2020 Tim C 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 CLUE.
27+
28+
29+
* Author(s): Kattni Rembor, Tim C
30+
31+
Implementation Notes
32+
--------------------
33+
34+
**Hardware:**
35+
36+
* `Adafruit CLUE <https://www.adafruit.com/product/4500>`_
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+
from gamepad import GamePad
49+
import neopixel
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", "a b c d")
56+
57+
58+
class MagTag(PyBadgerBase):
59+
"""Class that represents a single Mag Tag."""
60+
61+
_neopixel_count = 4
62+
63+
def __init__(self):
64+
super().__init__()
65+
66+
# NeoPixels
67+
self._neopixels = neopixel.NeoPixel(
68+
board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB
69+
)
70+
71+
# self._buttons = GamePad(
72+
# ,
73+
# digitalio.DigitalInOut(board.BUTTON_B),
74+
# digitalio.DigitalInOut(board.BUTTON_C),
75+
# digitalio.DigitalInOut(board.BUTTON_D),
76+
# )
77+
78+
@property
79+
def button(self):
80+
"""The buttons on the board.
81+
82+
Example use:
83+
84+
.. code-block:: python
85+
86+
from adafruit_pybadger import pybadger
87+
88+
while True:
89+
if pybadger.button.a:
90+
print("Button A")
91+
elif pybadger.button.b:
92+
print("Button B")
93+
"""
94+
pass
95+
# button_values = self._buttons.get_pressed()
96+
# return Buttons(
97+
# button_values & PyBadgerBase.BUTTON_B, button_values & PyBadgerBase.BUTTON_A,
98+
# button_values & PyBadgerBase.BUTTON_START, button_values & PyBadgerBase.BUTTON_SELECT
99+
# )
100+
101+
@property
102+
def _unsupported(self):
103+
"""This feature is not supported on Mag Tag."""
104+
raise NotImplementedError("This feature is not supported on Mag Tag.")
105+
106+
# The following is a list of the features available in other PyBadger modules but
107+
# not available for Mag Tag. If called while using a Mag Tag, they will result in the
108+
# NotImplementedError raised in the property above.
109+
play_file = _unsupported
110+
light = _unsupported
111+
acceleration = _unsupported
112+
button = _unsupported
113+
114+
115+
mag_tag = MagTag() # pylint: disable=invalid-name
116+
"""Object that is automatically created on import."""

examples/pybadger_magtag_simpletest.py

Whitespace-only changes.

0 commit comments

Comments
 (0)