mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Update python bindings for new libmp
This commit is contained in:
parent
a5493fe620
commit
7630a9be74
@ -4,7 +4,7 @@
|
||||
do { \
|
||||
if ((cond) ==0){ \
|
||||
nlr_jump(mp_obj_new_exception_msg( \
|
||||
MP_QSTR_OSError, \
|
||||
&mp_type_OSError, \
|
||||
"Operation not supported")); \
|
||||
} \
|
||||
} while(0)
|
||||
@ -15,7 +15,7 @@
|
||||
__typeof__ (type) _b = (type); \
|
||||
if (!MP_OBJ_IS_TYPE(_a, _b)) { \
|
||||
nlr_jump(mp_obj_new_exception_msg_varg( \
|
||||
MP_QSTR_TypeError, \
|
||||
&mp_type_TypeError, \
|
||||
"can't convert %s to %s", \
|
||||
mp_obj_get_type_str(_a), \
|
||||
_b->name)); \
|
||||
@ -27,7 +27,7 @@
|
||||
__typeof__ (obj) _a = (obj); \
|
||||
if (!MP_OBJ_IS_STR(_a)) { \
|
||||
nlr_jump(mp_obj_new_exception_msg_varg( \
|
||||
MP_QSTR_TypeError, \
|
||||
&mp_type_TypeError, \
|
||||
"can't convert %s to %s", \
|
||||
mp_obj_get_type_str(_a), \
|
||||
str_type.name)); \
|
||||
|
||||
@ -57,14 +57,14 @@ mp_obj_t py_file_read(py_file_obj_t *file, mp_obj_t n_obj)
|
||||
mp_obj_t py_file_write(py_file_obj_t *file, mp_obj_t buf)
|
||||
{
|
||||
uint len;
|
||||
const byte *str;
|
||||
const char *str;
|
||||
FRESULT res;
|
||||
|
||||
str = mp_obj_str_get_data(buf, &len);
|
||||
|
||||
res = f_write(&file->fp, str, len, &len);
|
||||
if (res != FR_OK) {
|
||||
nlr_jump(mp_obj_new_exception_msg(qstr_from_str("File"), ffs_strerror(res)));
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res)));
|
||||
}
|
||||
|
||||
return mp_obj_new_int(len);
|
||||
@ -87,8 +87,8 @@ static const mp_method_t py_file_methods[] = {
|
||||
};
|
||||
|
||||
static const mp_obj_type_t py_file_type = {
|
||||
{ &mp_const_type },
|
||||
"File",
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_File,
|
||||
.print = py_file_print,
|
||||
.methods = py_file_methods,
|
||||
};
|
||||
@ -113,7 +113,7 @@ mp_obj_t py_file_open(mp_obj_t path, mp_obj_t mode_str)
|
||||
mode = FA_READ|FA_WRITE|FA_OPEN_EXISTING;
|
||||
break;
|
||||
default:
|
||||
nlr_jump(mp_obj_new_exception_msg(qstr_from_str("File"), "invalid open mode"));
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid open mode"));
|
||||
}
|
||||
|
||||
/* Create new python file obj */
|
||||
@ -123,7 +123,7 @@ mp_obj_t py_file_open(mp_obj_t path, mp_obj_t mode_str)
|
||||
/* Open underlying file handle */
|
||||
res = f_open(&o->fp, mp_obj_str_get_str(path), mode);
|
||||
if (res != FR_OK) {
|
||||
nlr_jump(mp_obj_new_exception_msg(qstr_from_str("File"), ffs_strerror(res)));
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res)));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
@ -29,8 +29,8 @@ static const mp_method_t py_image_methods[] = {
|
||||
};
|
||||
|
||||
const mp_obj_type_t py_image_type = {
|
||||
{ &mp_const_type },
|
||||
"image",
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Image,
|
||||
.print = py_image_print,
|
||||
.methods = py_image_methods,
|
||||
// .load_attr = py_image_load_attr,
|
||||
|
||||
@ -28,7 +28,7 @@ static void py_cascade_print(void (*print)(void *env, const char *fmt, ...), voi
|
||||
}
|
||||
|
||||
static const mp_obj_type_t py_cascade_type = {
|
||||
{ &mp_const_type },
|
||||
{ &mp_type_type },
|
||||
"Cascade",
|
||||
.print = py_cascade_print,
|
||||
};
|
||||
@ -153,7 +153,7 @@ mp_obj_t py_imlib_load_cascade(mp_obj_t path_obj)
|
||||
const char *path = mp_obj_str_get_str(path_obj);
|
||||
int res = imlib_load_cascade(&cascade, path);
|
||||
if (res != FR_OK) {
|
||||
nlr_jump(mp_obj_new_exception_msg(qstr_from_str("Imlib"), ffs_strerror(res)));
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res)));
|
||||
}
|
||||
|
||||
o = m_new_obj(py_cascade_obj_t);
|
||||
@ -174,7 +174,7 @@ mp_obj_t py_imlib_load_template(mp_obj_t path_obj)
|
||||
|
||||
int res = imlib_load_template(image, path);
|
||||
if (res != FR_OK) {
|
||||
nlr_jump(mp_obj_new_exception_msg(qstr_from_str("Imlib"), ffs_strerror(res)));
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res)));
|
||||
}
|
||||
|
||||
return image_obj;
|
||||
@ -209,7 +209,7 @@ mp_obj_t py_imlib_save_template(mp_obj_t image_obj, mp_obj_t rectangle_obj, mp_o
|
||||
free(t.data);
|
||||
|
||||
if (res != FR_OK) {
|
||||
nlr_jump(mp_obj_new_exception_msg(qstr_from_str("Imlib"), ffs_strerror(res)));
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res)));
|
||||
}
|
||||
|
||||
return mp_const_true;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user