|
| 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.""" |
0 commit comments