2024-12-19 12:17:30 +08:00
|
|
|
# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
|
|
|
|
#
|
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
import os, sys, io
|
|
|
|
|
import M5
|
|
|
|
|
from M5 import *
|
|
|
|
|
import camera
|
|
|
|
|
import code_scanner
|
|
|
|
|
import image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
img = None
|
|
|
|
|
qrcode = None
|
|
|
|
|
|
2025-03-06 17:13:11 +08:00
|
|
|
|
2024-12-19 12:17:30 +08:00
|
|
|
def setup():
|
|
|
|
|
global img, qrcode
|
|
|
|
|
M5.begin()
|
|
|
|
|
Widgets.fillScreen(0x222222)
|
|
|
|
|
camera.init(pixformat=camera.RGB565, framesize=camera.QVGA)
|
|
|
|
|
camera.set_hmirror(False)
|
|
|
|
|
|
2025-03-06 17:13:11 +08:00
|
|
|
|
2024-12-19 12:17:30 +08:00
|
|
|
def loop():
|
|
|
|
|
global img, qrcode
|
|
|
|
|
M5.update()
|
|
|
|
|
img = camera.snapshot()
|
|
|
|
|
qrcode = code_scanner.find_qrcodes(img)
|
|
|
|
|
if qrcode:
|
|
|
|
|
print(qrcode.payload())
|
|
|
|
|
print(qrcode.type_name())
|
2025-03-06 17:13:11 +08:00
|
|
|
img.draw_string(10, 10, str(qrcode.payload()), color=0x3333FF, scale=2)
|
2024-12-19 12:17:30 +08:00
|
|
|
M5.Lcd.show(img, 0, 0, 320, 240)
|
|
|
|
|
|
2025-03-06 17:13:11 +08:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-12-19 12:17:30 +08:00
|
|
|
try:
|
|
|
|
|
setup()
|
|
|
|
|
while True:
|
|
|
|
|
loop()
|
|
|
|
|
except (Exception, KeyboardInterrupt) as e:
|
|
|
|
|
try:
|
|
|
|
|
from utility import print_error_msg
|
2025-03-06 17:13:11 +08:00
|
|
|
|
2024-12-19 12:17:30 +08:00
|
|
|
print_error_msg(e)
|
|
|
|
|
except ImportError:
|
|
|
|
|
print("please update to latest firmware")
|