diff --git a/micropython/examples/badger2040/assets/launchericons.png b/micropython/examples/badger2040/assets/launchericons.png index 6b536423..da93e0a0 100644 Binary files a/micropython/examples/badger2040/assets/launchericons.png and b/micropython/examples/badger2040/assets/launchericons.png differ diff --git a/micropython/examples/badger2040/launcher.py b/micropython/examples/badger2040/launcher.py index 089a6fc3..2c1119c4 100644 --- a/micropython/examples/badger2040/launcher.py +++ b/micropython/examples/badger2040/launcher.py @@ -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]) diff --git a/micropython/examples/badger2040/micropython-builtins.cmake b/micropython/examples/badger2040/micropython-builtins.cmake index b5d73b85..ad4260d9 100644 --- a/micropython/examples/badger2040/micropython-builtins.cmake +++ b/micropython/examples/badger2040/micropython-builtins.cmake @@ -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) diff --git a/micropython/examples/badger2040/qr_code.py b/micropython/examples/badger2040/qr_code.py new file mode 100644 index 00000000..b5c2b1ef --- /dev/null +++ b/micropython/examples/badger2040/qr_code.py @@ -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)