Skip to content

Commit 3bc5151

Browse files
Fix colormode QR decoding
But somehow buffer size is 8 bytes...
1 parent 4ef4f66 commit 3bc5151

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

c_mpos/src/quirc_decode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ static mp_obj_t qrdecode(mp_uint_t n_args, const mp_obj_t *args) {
3939
if (width <= 0 || height <= 0) {
4040
mp_raise_ValueError(MP_ERROR_TEXT("width and height must be positive"));
4141
}
42+
QRDECODE_DEBUG_PRINT("qrdecode bufsize: %u bytes\n", bufinfo.len);
4243
if (bufinfo.len != (size_t)(width * height)) {
4344
mp_raise_ValueError(MP_ERROR_TEXT("buffer size must match width * height"));
4445
}
45-
4646
struct quirc *qr = quirc_new();
4747
if (!qr) {
4848
mp_raise_OSError(MP_ENOMEM);
@@ -139,6 +139,7 @@ static mp_obj_t qrdecode_rgb565(mp_uint_t n_args, const mp_obj_t *args) {
139139
if (width <= 0 || height <= 0) {
140140
mp_raise_ValueError(MP_ERROR_TEXT("width and height must be positive"));
141141
}
142+
QRDECODE_DEBUG_PRINT("qrdecode bufsize: %u bytes\n", bufinfo.len);
142143
if (bufinfo.len != (size_t)(width * height * 2)) {
143144
mp_raise_ValueError(MP_ERROR_TEXT("buffer size must match width * height * 2 for RGB565"));
144145
}

internal_filesystem/apps/com.micropythonos.camera/assets/camera_app.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import lvgl as lv
2+
import time
23

34
try:
45
import webcam
@@ -16,8 +17,8 @@ class CameraApp(Activity):
1617
DEFAULT_WIDTH = 320 # 240 would be better but webcam doesn't support this (yet)
1718
DEFAULT_HEIGHT = 240
1819
PACKAGE = "com.micropythonos.camera"
19-
#DEFAULT_CONFIG = "config.json"
20-
#QRCODE_CONFIG = "config_qrmode.json"
20+
CONFIGFILE = "config.json"
21+
SCANQR_CONFIG = "config_scanqr_mode.json"
2122

2223
button_width = 60
2324
button_height = 45
@@ -48,9 +49,9 @@ class CameraApp(Activity):
4849
status_label_cont = None
4950

5051
def onCreate(self):
51-
from mpos.config import SharedPreferences
52-
self.prefs = SharedPreferences(self.PACKAGE)
5352
self.scanqr_mode = self.getIntent().extras.get("scanqr_mode")
53+
from mpos.config import SharedPreferences
54+
self.prefs = SharedPreferences(self.PACKAGE, filename=self.SCANQR_CONFIG if self.scanqr_mode else self.CONFIGFILE)
5455

5556
self.main_screen = lv.obj()
5657
self.main_screen.set_style_pad_all(1, 0)
@@ -219,7 +220,10 @@ def qrdecode_one(self):
219220
import qrdecode
220221
import utime
221222
before = time.ticks_ms()
222-
result = qrdecode.qrdecode(self.image_dsc.data, self.width, self.height)
223+
if self.colormode:
224+
result = qrdecode.qrdecode_rgb565(self.image_dsc.data, self.width, self.height)
225+
else:
226+
result = qrdecode.qrdecode(self.image_dsc.data, self.width, self.height)
223227
after = time.ticks_ms()
224228
#result = bytearray("INSERT_QR_HERE", "utf-8")
225229
if not result:

0 commit comments

Comments
 (0)