diff --git a/src/omv/mt9v034.c b/src/omv/mt9v034.c index e42cf5f14..ced4ab26c 100644 --- a/src/omv/mt9v034.c +++ b/src/omv/mt9v034.c @@ -272,12 +272,20 @@ static int set_auto_whitebal(sensor_t *sensor, int enable, int r_gain, int g_gai static int set_hmirror(sensor_t *sensor, int enable) { - return 0; + uint16_t read_mode; + int ret = cambus_readw(sensor->slv_addr, MT9V034_READ_MODE, &read_mode); + ret |= cambus_writew(sensor->slv_addr, MT9V034_ANALOG_GAIN_CONTROL, (read_mode & (~MT9V034_READ_MODE_COL_FLIP)) | ((enable != 0) ? MT9V034_READ_MODE_COL_FLIP : 0)); + + return ret; } static int set_vflip(sensor_t *sensor, int enable) { - return 0; + uint16_t read_mode; + int ret = cambus_readw(sensor->slv_addr, MT9V034_READ_MODE, &read_mode); + ret |= cambus_writew(sensor->slv_addr, MT9V034_ANALOG_GAIN_CONTROL, (read_mode & (~MT9V034_READ_MODE_ROW_FLIP)) | ((enable != 0) ? MT9V034_READ_MODE_ROW_FLIP : 0)); + + return ret; } static int set_special_effect(sensor_t *sensor, sde_t sde) diff --git a/src/omv/ov2640.c b/src/omv/ov2640.c index 6b17fec41..7c3bb8ec0 100644 --- a/src/omv/ov2640.c +++ b/src/omv/ov2640.c @@ -761,14 +761,11 @@ static int set_auto_whitebal(sensor_t *sensor, int enable, int r_gain, int g_gai return cambus_writeb(sensor->slv_addr, CTRL1, reg) | ret; } - static int set_hmirror(sensor_t *sensor, int enable) { uint8_t reg; - /* Switch to SENSOR register bank */ - int ret = cambus_writeb(sensor->slv_addr, BANK_SEL, BANK_SEL_SENSOR); - - /* Update REG04 */ + int ret = cambus_readb(sensor->slv_addr, BANK_SEL, ®); + ret |= cambus_writeb(sensor->slv_addr, BANK_SEL, reg | BANK_SEL_SENSOR); ret |= cambus_readb(sensor->slv_addr, REG04, ®); if (enable) { @@ -777,16 +774,16 @@ static int set_hmirror(sensor_t *sensor, int enable) reg &= ~REG04_HFLIP_IMG; } - return cambus_writeb(sensor->slv_addr, REG04, reg) | ret; + ret |= cambus_writeb(sensor->slv_addr, REG04, reg); + + return ret; } static int set_vflip(sensor_t *sensor, int enable) { uint8_t reg; - /* Switch to SENSOR register bank */ - int ret = cambus_writeb(sensor->slv_addr, BANK_SEL, BANK_SEL_SENSOR); - - /* Update REG04 */ + int ret = cambus_readb(sensor->slv_addr, BANK_SEL, ®); + ret |= cambus_writeb(sensor->slv_addr, BANK_SEL, reg | BANK_SEL_SENSOR); ret |= cambus_readb(sensor->slv_addr, REG04, ®); if (enable) { @@ -795,7 +792,9 @@ static int set_vflip(sensor_t *sensor, int enable) reg &= ~REG04_VFLIP_IMG; } - return cambus_writeb(sensor->slv_addr, REG04, reg) | ret; + ret |= cambus_writeb(sensor->slv_addr, REG04, reg); + + return ret; } int ov2640_init(sensor_t *sensor) diff --git a/src/omv/ov7725.c b/src/omv/ov7725.c index e068d9b4d..941536ea3 100644 --- a/src/omv/ov7725.c +++ b/src/omv/ov7725.c @@ -500,22 +500,18 @@ static int set_hmirror(sensor_t *sensor, int enable) { uint8_t reg; int ret = cambus_readb(sensor->slv_addr, COM3, ®); - // Set mirror on/off - reg = COM3_SET_MIRROR(reg, enable); + ret |= cambus_writeb(sensor->slv_addr, COM3, COM3_SET_MIRROR(reg, enable)) ; - // Write back register COM3 - return cambus_writeb(sensor->slv_addr, COM3, reg) | ret; + return ret; } static int set_vflip(sensor_t *sensor, int enable) { uint8_t reg; int ret = cambus_readb(sensor->slv_addr, COM3, ®); - // Set mirror on/off - reg = COM3_SET_FLIP(reg, enable); + ret |= cambus_writeb(sensor->slv_addr, COM3, COM3_SET_FLIP(reg, enable)); - // Write back register COM3 - return cambus_writeb(sensor->slv_addr, COM3, reg) | ret; + return ret; } static int set_special_effect(sensor_t *sensor, sde_t sde) diff --git a/src/omv/ov9650.c b/src/omv/ov9650.c index 8e7298593..507bc057a 100644 --- a/src/omv/ov9650.c +++ b/src/omv/ov9650.c @@ -460,23 +460,19 @@ static int set_auto_whitebal(sensor_t *sensor, int enable, int r_gain, int g_gai static int set_hmirror(sensor_t *sensor, int enable) { uint8_t val; - cambus_readb(sensor->slv_addr, REG_MVFP, &val); + int ret = cambus_readb(sensor->slv_addr, REG_MVFP, &val); + ret |= cambus_writeb(sensor->slv_addr, REG_MVFP, enable ? (val | REG_MVFP_HMIRROR) : (val & (~REG_MVFP_HMIRROR))); - cambus_writeb(sensor->slv_addr, REG_MVFP, - enable ? (val | REG_MVFP_HMIRROR) : (val & ~REG_MVFP_HMIRROR)); - - return 0; + return ret; } static int set_vflip(sensor_t *sensor, int enable) { uint8_t val; - cambus_readb(sensor->slv_addr, REG_MVFP, &val); + int ret = cambus_readb(sensor->slv_addr, REG_MVFP, &val); + ret |= cambus_writeb(sensor->slv_addr, REG_MVFP, enable ? (val | REG_MVFP_VFLIP) : (val & (~REG_MVFP_VFLIP))); - cambus_writeb(sensor->slv_addr, REG_MVFP, - enable ? (val | REG_MVFP_VFLIP) : (val & ~REG_MVFP_VFLIP)); - - return 0; + return ret; } int ov9650_init(sensor_t *sensor) diff --git a/src/omv/py/py_sensor.c b/src/omv/py/py_sensor.c index 639f981d7..3b97db31e 100644 --- a/src/omv/py/py_sensor.c +++ b/src/omv/py/py_sensor.c @@ -388,16 +388,16 @@ static mp_obj_t py_sensor_set_auto_whitebal(uint n_args, const mp_obj_t *args, m static mp_obj_t py_sensor_set_hmirror(mp_obj_t enable) { if (sensor_set_hmirror(mp_obj_is_true(enable)) != 0) { - return mp_const_false; + nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!")); } - return mp_const_true; + return mp_const_none; } static mp_obj_t py_sensor_set_vflip(mp_obj_t enable) { if (sensor_set_vflip(mp_obj_is_true(enable)) != 0) { - return mp_const_false; + nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!")); } - return mp_const_true; + return mp_const_none; } static mp_obj_t py_sensor_set_special_effect(mp_obj_t sde) { diff --git a/usr/examples/02-Board-Control/sensor_exposure_control.py b/usr/examples/21-Sensor-Control/sensor_exposure_control.py similarity index 97% rename from usr/examples/02-Board-Control/sensor_exposure_control.py rename to usr/examples/21-Sensor-Control/sensor_exposure_control.py index 08a63ceaa..edc994c44 100644 --- a/usr/examples/02-Board-Control/sensor_exposure_control.py +++ b/usr/examples/21-Sensor-Control/sensor_exposure_control.py @@ -35,6 +35,8 @@ clock = time.clock() # Create a clock object to track the FPS. # that you put in place... sensor.set_auto_gain(False) sensor.set_auto_whitebal(False) +# Need to let the above settings get in... +sensor.skip_frames(time = 500) current_exposure_time_in_microseconds = sensor.get_exposure_us() print("Current Exposure == %d" % current_exposure_time_in_microseconds) diff --git a/usr/examples/21-Sensor-Control/sensor_horizontal_mirror.py b/usr/examples/21-Sensor-Control/sensor_horizontal_mirror.py new file mode 100644 index 000000000..467b46286 --- /dev/null +++ b/usr/examples/21-Sensor-Control/sensor_horizontal_mirror.py @@ -0,0 +1,21 @@ +# Sensor Horizontal Mirror Example +# +# This example shows off horizontally mirroring the image in hardware +# from the camera sensor. + +import sensor, image, time + +sensor.reset() # Reset and initialize the sensor. +sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE) +sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240) +sensor.skip_frames(time = 2000) # Wait for settings take effect. +clock = time.clock() # Create a clock object to track the FPS. + +# Change this to False to undo the mirror. +sensor.set_hmirror(True) + +while(True): + clock.tick() # Update the FPS clock. + img = sensor.snapshot() # Take a picture and return the image. + print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected + # to the IDE. The FPS should increase once disconnected. diff --git a/usr/examples/21-Sensor-Control/sensor_vertical_flip.py b/usr/examples/21-Sensor-Control/sensor_vertical_flip.py new file mode 100644 index 000000000..0470f27bf --- /dev/null +++ b/usr/examples/21-Sensor-Control/sensor_vertical_flip.py @@ -0,0 +1,21 @@ +# Sensor Vertical Flip Example +# +# This example shows off vertically flipping the image in hardware +# from the camera sensor. + +import sensor, image, time + +sensor.reset() # Reset and initialize the sensor. +sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE) +sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240) +sensor.skip_frames(time = 2000) # Wait for settings take effect. +clock = time.clock() # Create a clock object to track the FPS. + +# Change this to False to undo the flip. +sensor.set_vflip(True) + +while(True): + clock.tick() # Update the FPS clock. + img = sensor.snapshot() # Take a picture and return the image. + print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected + # to the IDE. The FPS should increase once disconnected. diff --git a/usr/examples/02-Board-Control/sesnor_gain_control.py b/usr/examples/21-Sensor-Control/sesnor_gain_control.py similarity index 97% rename from usr/examples/02-Board-Control/sesnor_gain_control.py rename to usr/examples/21-Sensor-Control/sesnor_gain_control.py index 63884fca4..ac42e0e87 100644 --- a/usr/examples/02-Board-Control/sesnor_gain_control.py +++ b/usr/examples/21-Sensor-Control/sesnor_gain_control.py @@ -18,7 +18,7 @@ import sensor, image, time # Change this value to adjust the gain. Try 10.0/0/0.1/etc. -GAIN_SCALE = 1.00 +GAIN_SCALE = 1.0 sensor.reset() # Reset and initialize the sensor. sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE) @@ -35,6 +35,8 @@ clock = time.clock() # Create a clock object to track the FPS. # that you put in place... sensor.set_auto_exposure(False) sensor.set_auto_whitebal(False) +# Need to let the above settings get in... +sensor.skip_frames(time = 500) current_gain_in_decibels = sensor.get_gain_db() print("Current Gain == %f db" % current_gain_in_decibels)