qrdecode: return bytes instead of string

This commit is contained in:
Thomas Farstrike
2025-05-13 11:55:22 +02:00
parent a5d98bec3c
commit 9b0057eaf0
2 changed files with 25 additions and 21 deletions
+1 -1
View File
@@ -121,7 +121,7 @@ static mp_obj_t qrdecode(mp_uint_t n_args, const mp_obj_t *args) {
// Convert decoded data to Python string
QRDECODE_DEBUG_PRINT("qrdecode: Creating Python string\n");
mp_obj_t result = mp_obj_new_str((const char *)data->payload, data->payload_len);
mp_obj_t result = mp_obj_new_bytes((const uint8_t *)data->payload, data->payload_len);
QRDECODE_DEBUG_PRINT("qrdecode: Python string created\n");
// Clean up
@@ -1,3 +1,5 @@
import time
appscreen = lv.screen_active()
keepgoing = True
@@ -105,7 +107,7 @@ close_label.set_text(lv.SYMBOL.CLOSE)
close_label.center()
def close_button_click(e):
global keepgoing
print("Closing camera!")
print("Close button clicked")
keepgoing = False
close_button.add_event_cb(close_button_click,lv.EVENT.CLICKED,None)
@@ -113,23 +115,26 @@ close_button.add_event_cb(close_button_click,lv.EVENT.CLICKED,None)
from camera import Camera, GrabMode, PixelFormat, FrameSize, GainCeiling
cam = Camera(
data_pins=[12,13,15,11,14,10,7,2],
vsync_pin=6,
href_pin=4,
sda_pin=21,
scl_pin=16,
pclk_pin=9,
xclk_pin=8,
xclk_freq=20000000,
powerdown_pin=-1,
reset_pin=-1,
#pixel_format=PixelFormat.RGB565,
pixel_format=PixelFormat.GRAYSCALE,
frame_size=FrameSize.R240X240,
grab_mode=GrabMode.LATEST
)
#cam.init() automatically done when creating the Camera()
try:
cam = Camera(
data_pins=[12,13,15,11,14,10,7,2],
vsync_pin=6,
href_pin=4,
sda_pin=21,
scl_pin=16,
pclk_pin=9,
xclk_pin=8,
xclk_freq=20000000,
powerdown_pin=-1,
reset_pin=-1,
#pixel_format=PixelFormat.RGB565,
pixel_format=PixelFormat.GRAYSCALE,
frame_size=FrameSize.R240X240,
grab_mode=GrabMode.LATEST
)
#cam.init() automatically done when creating the Camera()
except Exception as e:
print(f"Exception while initializing camera: {e}")
#cam.reconfigure(frame_size=FrameSize.HVGA)
#frame_size=FrameSize.HVGA, # 480x320
@@ -186,8 +191,7 @@ def try_capture():
try_capture()
import time
while appscreen == lv.screen_active() and keepgoing:
while appscreen == lv.screen_active() and keepgoing is True:
try_capture()
time.sleep_ms(100) # Allow for the MicroPython REPL to still work. Reducing it doesn't seem to affect the on-display FPS.