-
Notifications
You must be signed in to change notification settings - Fork 25
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
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 | ||
============ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
||
""" | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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!") |
There was a problem hiding this comment.
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.