qrcode: Add example to badgerOS

pull/268/head
Phil Howard 2022-03-04 18:07:10 +00:00
rodzic 89172578ac
commit 3c70a3847e
4 zmienionych plików z 40 dodań i 2 usunięć

Plik binarny nie jest wyświetlany.

Przed

Szerokość:  |  Wysokość:  |  Rozmiar: 9.8 KiB

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 9.7 KiB

Wyświetl plik

@ -16,6 +16,7 @@ font_size = 1
inverted = False
icons = bytearray(launchericons.data())
icons_width = 576
examples = [
("_clock", 0),
@ -24,6 +25,7 @@ examples = [
("_image", 3),
("_list", 4),
("_badge", 5),
("_qr_code", 8),
("_info", 6),
("_help", 7)
]
@ -139,9 +141,9 @@ def render():
for i in range(max_icons):
x = centers[i]
label, icon = examples[i + (page * 3)]
label = label[1:]
label = label[1:].replace("_", " ")
display.pen(0)
display.icon(icons, icon, 512, 64, x - 32, 24)
display.icon(icons, icon, icons_width, 64, x - 32, 24)
w = display.measure_text(label, font_sizes[font_size])
display.text(label, x - int(w / 2), 16 + 80, font_sizes[font_size])

Wyświetl plik

@ -51,3 +51,4 @@ copy_module(usermod_badger2040 ${CMAKE_CURRENT_LIST_DIR}/list.py _list)
copy_module(usermod_badger2040 ${CMAKE_CURRENT_LIST_DIR}/badge.py _badge)
copy_module(usermod_badger2040 ${CMAKE_CURRENT_LIST_DIR}/help.py _help)
copy_module(usermod_badger2040 ${CMAKE_CURRENT_LIST_DIR}/info.py _info)
copy_module(usermod_badger2040 ${CMAKE_CURRENT_LIST_DIR}/qr_code.py _qr_code)

Wyświetl plik

@ -0,0 +1,35 @@
import badger2040
import qrcode
import time
display = badger2040.Badger2040()
code = qrcode.QRCode()
def measure_qr_code(size, code):
w, h = code.get_size()
module_size = int(size / w)
return module_size * w, module_size
def draw_qr_code(ox, oy, size, code):
size, module_size = measure_qr_code(size, code)
display.pen(15)
display.rectangle(ox, oy, size, size)
display.pen(0)
for x in range(size):
for y in range(size):
if code.get_module(x, y):
display.rectangle(ox + x * module_size, oy + y * module_size, module_size, module_size)
code.set_text("pimoroni.com/badger2040")
size, _ = measure_qr_code(128, code)
left = int((badger2040.WIDTH / 2) - (size / 2))
top = int((badger2040.HEIGHT / 2) - (size / 2))
draw_qr_code(left, top, 128, code)
display.update()
while True:
time.sleep(1.0)