Git Product home page Git Product logo

adafruit_circuitpython_pybadger's Introduction

Introduction

Documentation Status Discord Build Status Code Style: Black

Badge-focused CircuitPython helper library for PyBadge, PyBadge LC, PyGamer, CLUE, and Mag Tag.

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-pybadger

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-pybadger

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-pybadger

Usage Example

from adafruit_pybadger import pybadger

pybadger.show_badge(name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3)

while True:
    pybadger.auto_dim_display(delay=10)
    if pybadger.button.a:
        pybadger.show_business_card(image_name="Blinka.bmp", name_string="Blinka", name_scale=2,
                                    email_string_one="blinka@", email_string_two="adafruit.com")
    elif pybadger.button.b:
        pybadger.show_qr_code(data="https://circuitpython.org")
    elif pybadger.button.start:
        pybadger.show_badge(name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3)

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

adafruit_circuitpython_pybadger's People

Contributors

blitzcitydiy avatar caternuson avatar cedargrovestudios avatar dglaude avatar dhalbert avatar evaherrada avatar foamyguy avatar jepler avatar kattni avatar ladyada avatar lesamouraipourpre avatar liltux avatar makermelissa avatar nnja avatar retiredwizard avatar rhooper avatar sak917 avatar siddacious avatar sommersoft avatar tannewt avatar tekktrik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_circuitpython_pybadger's Issues

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_pybadger/pybadger_base.py:60
  • adafruit_pybadger/pybadger_base.py:172
  • adafruit_pybadger/pybadger_base.py:207
  • adafruit_pybadger/pybadger_base.py:236
  • adafruit_pybadger/pybadger_base.py:254
  • adafruit_pybadger/pybadger_base.py:352
  • adafruit_pybadger/pybadger_base.py:382
  • adafruit_pybadger/pybadger_base.py:397
  • adafruit_pybadger/pybadger_base.py:444
  • adafruit_pybadger/pybadger_base.py:449
  • adafruit_pybadger/pybadger_base.py:546
  • adafruit_pybadger/pybadger_base.py:632
  • adafruit_pybadger/pybadger_base.py:646
  • adafruit_pybadger/pybadger_base.py:684
  • adafruit_pybadger/pybadger_base.py:690
  • adafruit_pybadger/pybadger_base.py:703
  • adafruit_pybadger/pybadger_base.py:708
  • adafruit_pybadger/pybadger_base.py:721
  • adafruit_pybadger/pybadger_base.py:747

Remove use of GamePad and GamePadShift

#4940 in the core will remove gamepad and gamepadshift.

This library makes use of these objects to handle the buttons for some of the devices that are supported. We'll need to change over this library to use the newer keypad functionality when these do get removed from the core.

Another victim of lsm6ds33.

Traceback (most recent call last):
File "code.py", line 8, in
File "adafruit_pybadger/init.py", line 29, in
File "adafruit_pybadger/clue.py", line 117, in
File "adafruit_pybadger/clue.py", line 72, in init
AttributeError: 'module' object has no attribute 'LSM6DS33'

Incompatible with PyBadge LC

I think this library currently assumes that if the I2C bus exists then the accelerometer will as well with the code from here:

if i2c is None:
try:
i2c = board.I2C()
except RuntimeError:
self._accelerometer = None
if i2c is not None:
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
try:
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(
i2c, address=0x19, int1=int1
)
except ValueError:
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)

Since the PyBadge LC does not have the accelerometer populated this ends up raising an exception.

We could possible handle the missing accelerometer more gracefully and allow the remaining portions of the library that are supported by the LC hardware to work.

Does not run with CirCuit Python 7.0

I get the error:

Traceback (most recent call last):
  File "code.py", line 4, in <module>
  File "adafruit_pybadger/__init__.py", line 12, in <module>
  File "adafruit_pybadger/clue.py", line 32, in <module>
ImportError: no module named 'gamepad'

Matt

Type annotation corrections needed

This library needs type annotation improvements! It mistakenly uses Type[tuple] where there are namedtuple returns. For example:

from collections import namedtuple

NamedTupleClass = namedtuple("NamedTupleClass", ("A", "B", "C"))

Then if a function use a type annotation like Type[tuple]:

def some_method(arg_a: str, arg_b: int) -> Type[tuple]:
    return NamedTupleClass(1, 2, 3)

It should actually be:

def some_method(arg_a: str, arg_b: int) -> NamedTupleClass:
    return NamedTupleClass(1, 2, 3)

Throws I2C Exception on PyBadge LC

The accelerometer is not included on the LC which causes the constructor to throw an exception. We should detect which board it is and only init the relevant things. Don't catch the exception because then other errors may be hidden.

NEOPIXEL_POWER_INVERTED in use error on MagTag

Running the magtag simpletest from examples in this repo currently raises this error:

code.py output:
wait before anything
after show, going to loop
Traceback (most recent call last):
  File "code.py", line 55, in <module>
ValueError: NEOPIXEL_POWER_INVERTED in use

I think this is the same root cause as: adafruit/Adafruit_CircuitPython_MagTag#76

The Neopixel library was updated to make it attempt to handle the power pin internally. It does have a graceful fallback if the pin has already been grabbed by something else. The example script in this repo can be updated to remove handling of the power pin I think since Neopixel will handle it by itself now. Or the other option is for user code to initialize the power pin before initializing the neopixels which in this case occurs as soon as pybadger is imported.

I'm found this while working on some unrelated changes to MagTag for this library. When I submit the PR for that I'll include this fix to the example script to get it back to working with current version of Neopixel library.

Remove PyBadger library from PyPI

This lib does not belong on PyPI. This requires the following:

  • setup.pymust be renamed to setup.py.disabled and the contents replaced with the code block at the bottom of this issue.

  • Library must be manually removed from PyPI. (I can do this once setup.py is taken care of.)

setup.py.disabled contents:

"""
This library is not deployed to PyPI. It is either a board-specific helper library, or
does not make sense for use on or is incompatible with single board computers and Linux.
"""

Sensor Data

Im trying to display the Temp and humidity data using the sensors built in to the Clue, but i tried using the code bellow, but i get an error:
Traceback (most recent call last):
File "code.py", line 7, in
File "adafruit_clue.py", line 930, in
File "adafruit_clue.py", line 195, in init
ValueError: P5 in use

# Write your code here :-)
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import board
from adafruit_pybadger import pybadger
from adafruit_clue import clue
from adafruit_bmp280 import bmp280

temperature = clue.temperature
humidity = clue.humidity

pybadger.badge_background(
    background_color=pybadger.YELLOW,
    rectangle_color=pybadger.BLUE,
    rectangle_drop=0.2,
    rectangle_height=0.6,
)

pybadger.badge_line(
    text="Stingers of Steel", color=pybadger.BLUE, scale=2, padding_above=2
)
pybadger.badge_line(text="Emerson C.", color=pybadger.YELLOW, scale=4, padding_above=4)
pybadger.badge_line(
    text="Mentor / Mechanic", color=pybadger.YELLOW, scale=2, padding_above=2
)
pybadger.badge_line(
    text="Temp: {:.1f} C".format(temperature), color=pybadger.YELLOW, scale=2, padding_above=2
)
pybadger.badge_line(
    text="Humi: {:.1f} %".format(humidity), color=pybadger.YELLOW, scale=2, padding_above=2
)
pybadger.badge_line(
    text="6642", color=pybadger.BLUE, scale=4, padding_above=10
)

display = board.DISPLAY
display.rotation = 180

pybadger.show_custom_badge()

while True:
    
    if pybadger.button.a:
        pybadger.show_qr_code("https://www.facebook.com/stingers6642")
        pybadger.pixels.fill(pybadger.BLUE)
    if pybadger.button.b:
        pybadger.show_custom_badge()
        pybadger.pixels.fill(pybadger.YELLOW)

Issue specifying font through show_badge

when passing a .bdf font through pybadger.show_badge

pybadger.show_badge(hello_string="Ola!", name_string="Blinka", hello_font="Helvetica-Bold-16.bdf", hello_scale=2, my_name_is_scale=1, name_scale=2)

causes the following exception:

Traceback (most recent call last):
File "code.py", line 14, in
File "adafruit_pybadger.py", line 332, in show_badge
File "adafruit_display_text/label.py", line 73, in init
AttributeError: 'str' object has no attribute 'get_bounding_box'

I've tested with the adafruit generated fonts Helvetica-Bold-16.bdf and Noto-18.bdf, both which work when using:

name_font = bitmap_font.load_font(name_font_name)
name_font.load_glyphs(NAME_STRING.encode('utf-8'))

I also renamed *.bdf to *.FONT on the off chance that the libraries were looking for that extension, as in the example terminalio.FONT, but that did not change the exception returned.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.