Skip to content

Commit 9b0057e

Browse files
qrdecode: return bytes instead of string
1 parent a5d98be commit 9b0057e

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

c_mpos/src/quirc_decode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static mp_obj_t qrdecode(mp_uint_t n_args, const mp_obj_t *args) {
121121

122122
// Convert decoded data to Python string
123123
QRDECODE_DEBUG_PRINT("qrdecode: Creating Python string\n");
124-
mp_obj_t result = mp_obj_new_str((const char *)data->payload, data->payload_len);
124+
mp_obj_t result = mp_obj_new_bytes((const uint8_t *)data->payload, data->payload_len);
125125
QRDECODE_DEBUG_PRINT("qrdecode: Python string created\n");
126126

127127
// Clean up

internal_filesystem/apps/com.example.camtest/assets/camtest.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import time
2+
13
appscreen = lv.screen_active()
24

35
keepgoing = True
@@ -105,31 +107,34 @@ def qr_button_click(e):
105107
close_label.center()
106108
def close_button_click(e):
107109
global keepgoing
108-
print("Closing camera!")
110+
print("Close button clicked")
109111
keepgoing = False
110112

111113
close_button.add_event_cb(close_button_click,lv.EVENT.CLICKED,None)
112114

113115

114116
from camera import Camera, GrabMode, PixelFormat, FrameSize, GainCeiling
115117

116-
cam = Camera(
117-
data_pins=[12,13,15,11,14,10,7,2],
118-
vsync_pin=6,
119-
href_pin=4,
120-
sda_pin=21,
121-
scl_pin=16,
122-
pclk_pin=9,
123-
xclk_pin=8,
124-
xclk_freq=20000000,
125-
powerdown_pin=-1,
126-
reset_pin=-1,
127-
#pixel_format=PixelFormat.RGB565,
128-
pixel_format=PixelFormat.GRAYSCALE,
129-
frame_size=FrameSize.R240X240,
130-
grab_mode=GrabMode.LATEST
131-
)
132-
#cam.init() automatically done when creating the Camera()
118+
try:
119+
cam = Camera(
120+
data_pins=[12,13,15,11,14,10,7,2],
121+
vsync_pin=6,
122+
href_pin=4,
123+
sda_pin=21,
124+
scl_pin=16,
125+
pclk_pin=9,
126+
xclk_pin=8,
127+
xclk_freq=20000000,
128+
powerdown_pin=-1,
129+
reset_pin=-1,
130+
#pixel_format=PixelFormat.RGB565,
131+
pixel_format=PixelFormat.GRAYSCALE,
132+
frame_size=FrameSize.R240X240,
133+
grab_mode=GrabMode.LATEST
134+
)
135+
#cam.init() automatically done when creating the Camera()
136+
except Exception as e:
137+
print(f"Exception while initializing camera: {e}")
133138

134139
#cam.reconfigure(frame_size=FrameSize.HVGA)
135140
#frame_size=FrameSize.HVGA, # 480x320
@@ -186,8 +191,7 @@ def try_capture():
186191
try_capture()
187192

188193

189-
import time
190-
while appscreen == lv.screen_active() and keepgoing:
194+
while appscreen == lv.screen_active() and keepgoing is True:
191195
try_capture()
192196
time.sleep_ms(100) # Allow for the MicroPython REPL to still work. Reducing it doesn't seem to affect the on-display FPS.
193197

0 commit comments

Comments
 (0)