mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Switch to compressed error messages (#1116)
This commit is contained in:
parent
4c8a3ab750
commit
ad00a842e9
@ -7,7 +7,7 @@
|
||||
*
|
||||
*/
|
||||
#include "py/obj.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "fb_alloc.h"
|
||||
#include "framebuffer.h"
|
||||
#include "omv_boardconfig.h"
|
||||
@ -42,8 +42,8 @@ char *fb_alloc_stack_pointer()
|
||||
|
||||
MP_WEAK NORETURN void fb_alloc_fail()
|
||||
{
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_MemoryError,
|
||||
"Out of fast Frame Buffer Stack Memory!"
|
||||
mp_raise_msg(&mp_type_MemoryError,
|
||||
MP_ERROR_TEXT("Out of fast Frame Buffer Stack Memory!"
|
||||
" Please reduce the resolution of the image you are running this algorithm on to bypass this issue!"));
|
||||
}
|
||||
|
||||
@ -68,8 +68,8 @@ void fb_alloc_mark()
|
||||
// Check if allocation overwrites the framebuffer pixels
|
||||
if (new_pointer < fb_alloc_min_address()) {
|
||||
nlr_raise_for_fb_alloc_mark(mp_obj_new_exception_msg(&mp_type_MemoryError,
|
||||
"Out of fast Frame Buffer Stack Memory!"
|
||||
" Please reduce the resolution of the image you are running this algorithm on to bypass this issue!"));
|
||||
MP_ERROR_TEXT("Out of fast Frame Buffer Stack Memory!"
|
||||
" Please reduce the resolution of the image you are running this algorithm on to bypass this issue!")));
|
||||
}
|
||||
|
||||
// fb_alloc does not allow regions which are a size of 0 to be alloced,
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
* UMM memory allocator.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/mphal.h"
|
||||
#include "fb_alloc.h"
|
||||
#include "umm_malloc.h"
|
||||
@ -17,8 +17,8 @@
|
||||
|
||||
NORETURN void umm_alloc_fail()
|
||||
{
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_MemoryError,
|
||||
"Out of temporary Frame Buffer Heap Memory!"
|
||||
mp_raise_msg(&mp_type_MemoryError,
|
||||
MP_ERROR_TEXT("Out of temporary Frame Buffer Heap Memory!"
|
||||
" Please reduce the resolution of the image you are running this algorithm on to bypass this issue!"));
|
||||
}
|
||||
|
||||
|
||||
@ -9,14 +9,14 @@
|
||||
* Memory allocation functions.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/gc.h"
|
||||
#include "py/mphal.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
NORETURN static void xalloc_fail()
|
||||
{
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_MemoryError, "Out of normal MicroPython Heap Memory!"
|
||||
mp_raise_msg(&mp_type_MemoryError, MP_ERROR_TEXT("Out of normal MicroPython Heap Memory!"
|
||||
" Please reduce the resolution of the image you are running this algorithm on to bypass this issue!"));
|
||||
}
|
||||
|
||||
|
||||
@ -22,49 +22,49 @@
|
||||
NORETURN static void ff_fail(FIL *fp, FRESULT res)
|
||||
{
|
||||
if (fp) f_close(fp);
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res)));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT(ffs_strerror(res)));
|
||||
}
|
||||
|
||||
NORETURN static void ff_read_fail(FIL *fp)
|
||||
{
|
||||
if (fp) f_close(fp);
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Failed to read requested bytes!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to read requested bytes!"));
|
||||
}
|
||||
|
||||
NORETURN static void ff_write_fail(FIL *fp)
|
||||
{
|
||||
if (fp) f_close(fp);
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Failed to write requested bytes!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to write requested bytes!"));
|
||||
}
|
||||
|
||||
NORETURN static void ff_expect_fail(FIL *fp)
|
||||
{
|
||||
if (fp) f_close(fp);
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Unexpected value read!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Unexpected value read!"));
|
||||
}
|
||||
|
||||
NORETURN void ff_unsupported_format(FIL *fp)
|
||||
{
|
||||
if (fp) f_close(fp);
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Unsupported format!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Unsupported format!"));
|
||||
}
|
||||
|
||||
NORETURN void ff_file_corrupted(FIL *fp)
|
||||
{
|
||||
if (fp) f_close(fp);
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "File corrupted!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("File corrupted!"));
|
||||
}
|
||||
|
||||
NORETURN void ff_not_equal(FIL *fp)
|
||||
{
|
||||
if (fp) f_close(fp);
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Images not equal!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Images not equal!"));
|
||||
}
|
||||
|
||||
NORETURN void ff_no_intersection(FIL *fp)
|
||||
{
|
||||
if (fp) f_close(fp);
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "No intersection!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("No intersection!"));
|
||||
}
|
||||
|
||||
void file_read_open(FIL *fp, const char *path)
|
||||
@ -246,7 +246,7 @@ void file_buffer_on(FIL *fp)
|
||||
file_buffer_offset = f_tell(fp) % 4;
|
||||
file_buffer_pointer = fb_alloc_all(&file_buffer_size, FB_ALLOC_PREFER_SIZE) + file_buffer_offset;
|
||||
if (!file_buffer_size) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_MemoryError, "No memory!"));
|
||||
mp_raise_msg(&mp_type_MemoryError, MP_ERROR_TEXT("No memory!"));
|
||||
}
|
||||
file_buffer_size -= file_buffer_offset;
|
||||
file_buffer_index = 0;
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "py/obj.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "xalloc.h"
|
||||
#include "ff_wrapper.h"
|
||||
@ -220,7 +220,7 @@ void bmp_write_subimg(image_t *img, const char *path, rectangle_t *r)
|
||||
{
|
||||
rectangle_t rect;
|
||||
if (!rectangle_subimg(img, r, &rect)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "No intersection!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("No intersection!"));
|
||||
}
|
||||
|
||||
FIL fp;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
* FFT LIB - can do 1024 point real FFTs and 512 point complex FFTs
|
||||
*
|
||||
*/
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/obj.h"
|
||||
#include <arm_math.h>
|
||||
#include "fb_alloc.h"
|
||||
@ -551,7 +551,7 @@ void fft2d_alloc(fft2d_controller_t *controller, image_t *img, rectangle_t *r)
|
||||
{
|
||||
controller->img = img;
|
||||
if (!rectangle_subimg(controller->img, r, &controller->r)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "No intersection!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("No intersection!"));
|
||||
}
|
||||
|
||||
controller->w_pow2 = int_clog2(controller->r.w);
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include "py/obj.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "font.h"
|
||||
#include "array.h"
|
||||
@ -964,7 +964,7 @@ static save_image_format_t imblib_parse_extension(image_t *img, const char *path
|
||||
&& ((p[-3] == 'b') || (p[-3] == 'B'))
|
||||
&& ((p[-4] == '.') || (p[-4] == '.'))) {
|
||||
if (IM_IS_JPEG(img) || IM_IS_BAYER(img)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Image is not BMP!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Image is not BMP!"));
|
||||
}
|
||||
return FORMAT_BMP;
|
||||
} else if (((p[-1] == 'm') || (p[-1] == 'M'))
|
||||
@ -972,7 +972,7 @@ static save_image_format_t imblib_parse_extension(image_t *img, const char *path
|
||||
&& ((p[-3] == 'p') || (p[-3] == 'P'))
|
||||
&& ((p[-4] == '.') || (p[-4] == '.'))) {
|
||||
if (!IM_IS_RGB565(img)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Image is not PPM!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Image is not PPM!"));
|
||||
}
|
||||
return FORMAT_PNM;
|
||||
} else if (((p[-1] == 'm') || (p[-1] == 'M'))
|
||||
@ -980,7 +980,7 @@ static save_image_format_t imblib_parse_extension(image_t *img, const char *path
|
||||
&& ((p[-3] == 'p') || (p[-3] == 'P'))
|
||||
&& ((p[-4] == '.') || (p[-4] == '.'))) {
|
||||
if (!IM_IS_GS(img)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Image is not PGM!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Image is not PGM!"));
|
||||
}
|
||||
return FORMAT_PNM;
|
||||
} else if (((p[-1] == 'w') || (p[-1] == 'W'))
|
||||
@ -988,7 +988,7 @@ static save_image_format_t imblib_parse_extension(image_t *img, const char *path
|
||||
&& ((p[-3] == 'r') || (p[-3] == 'R'))
|
||||
&& ((p[-4] == '.') || (p[-4] == '.'))) {
|
||||
if (!IM_IS_BAYER(img)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Image is not BAYER!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Image is not BAYER!"));
|
||||
}
|
||||
return FORMAT_RAW;
|
||||
}
|
||||
@ -1057,7 +1057,7 @@ void imlib_image_operation(image_t *img, const char *path, image_t *other, int s
|
||||
bool vflipped = imlib_read_geometry(&fp, &temp, path, &rs);
|
||||
if (!IM_EQUAL(img, &temp)) {
|
||||
f_close(&fp);
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Images not equal!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Images not equal!"));
|
||||
}
|
||||
// When processing vertically flipped images the read function will fill
|
||||
// the window up from the bottom. The read function assumes that the
|
||||
@ -1068,8 +1068,7 @@ void imlib_image_operation(image_t *img, const char *path, image_t *other, int s
|
||||
temp.h = IM_MIN(img->h, (size / (temp.w * temp.bpp)));
|
||||
// This should never happen unless someone forgot to free.
|
||||
if ((!temp.pixels) || (!temp.h)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_MemoryError,
|
||||
"Not enough memory available!"));
|
||||
mp_raise_msg(&mp_type_MemoryError, MP_ERROR_TEXT("Not enough memory available!"));
|
||||
}
|
||||
for (int i=0; i<img->h; i+=temp.h) { // goes past end
|
||||
int lines = IM_MIN(temp.h, img->h-i);
|
||||
@ -1086,11 +1085,11 @@ void imlib_image_operation(image_t *img, const char *path, image_t *other, int s
|
||||
file_close(&fp);
|
||||
fb_free();
|
||||
#else
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Image I/O is not supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Image I/O is not supported"));
|
||||
#endif
|
||||
} else if (other) {
|
||||
if (!IM_EQUAL(img, other)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Images not equal!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Images not equal!"));
|
||||
}
|
||||
switch (img->bpp) {
|
||||
case IMAGE_BPP_BINARY: {
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include "py/obj.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "xalloc.h"
|
||||
#include "imlib.h"
|
||||
@ -127,7 +127,7 @@ void ppm_write_subimg(image_t *img, const char *path, rectangle_t *r)
|
||||
{
|
||||
rectangle_t rect;
|
||||
if (!rectangle_subimg(img, r, &rect)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "No intersection!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("No intersection!"));
|
||||
}
|
||||
|
||||
FIL fp;
|
||||
|
||||
@ -13,8 +13,8 @@
|
||||
#define PY_ASSERT_TRUE(cond) \
|
||||
do { \
|
||||
if ((cond) == 0) { \
|
||||
nlr_raise(mp_obj_new_exception_msg( \
|
||||
&mp_type_OSError, \
|
||||
mp_raise_msg(&mp_type_OSError, \
|
||||
MP_ERROR_TEXT( \
|
||||
"Operation not supported")); \
|
||||
} \
|
||||
} while(0)
|
||||
@ -22,16 +22,16 @@
|
||||
#define PY_ASSERT_TRUE_MSG(cond, msg) \
|
||||
do { \
|
||||
if ((cond) == 0) { \
|
||||
nlr_raise(mp_obj_new_exception_msg( \
|
||||
&mp_type_OSError, msg)); \
|
||||
mp_raise_msg(&mp_type_OSError, \
|
||||
MP_ERROR_TEXT(msg)); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define PY_ASSERT_FALSE_MSG(cond, msg) \
|
||||
do { \
|
||||
if ((cond) == 1) { \
|
||||
nlr_raise(mp_obj_new_exception_msg( \
|
||||
&mp_type_OSError, msg)); \
|
||||
mp_raise_msg(&mp_type_OSError, \
|
||||
MP_ERROR_TEXT(msg)); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
@ -40,11 +40,11 @@
|
||||
__typeof__ (obj) _a = (obj); \
|
||||
__typeof__ (type) _b = (type); \
|
||||
if (!MP_OBJ_IS_TYPE(_a, _b)) { \
|
||||
nlr_raise(mp_obj_new_exception_msg_varg( \
|
||||
&mp_type_TypeError, \
|
||||
"Can't convert %s to %s", \
|
||||
mp_raise_msg_varg(&mp_type_TypeError, \
|
||||
MP_ERROR_TEXT( \
|
||||
"Can't convert %s to %s"), \
|
||||
mp_obj_get_type_str(_a), \
|
||||
mp_obj_get_type_str(_b))); \
|
||||
mp_obj_get_type_str(_b)); \
|
||||
} \
|
||||
} while(0)
|
||||
/* IS_TYPE doesn't work for str objs */
|
||||
@ -52,11 +52,12 @@
|
||||
do { \
|
||||
__typeof__ (obj) _a = (obj); \
|
||||
if (!MP_OBJ_IS_STR(_a)) { \
|
||||
nlr_raise(mp_obj_new_exception_msg_varg( \
|
||||
mp_raise_msg_varg( \
|
||||
&mp_type_TypeError, \
|
||||
"Can't convert %s to %s", \
|
||||
MP_ERROR_TEXT( \
|
||||
"Can't convert %s to %s"), \
|
||||
mp_obj_get_type_str(_a), \
|
||||
str_type.name)); \
|
||||
str_type.name); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
*
|
||||
* FIR Python module.
|
||||
*/
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/objlist.h"
|
||||
|
||||
#include "omv_boardconfig.h"
|
||||
@ -323,7 +323,7 @@ mp_obj_t py_fir_init(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||
cambus_pulse_scl(&fir_bus);
|
||||
goto FIR_SCAN_RETRY;
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Failed to detect any FIR sensor"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Failed to detect any FIR sensor"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -369,7 +369,7 @@ mp_obj_t py_fir_init(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||
goto FIR_MLX90621_RETRY;
|
||||
} else {
|
||||
py_fir_deinit();
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Failed to init the MLX90621!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Failed to init the MLX90621!"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -415,7 +415,7 @@ mp_obj_t py_fir_init(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||
goto FIR_MLX90640_RETRY;
|
||||
} else {
|
||||
py_fir_deinit();
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Failed to init the MLX90640!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Failed to init the MLX90640!"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -445,7 +445,7 @@ mp_obj_t py_fir_init(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||
goto FIR_AMG8833_RETRY;
|
||||
} else {
|
||||
py_fir_deinit();
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Failed to init the AMG8833!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Failed to init the AMG8833!"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -471,8 +471,7 @@ mp_obj_t py_fir_init(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||
goto FIR_LEPTON_RETRY;
|
||||
} else {
|
||||
py_fir_deinit();
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
|
||||
"Failed to init the Lepton!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Failed to init the Lepton!"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -480,7 +479,7 @@ mp_obj_t py_fir_init(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||
}
|
||||
#endif
|
||||
default: {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid sensor type!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid sensor type!"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -731,7 +730,7 @@ mp_obj_t py_fir_draw_ir(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||
mp_obj_get_array_fixed_n(args[1], src_img.w * src_img.h, &arg_to);
|
||||
}
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "Invalid IR array!"));
|
||||
mp_raise_msg(&mp_type_TypeError, MP_ERROR_TEXT("Invalid IR array!"));
|
||||
}
|
||||
|
||||
int arg_x_off = 0;
|
||||
@ -749,7 +748,7 @@ mp_obj_t py_fir_draw_ir(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||
arg_y_off = mp_obj_get_int(args[3]);
|
||||
offset = 4;
|
||||
} else if (n_args > 2) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "Expected x and y offset!"));
|
||||
mp_raise_msg(&mp_type_TypeError, MP_ERROR_TEXT("Expected x and y offset!"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -783,12 +782,12 @@ mp_obj_t py_fir_draw_ir(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||
|
||||
int arg_rgb_channel = py_helper_keyword_int(n_args, args, offset + 3, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_rgb_channel), -1);
|
||||
if ((arg_rgb_channel < -1) || (2 < arg_rgb_channel)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "-1 <= rgb_channel <= 2!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("-1 <= rgb_channel <= 2!"));
|
||||
}
|
||||
|
||||
int arg_alpha = py_helper_keyword_int(n_args, args, offset + 4, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_alpha), 128);
|
||||
if ((arg_alpha < 0) || (256 < arg_alpha)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "0 <= alpha <= 256!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("0 <= alpha <= 256!"));
|
||||
}
|
||||
|
||||
const uint16_t *color_palette = py_helper_keyword_color_palette(n_args, args, offset + 5, kw_args, rainbow_table);
|
||||
@ -803,11 +802,11 @@ mp_obj_t py_fir_draw_ir(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||
bool got_y_size = py_helper_keyword_int_maybe(n_args, args, offset + 9, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_y_size), &arg_y_size);
|
||||
|
||||
if (got_x_scale && got_x_size) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Choose either x_scale or x_size not both!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Choose either x_scale or x_size not both!"));
|
||||
}
|
||||
|
||||
if (got_y_scale && got_y_size) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Choose either y_scale or y_size not both!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Choose either y_scale or y_size not both!"));
|
||||
}
|
||||
|
||||
if (got_x_size) {
|
||||
@ -884,12 +883,12 @@ mp_obj_t py_fir_snapshot(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||
|
||||
int arg_rgb_channel = py_helper_keyword_int(n_args, args, 6, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_rgb_channel), -1);
|
||||
if ((arg_rgb_channel < -1) || (2 < arg_rgb_channel)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "-1 <= rgb_channel <= 2!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("-1 <= rgb_channel <= 2!"));
|
||||
}
|
||||
|
||||
int arg_alpha = py_helper_keyword_int(n_args, args, 7, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_alpha), 128);
|
||||
if ((arg_alpha < 0) || (256 < arg_alpha)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "0 <= alpha <= 256!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("0 <= alpha <= 256!"));
|
||||
}
|
||||
|
||||
const uint16_t *color_palette = py_helper_keyword_color_palette(n_args, args, 8, kw_args, rainbow_table);
|
||||
@ -904,11 +903,11 @@ mp_obj_t py_fir_snapshot(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||
bool got_y_size = py_helper_keyword_int_maybe(n_args, args, 12, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_y_size), &arg_y_size);
|
||||
|
||||
if (got_x_scale && got_x_size) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Choose either x_scale or x_size not both!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Choose either x_scale or x_size not both!"));
|
||||
}
|
||||
|
||||
if (got_y_scale && got_y_size) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Choose either y_scale or y_size not both!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Choose either y_scale or y_size not both!"));
|
||||
}
|
||||
|
||||
if (got_x_size) {
|
||||
@ -939,7 +938,7 @@ mp_obj_t py_fir_snapshot(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||
|
||||
int arg_pixformat = py_helper_keyword_int(n_args, args, 14, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_pixformat), PIXFORMAT_RGB565);
|
||||
if ((arg_pixformat != PIXFORMAT_GRAYSCALE) && (arg_pixformat != PIXFORMAT_RGB565)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid pixformat!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid pixformat!"));
|
||||
}
|
||||
|
||||
mp_obj_t copy_to_fb_obj = py_helper_keyword_object(n_args, args, 15, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_copy_to_fb), NULL);
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
* GIF Python module.
|
||||
*/
|
||||
#include "py/mphal.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "ff_wrapper.h"
|
||||
#include "framebuffer.h"
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
* Python helper functions.
|
||||
*/
|
||||
#include "py/obj.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "framebuffer.h"
|
||||
#include "py_helper.h"
|
||||
#include "py_assert.h"
|
||||
@ -426,8 +426,8 @@ const uint16_t *py_helper_keyword_color_palette(uint n_args, const mp_obj_t *arg
|
||||
} else if (palette == COLOR_PALETTE_IRONBOW) {
|
||||
default_color_palette = ironbow_table;
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
|
||||
"Invalid pre-defined color palette!"));
|
||||
mp_raise_msg(&mp_type_ValueError,
|
||||
MP_ERROR_TEXT("Invalid pre-defined color palette!"));
|
||||
}
|
||||
} else {
|
||||
image_t *arg_color_palette =
|
||||
@ -435,13 +435,13 @@ const uint16_t *py_helper_keyword_color_palette(uint n_args, const mp_obj_t *arg
|
||||
|
||||
if (arg_color_palette) {
|
||||
if (arg_color_palette->bpp != IMAGE_BPP_RGB565) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
|
||||
"Color palette must be RGB565!"));
|
||||
mp_raise_msg(&mp_type_ValueError,
|
||||
MP_ERROR_TEXT("Color palette must be RGB565!"));
|
||||
}
|
||||
|
||||
if ((arg_color_palette->w * arg_color_palette->h) != 256) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
|
||||
"Color palette must be 256 pixels!"));
|
||||
mp_raise_msg(&mp_type_ValueError,
|
||||
MP_ERROR_TEXT("Color palette must be 256 pixels!"));
|
||||
}
|
||||
|
||||
default_color_palette = (uint16_t *) arg_color_palette->data;
|
||||
@ -459,13 +459,13 @@ const uint8_t *py_helper_keyword_alpha_palette(uint n_args, const mp_obj_t *args
|
||||
|
||||
if (arg_alpha_palette) {
|
||||
if (arg_alpha_palette->bpp != IMAGE_BPP_GRAYSCALE) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
|
||||
"Alpha palette must be GRAYSCALE!"));
|
||||
mp_raise_msg(&mp_type_ValueError,
|
||||
MP_ERROR_TEXT("Alpha palette must be GRAYSCALE!"));
|
||||
}
|
||||
|
||||
if ((arg_alpha_palette->w * arg_alpha_palette->h) != 256) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
|
||||
"Alpha palette must be 256 pixels!"));
|
||||
mp_raise_msg(&mp_type_ValueError,
|
||||
MP_ERROR_TEXT("Alpha palette must be 256 pixels!"));
|
||||
}
|
||||
|
||||
default_alpha_palette = (uint8_t *) arg_alpha_palette->data;
|
||||
|
||||
@ -181,7 +181,7 @@ static mp_obj_t py_kptmatch_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t va
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(kptmatch_obj_size, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
mp_seq_copy(result->items, &(self->x) + slice.start, result->len, mp_obj_t);
|
||||
@ -409,7 +409,7 @@ static mp_obj_t py_image_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(self->_cobj.w * self->_cobj.h, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
for (mp_uint_t i = 0; i < result->len; i++) {
|
||||
@ -425,7 +425,7 @@ static mp_obj_t py_image_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(self->_cobj.w * self->_cobj.h, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
for (mp_uint_t i = 0; i < result->len; i++) {
|
||||
@ -442,7 +442,7 @@ static mp_obj_t py_image_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(self->_cobj.w * self->_cobj.h, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
for (mp_uint_t i = 0; i < result->len; i++) {
|
||||
@ -463,7 +463,7 @@ static mp_obj_t py_image_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(self->_cobj.bpp, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
for (mp_uint_t i = 0; i < result->len; i++) {
|
||||
@ -481,7 +481,7 @@ static mp_obj_t py_image_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(self->_cobj.w * self->_cobj.h, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
if (MP_OBJ_IS_TYPE(value, &mp_type_list)) {
|
||||
mp_uint_t value_l_len;
|
||||
@ -508,7 +508,7 @@ static mp_obj_t py_image_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(self->_cobj.w * self->_cobj.h, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
if (MP_OBJ_IS_TYPE(value, &mp_type_list)) {
|
||||
mp_uint_t value_l_len;
|
||||
@ -536,7 +536,7 @@ static mp_obj_t py_image_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(self->_cobj.w * self->_cobj.h, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
if (MP_OBJ_IS_TYPE(value, &mp_type_list)) {
|
||||
mp_uint_t value_l_len;
|
||||
@ -570,7 +570,7 @@ static mp_obj_t py_image_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(self->_cobj.bpp, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
if (MP_OBJ_IS_TYPE(value, &mp_type_list)) {
|
||||
mp_uint_t value_l_len;
|
||||
@ -1177,7 +1177,7 @@ static mp_obj_t py_image_to_rainbow(uint n_args, const mp_obj_t *args, mp_map_t
|
||||
} else if (palette == COLOR_PALETTE_IRONBOW) {
|
||||
color_palette = ironbow_table;
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid color palette!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid color palette!"));
|
||||
}
|
||||
|
||||
image_t out;
|
||||
@ -1888,10 +1888,10 @@ STATIC mp_obj_t py_image_draw_image(uint n_args, const mp_obj_t *args, mp_map_t
|
||||
py_helper_keyword_rectangle_roi(arg_other, n_args, args, offset + 2, kw_args, &arg_roi);
|
||||
|
||||
int arg_rgb_channel = py_helper_keyword_int(n_args, args, offset + 3, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_rgb_channel), -1);
|
||||
if ((arg_rgb_channel < -1) || (2 < arg_rgb_channel)) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "-1 <= rgb_channel <= 2!"));
|
||||
if ((arg_rgb_channel < -1) || (2 < arg_rgb_channel)) mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("-1 <= rgb_channel <= 2!"));
|
||||
|
||||
int arg_alpha = py_helper_keyword_int(n_args, args, offset + 4, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_alpha), 256);
|
||||
if ((arg_alpha < 0) || (256 < arg_alpha)) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "0 <= alpha <= 256!"));
|
||||
if ((arg_alpha < 0) || (256 < arg_alpha)) mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("0 <= alpha <= 256!"));
|
||||
|
||||
const uint16_t *color_palette = py_helper_keyword_color_palette(n_args, args, offset + 5, kw_args, NULL);
|
||||
const uint8_t *alpha_palette = py_helper_keyword_alpha_palette(n_args, args, offset + 6, kw_args, NULL);
|
||||
@ -1904,8 +1904,8 @@ STATIC mp_obj_t py_image_draw_image(uint n_args, const mp_obj_t *args, mp_map_t
|
||||
int arg_y_size;
|
||||
bool got_y_size = py_helper_keyword_int_maybe(n_args, args, offset + 9, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_y_size), &arg_y_size);
|
||||
|
||||
if (got_x_scale && got_x_size) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Choose either x_scale or x_size not both!"));
|
||||
if (got_y_scale && got_y_size) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Choose either y_scale or y_size not both!"));
|
||||
if (got_x_scale && got_x_size) mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Choose either x_scale or x_size not both!"));
|
||||
if (got_y_scale && got_y_size) mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Choose either y_scale or y_size not both!"));
|
||||
|
||||
if (got_x_size) arg_x_scale = arg_x_size / ((float) arg_roi.w);
|
||||
if (got_y_size) arg_y_scale = arg_y_size / ((float) arg_roi.h);
|
||||
@ -3200,7 +3200,7 @@ static mp_obj_t py_similarity_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(py_similarity_obj_size, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
mp_seq_copy(result->items, &(self->avg) + slice.start, result->len, mp_obj_t);
|
||||
@ -3355,7 +3355,7 @@ static mp_obj_t py_statistics_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(py_statistics_obj_size, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
mp_seq_copy(result->items, &(self->LMean) + slice.start, result->len, mp_obj_t);
|
||||
@ -3545,7 +3545,7 @@ static mp_obj_t py_percentile_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(py_percentile_obj_size, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
mp_seq_copy(result->items, &(self->LValue) + slice.start, result->len, mp_obj_t);
|
||||
@ -3630,7 +3630,7 @@ static mp_obj_t py_threshold_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t v
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(py_threshold_obj_size, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
mp_seq_copy(result->items, &(self->LValue) + slice.start, result->len, mp_obj_t);
|
||||
@ -3720,7 +3720,7 @@ static mp_obj_t py_histogram_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t v
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(py_histogram_obj_size, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
mp_seq_copy(result->items, &(self->LBins) + slice.start, result->len, mp_obj_t);
|
||||
@ -4149,7 +4149,7 @@ static mp_obj_t py_line_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value)
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(py_line_obj_size, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
mp_seq_copy(result->items, &(self->x1) + slice.start, result->len, mp_obj_t);
|
||||
@ -4308,7 +4308,7 @@ static mp_obj_t py_blob_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value)
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(py_blob_obj_size, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
mp_seq_copy(result->items, &(self->x) + slice.start, result->len, mp_obj_t);
|
||||
@ -5024,7 +5024,7 @@ static mp_obj_t py_circle_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t valu
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(py_circle_obj_size, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
mp_seq_copy(result->items, &(self->x) + slice.start, result->len, mp_obj_t);
|
||||
@ -5151,7 +5151,7 @@ static mp_obj_t py_rect_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value)
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(py_rect_obj_size, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
mp_seq_copy(result->items, &(self->x) + slice.start, result->len, mp_obj_t);
|
||||
@ -5285,7 +5285,7 @@ static mp_obj_t py_qrcode_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t valu
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(py_qrcode_obj_size, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
mp_seq_copy(result->items, &(self->x) + slice.start, result->len, mp_obj_t);
|
||||
@ -5467,7 +5467,7 @@ static mp_obj_t py_apriltag_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t va
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(py_apriltag_obj_size, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
mp_seq_copy(result->items, &(self->x) + slice.start, result->len, mp_obj_t);
|
||||
@ -5680,7 +5680,7 @@ static mp_obj_t py_datamatrix_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(py_datamatrix_obj_size, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
mp_seq_copy(result->items, &(self->x) + slice.start, result->len, mp_obj_t);
|
||||
@ -5838,7 +5838,7 @@ static mp_obj_t py_barcode_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t val
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(py_barcode_obj_size, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
mp_seq_copy(result->items, &(self->x) + slice.start, result->len, mp_obj_t);
|
||||
@ -5979,7 +5979,7 @@ static mp_obj_t py_displacement_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_
|
||||
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
|
||||
mp_bound_slice_t slice;
|
||||
if (!mp_seq_get_fast_slice_indexes(py_displacement_obj_size, index, &slice)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "only slices with step=1 (aka None) are supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("only slices with step=1 (aka None) are supported"));
|
||||
}
|
||||
mp_obj_tuple_t *result = mp_obj_new_tuple(slice.stop - slice.start, NULL);
|
||||
mp_seq_copy(result->items, &(self->x_translation) + slice.start, result->len, mp_obj_t);
|
||||
@ -6941,7 +6941,7 @@ mp_obj_t py_image_load_image(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
|
||||
file_close(&fp);
|
||||
#else
|
||||
(void) path;
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Image I/O is not supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Image I/O is not supported"));
|
||||
#endif //IMLIB_ENABLE_IMAGE_FILE_IO
|
||||
}
|
||||
|
||||
@ -6989,10 +6989,10 @@ mp_obj_t py_image_load_cascade(uint n_args, const mp_obj_t *args, mp_map_t *kw_a
|
||||
if (res != FR_OK) {
|
||||
#if defined(IMLIB_ENABLE_IMAGE_FILE_IO)
|
||||
// cascade is not built-in and failed to load it from file.
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res)));
|
||||
mp_raise_msg(&mp_type_OSError, ffs_strerror(res));
|
||||
#else
|
||||
// cascade is not built-in.
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Image I/O is not supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Image I/O is not supported"));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -7070,12 +7070,12 @@ mp_obj_t py_image_load_descriptor(uint n_args, const mp_obj_t *args, mp_map_t *k
|
||||
error:
|
||||
// File open or write error
|
||||
if (res != FR_OK) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res)));
|
||||
mp_raise_msg(&mp_type_OSError, ffs_strerror(res));
|
||||
}
|
||||
|
||||
// If no file error and descriptor is still none, then it's not supported.
|
||||
if (desc == mp_const_none) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Descriptor type is not supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Descriptor type is not supported"));
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
@ -7104,7 +7104,7 @@ mp_obj_t py_image_save_descriptor(uint n_args, const mp_obj_t *args, mp_map_t *k
|
||||
#endif //IMLIB_ENABLE_FIND_KEYPOINTS
|
||||
} else {
|
||||
(void) desc_obj_type;
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Descriptor type is not supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Descriptor type is not supported"));
|
||||
}
|
||||
|
||||
// Write descriptor type
|
||||
@ -7137,7 +7137,7 @@ mp_obj_t py_image_save_descriptor(uint n_args, const mp_obj_t *args, mp_map_t *k
|
||||
error:
|
||||
// File open or read error
|
||||
if (res != FR_OK) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res)));
|
||||
mp_raise_msg(&mp_type_OSError, ffs_strerror(res));
|
||||
}
|
||||
return mp_const_true;
|
||||
}
|
||||
@ -7221,7 +7221,7 @@ static mp_obj_t py_image_match_descriptor(uint n_args, const mp_obj_t *args, mp_
|
||||
match_obj = o;
|
||||
#endif //IMLIB_ENABLE_FIND_KEYPOINTS
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Descriptor type is not supported"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Descriptor type is not supported"));
|
||||
}
|
||||
|
||||
return match_obj;
|
||||
@ -7246,7 +7246,7 @@ int py_image_descriptor_from_roi(image_t *img, const char *path, rectangle_t *ro
|
||||
}
|
||||
// File open/write error
|
||||
if (res != FR_OK) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res)));
|
||||
mp_raise_msg(&mp_type_OSError, ffs_strerror(res));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
* MJPEG Python module.
|
||||
*/
|
||||
#include "py/obj.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "ff_wrapper.h"
|
||||
#include "framebuffer.h"
|
||||
#include "py_assert.h"
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
*/
|
||||
#include <stdarg.h>
|
||||
#include "py/mphal.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "pin.h"
|
||||
|
||||
#if MICROPY_PY_SENSOR
|
||||
@ -63,8 +63,8 @@ static mp_obj_t py_sensor__init__()
|
||||
// it gets called when the module is imported. This is good
|
||||
// place to check if the sensor was detected or not.
|
||||
if (sensor_is_detected() == false) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError,
|
||||
"The image sensor is detached or failed to initialize!"));
|
||||
mp_raise_msg(&mp_type_RuntimeError,
|
||||
MP_ERROR_TEXT("The image sensor is detached or failed to initialize!"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
@ -111,7 +111,7 @@ static mp_obj_t py_sensor_snapshot(uint n_args, const mp_obj_t *args, mp_map_t *
|
||||
int ret = sensor.snapshot(&sensor, (image_t *) py_image_cobj(image), NULL);
|
||||
|
||||
if (ret < 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_RuntimeError, "Capture Failed: %d", ret));
|
||||
mp_raise_msg_varg(&mp_type_RuntimeError, MP_ERROR_TEXT("Capture Failed: %d"), ret);
|
||||
}
|
||||
|
||||
return image;
|
||||
@ -222,28 +222,28 @@ static mp_obj_t py_sensor_dealloc_extra_fb()
|
||||
|
||||
static mp_obj_t py_sensor_set_pixformat(mp_obj_t pixformat) {
|
||||
if (sensor_set_pixformat(mp_obj_get_int(pixformat)) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Pixel format is not supported!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Pixel format is not supported!"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
static mp_obj_t py_sensor_get_pixformat() {
|
||||
if (sensor.pixformat == PIXFORMAT_INVALID) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Pixel format not set yet!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Pixel format not set yet!"));
|
||||
}
|
||||
return mp_obj_new_int(sensor.pixformat);
|
||||
}
|
||||
|
||||
static mp_obj_t py_sensor_set_framesize(mp_obj_t framesize) {
|
||||
if (sensor_set_framesize(mp_obj_get_int(framesize)) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Failed to set framesize!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Failed to set framesize!"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
static mp_obj_t py_sensor_get_framesize() {
|
||||
if (sensor.framesize == FRAMESIZE_INVALID) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Frame size not set yet!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Frame size not set yet!"));
|
||||
}
|
||||
return mp_obj_new_int(sensor.framesize);
|
||||
}
|
||||
@ -269,22 +269,22 @@ static mp_obj_t py_sensor_set_windowing(mp_obj_t roi_obj)
|
||||
x = (res_w / 2) - (w / 2);
|
||||
y = (res_h / 2) - (h / 2);
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
|
||||
"The tuple/list must either be (x, y, w, h) or (w, h)"));
|
||||
mp_raise_msg(&mp_type_ValueError,
|
||||
MP_ERROR_TEXT("The tuple/list must either be (x, y, w, h) or (w, h)"));
|
||||
}
|
||||
|
||||
if (w < 8 || h < 8) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
|
||||
"The selected window is too small"));
|
||||
mp_raise_msg(&mp_type_ValueError,
|
||||
MP_ERROR_TEXT("The selected window is too small"));
|
||||
}
|
||||
|
||||
if (x < 0 || (x + w) > res_w || y < 0 || (y + h) > res_h) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
|
||||
"The selected window is outside the bounds of the frame"));
|
||||
mp_raise_msg(&mp_type_ValueError,
|
||||
MP_ERROR_TEXT("The selected window is outside the bounds of the frame"));
|
||||
}
|
||||
|
||||
if (sensor_set_windowing(x, y, w, h) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Failed to set windowing!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Failed to set windowing!"));
|
||||
}
|
||||
|
||||
return mp_const_none;
|
||||
@ -323,7 +323,7 @@ static mp_obj_t py_sensor_set_gainceiling(mp_obj_t gainceiling) {
|
||||
gain = GAINCEILING_128X;
|
||||
break;
|
||||
default:
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid gainceiling"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid gainceiling"));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -378,7 +378,7 @@ static mp_obj_t py_sensor_set_auto_gain(uint n_args, const mp_obj_t *args, mp_ma
|
||||
float gain_db = py_helper_keyword_float(n_args, args, 1, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_gain_db), NAN);
|
||||
float gain_db_ceiling = py_helper_keyword_float(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_gain_db_ceiling), NAN);
|
||||
if (sensor_set_auto_gain(enable, gain_db, gain_db_ceiling) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
@ -386,7 +386,7 @@ static mp_obj_t py_sensor_set_auto_gain(uint n_args, const mp_obj_t *args, mp_ma
|
||||
static mp_obj_t py_sensor_get_gain_db() {
|
||||
float gain_db;
|
||||
if (sensor_get_gain_db(&gain_db) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
return mp_obj_new_float(gain_db);
|
||||
}
|
||||
@ -394,7 +394,7 @@ static mp_obj_t py_sensor_get_gain_db() {
|
||||
static mp_obj_t py_sensor_set_auto_exposure(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
int exposure_us = py_helper_keyword_int(n_args, args, 1, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_exposure_us), -1);
|
||||
if (sensor_set_auto_exposure(mp_obj_get_int(args[0]), exposure_us) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
@ -402,7 +402,7 @@ static mp_obj_t py_sensor_set_auto_exposure(uint n_args, const mp_obj_t *args, m
|
||||
static mp_obj_t py_sensor_get_exposure_us() {
|
||||
int exposure_us;
|
||||
if (sensor_get_exposure_us(&exposure_us) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
return mp_obj_new_int(exposure_us);
|
||||
}
|
||||
@ -412,7 +412,7 @@ static mp_obj_t py_sensor_set_auto_whitebal(uint n_args, const mp_obj_t *args, m
|
||||
float rgb_gain_db[3] = {NAN, NAN, NAN};
|
||||
py_helper_keyword_float_array(n_args, args, 1, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_rgb_gain_db), rgb_gain_db, 3);
|
||||
if (sensor_set_auto_whitebal(enable, rgb_gain_db[0], rgb_gain_db[1], rgb_gain_db[2]) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
@ -420,14 +420,14 @@ static mp_obj_t py_sensor_set_auto_whitebal(uint n_args, const mp_obj_t *args, m
|
||||
static mp_obj_t py_sensor_get_rgb_gain_db() {
|
||||
float r_gain_db = 0.0, g_gain_db = 0.0, b_gain_db = 0.0;
|
||||
if (sensor_get_rgb_gain_db(&r_gain_db, &g_gain_db, &b_gain_db) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
return mp_obj_new_tuple(3, (mp_obj_t []) {mp_obj_new_float(r_gain_db), mp_obj_new_float(g_gain_db), mp_obj_new_float(b_gain_db)});
|
||||
}
|
||||
|
||||
static mp_obj_t py_sensor_set_hmirror(mp_obj_t enable) {
|
||||
if (sensor_set_hmirror(mp_obj_is_true(enable)) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
@ -438,7 +438,7 @@ static mp_obj_t py_sensor_get_hmirror() {
|
||||
|
||||
static mp_obj_t py_sensor_set_vflip(mp_obj_t enable) {
|
||||
if (sensor_set_vflip(mp_obj_is_true(enable)) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
@ -449,7 +449,7 @@ static mp_obj_t py_sensor_get_vflip() {
|
||||
|
||||
static mp_obj_t py_sensor_set_transpose(mp_obj_t enable) {
|
||||
if (sensor_set_transpose(mp_obj_is_true(enable)) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Cannot transpose in JPEG mode!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Cannot transpose in JPEG mode!"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
@ -460,7 +460,7 @@ static mp_obj_t py_sensor_get_transpose() {
|
||||
|
||||
static mp_obj_t py_sensor_set_auto_rotation(mp_obj_t enable) {
|
||||
if (sensor_set_auto_rotation(mp_obj_is_true(enable)) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Cannot auto rotate in JPEG mode!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Cannot auto rotate in JPEG mode!"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
@ -498,7 +498,7 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
switch (request) {
|
||||
case IOCTL_SET_READOUT_WINDOW: {
|
||||
if (n_args < 2) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
|
||||
int x, y, w, h;
|
||||
@ -518,12 +518,12 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
x = 0;
|
||||
y = 0;
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
|
||||
"The tuple/list must either be (x, y, w, h) or (w, h)"));
|
||||
mp_raise_msg(&mp_type_ValueError,
|
||||
MP_ERROR_TEXT("The tuple/list must either be (x, y, w, h) or (w, h)"));
|
||||
}
|
||||
|
||||
if (sensor_ioctl(request, x, y, w, h) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
|
||||
break;
|
||||
@ -532,7 +532,7 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
case IOCTL_GET_READOUT_WINDOW: {
|
||||
int x, y, w, h;
|
||||
if (sensor_ioctl(request, &x, &y, &w, &h) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
ret_obj = mp_obj_new_tuple(4, (mp_obj_t []) {mp_obj_new_int(x),
|
||||
mp_obj_new_int(y),
|
||||
@ -543,7 +543,7 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
|
||||
case IOCTL_SET_TRIGGERED_MODE: {
|
||||
if (n_args < 2 || sensor_ioctl(request, mp_obj_get_int(args[1])) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -551,7 +551,7 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
case IOCTL_GET_TRIGGERED_MODE: {
|
||||
int enabled;
|
||||
if (sensor_ioctl(request, &enabled) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
ret_obj = mp_obj_new_bool(enabled);
|
||||
break;
|
||||
@ -562,13 +562,13 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
case IOCTL_PAUSE_AUTO_FOCUS:
|
||||
case IOCTL_RESET_AUTO_FOCUS: {
|
||||
if (sensor_ioctl(request) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IOCTL_WAIT_ON_AUTO_FOCUS: {
|
||||
if (sensor_ioctl(request, (n_args < 2) ? 5000 : mp_obj_get_int(args[1])) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -577,7 +577,7 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
case IOCTL_LEPTON_GET_WIDTH: {
|
||||
int width;
|
||||
if (sensor_ioctl(request, &width) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
ret_obj = mp_obj_new_int(width);
|
||||
break;
|
||||
@ -586,7 +586,7 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
case IOCTL_LEPTON_GET_HEIGHT: {
|
||||
int height;
|
||||
if (sensor_ioctl(request, &height) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
ret_obj = mp_obj_new_int(height);
|
||||
break;
|
||||
@ -595,7 +595,7 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
case IOCTL_LEPTON_GET_RADIOMETRY: {
|
||||
int radiometry;
|
||||
if (sensor_ioctl(request, &radiometry) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
ret_obj = mp_obj_new_int(radiometry);
|
||||
break;
|
||||
@ -604,7 +604,7 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
case IOCTL_LEPTON_GET_REFRESH: {
|
||||
int refresh;
|
||||
if (sensor_ioctl(request, &refresh) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
ret_obj = mp_obj_new_int(refresh);
|
||||
break;
|
||||
@ -613,7 +613,7 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
case IOCTL_LEPTON_GET_RESOLUTION: {
|
||||
int resolution;
|
||||
if (sensor_ioctl(request, &resolution) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
ret_obj = mp_obj_new_int(resolution);
|
||||
break;
|
||||
@ -621,7 +621,7 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
|
||||
case IOCTL_LEPTON_RUN_COMMAND: {
|
||||
if (n_args < 2 || sensor_ioctl(request, mp_obj_get_int(args[1])) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -632,7 +632,7 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
uint16_t *data = (uint16_t *) mp_obj_str_get_data(args[2], &data_len);
|
||||
PY_ASSERT_TRUE_MSG(data_len > 0, "0 bytes transferred!");
|
||||
if (sensor_ioctl(request, command, data, data_len / sizeof(uint16_t)) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -643,7 +643,7 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
PY_ASSERT_TRUE_MSG(data_len > 0, "0 bytes transferred!");
|
||||
uint16_t *data = xalloc(data_len * sizeof(uint16_t));
|
||||
if (sensor_ioctl(request, command, data, data_len) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
ret_obj = mp_obj_new_bytearray_by_ref(data_len * sizeof(uint16_t), data);
|
||||
break;
|
||||
@ -653,7 +653,7 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
case IOCTL_LEPTON_GET_AUX_TEMPERATURE: {
|
||||
int temp;
|
||||
if (sensor_ioctl(request, &temp) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
ret_obj = mp_obj_new_float((((float) temp) / 100) - 273.15f);
|
||||
break;
|
||||
@ -661,14 +661,14 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
|
||||
case IOCTL_LEPTON_SET_MEASUREMENT_MODE:
|
||||
if (n_args < 2 || sensor_ioctl(request, mp_obj_get_int(args[1])) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
break;
|
||||
|
||||
case IOCTL_LEPTON_GET_MEASUREMENT_MODE: {
|
||||
int enabled;
|
||||
if (sensor_ioctl(request, &enabled) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
ret_obj = mp_obj_new_bool(enabled);
|
||||
break;
|
||||
@ -676,27 +676,27 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
||||
|
||||
case IOCTL_LEPTON_SET_MEASUREMENT_RANGE:
|
||||
if (n_args < 3) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
// GCC will not less us pass floats to ... so we have to pass float pointers instead.
|
||||
float min = mp_obj_get_float(args[1]);
|
||||
float max = mp_obj_get_float(args[2]);
|
||||
if (sensor_ioctl(request, &min, &max) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
break;
|
||||
|
||||
case IOCTL_LEPTON_GET_MEASUREMENT_RANGE: {
|
||||
float min, max;
|
||||
if (sensor_ioctl(request, &min, &max) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Sensor control failed!"));
|
||||
}
|
||||
ret_obj = mp_obj_new_tuple(2, (mp_obj_t []) {mp_obj_new_float(min), mp_obj_new_float(max)});
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Operation not supported!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Operation not supported!"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -713,7 +713,7 @@ static mp_obj_t py_sensor_set_color_palette(mp_obj_t palette_obj) {
|
||||
sensor_set_color_palette(ironbow_table);
|
||||
break;
|
||||
default:
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid color palette!"));
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid color palette!"));
|
||||
break;
|
||||
}
|
||||
return mp_const_none;
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/obj.h"
|
||||
#include "py/objlist.h"
|
||||
#include "py/objtuple.h"
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
#define NRF_PDM_FREQ_2667K (nrf_pdm_freq_t)(0x15000000UL) ///< PDM_CLK= 2.667 MHz (32 MHz / 12) => Fs= 41667 Hz
|
||||
#define NRF_PDM_FREQ_3200K (nrf_pdm_freq_t)(0x19000000UL) ///< PDM_CLK= 3.200 MHz (32 MHz / 10) => Fs= 50000 Hz
|
||||
#define NRF_PDM_FREQ_4000K (nrf_pdm_freq_t)(0x20000000UL) ///< PDM_CLK= 4.000 MHz (32 MHz / 8) => Fs= 62500 Hz
|
||||
#define RAISE_OS_EXCEPTION(msg) nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, msg))
|
||||
#define RAISE_OS_EXCEPTION(msg) mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT(msg))
|
||||
|
||||
static mp_obj_array_t *g_pcmbuf = NULL;
|
||||
static mp_obj_t g_audio_callback = mp_const_none;
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
|
||||
#if MICROPY_PY_AUDIO
|
||||
|
||||
#define RAISE_OS_EXCEPTION(msg) nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, msg))
|
||||
#define RAISE_OS_EXCEPTION(msg) mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT(msg))
|
||||
|
||||
static CRC_HandleTypeDef hcrc;
|
||||
static SAI_HandleTypeDef hsai;
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "py/obj.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "py_cpufreq.h"
|
||||
#include "py_helper.h"
|
||||
@ -125,7 +125,7 @@ mp_obj_t py_cpufreq_set_frequency(mp_obj_t cpufreq_obj)
|
||||
|
||||
// Frequency is Not supported.
|
||||
if (cpufreq_idx == -1) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Unsupported frequency!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Unsupported frequency!"));
|
||||
}
|
||||
|
||||
// Return if frequency hasn't changed.
|
||||
@ -181,7 +181,7 @@ mp_obj_t py_cpufreq_set_frequency(mp_obj_t cpufreq_obj)
|
||||
break;
|
||||
|
||||
default:
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Unsupported frequency!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Unsupported frequency!"));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ mp_obj_t py_cpufreq_set_frequency(mp_obj_t cpufreq_obj)
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||
if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK) {
|
||||
// Initialization Error
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "RCC CLK Initialization Error!!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("RCC CLK Initialization Error!!"));
|
||||
}
|
||||
|
||||
// Enable HSE Oscillator and activate PLL with HSE as source
|
||||
@ -211,7 +211,7 @@ mp_obj_t py_cpufreq_set_frequency(mp_obj_t cpufreq_obj)
|
||||
|
||||
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
|
||||
// Initialization Error
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "RCC OSC Initialization Error!!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("RCC OSC Initialization Error!!"));
|
||||
}
|
||||
|
||||
// Select PLL as system clock source
|
||||
@ -222,7 +222,7 @@ mp_obj_t py_cpufreq_set_frequency(mp_obj_t cpufreq_obj)
|
||||
|
||||
if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, flatency) != HAL_OK) {
|
||||
// Initialization Error
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "RCC CLK Initialization Error!!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("RCC CLK Initialization Error!!"));
|
||||
}
|
||||
return mp_const_true;
|
||||
}
|
||||
|
||||
@ -520,7 +520,7 @@ static int fir_lepton_get_temperature()
|
||||
LEP_SYS_FPA_TEMPERATURE_KELVIN_T kelvin;
|
||||
|
||||
if (LEP_GetSysFpaTemperatureKelvin(&fir_lepton_handle, &kelvin) != LEP_OK) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "FPA Error!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("FPA Error!"));
|
||||
}
|
||||
|
||||
return kelvin;
|
||||
@ -659,7 +659,7 @@ void fir_lepton_fill_image(image_t *img, int w, int h, bool auto_range, float mi
|
||||
void fir_lepton_trigger_ffc()
|
||||
{
|
||||
if (LEP_RunSysFFCNormalization(&fir_lepton_handle) != LEP_OK) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "FFC Error!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("FFC Error!"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -672,7 +672,7 @@ void fir_lepton_wait_on_ffc(uint n_args, const mp_obj_t *args)
|
||||
LEP_SYS_STATUS_E status;
|
||||
|
||||
if (LEP_GetSysFFCStatus(&fir_lepton_handle, &status) != LEP_OK) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "SYS Error!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("SYS Error!"));
|
||||
}
|
||||
|
||||
if (status == LEP_SYS_STATUS_READY) {
|
||||
@ -680,7 +680,7 @@ void fir_lepton_wait_on_ffc(uint n_args, const mp_obj_t *args)
|
||||
}
|
||||
|
||||
if ((systick_current_millis() - start) >= delay_ms) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Timeout!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Timeout!"));
|
||||
}
|
||||
|
||||
systick_sleep(1);
|
||||
|
||||
@ -872,7 +872,7 @@ static void ltdc_pll_config_init(int frame_size, int refresh_rate)
|
||||
}
|
||||
}
|
||||
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Unable to initialize LTDC PLL!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Unable to initialize LTDC PLL!"));
|
||||
}
|
||||
|
||||
static void ltdc_config_deinit()
|
||||
@ -1109,7 +1109,7 @@ static mp_obj_t ltdc_dvi_get_display_connected()
|
||||
}), MP_MACHINE_I2C_FLAG_STOP);
|
||||
}
|
||||
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Failed to get display connected!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to get display connected!"));
|
||||
}
|
||||
|
||||
#ifdef OMV_DDC_PRESENT
|
||||
@ -1164,7 +1164,7 @@ static mp_obj_t ltdc_dvi_get_display_id_data()
|
||||
}
|
||||
}
|
||||
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Failed to get display id data!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to get display id data!"));
|
||||
}
|
||||
#endif // OMV_DDC_PRESENT
|
||||
|
||||
@ -1229,7 +1229,7 @@ static void ltdc_dvi_init()
|
||||
}), MP_MACHINE_I2C_FLAG_STOP) == 4) {
|
||||
extint_register((mp_obj_t) OMV_DVI_INT_PIN, GPIO_MODE_IT_FALLING, GPIO_PULLUP, (mp_obj_t) <dc_dvi_extint_callback_obj, true);
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Display init failed!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Display init failed!"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1300,11 +1300,11 @@ STATIC mp_obj_t py_lcd_init(uint n_args, const mp_obj_t *args, mp_map_t *kw_args
|
||||
#ifdef OMV_SPI_LCD_CONTROLLER
|
||||
case LCD_SHIELD: {
|
||||
int w = py_helper_keyword_int(n_args, args, 1, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_width), 128);
|
||||
if ((w <= 0) || (32767 < w)) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid Width!"));
|
||||
if ((w <= 0) || (32767 < w)) mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid Width!"));
|
||||
int h = py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_height), 160);
|
||||
if ((h <= 0) || (32767 < h)) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid Height!"));
|
||||
if ((h <= 0) || (32767 < h)) mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid Height!"));
|
||||
int refresh_rate = py_helper_keyword_int(n_args, args, 3, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_refresh), 60);
|
||||
if ((refresh_rate < 30) || (120 < refresh_rate)) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid Refresh Rate!"));
|
||||
if ((refresh_rate < 30) || (120 < refresh_rate)) mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid Refresh Rate!"));
|
||||
bool triple_buffer = py_helper_keyword_int(n_args, args, 4, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_triple_buffer), false);
|
||||
bool bgr = py_helper_keyword_int(n_args, args, 5, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_bgr), false);
|
||||
spi_config_init(w, h, refresh_rate, triple_buffer, bgr);
|
||||
@ -1324,9 +1324,9 @@ STATIC mp_obj_t py_lcd_init(uint n_args, const mp_obj_t *args, mp_map_t *kw_args
|
||||
#ifdef OMV_LCD_CONTROLLER
|
||||
case LCD_DISPLAY: case LCD_DISPLAY_WITH_HDMI: case LCD_DISPLAY_ONLY_HDMI: {
|
||||
int frame_size = py_helper_keyword_int(n_args, args, 1, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_framesize), LCD_DISPLAY_FWVGA);
|
||||
if ((frame_size < 0) || (LCD_DISPLAY_MAX <= frame_size)) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid Frame Size!"));
|
||||
if ((frame_size < 0) || (LCD_DISPLAY_MAX <= frame_size)) mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid Frame Size!"));
|
||||
int refresh_rate = py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_refresh), 60);
|
||||
if ((refresh_rate < 30) || (120 < refresh_rate)) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid Refresh Rate!"));
|
||||
if ((refresh_rate < 30) || (120 < refresh_rate)) mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid Refresh Rate!"));
|
||||
ltdc_config_init(frame_size, refresh_rate);
|
||||
#ifdef OMV_LCD_BL_PIN
|
||||
if ((type == LCD_DISPLAY) || (type == LCD_DISPLAY_WITH_HDMI)) ltdc_set_backlight(255); // to on state
|
||||
@ -1413,7 +1413,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(py_lcd_refresh_obj, py_lcd_refresh);
|
||||
STATIC mp_obj_t py_lcd_set_backlight(mp_obj_t intensity_obj)
|
||||
{
|
||||
int intensity = mp_obj_get_int(intensity_obj);
|
||||
if ((intensity < 0) || (255 < intensity)) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "0 <= intensity <= 255!"));
|
||||
if ((intensity < 0) || (255 < intensity)) mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("0 <= intensity <= 255!"));
|
||||
|
||||
switch (lcd_type) {
|
||||
#if defined(OMV_SPI_LCD_CONTROLLER) && defined(OMV_SPI_LCD_BL_PIN)
|
||||
@ -1571,7 +1571,7 @@ STATIC mp_obj_t py_lcd_display(uint n_args, const mp_obj_t *args, mp_map_t *kw_a
|
||||
arg_y_off = mp_obj_get_int(args[2]);
|
||||
offset = 3;
|
||||
} else if (n_args > 1) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "Expected x and y offset!"));
|
||||
mp_raise_msg(&mp_type_TypeError, MP_ERROR_TEXT("Expected x and y offset!"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1585,10 +1585,10 @@ STATIC mp_obj_t py_lcd_display(uint n_args, const mp_obj_t *args, mp_map_t *kw_a
|
||||
py_helper_keyword_rectangle_roi(arg_img, n_args, args, offset + 2, kw_args, &arg_roi);
|
||||
|
||||
int arg_rgb_channel = py_helper_keyword_int(n_args, args, offset + 3, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_rgb_channel), -1);
|
||||
if ((arg_rgb_channel < -1) || (2 < arg_rgb_channel)) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "-1 <= rgb_channel <= 2!"));
|
||||
if ((arg_rgb_channel < -1) || (2 < arg_rgb_channel)) mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("-1 <= rgb_channel <= 2!"));
|
||||
|
||||
int arg_alpha = py_helper_keyword_int(n_args, args, offset + 4, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_alpha), 256);
|
||||
if ((arg_alpha < 0) || (256 < arg_alpha)) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "0 <= alpha <= 256!"));
|
||||
if ((arg_alpha < 0) || (256 < arg_alpha)) mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("0 <= alpha <= 256!"));
|
||||
|
||||
const uint16_t *color_palette = py_helper_keyword_color_palette(n_args, args, offset + 5, kw_args, NULL);
|
||||
const uint8_t *alpha_palette = py_helper_keyword_alpha_palette(n_args, args, offset + 6, kw_args, NULL);
|
||||
@ -1601,8 +1601,8 @@ STATIC mp_obj_t py_lcd_display(uint n_args, const mp_obj_t *args, mp_map_t *kw_a
|
||||
int arg_y_size;
|
||||
bool got_y_size = py_helper_keyword_int_maybe(n_args, args, offset + 9, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_y_size), &arg_y_size);
|
||||
|
||||
if (got_x_scale && got_x_size) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Choose either x_scale or x_size not both!"));
|
||||
if (got_y_scale && got_y_size) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Choose either y_scale or y_size not both!"));
|
||||
if (got_x_scale && got_x_size) mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Choose either x_scale or x_size not both!"));
|
||||
if (got_y_scale && got_y_size) mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Choose either y_scale or y_size not both!"));
|
||||
|
||||
if (got_x_size) arg_x_scale = arg_x_size / ((float) arg_roi.w);
|
||||
if (got_y_size) arg_y_scale = arg_y_size / ((float) arg_roi.h);
|
||||
|
||||
@ -250,7 +250,7 @@ static void CEC_SendAckBit()
|
||||
mp_uint_t start = mp_hal_ticks_ms();
|
||||
/* Wait for falling edge: end of EOM bit sent by the initiator */
|
||||
while (HAL_GPIO_ReadPin(OMV_CEC_PIN->gpio, OMV_CEC_PIN->pin_mask)) {
|
||||
if ((mp_hal_ticks_ms() - start) > 10) nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Ack timeout!"));
|
||||
if ((mp_hal_ticks_ms() - start) > 10) mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Ack timeout!"));
|
||||
}
|
||||
|
||||
/* Send ACK bit */
|
||||
@ -279,7 +279,7 @@ static uint8_t CEC_ReceiveAckBit()
|
||||
mp_uint_t start = mp_hal_ticks_ms();
|
||||
/* Wait for falling edge of ACK bit (the end of ACK bit)*/
|
||||
while (HAL_GPIO_ReadPin(OMV_CEC_PIN->gpio, OMV_CEC_PIN->pin_mask)) {
|
||||
if ((mp_hal_ticks_ms() - start) > 10) nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Ack timeout!"));
|
||||
if ((mp_hal_ticks_ms() - start) > 10) mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Ack timeout!"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -507,7 +507,7 @@ static bool lcd_cec_receive_frame_int(mp_obj_t dst_addr, bool assertOnError)
|
||||
bool frameSendToMe = result & FrameSendToMeMask;
|
||||
|
||||
if (assertOnError && (!receiveFrameStatus)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Receive Failed!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Receive Failed!"));
|
||||
}
|
||||
|
||||
if (receiveFrameStatus && frameSendToMe) {
|
||||
@ -524,7 +524,7 @@ void lcd_cec_send_frame(mp_obj_t dst_addr, mp_obj_t src_addr, mp_obj_t bytes)
|
||||
size_t len;
|
||||
uint8_t *data = (uint8_t *) mp_obj_str_get_data(bytes, &len);
|
||||
if (!CEC_SendFrame(mp_obj_get_int(src_addr), mp_obj_get_int(dst_addr), len, data)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Send Failed!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Send Failed!"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -545,13 +545,13 @@ mp_obj_t lcd_cec_receive_frame(uint n_args, const mp_obj_t *args, mp_map_t *kw_a
|
||||
|
||||
mp_uint_t start = mp_hal_ticks_ms();
|
||||
while (HAL_GPIO_ReadPin(OMV_CEC_PIN->gpio, OMV_CEC_PIN->pin_mask)) {
|
||||
if ((mp_hal_ticks_ms() - start) > timeout) nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Receive timeout!"));
|
||||
if ((mp_hal_ticks_ms() - start) > timeout) mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Receive timeout!"));
|
||||
}
|
||||
|
||||
return mp_obj_new_bool(lcd_cec_receive_frame_int(args[0], true));
|
||||
}
|
||||
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Expected destination address!"));
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Expected destination address!"));
|
||||
}
|
||||
|
||||
STATIC mp_obj_t lcd_cec_extint_callback(mp_obj_t line)
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
#include <stdio.h>
|
||||
#include "py/obj.h"
|
||||
#include "py/objarray.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/mphal.h"
|
||||
#include "systick.h"
|
||||
#include "py/binary.h"
|
||||
@ -36,7 +36,7 @@
|
||||
#define kFeatureSliceDurationMs (30)
|
||||
#define kCategoryCount (4)
|
||||
#define kAverageWindowSamples (1020 / kFeatureSliceDurationMs)
|
||||
#define RAISE_OS_EXCEPTION(msg) nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, msg))
|
||||
#define RAISE_OS_EXCEPTION(msg) mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT(msg))
|
||||
|
||||
typedef struct _py_micro_speech_obj {
|
||||
mp_obj_base_t base;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
* TV Python module.
|
||||
*
|
||||
*/
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/mphal.h"
|
||||
#include "systick.h"
|
||||
#include "py/obj.h"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user