Skip to content

Commit 170ec4f

Browse files
Debugging qrdecode
1 parent 053595a commit 170ec4f

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

c_mpos/src/quirc_decode.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ static const char *TAG = "qrdecode";
1212

1313
// Function to decode a QR code from a grayscale image buffer
1414
static mp_obj_t qrdecode(mp_uint_t n_args, const mp_obj_t *args) {
15-
printf("qrdecode: Starting\n");
16-
ESP_LOGI(TAG, "qrdecode starting");
17-
QRDECODE_DEBUG_PRINT("mp_printf works in qrdecode!");
18-
fflush(stdout);
15+
QRDECODE_DEBUG_PRINT("qrdecode: Starting\n");
1916

2017
// Check argument count (expecting buffer, width, height)
2118
QRDECODE_DEBUG_PRINT("qrdecode: Checking argument count\n");
@@ -62,7 +59,6 @@ static mp_obj_t qrdecode(mp_uint_t n_args, const mp_obj_t *args) {
6259
mp_raise_OSError(MP_ENOMEM);
6360
}
6461
QRDECODE_DEBUG_PRINT("qrdecode: quirc initialized\n");
65-
QRDECODE_DEBUG_PRINT("mp_printf works in qrdecode!");
6662
fflush(stdout);
6763

6864
// Resize quirc for the image dimensions
@@ -83,10 +79,10 @@ static mp_obj_t qrdecode(mp_uint_t n_args, const mp_obj_t *args) {
8379
image = quirc_begin(qr, NULL, NULL); // Get pointer to quirc's image buffer
8480
QRDECODE_DEBUG_PRINT("qrdecode: quirc image buffer obtained\n");
8581
fflush(stdout);
86-
QRDECODE_DEBUG_PRINT("qrdecode: Copying buffer, size=%zu\n", (size_t)(width * height));
82+
QRDECODE_DEBUG_PRINT("qrdecode: Copying buffer, size=%ul\n", (size_t)(width * height));
8783
fflush(stdout);
8884
memcpy(image, bufinfo.buf, width * height);
89-
QRDECODE_DEBUG_PRINT
85+
QRDECODE_DEBUG_PRINT("qrdecode: Buffer copied\n");
9086
fflush(stdout);
9187
quirc_end(qr);
9288
QRDECODE_DEBUG_PRINT("qrdecode: quirc processing ended\n");
@@ -102,6 +98,7 @@ static mp_obj_t qrdecode(mp_uint_t n_args, const mp_obj_t *args) {
10298
quirc_destroy(qr);
10399
mp_raise_ValueError(MP_ERROR_TEXT("no QR code found"));
104100
}
101+
// it works until here, it finds 1 QR code!
105102

106103
// Extract and decode the first QR code
107104
QRDECODE_DEBUG_PRINT("qrdecode: Extracting first QR code\n");
@@ -110,6 +107,7 @@ static mp_obj_t qrdecode(mp_uint_t n_args, const mp_obj_t *args) {
110107
quirc_extract(qr, 0, &code);
111108
QRDECODE_DEBUG_PRINT("qrdecode: QR code extracted\n");
112109
fflush(stdout);
110+
// it works until here!
113111

114112
// Decode the QR code
115113
QRDECODE_DEBUG_PRINT("qrdecode: Decoding QR code\n");
@@ -122,7 +120,10 @@ static mp_obj_t qrdecode(mp_uint_t n_args, const mp_obj_t *args) {
122120
}
123121
QRDECODE_DEBUG_PRINT("qrdecode: QR code decoded, payload_len=%d\n", data.payload_len);
124122
fflush(stdout);
125-
123+
QRDECODE_DEBUG_PRINT("qrdecode: got result: %s\n", data.payload);
124+
fflush(stdout);
125+
QRDECODE_DEBUG_PRINT("ok so now what?!");
126+
/*
126127
// Convert decoded data to Python string
127128
QRDECODE_DEBUG_PRINT("qrdecode: Creating Python string\n");
128129
fflush(stdout);
@@ -136,10 +137,11 @@ static mp_obj_t qrdecode(mp_uint_t n_args, const mp_obj_t *args) {
136137
quirc_destroy(qr);
137138
QRDECODE_DEBUG_PRINT("qrdecode: quirc destroyed\n");
138139
fflush(stdout);
140+
*/
139141

140142
printf("qrdecode: Returning result\n");
141-
return result;
142-
//return mp_const_none; // MicroPython functions typically return None
143+
//return result;
144+
return mp_const_none; // MicroPython functions typically return None
143145
}
144146

145147
// Wrapper function to fix incompatible pointer type warning

draft_code/qrdecode.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
try:
1414
# Allocate buffer for grayscale image
1515
buffer = bytearray(buffer_size)
16-
for i in range(240 * 240):
17-
buffer[i] = random.getrandbits(8)
16+
#for i in range(240 * 240):
17+
# buffer[i] = random.getrandbits(8)
1818
# Read the raw grayscale image file
19-
#with open('qrcode2.raw', 'rb') as f:
20-
# bytes_read = f.readinto(buffer)
21-
# if bytes_read != buffer_size:
22-
# raise ValueError("File size does not match expected 240x240 grayscale image")
19+
with open('qrcode2.raw', 'rb') as f:
20+
bytes_read = f.readinto(buffer)
21+
if bytes_read != buffer_size:
22+
raise ValueError("File size does not match expected 240x240 grayscale image")
2323
# Decode QR code using qrdecode module
2424
print("decoding...")
2525
print(f"buffer length: {len(buffer)}")
@@ -28,8 +28,8 @@
2828
result = qrdecode.qrdecode(buffer, width, height)
2929
print(f"result: {result}")
3030
# Remove BOM (\ufeff) from the start of the decoded string, if present
31-
if result.startswith('\ufeff'):
32-
result = result[1:]
31+
#if result.startswith('\ufeff'):
32+
# result = result[1:]
3333
print(f"result: {result}")
3434
except OSError as e:
3535
print("Error reading file:", e)

0 commit comments

Comments
 (0)