Skip to content

Business card update #3

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 6 commits into from
Jul 6, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 5 additions & 5 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.show_badge(hello_scale=2, my_name_is_scale=2, name_scale=3)
pybadger.show_badge(name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend moving show_badge and auto_dim out of the loop and then allowing something like pressing the start button to switch back to badge mode.

pybadger.auto_dim_display()

if pybadger.button.a:
pybadger.show_business_card(image_name="Blinka.bmp")
pybadger.show_business_card(image_name="Blinka.bmp", email_string="[email protected]")
elif pybadger.button.b:
print("b B")
pybadger.show_qr_code(data="https://circuitpython.org")
elif pybadger.button.start:
print("b start")
print("Start button pressed!")
elif pybadger.button.select:
pybadger.show_qr_code()
print("Select button pressed!")

Contributing
============
Expand Down
26 changes: 19 additions & 7 deletions adafruit_pybadger.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,16 @@ def brightness(self):
def brightness(self, value):
self.display.brightness = value

def show_business_card(self, image_name=None, dwell=20):
# pylint: disable=too-many-arguments,too-many-locals
def show_business_card(self, image_name=None, email_string=None,
email_scale=1, email_font=terminalio.FONT, 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.

:param str image_name: The name of the bitmap image including .bmp, e.g. ``"Blinka.bmp"``.
:param str email_string: A string to display along the bottom of the display, e.g.
``"[email protected]"``.
:param int email_scale: The scale of ``email_string``. Defaults to 1.
:param email_font: The font for the email string. Defaults to ``terminalio.FONT``.
:param int dwell: The amount of time in seconds to display the business card.

"""
Expand All @@ -227,9 +232,16 @@ def show_business_card(self, image_name=None, dwell=20):
on_disk_bitmap = displayio.OnDiskBitmap(file_name)
face_image = displayio.TileGrid(on_disk_bitmap, pixel_shader=displayio.ColorConverter())
business_card_splash.append(face_image)
# Wait for the image to load.
self.display.wait_for_frame()
time.sleep(dwell)
email_group = displayio.Group(scale=email_scale)
email_label = Label(email_font, text=email_string)
(_, _, width, height) = email_label.bounding_box
email_label.x = ((self.display.width // (2 * email_scale)) - width // 2)
email_label.y = int(height // (0.13 * email_scale))
email_label.color = 0xFFFFFF
email_group.append(email_label)
business_card_splash.append(email_group)
time.sleep(dwell)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure of the point of the automatically sleep for 20 seconds is. If this is for the purposes of the simepletest, would it be more useful to put it in the simpletest itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realised earlier that I need to make the code non-blocking, but didn't have the time to do so yet. Please do not merge until I have done that - I'll get to it this evening.


# pylint: disable=too-many-locals
def show_badge(self, *, background_color=0xFF0000, foreground_color=0xFFFFFF,
Expand Down Expand Up @@ -327,15 +339,15 @@ def bitmap_qr(matrix):
bitmap[x + border_pixels, y + border_pixels] = 0
return bitmap

def show_qr_code(self, data=b'https://circuitpython.org', dwell=20):
def show_qr_code(self, data="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
:param string data: A string of data for the QR code
:param int dwell: The amount of time in seconds to display the QR code

"""
qr_code = adafruit_miniqr.QRCode(qr_type=3, error_correct=adafruit_miniqr.L)
qr_code.add_data(data)
qr_code.add_data(bytearray(data))
qr_code.make()
qr_bitmap = self.bitmap_qr(qr_code.matrix)
palette = displayio.Palette(2)
Expand Down
10 changes: 5 additions & 5 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.show_badge(hello_scale=2, my_name_is_scale=2, name_scale=3)
pybadger.show_badge(name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3)
pybadger.auto_dim_display()

if pybadger.button.a:
pybadger.show_business_card(image_name="Blinka.bmp")
pybadger.show_business_card(image_name="Blinka.bmp", email_string="[email protected]")
elif pybadger.button.b:
print("b B")
pybadger.show_qr_code(data="https://circuitpython.org")
elif pybadger.button.start:
print("b start")
print("Start button pressed!")
elif pybadger.button.select:
pybadger.show_qr_code()
print("Select button pressed!")