Skip to content

Commit 9085630

Browse files
Doesn't crash...
1 parent 11af02e commit 9085630

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

c_mpos/src/hello_world.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
// C function to print "Hello World"
88
static mp_obj_t hello_world(void) {
9-
printf("Hello World from C!\n");
9+
printf("Hello World from C compiled!\n");
1010
return mp_const_none; // MicroPython functions typically return None
1111
}
1212

c_mpos/src/quirc_decode.c

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <stdio.h>
12
#include "py/obj.h"
23
#include "py/runtime.h"
34
#include "py/mperrno.h"
@@ -7,100 +8,127 @@
78
// Function to decode a QR code from a grayscale image buffer
89
static mp_obj_t qrdecode(mp_uint_t n_args, const mp_obj_t *args) {
910
printf("qrdecode: Starting\n");
11+
fflush(stdout);
1012

1113
// Check argument count (expecting buffer, width, height)
1214
printf("qrdecode: Checking argument count\n");
15+
fflush(stdout);
1316
if (n_args != 3) {
1417
mp_raise_ValueError(MP_ERROR_TEXT("quirc_decode expects 3 arguments: buffer, width, height"));
1518
}
16-
19+
/*
1720
// Extract buffer
1821
printf("qrdecode: Extracting buffer\n");
22+
fflush(stdout);
1923
mp_buffer_info_t bufinfo;
2024
mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ);
2125
printf("qrdecode: Buffer extracted, len=%zu\n", bufinfo.len);
2226
2327
// Extract width and height
2428
printf("qrdecode: Extracting width and height\n");
29+
fflush(stdout);
2530
mp_int_t width = mp_obj_get_int(args[1]);
2631
mp_int_t height = mp_obj_get_int(args[2]);
2732
printf("qrdecode: Width=%ld, Height=%ld\n", width, height);
33+
fflush(stdout);
2834
2935
// Validate dimensions
3036
printf("qrdecode: Validating dimensions\n");
37+
fflush(stdout);
3138
if (width <= 0 || height <= 0) {
3239
mp_raise_ValueError(MP_ERROR_TEXT("width and height must be positive"));
3340
}
3441
if (bufinfo.len != (size_t)(width * height)) {
3542
mp_raise_ValueError(MP_ERROR_TEXT("buffer size must match width * height"));
3643
}
3744
printf("qrdecode: Dimensions validated\n");
45+
fflush(stdout);
3846
3947
// Initialize quirc
4048
printf("qrdecode: Initializing quirc\n");
49+
fflush(stdout);
4150
struct quirc *qr = quirc_new();
4251
if (!qr) {
4352
mp_raise_OSError(MP_ENOMEM);
4453
}
4554
printf("qrdecode: quirc initialized\n");
55+
fflush(stdout);
4656
4757
// Resize quirc for the image dimensions
4858
printf("qrdecode: Resizing quirc\n");
59+
fflush(stdout);
4960
if (quirc_resize(qr, width, height) < 0) {
5061
quirc_destroy(qr);
5162
mp_raise_OSError(MP_ENOMEM);
5263
}
5364
printf("qrdecode: quirc resized\n");
65+
fflush(stdout);
5466
5567
// Get quirc image buffer and copy grayscale data
5668
printf("qrdecode: Beginning quirc processing\n");
69+
fflush(stdout);
5770
uint8_t *image;
5871
quirc_begin(qr, NULL, NULL);
5972
image = quirc_begin(qr, NULL, NULL); // Get pointer to quirc's image buffer
6073
printf("qrdecode: quirc image buffer obtained\n");
74+
fflush(stdout);
6175
printf("qrdecode: Copying buffer, size=%zu\n", (size_t)(width * height));
76+
fflush(stdout);
6277
memcpy(image, bufinfo.buf, width * height);
6378
printf("qrdecode: Buffer copied\n");
79+
fflush(stdout);
6480
quirc_end(qr);
6581
printf("qrdecode: quirc processing ended\n");
82+
fflush(stdout);
6683
6784
// Check for QR codes
6885
printf("qrdecode: Counting QR codes\n");
86+
fflush(stdout);
6987
int count = quirc_count(qr);
7088
printf("qrdecode: Found %d QR codes\n", count);
89+
fflush(stdout);
7190
if (count == 0) {
7291
quirc_destroy(qr);
7392
mp_raise_ValueError(MP_ERROR_TEXT("no QR code found"));
7493
}
7594
7695
// Extract and decode the first QR code
7796
printf("qrdecode: Extracting first QR code\n");
97+
fflush(stdout);
7898
struct quirc_code code;
7999
quirc_extract(qr, 0, &code);
80100
printf("qrdecode: QR code extracted\n");
101+
fflush(stdout);
81102
82103
// Decode the QR code
83104
printf("qrdecode: Decoding QR code\n");
105+
fflush(stdout);
84106
struct quirc_data data;
85107
int err = quirc_decode(&code, &data);
86108
if (err != QUIRC_SUCCESS) {
87109
quirc_destroy(qr);
88110
mp_raise_ValueError(MP_ERROR_TEXT("failed to decode QR code"));
89111
}
90112
printf("qrdecode: QR code decoded, payload_len=%d\n", data.payload_len);
113+
fflush(stdout);
91114
92115
// Convert decoded data to Python string
93116
printf("qrdecode: Creating Python string\n");
117+
fflush(stdout);
94118
mp_obj_t result = mp_obj_new_str((const char *)data.payload, data.payload_len);
95119
printf("qrdecode: Python string created\n");
120+
fflush(stdout);
96121
97122
// Clean up
98123
printf("qrdecode: Cleaning up\n");
124+
fflush(stdout);
99125
quirc_destroy(qr);
100126
printf("qrdecode: quirc destroyed\n");
101-
127+
fflush(stdout);
128+
*/
102129
printf("qrdecode: Returning result\n");
103-
return result;
130+
//return result;
131+
return mp_const_none; // MicroPython functions typically return None
104132
}
105133

106134
// Wrapper function to fix incompatible pointer type warning

draft_code/qrdecode.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
raise ValueError("File size does not match expected 240x240 grayscale image")
1616
# Decode QR code using qrdecode module
1717
print("decoding...")
18+
print(f"buffer length: {len(buffer)}")
19+
for i in range(15):
20+
print(buffer[i])
1821
result = qrdecode.qrdecode(buffer, width, height)
1922
print(f"result: {result}")
2023
# Remove BOM (\ufeff) from the start of the decoded string, if present

scripts/install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ if [ ! -z "$appname" ]; then
2626
exit 1
2727
fi
2828
fi
29-
~/sources/lvgl_micropython/lib/micropython/tools/mpremote/mpremote.py mkdir "builtin"
30-
~/sources/lvgl_micropython/lib/micropython/tools/mpremote/mpremote.py mkdir "builtin/apps"
29+
~/sources/lvgl_micropython/lib/micropython/tools/mpremote/mpremote.py mkdir "/builtin"
30+
~/sources/lvgl_micropython/lib/micropython/tools/mpremote/mpremote.py mkdir "/builtin/apps"
3131
~/sources/lvgl_micropython/lib/micropython/tools/mpremote/mpremote.py fs cp -r "$appdir" :/"$target"
3232
echo "start_app(\"/$appdir\")"
3333
~/sources/lvgl_micropython/lib/micropython/tools/mpremote/mpremote.py

0 commit comments

Comments
 (0)