diff --git a/.gitmodules b/.gitmodules index 87e37f064..474f7d55e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -14,3 +14,6 @@ [submodule "drivers/scd4x/src"] path = drivers/scd4x/src url = https://github.com/Sensirion/embedded-i2c-scd4x +[submodule "micropython/modules/qrcode"] + path = micropython/modules/qrcode + url = https://github.com/pimoroni/QR-Code-Generator diff --git a/micropython/examples/badger2040/assets/launchericons.png b/micropython/examples/badger2040/assets/launchericons.png index 6b5364232..da93e0a09 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 089a6fc31..aecf043f5 100644 --- a/micropython/examples/badger2040/launcher.py +++ b/micropython/examples/badger2040/launcher.py @@ -16,6 +16,7 @@ inverted = False icons = bytearray(launchericons.data()) +icons_width = 576 examples = [ ("_clock", 0), @@ -24,6 +25,7 @@ ("_image", 3), ("_list", 4), ("_badge", 5), + ("_qrgen", 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 b5d73b851..1e748026f 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}/qrgen.py _qrgen) diff --git a/micropython/examples/badger2040/qrgen.py b/micropython/examples/badger2040/qrgen.py new file mode 100644 index 000000000..1c980c1ea --- /dev/null +++ b/micropython/examples/badger2040/qrgen.py @@ -0,0 +1,70 @@ +import badger2040 +import qrcode +import time + + +# Open the qrcode file +try: + text = open("qrcode.txt", "r") +except OSError: + text = open("qrcode.txt", "w") + text.write("""https://pimoroni.com/badger2040 +Badger 2040 +* 296x128 1-bit e-ink +* six user buttons +* user LED +* 2MB QSPI flash + +Scan this code to learn +more about Badger 2040. +""") + text.flush() + text.seek(0) + + +lines = text.read().strip().split("\n") +code_text = lines.pop(0) +title_text = lines.pop(0) +detail_text = lines + +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(code_text) +size, _ = measure_qr_code(128, code) +left = top = int((badger2040.HEIGHT / 2) - (size / 2)) +draw_qr_code(left, top, 128, code) + +left = 128 + 5 + +display.thickness(2) +display.text(title_text, left, 20, 0.5) +display.thickness(1) + +top = 40 +for line in detail_text: + display.text(line, left, top, 0.4) + top += 10 + +display.update() + +while True: + time.sleep(1.0) diff --git a/micropython/examples/pico_display/basic_qrcode.py b/micropython/examples/pico_display/basic_qrcode.py new file mode 100644 index 000000000..72ac1af87 --- /dev/null +++ b/micropython/examples/pico_display/basic_qrcode.py @@ -0,0 +1,43 @@ +import picodisplay as display # Comment this line out to use PicoDisplay2 +# import picodisplay2 as display # Uncomment this line to use PicoDisplay2 +import 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.set_pen(128, 128, 128) + display.rectangle(ox, oy, size, size) + display.set_pen(0, 0, 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) + + +width = display.get_width() +height = display.get_height() + +code = qrcode.QRCode() +code.set_text("shop.pimoroni.com") + +display.init(bytearray(width * height * 2)) + +display.set_pen(128, 128, 128) +display.clear() +display.set_pen(0, 0, 0) + +size, module_size = measure_qr_code(height, code) +left = int((width // 2) - (size // 2)) +top = int((height // 2) - (size // 2)) +draw_qr_code(left, top, height, code) + +display.update() + +while True: + pass diff --git a/micropython/modules/badger2040-micropython.cmake b/micropython/modules/badger2040-micropython.cmake index fd3f12fc8..274e651c9 100644 --- a/micropython/modules/badger2040-micropython.cmake +++ b/micropython/modules/badger2040-micropython.cmake @@ -34,3 +34,4 @@ include(badger2040/micropython) include(micropython/examples/badger2040/micropython-builtins) include(plasma/micropython) include(ulab/code/micropython) +include(qrcode/micropython/micropython) diff --git a/micropython/modules/micropython.cmake b/micropython/modules/micropython.cmake index 4f2ea23bc..f8010f9e9 100644 --- a/micropython/modules/micropython.cmake +++ b/micropython/modules/micropython.cmake @@ -42,5 +42,6 @@ include(pico_wireless/micropython) include(plasma/micropython) include(hub75/micropython) include(ulab/code/micropython) +include(qrcode/micropython/micropython) -include(modules_py/modules_py) \ No newline at end of file +include(modules_py/modules_py) diff --git a/micropython/modules/qrcode b/micropython/modules/qrcode new file mode 160000 index 000000000..b5afd3c03 --- /dev/null +++ b/micropython/modules/qrcode @@ -0,0 +1 @@ +Subproject commit b5afd3c031c3f6ddd89e73833a1c8e551134e291