-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,12 +213,31 @@ 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-locals | ||
def show_business_card(self, *, image_name=None, name_string=None, name_scale=1, | ||
name_font=terminalio.FONT, email_string_one=None, | ||
email_scale_one=1, email_font_one=terminalio.FONT, | ||
email_string_two=None, email_scale_two=1, | ||
email_font_two=terminalio.FONT): | ||
"""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 int dwell: The amount of time in seconds to display the business card. | ||
:param str image_name: REQUIRED. The name of the bitmap image including .bmp, e.g. | ||
``"Blinka.bmp"``. | ||
:param str name_string: A name string to display along the bottom of the display, e.g. | ||
``"Blinka"``. | ||
:param int name_scale: The scale of ``name_string``. Defaults to 1. | ||
:param name_font: The font for the name string. Defaults to ``terminalio.FONT``. | ||
:param str email_string_one: A string to display along the bottom of the display, e.g. | ||
``"[email protected]"``. | ||
:param int email_scale_one: The scale of ``email_string_one``. Defaults to 1. | ||
:param email_font_one: The font for the first email string. Defaults to ``terminalio.FONT``. | ||
:param str email_string_two: A second string to display along the bottom of the display. | ||
Use if your email address is longer than one line or to add | ||
more space between the name and email address, | ||
e.g. (blinka@) ``"adafruit.com"``. | ||
:param int email_scale_two: The scale of ``email_string_two``. Defaults to 1. | ||
:param email_font_two: The font for the second email string. Defaults to | ||
``terminalio.FONT``. | ||
|
||
""" | ||
business_card_splash = displayio.Group(max_size=30) | ||
|
@@ -227,9 +246,36 @@ 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) | ||
if name_string: | ||
name_group = displayio.Group(scale=name_scale) | ||
name_label = Label(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.15 * name_scale)) | ||
name_label.color = 0xFFFFFF | ||
name_group.append(name_label) | ||
business_card_splash.append(name_group) | ||
if email_string_one: | ||
email_group_one = displayio.Group(scale=email_scale_one) | ||
email_label_one = Label(email_font_one, text=email_string_one) | ||
(_, _, width, height) = email_label_one.bounding_box | ||
email_label_one.width = self.display.width | ||
email_label_one.x = ((self.display.width // (2 * email_scale_one)) - width // 2) | ||
email_label_one.y = int(height // (0.13 * email_scale_one)) | ||
email_label_one.color = 0xFFFFFF | ||
email_group_one.append(email_label_one) | ||
business_card_splash.append(email_group_one) | ||
if email_string_two: | ||
email_group_two = displayio.Group(scale=email_scale_two) | ||
email_label_two = Label(email_font_two, text=email_string_two) | ||
(_, _, width, height) = email_label_two.bounding_box | ||
email_label_two.width = self.display.width | ||
email_label_two.x = ((self.display.width // (2 * email_scale_two)) - width // 2) | ||
email_label_two.y = int(height // (0.12 * email_scale_two)) | ||
email_label_two.color = 0xFFFFFF | ||
email_group_two.append(email_label_two) | ||
business_card_splash.append(email_group_two) | ||
|
||
# pylint: disable=too-many-locals | ||
def show_badge(self, *, background_color=0xFF0000, foreground_color=0xFFFFFF, | ||
|
@@ -258,7 +304,6 @@ def show_badge(self, *, background_color=0xFF0000, foreground_color=0xFFFFFF, | |
"Blinka". | ||
|
||
""" | ||
# Make the Display Background | ||
splash = displayio.Group(max_size=20) | ||
|
||
color_bitmap = displayio.Bitmap(self.display.width, self.display.height, 1) | ||
|
@@ -270,15 +315,12 @@ def show_badge(self, *, background_color=0xFF0000, foreground_color=0xFFFFFF, | |
x=0, y=0) | ||
splash.append(bg_sprite) | ||
|
||
# Draw a Foreground Rectangle where the name goes | ||
# x, y, width, height | ||
rect = Rect(0, (int(self.display.height * 0.4)), self.display.width, | ||
(int(self.display.height * 0.5)), fill=foreground_color) | ||
splash.append(rect) | ||
|
||
hello_scale = hello_scale | ||
hello_group = displayio.Group(scale=hello_scale) | ||
# Setup and Center the Hello Label | ||
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) | ||
|
@@ -288,7 +330,6 @@ def show_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(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) | ||
|
@@ -298,7 +339,6 @@ def show_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(font=name_font, text=name_string) | ||
(_, _, width, height) = name_label.bounding_box | ||
name_label.x = ((self.display.width // (2 * name_scale)) - width // 2) | ||
|
@@ -327,15 +367,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"): | ||
"""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) | ||
|
@@ -350,7 +390,6 @@ def show_qr_code(self, data=b'https://circuitpython.org', dwell=20): | |
qr_code = displayio.Group(scale=qr_code_scale) | ||
qr_code.append(qr_img) | ||
self.display.show(qr_code) | ||
time.sleep(dwell) | ||
|
||
@staticmethod | ||
def _sine_sample(length): | ||
|
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.