Merge pull request #1429 from openmv/fix_exceptions

Enable text compression and fix all exception issues.
This commit is contained in:
Ibrahim Abd Elkader 2021-08-11 18:01:29 +02:00 committed by GitHub
commit ece89364e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 222 additions and 192 deletions

View File

@ -68,10 +68,13 @@ OMV_COMMON_DIR=$(TOP_DIR)/$(OMV_DIR)/common
# Debugging/Optimization # Debugging/Optimization
ifeq ($(DEBUG), 1) ifeq ($(DEBUG), 1)
ROM_TEXT_COMPRESSION = 0
CFLAGS += -Og -ggdb3 -Wno-maybe-uninitialized CFLAGS += -Og -ggdb3 -Wno-maybe-uninitialized
else else
DEBUG=0 DEBUG=0
ROM_TEXT_COMPRESSION = 1
CFLAGS += -O2 -DNDEBUG CFLAGS += -O2 -DNDEBUG
MPY_CFLAGS += -DMICROPY_ROM_TEXT_COMPRESSION=1
endif endif
# Enable debug printf # Enable debug printf
@ -100,7 +103,7 @@ OMV_SRC_QSTR := $(wildcard $(TOP_DIR)/$(OMV_DIR)/modules/*.c)
OMV_SRC_QSTR += $(wildcard $(TOP_DIR)/$(OMV_DIR)/ports/$(PORT)/modules/*.c) OMV_SRC_QSTR += $(wildcard $(TOP_DIR)/$(OMV_DIR)/ports/$(PORT)/modules/*.c)
# The following command line args are passed to MicroPython's top Makefile. # The following command line args are passed to MicroPython's top Makefile.
MICROPY_ARGS = BOARD=$(TARGET) DEBUG=$(DEBUG) OMV_SRC_QSTR="$(OMV_SRC_QSTR)" MPY_LIB_DIR=$(MPY_LIB_DIR) MICROPY_ARGS = PORT=$(PORT) BOARD=$(TARGET) DEBUG=$(DEBUG) OMV_SRC_QSTR="$(OMV_SRC_QSTR)" MPY_LIB_DIR=$(MPY_LIB_DIR) MICROPY_ROM_TEXT_COMPRESSION=$(ROM_TEXT_COMPRESSION)
# Configure additional built-in modules. Note must define both the CFLAGS and the Make command line args. # Configure additional built-in modules. Note must define both the CFLAGS and the Make command line args.
ifeq ($(MICROPY_PY_SENSOR), 1) ifeq ($(MICROPY_PY_SENSOR), 1)

View File

@ -22,7 +22,7 @@
NORETURN static void ff_fail(FIL *fp, FRESULT res) NORETURN static void ff_fail(FIL *fp, FRESULT res)
{ {
if (fp) f_close(fp); if (fp) f_close(fp);
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT(ffs_strerror(res))); mp_raise_msg(&mp_type_OSError, (mp_rom_error_text_t) ffs_strerror(res));
} }
NORETURN static void ff_read_fail(FIL *fp) NORETURN static void ff_read_fail(FIL *fp)

View File

@ -1201,29 +1201,30 @@ __weak int sensor_auto_crop_framebuffer()
return 0; return 0;
} }
mp_rom_error_text_t sensor_strerror(int error) const char *sensor_strerror(int error)
{ {
static mp_rom_error_text_t sensor_errors[] = { static const char *sensor_errors[] = {
MP_ERROR_TEXT("No error."), "No error.",
MP_ERROR_TEXT("Sensor control failed."), "Sensor control failed.",
MP_ERROR_TEXT("The requested operation is not supported by the image sensor."), "The requested operation is not supported by the image sensor.",
MP_ERROR_TEXT("Failed to detect the image sensor or image sensor is detached."), "Failed to detect the image sensor or image sensor is detached.",
MP_ERROR_TEXT("The detected image sensor is not supported."), "The detected image sensor is not supported.",
MP_ERROR_TEXT("Failed to initialize the image sensor."), "Failed to initialize the image sensor.",
MP_ERROR_TEXT("Failed to initialize the image sensor clock."), "Failed to initialize the image sensor clock.",
MP_ERROR_TEXT("Failed to initialize the image sensor DMA."), "Failed to initialize the image sensor DMA.",
MP_ERROR_TEXT("Failed to initialize the image sensor DCMI."), "Failed to initialize the image sensor DCMI.",
MP_ERROR_TEXT("An low level I/O error has occurred."), "An low level I/O error has occurred.",
MP_ERROR_TEXT("Frame capture has failed."), "Frame capture has failed.",
MP_ERROR_TEXT("Frame capture has timed out."), "Frame capture has timed out.",
MP_ERROR_TEXT("Frame size is not supported or is not set."), "Frame size is not supported or is not set.",
MP_ERROR_TEXT("Pixel format is not supported or is not set."), "Pixel format is not supported or is not set.",
MP_ERROR_TEXT("Window is not supported or is not set."), "Window is not supported or is not set.",
MP_ERROR_TEXT("An invalid argument is used."), "Frame rate is not supported or is not set.",
MP_ERROR_TEXT("The requested operation is not supported on the current pixel format."), "An invalid argument is used.",
MP_ERROR_TEXT("Frame buffer error."), "The requested operation is not supported on the current pixel format.",
MP_ERROR_TEXT("Frame buffer overflow, try reducing the frame size."), "Frame buffer error.",
MP_ERROR_TEXT("JPEG frame buffer overflow."), "Frame buffer overflow, try reducing the frame size.",
"JPEG frame buffer overflow.",
}; };
// Sensor errors are negative. // Sensor errors are negative.

View File

@ -49,7 +49,7 @@ void usbdbg_init()
script_running=false; script_running=false;
irq_enabled = false; irq_enabled = false;
vstr_init(&script_buf, 32); vstr_init(&script_buf, 32);
mp_const_ide_interrupt = mp_obj_new_exception_msg(&mp_type_Exception, "IDE interrupt"); mp_const_ide_interrupt = mp_obj_new_exception_msg(&mp_type_Exception, MP_ERROR_TEXT("IDE interrupt"));
} }
void usbdbg_wait_for_command(uint32_t timeout) void usbdbg_wait_for_command(uint32_t timeout)

View File

@ -44,7 +44,7 @@ static mp_obj_t py_gif_open(uint n_args, const mp_obj_t *args, mp_map_t *kw_args
file_write_open(&gif->fp, mp_obj_str_get_str(args[0])); file_write_open(&gif->fp, mp_obj_str_get_str(args[0]));
gif_open(&gif->fp, gif->width, gif->height, gif->color, gif->loop); gif_open(&gif->fp, gif->width, gif->height, gif->color, gif->loop);
#else #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 #endif
return gif; return gif;
} }
@ -97,7 +97,7 @@ static mp_obj_t py_gif_add_frame(uint n_args, const mp_obj_t *args, mp_map_t *kw
gif_add_frame(&arg_gif->fp, arg_img, delay); gif_add_frame(&arg_gif->fp, arg_img, delay);
#else #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 #endif
return mp_const_none; return mp_const_none;
} }

View File

@ -6591,7 +6591,7 @@ 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 (res != FR_OK) {
#if defined(IMLIB_ENABLE_IMAGE_FILE_IO) #if defined(IMLIB_ENABLE_IMAGE_FILE_IO)
// cascade is not built-in and failed to load it from file. // cascade is not built-in and failed to load it from file.
mp_raise_msg(&mp_type_OSError, ffs_strerror(res)); mp_raise_msg(&mp_type_OSError, (mp_rom_error_text_t) ffs_strerror(res));
#else #else
// cascade is not built-in. // cascade is not built-in.
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Image I/O is not supported")); mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Image I/O is not supported"));
@ -6672,7 +6672,7 @@ mp_obj_t py_image_load_descriptor(uint n_args, const mp_obj_t *args, mp_map_t *k
error: error:
// File open or write error // File open or write error
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_msg(&mp_type_OSError, ffs_strerror(res)); mp_raise_msg(&mp_type_OSError, (mp_rom_error_text_t) ffs_strerror(res));
} }
// If no file error and descriptor is still none, then it's not supported. // If no file error and descriptor is still none, then it's not supported.
@ -6739,7 +6739,7 @@ mp_obj_t py_image_save_descriptor(uint n_args, const mp_obj_t *args, mp_map_t *k
error: error:
// File open or read error // File open or read error
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_msg(&mp_type_OSError, ffs_strerror(res)); mp_raise_msg(&mp_type_OSError, (mp_rom_error_text_t) ffs_strerror(res));
} }
return mp_const_true; return mp_const_true;
} }
@ -6848,7 +6848,7 @@ int py_image_descriptor_from_roi(image_t *img, const char *path, rectangle_t *ro
} }
// File open/write error // File open/write error
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_msg(&mp_type_OSError, ffs_strerror(res)); mp_raise_msg(&mp_type_OSError, (mp_rom_error_text_t) ffs_strerror(res));
} }
} }
return 0; return 0;

View File

@ -42,7 +42,7 @@ static mp_obj_t py_mjpeg_open(uint n_args, const mp_obj_t *args, mp_map_t *kw_ar
file_write_open(&mjpeg->fp, mp_obj_str_get_str(args[0])); file_write_open(&mjpeg->fp, mp_obj_str_get_str(args[0]));
mjpeg_open(&mjpeg->fp, mjpeg->width, mjpeg->height); mjpeg_open(&mjpeg->fp, mjpeg->width, mjpeg->height);
#else #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 #endif
return mjpeg; return mjpeg;
} }
@ -82,7 +82,7 @@ static mp_obj_t py_mjpeg_add_frame(uint n_args, const mp_obj_t *args, mp_map_t *
arg_q = IM_MIN(IM_MAX(arg_q, 1), 100); arg_q = IM_MIN(IM_MAX(arg_q, 1), 100);
mjpeg_add_frame(&arg_mjpeg->fp, &arg_mjpeg->frames, &arg_mjpeg->bytes, arg_img, arg_q); mjpeg_add_frame(&arg_mjpeg->fp, &arg_mjpeg->frames, &arg_mjpeg->bytes, arg_img, arg_q);
#else #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 #endif
return mp_const_none; return mp_const_none;
} }

View File

@ -31,6 +31,8 @@ extern sensor_t sensor;
static mp_obj_t vsync_callback = mp_const_none; static mp_obj_t vsync_callback = mp_const_none;
static mp_obj_t frame_callback = mp_const_none; static mp_obj_t frame_callback = mp_const_none;
#define sensor_raise_error(err) mp_raise_msg(&mp_type_RuntimeError, (mp_rom_error_text_t) sensor_strerror(err))
#if MICROPY_PY_IMU #if MICROPY_PY_IMU
static void do_auto_rotation(int pitch_deadzone, int roll_activezone) static void do_auto_rotation(int pitch_deadzone, int roll_activezone)
{ {
@ -67,16 +69,16 @@ static mp_obj_t py_sensor__init__()
// it gets called when the module is imported. This is good // it gets called when the module is imported. This is good
// place to check if the sensor was detected or not. // place to check if the sensor was detected or not.
if (sensor_is_detected() == false) { if (sensor_is_detected() == false) {
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(SENSOR_ERROR_ISC_UNDETECTED)); sensor_raise_error(SENSOR_ERROR_ISC_UNDETECTED);
} }
return mp_const_none; return mp_const_none;
} }
static mp_obj_t py_sensor_reset() static mp_obj_t py_sensor_reset()
{ {
int ret = sensor_reset(); int error = sensor_reset();
if (ret != 0) { if (error != 0) {
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(ret)); sensor_raise_error(error);
} }
#if MICROPY_PY_IMU #if MICROPY_PY_IMU
// +-10 degree dead-zone around pitch 90/270. // +-10 degree dead-zone around pitch 90/270.
@ -117,9 +119,9 @@ static mp_obj_t py_sensor_snapshot(uint n_args, const mp_obj_t *args, mp_map_t *
#endif // MICROPY_PY_IMU #endif // MICROPY_PY_IMU
mp_obj_t image = py_image(0, 0, 0, 0); mp_obj_t image = py_image(0, 0, 0, 0);
int ret = sensor.snapshot(&sensor, (image_t *) py_image_cobj(image), 0); int error = sensor.snapshot(&sensor, (image_t *) py_image_cobj(image), 0);
if (ret != 0) { if (error != 0) {
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(ret)); sensor_raise_error(error);
} }
return image; return image;
} }
@ -235,8 +237,9 @@ static mp_obj_t py_sensor_dealloc_extra_fb()
static mp_obj_t py_sensor_set_pixformat(mp_obj_t pixformat) static mp_obj_t py_sensor_set_pixformat(mp_obj_t pixformat)
{ {
if (sensor_set_pixformat(mp_obj_get_int(pixformat)) != 0) { int error = sensor_set_pixformat(mp_obj_get_int(pixformat));
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(SENSOR_ERROR_INVALID_PIXFORMAT)); if (error != 0) {
sensor_raise_error(error);
} }
return mp_const_none; return mp_const_none;
} }
@ -244,15 +247,16 @@ static mp_obj_t py_sensor_set_pixformat(mp_obj_t pixformat)
static mp_obj_t py_sensor_get_pixformat() static mp_obj_t py_sensor_get_pixformat()
{ {
if (sensor.pixformat == PIXFORMAT_INVALID) { if (sensor.pixformat == PIXFORMAT_INVALID) {
mp_raise_msg(&mp_type_ValueError, sensor_strerror(SENSOR_ERROR_INVALID_PIXFORMAT)); sensor_raise_error(SENSOR_ERROR_INVALID_PIXFORMAT);
} }
return mp_obj_new_int(sensor.pixformat); return mp_obj_new_int(sensor.pixformat);
} }
static mp_obj_t py_sensor_set_framesize(mp_obj_t framesize) static mp_obj_t py_sensor_set_framesize(mp_obj_t framesize)
{ {
if (sensor_set_framesize(mp_obj_get_int(framesize)) != 0) { int error = sensor_set_framesize(mp_obj_get_int(framesize));
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(SENSOR_ERROR_INVALID_FRAMESIZE)); if (error != 0) {
sensor_raise_error(error);
} }
return mp_const_none; return mp_const_none;
} }
@ -260,15 +264,16 @@ static mp_obj_t py_sensor_set_framesize(mp_obj_t framesize)
static mp_obj_t py_sensor_get_framesize() static mp_obj_t py_sensor_get_framesize()
{ {
if (sensor.framesize == FRAMESIZE_INVALID) { if (sensor.framesize == FRAMESIZE_INVALID) {
mp_raise_msg(&mp_type_ValueError, sensor_strerror(SENSOR_ERROR_INVALID_FRAMESIZE)); sensor_raise_error(SENSOR_ERROR_INVALID_FRAMESIZE);
} }
return mp_obj_new_int(sensor.framesize); return mp_obj_new_int(sensor.framesize);
} }
static mp_obj_t py_sensor_set_framerate(mp_obj_t framerate) static mp_obj_t py_sensor_set_framerate(mp_obj_t framerate)
{ {
if (sensor_set_framerate(mp_obj_get_int(framerate)) != 0) { int error = sensor_set_framerate(mp_obj_get_int(framerate));
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(SENSOR_ERROR_INVALID_FRAMERATE)); if (error != 0) {
sensor_raise_error(error);
} }
return mp_const_none; return mp_const_none;
} }
@ -276,7 +281,7 @@ static mp_obj_t py_sensor_set_framerate(mp_obj_t framerate)
static mp_obj_t py_sensor_get_framerate() static mp_obj_t py_sensor_get_framerate()
{ {
if (sensor.framerate == 0) { if (sensor.framerate == 0) {
mp_raise_msg(&mp_type_ValueError, sensor_strerror(SENSOR_ERROR_INVALID_FRAMERATE)); sensor_raise_error(SENSOR_ERROR_INVALID_FRAMERATE);
} }
return mp_obj_new_int(sensor.framerate); return mp_obj_new_int(sensor.framerate);
} }
@ -284,7 +289,7 @@ static mp_obj_t py_sensor_get_framerate()
static mp_obj_t py_sensor_set_windowing(uint n_args, const mp_obj_t *args) static mp_obj_t py_sensor_set_windowing(uint n_args, const mp_obj_t *args)
{ {
if (sensor.framesize == FRAMESIZE_INVALID) { if (sensor.framesize == FRAMESIZE_INVALID) {
mp_raise_msg(&mp_type_ValueError, sensor_strerror(SENSOR_ERROR_INVALID_FRAMESIZE)); sensor_raise_error(SENSOR_ERROR_INVALID_FRAMESIZE);
} }
rectangle_t temp; rectangle_t temp;
@ -326,8 +331,9 @@ static mp_obj_t py_sensor_set_windowing(uint n_args, const mp_obj_t *args)
rectangle_intersected(&r, &temp); rectangle_intersected(&r, &temp);
if (sensor_set_windowing(r.x, r.y, r.w, r.h) != 0) { int error = sensor_set_windowing(r.x, r.y, r.w, r.h);
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(SENSOR_ERROR_INVALID_WINDOW)); if (error != 0) {
sensor_raise_error(error);
} }
return mp_const_none; return mp_const_none;
@ -336,7 +342,7 @@ static mp_obj_t py_sensor_set_windowing(uint n_args, const mp_obj_t *args)
static mp_obj_t py_sensor_get_windowing() static mp_obj_t py_sensor_get_windowing()
{ {
if (sensor.framesize == FRAMESIZE_INVALID) { if (sensor.framesize == FRAMESIZE_INVALID) {
mp_raise_msg(&mp_type_ValueError, sensor_strerror(SENSOR_ERROR_INVALID_FRAMESIZE)); sensor_raise_error(SENSOR_ERROR_INVALID_FRAMESIZE);
} }
return mp_obj_new_tuple(4, (mp_obj_t []) {mp_obj_new_int(framebuffer_get_x()), return mp_obj_new_tuple(4, (mp_obj_t []) {mp_obj_new_int(framebuffer_get_x()),
@ -371,7 +377,7 @@ static mp_obj_t py_sensor_set_gainceiling(mp_obj_t gainceiling)
gain = GAINCEILING_128X; gain = GAINCEILING_128X;
break; break;
default: default:
mp_raise_msg(&mp_type_ValueError, sensor_strerror(SENSOR_ERROR_INVALID_ARGUMENT)); sensor_raise_error(SENSOR_ERROR_INVALID_ARGUMENT);
break; break;
} }
@ -432,9 +438,9 @@ 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 = 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); float gain_db_ceiling = py_helper_keyword_float(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_gain_db_ceiling), NAN);
int ret = sensor_set_auto_gain(enable, gain_db, gain_db_ceiling); int error = sensor_set_auto_gain(enable, gain_db, gain_db_ceiling);
if (ret != 0) { if (error != 0) {
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(ret)); sensor_raise_error(error);
} }
return mp_const_none; return mp_const_none;
} }
@ -442,9 +448,9 @@ 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() static mp_obj_t py_sensor_get_gain_db()
{ {
float gain_db; float gain_db;
int ret = sensor_get_gain_db(&gain_db); int error = sensor_get_gain_db(&gain_db);
if (ret != 0) { if (error != 0) {
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(ret)); sensor_raise_error(error);
} }
return mp_obj_new_float(gain_db); return mp_obj_new_float(gain_db);
} }
@ -452,9 +458,9 @@ 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) 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); int exposure_us = py_helper_keyword_int(n_args, args, 1, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_exposure_us), -1);
int ret = sensor_set_auto_exposure(mp_obj_get_int(args[0]), exposure_us); int error = sensor_set_auto_exposure(mp_obj_get_int(args[0]), exposure_us);
if (ret != 0) { if (error != 0) {
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(ret)); sensor_raise_error(error);
} }
return mp_const_none; return mp_const_none;
} }
@ -462,9 +468,9 @@ 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() static mp_obj_t py_sensor_get_exposure_us()
{ {
int exposure_us; int exposure_us;
int ret = sensor_get_exposure_us(&exposure_us); int error = sensor_get_exposure_us(&exposure_us);
if (ret != 0) { if (error != 0) {
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(ret)); sensor_raise_error(error);
} }
return mp_obj_new_int(exposure_us); return mp_obj_new_int(exposure_us);
} }
@ -475,9 +481,9 @@ 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}; 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); py_helper_keyword_float_array(n_args, args, 1, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_rgb_gain_db), rgb_gain_db, 3);
int ret = sensor_set_auto_whitebal(enable, rgb_gain_db[0], rgb_gain_db[1], rgb_gain_db[2]); int error = sensor_set_auto_whitebal(enable, rgb_gain_db[0], rgb_gain_db[1], rgb_gain_db[2]);
if (ret != 0) { if (error != 0) {
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(ret)); sensor_raise_error(error);
} }
return mp_const_none; return mp_const_none;
} }
@ -485,9 +491,9 @@ 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() 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; float r_gain_db = 0.0, g_gain_db = 0.0, b_gain_db = 0.0;
int ret = sensor_get_rgb_gain_db(&r_gain_db, &g_gain_db, &b_gain_db); int error = sensor_get_rgb_gain_db(&r_gain_db, &g_gain_db, &b_gain_db);
if (ret != 0) { if (error != 0) {
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(ret)); sensor_raise_error(error);
} }
return mp_obj_new_tuple(3, (mp_obj_t []) { return mp_obj_new_tuple(3, (mp_obj_t []) {
mp_obj_new_float(r_gain_db), mp_obj_new_float(r_gain_db),
@ -497,9 +503,9 @@ static mp_obj_t py_sensor_get_rgb_gain_db()
static mp_obj_t py_sensor_set_hmirror(mp_obj_t enable) static mp_obj_t py_sensor_set_hmirror(mp_obj_t enable)
{ {
int ret = sensor_set_hmirror(mp_obj_is_true(enable)); int error = sensor_set_hmirror(mp_obj_is_true(enable));
if (ret != 0) { if (error != 0) {
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(ret)); sensor_raise_error(error);
} }
return mp_const_none; return mp_const_none;
} }
@ -511,9 +517,9 @@ static mp_obj_t py_sensor_get_hmirror()
static mp_obj_t py_sensor_set_vflip(mp_obj_t enable) static mp_obj_t py_sensor_set_vflip(mp_obj_t enable)
{ {
int ret = sensor_set_vflip(mp_obj_is_true(enable)); int error = sensor_set_vflip(mp_obj_is_true(enable));
if (ret != 0) { if (error != 0) {
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(ret)); sensor_raise_error(error);
} }
return mp_const_none; return mp_const_none;
} }
@ -525,9 +531,9 @@ static mp_obj_t py_sensor_get_vflip()
static mp_obj_t py_sensor_set_transpose(mp_obj_t enable) static mp_obj_t py_sensor_set_transpose(mp_obj_t enable)
{ {
int ret = sensor_set_transpose(mp_obj_is_true(enable)); int error = sensor_set_transpose(mp_obj_is_true(enable));
if (ret != 0) { if (error != 0) {
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(ret)); sensor_raise_error(error);
} }
return mp_const_none; return mp_const_none;
} }
@ -539,9 +545,9 @@ static mp_obj_t py_sensor_get_transpose()
static mp_obj_t py_sensor_set_auto_rotation(mp_obj_t enable) static mp_obj_t py_sensor_set_auto_rotation(mp_obj_t enable)
{ {
int ret = sensor_set_auto_rotation(mp_obj_is_true(enable)); int error = sensor_set_auto_rotation(mp_obj_is_true(enable));
if (ret != 0) { if (error != 0) {
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(ret)); sensor_raise_error(error);
} }
return mp_const_none; return mp_const_none;
} }
@ -560,12 +566,12 @@ static mp_obj_t py_sensor_set_framebuffers(mp_obj_t count)
} }
if (c < 1) { if (c < 1) {
mp_raise_msg(&mp_type_ValueError, sensor_strerror(SENSOR_ERROR_INVALID_ARGUMENT)); sensor_raise_error(SENSOR_ERROR_INVALID_ARGUMENT);
} }
int ret = sensor_set_framebuffers(c); int error = sensor_set_framebuffers(c);
if (ret != 0) { if (error != 0) {
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(ret)); sensor_raise_error(error);
} }
return mp_const_none; return mp_const_none;
@ -647,7 +653,7 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
{ {
mp_obj_t ret_obj = mp_const_none; mp_obj_t ret_obj = mp_const_none;
int request = mp_obj_get_int(args[0]); int request = mp_obj_get_int(args[0]);
int ret = SENSOR_ERROR_INVALID_ARGUMENT; int error = SENSOR_ERROR_INVALID_ARGUMENT;
switch (request) { switch (request) {
case IOCTL_SET_READOUT_WINDOW: { case IOCTL_SET_READOUT_WINDOW: {
@ -672,15 +678,15 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
MP_ERROR_TEXT("The tuple/list must either be (x, y, w, h) or (w, h)")); MP_ERROR_TEXT("The tuple/list must either be (x, y, w, h) or (w, h)"));
} }
ret = sensor_ioctl(request, x, y, w, h); error = sensor_ioctl(request, x, y, w, h);
} }
break; break;
} }
case IOCTL_GET_READOUT_WINDOW: { case IOCTL_GET_READOUT_WINDOW: {
int x, y, w, h; int x, y, w, h;
ret = sensor_ioctl(request, &x, &y, &w, &h); error = sensor_ioctl(request, &x, &y, &w, &h);
if (ret == 0) { if (error == 0) {
ret_obj = mp_obj_new_tuple(4, (mp_obj_t []) {mp_obj_new_int(x), ret_obj = mp_obj_new_tuple(4, (mp_obj_t []) {mp_obj_new_int(x),
mp_obj_new_int(y), mp_obj_new_int(y),
mp_obj_new_int(w), mp_obj_new_int(w),
@ -691,15 +697,15 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
case IOCTL_SET_TRIGGERED_MODE: { case IOCTL_SET_TRIGGERED_MODE: {
if (n_args > 2) { if (n_args > 2) {
ret = sensor_ioctl(request, mp_obj_get_int(args[1])); error = sensor_ioctl(request, mp_obj_get_int(args[1]));
} }
break; break;
} }
case IOCTL_GET_TRIGGERED_MODE: { case IOCTL_GET_TRIGGERED_MODE: {
int enabled; int enabled;
ret = sensor_ioctl(request, &enabled); error = sensor_ioctl(request, &enabled);
if (ret == 0) { if (error == 0) {
ret_obj = mp_obj_new_bool(enabled); ret_obj = mp_obj_new_bool(enabled);
} }
break; break;
@ -709,19 +715,19 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
case IOCTL_TRIGGER_AUTO_FOCUS: case IOCTL_TRIGGER_AUTO_FOCUS:
case IOCTL_PAUSE_AUTO_FOCUS: case IOCTL_PAUSE_AUTO_FOCUS:
case IOCTL_RESET_AUTO_FOCUS: { case IOCTL_RESET_AUTO_FOCUS: {
ret = sensor_ioctl(request); error = sensor_ioctl(request);
break; break;
} }
case IOCTL_WAIT_ON_AUTO_FOCUS: { case IOCTL_WAIT_ON_AUTO_FOCUS: {
ret = sensor_ioctl(request, (n_args < 2) ? 5000 : mp_obj_get_int(args[1])); error = sensor_ioctl(request, (n_args < 2) ? 5000 : mp_obj_get_int(args[1]));
break; break;
} }
#endif #endif
case IOCTL_LEPTON_GET_WIDTH: { case IOCTL_LEPTON_GET_WIDTH: {
int width; int width;
ret = sensor_ioctl(request, &width); error = sensor_ioctl(request, &width);
if (ret == 0) { if (error == 0) {
ret_obj = mp_obj_new_int(width); ret_obj = mp_obj_new_int(width);
} }
break; break;
@ -729,8 +735,8 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
case IOCTL_LEPTON_GET_HEIGHT: { case IOCTL_LEPTON_GET_HEIGHT: {
int height; int height;
ret = sensor_ioctl(request, &height); error = sensor_ioctl(request, &height);
if (ret == 0) { if (error == 0) {
ret_obj = mp_obj_new_int(height); ret_obj = mp_obj_new_int(height);
} }
break; break;
@ -738,8 +744,8 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
case IOCTL_LEPTON_GET_RADIOMETRY: { case IOCTL_LEPTON_GET_RADIOMETRY: {
int radiometry; int radiometry;
ret = sensor_ioctl(request, &radiometry); error = sensor_ioctl(request, &radiometry);
if (ret == 0) { if (error == 0) {
ret_obj = mp_obj_new_int(radiometry); ret_obj = mp_obj_new_int(radiometry);
} }
break; break;
@ -747,8 +753,8 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
case IOCTL_LEPTON_GET_REFRESH: { case IOCTL_LEPTON_GET_REFRESH: {
int refresh; int refresh;
ret = sensor_ioctl(request, &refresh); error = sensor_ioctl(request, &refresh);
if (ret == 0) { if (error == 0) {
ret_obj = mp_obj_new_int(refresh); ret_obj = mp_obj_new_int(refresh);
} }
break; break;
@ -756,8 +762,8 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
case IOCTL_LEPTON_GET_RESOLUTION: { case IOCTL_LEPTON_GET_RESOLUTION: {
int resolution; int resolution;
ret = sensor_ioctl(request, &resolution); error = sensor_ioctl(request, &resolution);
if (ret == 0) { if (error == 0) {
ret_obj = mp_obj_new_int(resolution); ret_obj = mp_obj_new_int(resolution);
} }
break; break;
@ -765,7 +771,7 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
case IOCTL_LEPTON_RUN_COMMAND: { case IOCTL_LEPTON_RUN_COMMAND: {
if (n_args > 2) { if (n_args > 2) {
ret = sensor_ioctl(request, mp_obj_get_int(args[1])); error = sensor_ioctl(request, mp_obj_get_int(args[1]));
} }
break; break;
} }
@ -775,7 +781,7 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
int command = mp_obj_get_int(args[1]); int command = mp_obj_get_int(args[1]);
uint16_t *data = (uint16_t *) mp_obj_str_get_data(args[2], &data_len); uint16_t *data = (uint16_t *) mp_obj_str_get_data(args[2], &data_len);
PY_ASSERT_TRUE_MSG(data_len > 0, "0 bytes transferred!"); PY_ASSERT_TRUE_MSG(data_len > 0, "0 bytes transferred!");
ret = sensor_ioctl(request, command, data, data_len / sizeof(uint16_t)); error = sensor_ioctl(request, command, data, data_len / sizeof(uint16_t));
break; break;
} }
@ -784,8 +790,8 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
size_t data_len = mp_obj_get_int(args[2]); size_t data_len = mp_obj_get_int(args[2]);
PY_ASSERT_TRUE_MSG(data_len > 0, "0 bytes transferred!"); PY_ASSERT_TRUE_MSG(data_len > 0, "0 bytes transferred!");
uint16_t *data = xalloc(data_len * sizeof(uint16_t)); uint16_t *data = xalloc(data_len * sizeof(uint16_t));
ret = sensor_ioctl(request, command, data, data_len); error = sensor_ioctl(request, command, data, data_len);
if (ret == 0) { if (error == 0) {
ret_obj = mp_obj_new_bytearray_by_ref(data_len * sizeof(uint16_t), data); ret_obj = mp_obj_new_bytearray_by_ref(data_len * sizeof(uint16_t), data);
} }
break; break;
@ -794,8 +800,8 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
case IOCTL_LEPTON_GET_FPA_TEMPERATURE: case IOCTL_LEPTON_GET_FPA_TEMPERATURE:
case IOCTL_LEPTON_GET_AUX_TEMPERATURE: { case IOCTL_LEPTON_GET_AUX_TEMPERATURE: {
int temp; int temp;
ret = sensor_ioctl(request, &temp); error = sensor_ioctl(request, &temp);
if (ret == 0) { if (error == 0) {
ret_obj = mp_obj_new_float((((float) temp) / 100) - 273.15f); ret_obj = mp_obj_new_float((((float) temp) / 100) - 273.15f);
} }
break; break;
@ -803,14 +809,14 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
case IOCTL_LEPTON_SET_MEASUREMENT_MODE: case IOCTL_LEPTON_SET_MEASUREMENT_MODE:
if (n_args > 2) { if (n_args > 2) {
ret = sensor_ioctl(request, mp_obj_get_int(args[1])); error = sensor_ioctl(request, mp_obj_get_int(args[1]));
} }
break; break;
case IOCTL_LEPTON_GET_MEASUREMENT_MODE: { case IOCTL_LEPTON_GET_MEASUREMENT_MODE: {
int enabled; int enabled;
ret = sensor_ioctl(request, &enabled); error = sensor_ioctl(request, &enabled);
if (ret == 0) { if (error == 0) {
ret_obj = mp_obj_new_bool(enabled); ret_obj = mp_obj_new_bool(enabled);
} }
break; break;
@ -821,14 +827,14 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
// GCC will not let us pass floats to ... so we have to pass float pointers instead. // GCC will not let us pass floats to ... so we have to pass float pointers instead.
float min = mp_obj_get_float(args[1]); float min = mp_obj_get_float(args[1]);
float max = mp_obj_get_float(args[2]); float max = mp_obj_get_float(args[2]);
ret = sensor_ioctl(request, &min, &max); error = sensor_ioctl(request, &min, &max);
} }
break; break;
case IOCTL_LEPTON_GET_MEASUREMENT_RANGE: { case IOCTL_LEPTON_GET_MEASUREMENT_RANGE: {
float min, max; float min, max;
ret = sensor_ioctl(request, &min, &max); error = sensor_ioctl(request, &min, &max);
if (ret == 0) { if (error == 0) {
ret_obj = mp_obj_new_tuple(2, (mp_obj_t []) {mp_obj_new_float(min), mp_obj_new_float(max)}); ret_obj = mp_obj_new_tuple(2, (mp_obj_t []) {mp_obj_new_float(min), mp_obj_new_float(max)});
} }
break; break;
@ -837,7 +843,7 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
#if (OMV_ENABLE_HM01B0 == 1) #if (OMV_ENABLE_HM01B0 == 1)
case IOCTL_HIMAX_MD_ENABLE: { case IOCTL_HIMAX_MD_ENABLE: {
if (n_args > 2) { if (n_args > 2) {
ret = sensor_ioctl(request, mp_obj_get_int(args[1])); error = sensor_ioctl(request, mp_obj_get_int(args[1]));
} }
break; break;
} }
@ -864,26 +870,26 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
MP_ERROR_TEXT("The tuple/list must either be (x, y, w, h) or (w, h)")); MP_ERROR_TEXT("The tuple/list must either be (x, y, w, h) or (w, h)"));
} }
ret = sensor_ioctl(request, x, y, w, h); error = sensor_ioctl(request, x, y, w, h);
} }
break; break;
} }
case IOCTL_HIMAX_MD_THRESHOLD: { case IOCTL_HIMAX_MD_THRESHOLD: {
if (n_args > 2) { if (n_args > 2) {
ret = sensor_ioctl(request, mp_obj_get_int(args[1])); error = sensor_ioctl(request, mp_obj_get_int(args[1]));
} }
break; break;
} }
case IOCTL_HIMAX_MD_CLEAR: { case IOCTL_HIMAX_MD_CLEAR: {
ret = sensor_ioctl(request); error = sensor_ioctl(request);
break; break;
} }
case IOCTL_HIMAX_OSC_ENABLE: { case IOCTL_HIMAX_OSC_ENABLE: {
if (n_args > 2) { if (n_args > 2) {
ret = sensor_ioctl(request, mp_obj_get_int(args[1])); error = sensor_ioctl(request, mp_obj_get_int(args[1]));
} }
break; break;
} }
@ -891,13 +897,13 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
#endif // (OMV_ENABLE_HM01B0 == 1) #endif // (OMV_ENABLE_HM01B0 == 1)
default: { default: {
mp_raise_msg(&mp_type_ValueError, sensor_strerror(SENSOR_ERROR_CTL_UNSUPPORTED)); sensor_raise_error(SENSOR_ERROR_CTL_UNSUPPORTED);
break; break;
} }
} }
if (ret != 0) { if (error != 0) {
mp_raise_msg(&mp_type_RuntimeError, sensor_strerror(ret)); sensor_raise_error(error);
} }
return ret_obj; return ret_obj;
@ -914,7 +920,7 @@ static mp_obj_t py_sensor_set_color_palette(mp_obj_t palette_obj)
sensor_set_color_palette(ironbow_table); sensor_set_color_palette(ironbow_table);
break; break;
default: default:
mp_raise_msg(&mp_type_ValueError, sensor_strerror(SENSOR_ERROR_INVALID_ARGUMENT)); sensor_raise_error(SENSOR_ERROR_INVALID_ARGUMENT);
break; break;
} }
return mp_const_none; return mp_const_none;

View File

@ -67,7 +67,7 @@ STATIC mp_obj_t py_tf_classification_subscr(mp_obj_t self_in, mp_obj_t index, mp
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) { if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
mp_bound_slice_t slice; mp_bound_slice_t slice;
if (!mp_seq_get_fast_slice_indexes(py_tf_classification_obj_size, index, &slice)) { if (!mp_seq_get_fast_slice_indexes(py_tf_classification_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_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); mp_seq_copy(result->items, &(self->x) + slice.start, result->len, mp_obj_t);
@ -150,7 +150,7 @@ STATIC mp_obj_t int_py_tf_load(mp_obj_t path_obj, bool alloc_mode, bool helper_m
read_data(&fp, tf_model->model_data, tf_model->model_data_len); read_data(&fp, tf_model->model_data, tf_model->model_data_len);
file_close(&fp); file_close(&fp);
#else #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 #endif
} }
@ -161,15 +161,18 @@ STATIC mp_obj_t int_py_tf_load(mp_obj_t path_obj, bool alloc_mode, bool helper_m
uint32_t tensor_arena_size; uint32_t tensor_arena_size;
uint8_t *tensor_arena = fb_alloc_all(&tensor_arena_size, FB_ALLOC_PREFER_SIZE); uint8_t *tensor_arena = fb_alloc_all(&tensor_arena_size, FB_ALLOC_PREFER_SIZE);
PY_ASSERT_FALSE_MSG(libtf_get_input_data_hwc(tf_model->model_data, if (libtf_get_input_data_hwc(tf_model->model_data,
tensor_arena, tensor_arena,
tensor_arena_size, tensor_arena_size,
&tf_model->height, &tf_model->height,
&tf_model->width, &tf_model->width,
&tf_model->channels, &tf_model->channels,
&tf_model->signed_or_unsigned, &tf_model->signed_or_unsigned,
&tf_model->is_float), &tf_model->is_float) != 0) {
py_tf_putchar_buffer - (PY_TF_PUTCHAR_BUFFER_LEN - py_tf_putchar_buffer_len)); // Note can't use MP_ERROR_TEXT here.
mp_raise_msg(&mp_type_OSError, (mp_rom_error_text_t)
py_tf_putchar_buffer - (PY_TF_PUTCHAR_BUFFER_LEN - py_tf_putchar_buffer_len));
}
fb_free(); // free fb_alloc_all() fb_free(); // free fb_alloc_all()
@ -437,14 +440,17 @@ STATIC mp_obj_t py_tf_classify(uint n_args, const mp_obj_t *args, mp_map_t *kw_a
py_tf_classify_output_data_callback_data_t py_tf_classify_output_data_callback_data; py_tf_classify_output_data_callback_data_t py_tf_classify_output_data_callback_data;
PY_ASSERT_FALSE_MSG(libtf_invoke(arg_model->model_data, if (libtf_invoke(arg_model->model_data,
tensor_arena, tensor_arena,
tensor_arena_size, tensor_arena_size,
py_tf_input_data_callback, py_tf_input_data_callback,
&py_tf_input_data_callback_data, &py_tf_input_data_callback_data,
py_tf_classify_output_data_callback, py_tf_classify_output_data_callback,
&py_tf_classify_output_data_callback_data), &py_tf_classify_output_data_callback_data) != 0) {
py_tf_putchar_buffer - (PY_TF_PUTCHAR_BUFFER_LEN - py_tf_putchar_buffer_len)); // Note can't use MP_ERROR_TEXT here.
mp_raise_msg(&mp_type_OSError, (mp_rom_error_text_t)
py_tf_putchar_buffer - (PY_TF_PUTCHAR_BUFFER_LEN - py_tf_putchar_buffer_len));
}
py_tf_classification_obj_t *o = m_new_obj(py_tf_classification_obj_t); py_tf_classification_obj_t *o = m_new_obj(py_tf_classification_obj_t);
o->base.type = &py_tf_classification_type; o->base.type = &py_tf_classification_type;
@ -524,14 +530,17 @@ STATIC mp_obj_t py_tf_segment(uint n_args, const mp_obj_t *args, mp_map_t *kw_ar
py_tf_segment_output_data_callback_data_t py_tf_segment_output_data_callback_data; py_tf_segment_output_data_callback_data_t py_tf_segment_output_data_callback_data;
PY_ASSERT_FALSE_MSG(libtf_invoke(arg_model->model_data, if (libtf_invoke(arg_model->model_data,
tensor_arena, tensor_arena,
tensor_arena_size, tensor_arena_size,
py_tf_input_data_callback, py_tf_input_data_callback,
&py_tf_input_data_callback_data, &py_tf_input_data_callback_data,
py_tf_segment_output_data_callback, py_tf_segment_output_data_callback,
&py_tf_segment_output_data_callback_data), &py_tf_segment_output_data_callback_data) != 0) {
py_tf_putchar_buffer - (PY_TF_PUTCHAR_BUFFER_LEN - py_tf_putchar_buffer_len)); // Note can't use MP_ERROR_TEXT here.
mp_raise_msg(&mp_type_OSError, (mp_rom_error_text_t)
py_tf_putchar_buffer - (PY_TF_PUTCHAR_BUFFER_LEN - py_tf_putchar_buffer_len));
}
fb_alloc_free_till_mark(); fb_alloc_free_till_mark();

View File

@ -159,12 +159,12 @@ static mp_obj_t py_nina_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_m
mp_uint_t channel = args[3].u_int; mp_uint_t channel = args[3].u_int;
if (security != NINA_SEC_OPEN && security != NINA_SEC_WEP) { if (security != NINA_SEC_OPEN && security != NINA_SEC_WEP) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "AP mode supports WEP security only.")); mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("AP mode supports WEP security only."));
} }
// Initialize WiFi in AP mode. // Initialize WiFi in AP mode.
if (nina_start_ap(ssid, security, key, channel) != 0) { if (nina_start_ap(ssid, security, key, channel) != 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "failed to start in AP mode")); mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("failed to start in AP mode"));
} }
} }
return mp_const_none; return mp_const_none;

View File

@ -8,19 +8,18 @@
* *
* IMU Python module. * IMU Python module.
*/ */
#include "omv_boardconfig.h"
#if MICROPY_PY_IMU
#include "py/obj.h" #include "py/obj.h"
#include "py/nlr.h"
#include "py/mphal.h" #include "py/mphal.h"
#include "systick.h" #include "py/runtime.h"
#include "lsm6ds3tr_c_reg.h" #include "lsm6ds3tr_c_reg.h"
#include "omv_boardconfig.h"
#include "py_helper.h" #include "py_helper.h"
#include "py_imu.h" #include "py_imu.h"
#include STM32_HAL_H #include STM32_HAL_H
#if MICROPY_PY_IMU
typedef union { typedef union {
int16_t i16bit[3]; int16_t i16bit[3];
uint8_t u8bit[6]; uint8_t u8bit[6];
@ -77,7 +76,9 @@ STATIC bool test_not_ready()
STATIC void error_on_not_ready() STATIC void error_on_not_ready()
{ {
if (test_not_ready()) nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "IMU Not Ready!")); if (test_not_ready()) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("IMU Not Ready!"));
}
} }
STATIC mp_obj_t py_imu_tuple(float x, float y, float z) STATIC mp_obj_t py_imu_tuple(float x, float y, float z)

View File

@ -47,28 +47,36 @@ mp_obj_t lcd_touch_get_points()
mp_obj_t lcd_touch_get_point_flag(mp_obj_t index) mp_obj_t lcd_touch_get_point_flag(mp_obj_t index)
{ {
int i = mp_obj_get_int(index); int i = mp_obj_get_int(index);
if ((i < 0) || (NUM_TOUCH_POINTS <= i)) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Index out of bounds!")); if ((i < 0) || (NUM_TOUCH_POINTS <= i)) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Index out of bounds!"));
}
return mp_obj_new_int(lcd_touch_flag[i]); return mp_obj_new_int(lcd_touch_flag[i]);
} }
mp_obj_t lcd_touch_get_point_id(mp_obj_t index) mp_obj_t lcd_touch_get_point_id(mp_obj_t index)
{ {
int i = mp_obj_get_int(index); int i = mp_obj_get_int(index);
if ((i < 0) || (NUM_TOUCH_POINTS <= i)) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Index out of bounds!")); if ((i < 0) || (NUM_TOUCH_POINTS <= i)) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Index out of bounds!"));
}
return mp_obj_new_int(lcd_touch_id[i]); return mp_obj_new_int(lcd_touch_id[i]);
} }
mp_obj_t lcd_touch_get_point_x_position(mp_obj_t index) mp_obj_t lcd_touch_get_point_x_position(mp_obj_t index)
{ {
int i = mp_obj_get_int(index); int i = mp_obj_get_int(index);
if ((i < 0) || (NUM_TOUCH_POINTS <= i)) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Index out of bounds!")); if ((i < 0) || (NUM_TOUCH_POINTS <= i)) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Index out of bounds!"));
}
return mp_obj_new_int(lcd_touch_x_position[i]); return mp_obj_new_int(lcd_touch_x_position[i]);
} }
mp_obj_t lcd_touch_get_point_y_position(mp_obj_t index) mp_obj_t lcd_touch_get_point_y_position(mp_obj_t index)
{ {
int i = mp_obj_get_int(index); int i = mp_obj_get_int(index);
if ((i < 0) || (NUM_TOUCH_POINTS <= i)) nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Index out of bounds!")); if ((i < 0) || (NUM_TOUCH_POINTS <= i)) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Index out of bounds!"));
}
return mp_obj_new_int(lcd_touch_y_position[i]); return mp_obj_new_int(lcd_touch_y_position[i]);
} }
@ -119,7 +127,7 @@ mp_obj_t lcd_touch_update_touch_points()
} }
} }
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Failed to update the number of touch points!")); mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to update the number of touch points!"));
} }
STATIC mp_obj_t lcd_touch_extint_callback(mp_obj_t line) STATIC mp_obj_t lcd_touch_extint_callback(mp_obj_t line)
@ -178,7 +186,7 @@ void lcd_touch_init()
}), MP_MACHINE_I2C_FLAG_STOP) == 2) { }), MP_MACHINE_I2C_FLAG_STOP) == 2) {
extint_register((mp_obj_t) OMV_TOUCH_INT_PIN, GPIO_MODE_IT_FALLING, GPIO_PULLUP, (mp_obj_t) &lcd_touch_extint_callback_obj, true); extint_register((mp_obj_t) OMV_TOUCH_INT_PIN, GPIO_MODE_IT_FALLING, GPIO_PULLUP, (mp_obj_t) &lcd_touch_extint_callback_obj, true);
} else { } else {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Touch init failed!")); mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Touch init failed!"));
} }
} }

View File

@ -173,14 +173,16 @@ STATIC mp_obj_t py_micro_speech_listen(uint n_args, const mp_obj_t *args, mp_map
__enable_irq(); __enable_irq();
// Run model on updated spectrogram // Run model on updated spectrogram
PY_ASSERT_FALSE_MSG(libtf_invoke(arg_model->model_data, if (libtf_invoke(arg_model->model_data,
tensor_arena, tensor_arena,
tensor_arena_size, tensor_arena_size,
py_tf_input_callback, py_tf_input_callback,
spectrogram, spectrogram,
py_tf_output_callback, py_tf_output_callback,
previous_scores[results_count]), previous_scores[results_count]) != 0) {
py_tf_putchar_buffer - (PY_TF_PUTCHAR_BUFFER_LEN - py_tf_putchar_buffer_len)); mp_raise_msg(&mp_type_OSError, (mp_rom_error_text_t)
py_tf_putchar_buffer - (PY_TF_PUTCHAR_BUFFER_LEN - py_tf_putchar_buffer_len));
}
// If we have enough samples calculate average scores. // If we have enough samples calculate average scores.
if ((HAL_GetTick() - start) > (kAverageWindowSamples * kFeatureSliceDurationMs)) { if ((HAL_GetTick() - start) > (kAverageWindowSamples * kFeatureSliceDurationMs)) {

View File

@ -54,8 +54,8 @@ static mp_obj_t py_winc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp
winc_mode_t winc_mode = args[0].u_int; winc_mode_t winc_mode = args[0].u_int;
int error = winc_init(winc_mode); int error = winc_init(winc_mode);
if (error != 0) { if (error != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, mp_raise_msg_varg(&mp_type_OSError,
"Failed to initialize WINC1500 module: %s\n", winc_strerror(error))); MP_ERROR_TEXT("Failed to initialize WINC1500 module: %s\n"), winc_strerror(error));
} }
switch (winc_mode) { switch (winc_mode) {
@ -76,7 +76,7 @@ static mp_obj_t py_winc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp
} }
break; break;
default: default:
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "WiFi mode is not supported!")); mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("WiFi mode is not supported!"));
} }
return (mp_obj_t)&winc_obj; return (mp_obj_t)&winc_obj;
@ -99,7 +99,7 @@ static mp_obj_t py_winc_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_m
const char *ssid = mp_obj_str_get_str(args[0].u_obj); const char *ssid = mp_obj_str_get_str(args[0].u_obj);
if (strlen(ssid) == 0) { if (strlen(ssid) == 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "SSID can't be empty!")); mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("SSID can't be empty!"));
} }
// get key and sec // get key and sec
@ -112,13 +112,13 @@ static mp_obj_t py_winc_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_m
} }
if (security != M2M_WIFI_SEC_OPEN && strlen(key) == 0) { if (security != M2M_WIFI_SEC_OPEN && strlen(key) == 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Key can't be empty!")); mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Key can't be empty!"));
} }
// connect to AP // connect to AP
if (winc_connect(ssid, security, key, M2M_WIFI_CH_ALL) != 0) { if (winc_connect(ssid, security, key, M2M_WIFI_CH_ALL) != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, mp_raise_msg_varg(&mp_type_OSError,
"could not connect to ssid=%s, sec=%d, key=%s\n", ssid, security, key)); MP_ERROR_TEXT("could not connect to ssid=%s, sec=%d, key=%s\n"), ssid, security, key);
} }
return mp_const_none; return mp_const_none;
@ -146,11 +146,11 @@ static mp_obj_t py_winc_start_ap(mp_uint_t n_args, const mp_obj_t *pos_args, mp_
mp_uint_t security = args[2].u_int; mp_uint_t security = args[2].u_int;
if (security != M2M_WIFI_SEC_OPEN && security != M2M_WIFI_SEC_WEP) { if (security != M2M_WIFI_SEC_OPEN && security != M2M_WIFI_SEC_WEP) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "AP mode supports WEP security only.")); mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("AP mode supports WEP security only."));
} }
if (security == M2M_WIFI_SEC_WEP && args[1].u_obj == MP_OBJ_NULL) { if (security == M2M_WIFI_SEC_WEP && args[1].u_obj == MP_OBJ_NULL) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Missing WEP key!")); mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Missing WEP key!"));
} }
if (security != M2M_WIFI_SEC_OPEN) { if (security != M2M_WIFI_SEC_OPEN) {
@ -162,7 +162,7 @@ static mp_obj_t py_winc_start_ap(mp_uint_t n_args, const mp_obj_t *pos_args, mp_
// Initialize WiFi in AP mode. // Initialize WiFi in AP mode.
if (winc_start_ap(ssid, security, key, channel) != 0) { if (winc_start_ap(ssid, security, key, channel) != 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "failed to start in AP mode")); mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("failed to start in AP mode"));
} }
printf("AP mode started. You can connect to %s.\r\n", ssid); printf("AP mode started. You can connect to %s.\r\n", ssid);
@ -321,7 +321,7 @@ static mp_obj_t py_winc_fw_dump(mp_obj_t self_in, mp_obj_t path_in)
printf("Dumping flash...\n"); printf("Dumping flash...\n");
const char *path = mp_obj_str_get_str(path_in); const char *path = mp_obj_str_get_str(path_in);
if (winc_flash_dump(path) != 0) { if (winc_flash_dump(path) != 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Failed to dump flash!")); mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to dump flash!"));
} }
return mp_const_none; return mp_const_none;
@ -334,25 +334,25 @@ static mp_obj_t py_winc_fw_update(mp_obj_t self_in, mp_obj_t path_in)
const char *path = mp_obj_str_get_str(path_in); const char *path = mp_obj_str_get_str(path_in);
if ((res = f_stat_helper(path, &fno)) != FR_OK) { if ((res = f_stat_helper(path, &fno)) != FR_OK) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res))); mp_raise_msg(&mp_type_OSError, (mp_rom_error_text_t) ffs_strerror(res));
} }
// Erase the WINC1500 flash. // Erase the WINC1500 flash.
printf("Erasing flash...\n"); printf("Erasing flash...\n");
if (winc_flash_erase() != 0) { if (winc_flash_erase() != 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Failed to erase the flash!")); mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to erase the flash!"));
} }
// Program the firmware on the WINC1500 flash. // Program the firmware on the WINC1500 flash.
printf("Programming firmware image...\n"); printf("Programming firmware image...\n");
if (winc_flash_write(path) != 0) { if (winc_flash_write(path) != 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Failed to write the firmware!")); mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to write the firmware!"));
} }
// Verify the firmware on the WINC1500 flash. // Verify the firmware on the WINC1500 flash.
printf("Verifying firmware image...\n"); printf("Verifying firmware image...\n");
if (winc_flash_verify(path) != 0) { if (winc_flash_verify(path) != 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Failed to verify the firmware!")); mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to verify the firmware!"));
} }
printf("All task completed successfully.\n"); printf("All task completed successfully.\n");