Skip to content

Fixes #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ from adafruit_pybadger import PyBadger
pybadger = PyBadger()

while True:
pybadger.badge(hello_scale=2, my_name_is_scale=2, name_scale=3)
pybadger.show_badge(hello_scale=2, my_name_is_scale=2, name_scale=3)
pybadger.auto_dim_display()

if pybadger.button.a:
pybadger.business_card(image_name="Blinka.bmp")
pybadger.show_business_card(image_name="Blinka.bmp")
elif pybadger.button.b:
print("b B")
elif pybadger.button.start:
print("b start")
elif pybadger.button.select:
pybadger.qr_code()
pybadger.show_qr_code()

Contributing
============
Expand Down
29 changes: 19 additions & 10 deletions adafruit_pybadger.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def __init__(self, i2c=None):
if i2c is None:
i2c = board.I2C()
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1)
try:
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1)
except ValueError:
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)

# Buttons
self._buttons = GamePadShift(digitalio.DigitalInOut(board.BUTTON_CLOCK),
Expand Down Expand Up @@ -210,7 +213,7 @@ def brightness(self):
def brightness(self, value):
self.display.brightness = value

def business_card(self, image_name=None, dwell=20):
def show_business_card(self, image_name=None, dwell=20):
"""Display a bitmap image and a text string, such as a personal image and email address.
CURRENTLY ONLY DISPLAYS BITMAP IMAGE. Text string to be added.

Expand All @@ -229,21 +232,27 @@ def business_card(self, image_name=None, dwell=20):
time.sleep(dwell)

# pylint: disable=too-many-locals
def badge(self, *, background_color=0xFF0000, foreground_color=0xFFFFFF,
background_text_color=0xFFFFFF, foreground_text_color=0x000000, hello_scale=1,
hello_string="HELLO", my_name_is_scale=1, my_name_is_string="MY NAME IS",
name_scale=1, name_string="Blinka"):
def show_badge(self, *, background_color=0xFF0000, foreground_color=0xFFFFFF,
background_text_color=0xFFFFFF, foreground_text_color=0x000000,
hello_font=terminalio.FONT, hello_scale=1, hello_string="HELLO",
my_name_is_font=terminalio.FONT, my_name_is_scale=1,
my_name_is_string="MY NAME IS", name_font=terminalio.FONT, name_scale=1,
name_string="Blinka"):
"""Create a "Hello My Name is"-style badge.

:param background_color: The color of the background. Defaults to 0xFF0000.
:param foreground_color: The color of the foreground rectangle. Defaults to 0xFFFFFF.
:param background_text_color: The color of the "HELLO MY NAME IS" text. Defaults to
0xFFFFFF.
:param foreground_text_color: The color of the name text. Defaults to 0x000000.
:param hello_font: The font for the "HELLO" string. Defaults to ``terminalio.FONT``.
:param hello_scale: The size scale of the "HELLO" string. Defaults to 1.
:param hello_string: The first string of the badge. Defaults to "HELLO".
:param my_name_is_font: The font for the "MY NAME IS" string. Defaults to
``terminalio.FONT``.
:param my_name_is_scale: The size scale of the "MY NAME IS" string. Defaults to 1.
:param my_name_is_string: The second string of the badge. Defaults to "MY NAME IS".
:param name_font: The font for the name string. Defaults to ``terminalio.FONT``.
:param name_scale: The size scale of the name string. Defaults to 1.
:param name_string: The third string of the badge - change to be your name. Defaults to
"Blinka".
Expand All @@ -270,7 +279,7 @@ def badge(self, *, background_color=0xFF0000, foreground_color=0xFFFFFF,
hello_scale = hello_scale
hello_group = displayio.Group(scale=hello_scale)
# Setup and Center the Hello Label
hello_label = Label(terminalio.FONT, text=hello_string)
hello_label = Label(font=hello_font, text=hello_string)
(_, _, width, height) = hello_label.bounding_box
hello_label.x = ((self.display.width // (2 * hello_scale)) - width // 2)
hello_label.y = int(height // (1.2 * hello_scale))
Expand All @@ -280,7 +289,7 @@ def badge(self, *, background_color=0xFF0000, foreground_color=0xFFFFFF,
my_name_is_scale = my_name_is_scale
my_name_is_group = displayio.Group(scale=my_name_is_scale)
# Setup and Center the "My Name Is" Label
my_name_is_label = Label(terminalio.FONT, text=my_name_is_string)
my_name_is_label = Label(font=my_name_is_font, text=my_name_is_string)
(_, _, width, height) = my_name_is_label.bounding_box
my_name_is_label.x = ((self.display.width // (2 * my_name_is_scale)) - width // 2)
my_name_is_label.y = int(height // (0.42 * my_name_is_scale))
Expand All @@ -290,7 +299,7 @@ def badge(self, *, background_color=0xFF0000, foreground_color=0xFFFFFF,
name_scale = name_scale
name_group = displayio.Group(scale=name_scale)
# Setup and Center the Name Label
name_label = Label(terminalio.FONT, text=name_string)
name_label = Label(font=name_font, text=name_string)
(_, _, width, height) = name_label.bounding_box
name_label.x = ((self.display.width // (2 * name_scale)) - width // 2)
name_label.y = int(height // (0.17 * name_scale))
Expand Down Expand Up @@ -318,7 +327,7 @@ def bitmap_qr(matrix):
bitmap[x + border_pixels, y + border_pixels] = 0
return bitmap

def qr_code(self, data=b'https://circuitpython.org', dwell=20):
def show_qr_code(self, data=b'https://circuitpython.org', dwell=20):
"""Generate a QR code and display it for ``dwell`` seconds.

:param bytearray data: A bytearray of data for the QR code
Expand Down
6 changes: 3 additions & 3 deletions examples/pybadger_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
pybadger = PyBadger()

while True:
pybadger.badge(hello_scale=2, my_name_is_scale=2, name_scale=3)
pybadger.show_badge(hello_scale=2, my_name_is_scale=2, name_scale=3)
pybadger.auto_dim_display()

if pybadger.button.a:
pybadger.business_card(image_name="Blinka.bmp")
pybadger.show_business_card(image_name="Blinka.bmp")
elif pybadger.button.b:
print("b B")
elif pybadger.button.start:
print("b start")
elif pybadger.button.select:
pybadger.qr_code()
pybadger.show_qr_code()