commit
6878e34ccc
3 changed files with 135 additions and 8 deletions
|
|
@ -35,3 +35,5 @@ elif "PewPew M4" in os.uname().machine:
|
|||
from .pewpewm4 import pewpewm4 as pybadger
|
||||
elif "PyPortal" in os.uname().machine:
|
||||
from .pyportal import pyportal as pybadger
|
||||
elif "Circuit Playground Bluefruit" in os.uname().machine:
|
||||
from .cpb_gizmo import cpb_gizmo as pybadger
|
||||
|
|
|
|||
125
adafruit_pybadger/cpb_gizmo.py
Normal file
125
adafruit_pybadger/cpb_gizmo.py
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2020 Kattni Rembor for Adafruit Industries
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
"""
|
||||
`adafruit_pybadger.cpb_gizmo`
|
||||
================================================================================
|
||||
|
||||
Badge-focused CircuitPython helper library for Circuit Playground Bluefruit with TFT Gizmo.
|
||||
|
||||
|
||||
* Author(s): Kattni Rembor
|
||||
|
||||
Implementation Notes
|
||||
--------------------
|
||||
|
||||
**Hardware:**
|
||||
|
||||
* `Adafruit Circuit Playground Bluefruit <https://www.adafruit.com/product/4333>`_
|
||||
* `Adafruit TFT Gizmo <https://www.adafruit.com/product/4367>`_
|
||||
|
||||
**Software and Dependencies:**
|
||||
|
||||
* Adafruit CircuitPython firmware for the supported boards:
|
||||
https://github.com/adafruit/circuitpython/releases
|
||||
|
||||
"""
|
||||
|
||||
from collections import namedtuple
|
||||
import board
|
||||
import digitalio
|
||||
import analogio
|
||||
import busio
|
||||
import audiopwmio
|
||||
from adafruit_gizmo import tft_gizmo
|
||||
from gamepad import GamePad
|
||||
import adafruit_lis3dh
|
||||
import neopixel
|
||||
from adafruit_pybadger.pybadger_base import PyBadgerBase
|
||||
|
||||
__version__ = "0.0.0-auto.0"
|
||||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyBadger.git"
|
||||
|
||||
Buttons = namedtuple("Buttons", "a b")
|
||||
|
||||
|
||||
class CPB_Gizmo(PyBadgerBase):
|
||||
"""Class that represents a single Circuit Playground Bluefruit with TFT Gizmo."""
|
||||
|
||||
display = None
|
||||
_audio_out = audiopwmio.PWMAudioOut
|
||||
_neopixel_count = 10
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
_i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
|
||||
_int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
|
||||
self.accelerometer = adafruit_lis3dh.LIS3DH_I2C(_i2c, address=0x19, int1=_int1)
|
||||
self.accelerometer.range = adafruit_lis3dh.RANGE_8_G
|
||||
|
||||
self.display = tft_gizmo.TFT_Gizmo()
|
||||
self._display_brightness = 1.0
|
||||
|
||||
# NeoPixels
|
||||
self._neopixels = neopixel.NeoPixel(
|
||||
board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB
|
||||
)
|
||||
_a_btn = digitalio.DigitalInOut(board.BUTTON_A)
|
||||
_a_btn.switch_to_input(pull=digitalio.Pull.DOWN)
|
||||
_b_btn = digitalio.DigitalInOut(board.BUTTON_B)
|
||||
_b_btn.switch_to_input(pull=digitalio.Pull.DOWN)
|
||||
self._buttons = GamePad(_a_btn, _b_btn)
|
||||
self._light_sensor = analogio.AnalogIn(board.LIGHT)
|
||||
|
||||
@property
|
||||
def button(self):
|
||||
"""The buttons on the board.
|
||||
|
||||
Example use:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from adafruit_pybadger import pybadger
|
||||
|
||||
while True:
|
||||
if pybadger.button.a:
|
||||
print("Button A")
|
||||
elif pybadger.button.b:
|
||||
print("Button B")
|
||||
"""
|
||||
button_values = self._buttons.get_pressed()
|
||||
return Buttons(
|
||||
button_values & PyBadgerBase.BUTTON_B, button_values & PyBadgerBase.BUTTON_A
|
||||
)
|
||||
|
||||
@property
|
||||
def _unsupported(self):
|
||||
"""This feature is not supported on CPB Gizmo."""
|
||||
raise NotImplementedError("This feature is not supported on CPB Gizmo.")
|
||||
|
||||
# The following is a list of the features available in other PyBadger modules but
|
||||
# not available for CPB Gizmo. If called while using a CPB Gizmo, they will result in the
|
||||
# NotImplementedError raised in the property above.
|
||||
|
||||
|
||||
cpb_gizmo = CPB_Gizmo() # pylint: disable=invalid-name
|
||||
"""Object that is automatically created on import."""
|
||||
|
|
@ -132,8 +132,9 @@ class PyBadgerBase:
|
|||
self._created_background = False
|
||||
|
||||
# Display
|
||||
self.display = board.DISPLAY
|
||||
self._display_brightness = 1.0
|
||||
if "DISPLAY" in dir(board):
|
||||
self.display = board.DISPLAY
|
||||
self._display_brightness = 1.0
|
||||
|
||||
self._neopixels = None
|
||||
|
||||
|
|
@ -212,9 +213,8 @@ class PyBadgerBase:
|
|||
)
|
||||
return self._background_group
|
||||
|
||||
@classmethod
|
||||
def _badge_background(
|
||||
cls,
|
||||
self,
|
||||
background_color=(255, 0, 0),
|
||||
rectangle_color=(255, 255, 255),
|
||||
rectangle_drop=0.4,
|
||||
|
|
@ -223,7 +223,7 @@ class PyBadgerBase:
|
|||
"""Populate the background color with a rectangle color block over it as the background for
|
||||
a name badge."""
|
||||
background_group = displayio.Group(max_size=30)
|
||||
color_bitmap = displayio.Bitmap(board.DISPLAY.width, board.DISPLAY.height, 1)
|
||||
color_bitmap = displayio.Bitmap(self.display.width, self.display.height, 1)
|
||||
color_palette = displayio.Palette(1)
|
||||
color_palette[0] = background_color
|
||||
|
||||
|
|
@ -234,9 +234,9 @@ class PyBadgerBase:
|
|||
|
||||
rectangle = Rect(
|
||||
0,
|
||||
(int(board.DISPLAY.height * rectangle_drop)),
|
||||
board.DISPLAY.width,
|
||||
(int(board.DISPLAY.height * rectangle_height)),
|
||||
(int(self.display.height * rectangle_drop)),
|
||||
self.display.width,
|
||||
(int(self.display.height * rectangle_height)),
|
||||
fill=rectangle_color,
|
||||
)
|
||||
background_group.append(rectangle)
|
||||
|
|
|
|||
Loading…
Reference in a new issue