diff --git a/src/omv/sensor.c b/src/omv/sensor.c index cf1d3fb88..01b9e6435 100644 --- a/src/omv/sensor.c +++ b/src/omv/sensor.c @@ -483,6 +483,14 @@ int sensor_set_framerate(enum sensor_framerate framerate) return 0; } +int sensor_set_contrast(int level) +{ + if (sensor.set_contrast != NULL) { + return sensor.set_contrast(level); + } + return -1; +} + int sensor_set_brightness(int level) { if (sensor.set_brightness != NULL) { @@ -491,10 +499,10 @@ int sensor_set_brightness(int level) return -1; } -int sensor_set_contrast(int level) +int sensor_set_saturation(int level) { - if (sensor.set_contrast != NULL) { - return sensor.set_contrast(level); + if (sensor.set_saturation != NULL) { + return sensor.set_saturation(level); } return -1; } diff --git a/src/omv/sensor.h b/src/omv/sensor.h index e535a82f3..477715b79 100644 --- a/src/omv/sensor.h +++ b/src/omv/sensor.h @@ -44,24 +44,11 @@ enum sensor_gainceiling { GAINCEILING_128X, }; -enum sensor_command { - CMD_RESET_SENSOR=1, - CMD_SET_PIXFORMAT, - CMD_SET_FRAMERATE, - CMD_SET_FRAMESIZE, - CMD_SET_BRIGHTNESS, - CMD_SET_GAINCEILING, - CMD_WRITE_REGISTER, - CMD_READ_REGISTER, - CMD_SNAPSHOT, - CMD_COLOR_TRACK, - CMD_MOTION_DETECTION, - CMD_FACE_DETECTION, -}; - -enum sensor_result { - CMD_ACK =0x01, - CMD_NACK =0x02, +enum sensor_attr { + ATTR_CONTRAST=0, + ATTR_BRIGHTNESS, + ATTR_SATURATION, + ATTR_GAINCEILING, }; enum reset_polarity { @@ -87,8 +74,9 @@ struct sensor_dev { int (*set_pixformat) (enum sensor_pixformat pixformat); int (*set_framesize) (enum sensor_framesize framesize); int (*set_framerate) (enum sensor_framerate framerate); + int (*set_contrast) (int level); int (*set_brightness) (int level); - int (*set_contrast) (int level); + int (*set_saturation) (int level); int (*set_exposure) (int exposure); int (*set_gainceiling) (enum sensor_gainceiling gainceiling); }; @@ -160,6 +148,14 @@ int sensor_set_framesize(enum sensor_framesize framesize); * @return On success, 0 is returned. If the operation not supported by the sensor, -1 is returned. */ int sensor_set_framerate(enum sensor_framerate framerate); +/** + * Set the sensor contrast level. + * + * @param sensor A pointer to the sensor device handle. + * @param level The new contrast level allowed values from -3 to +3. + * @return On success, 0 is returned. If the operation not supported by the sensor, -1 is returned. + */ +int sensor_set_contrast(int level); /** * Set the sensor brightness level. * @@ -169,13 +165,13 @@ int sensor_set_framerate(enum sensor_framerate framerate); */ int sensor_set_brightness(int level); /** - * Set the sensor contrast level. + * Set the sensor saturation level. * * @param sensor A pointer to the sensor device handle. - * @param level The new contrast level allowed values from -3 to +3. + * @param level The new saturation level allowed values from -3 to +3. * @return On success, 0 is returned. If the operation not supported by the sensor, -1 is returned. */ -int sensor_set_contrast(int level); +int sensor_set_saturation(int level); /** * Set the sensor exposure level. This function has no * effect when AEC (Automatic Exposure Control) is enabled. diff --git a/usr/openmv-ide.glade b/usr/openmv-ide.glade index 62449a80a..cddd36de4 100644 --- a/usr/openmv-ide.glade +++ b/usr/openmv-ide.glade @@ -4,6 +4,20 @@ + + -2 + 2 + 1 + 1 + + + + -2 + 2 + 1 + 1 + + True False @@ -27,6 +41,18 @@ + + 6 + 1 + + + + -2 + 2 + 1 + 1 + + False 5 @@ -467,33 +493,347 @@ True False - True - + True False + 2 + 0 + 0 + etched-out - - 200 - 200 + True False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_STRUCTURE_MASK - - - + 5 + + + 200 + 200 + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_STRUCTURE_MASK + + + + + + + + + + True + False + 0 + <b>Framebuffer</b> + True + + + + + True + True + 0 + + + + + True + False + 2 + 0 + 0 + etched-out + + + True + False + + + True + False + 4 + 2 + 12 + + + True + False + 0 + Contrast + + + GTK_FILL + GTK_FILL + + + + + True + False + 0 + Brightness + + + 1 + 2 + GTK_FILL + GTK_FILL + + + + + True + False + 0 + Saturation + + + 2 + 3 + GTK_FILL + GTK_FILL + + + + + True + True + delayed + contrast_adjust + True + 0 + 0 + right + + + 1 + 2 + + + + + True + True + delayed + brightness_adjust + 0 + 0 + right + + + 1 + 2 + 1 + 2 + + + + + True + True + delayed + saturation_adjust + off + off + 0 + 0 + right + + + 1 + 2 + 2 + 3 + + + + + True + False + 0 + Gain Ceiling + + + 3 + 4 + GTK_FILL + GTK_FILL + + + + + True + False + + + True + True + delayed + gainceiling_adjust + off + off + 0 + 0 + right + + + True + True + 0 + + + + + True + False + True + + + True + False + 0 + 2x + + + + + + True + True + 0 + + + + + True + False + 0 + 4x + + + + + + True + True + 1 + + + + + True + False + 0 + 8x + + + + + + True + True + 2 + + + + + True + False + 0 + 16x + + + + + + True + True + 3 + + + + + True + False + 0 + 32x + + + + + + True + True + 4 + + + + + True + False + 0 + 64x + + + + + + True + True + 5 + + + + + True + False + 0 + 128x + + + + + + True + True + 6 + + + + + False + True + 1 + + + + + 1 + 2 + 3 + 4 + + + + + + + + + + True + False + 0 + <b>Controls</b> + True - - True - True - 0 - False - False - 0 + True + 1 @@ -526,7 +866,7 @@ False - False + True diff --git a/usr/openmv-ide.py b/usr/openmv-ide.py index 6bd8006d0..b7d00bba9 100755 --- a/usr/openmv-ide.py +++ b/usr/openmv-ide.py @@ -77,6 +77,11 @@ class OMVGtk: self.selection_started=False self.sel_ended=False + # set control scales attributes + self.builder.get_object("contrast_adjust").attr= openmv.ATTR_CONTRAST + self.builder.get_object("brightness_adjust").attr= openmv.ATTR_BRIGHTNESS + self.builder.get_object("saturation_adjust").attr= openmv.ATTR_SATURATION + self.builder.get_object("gainceiling_adjust").attr= openmv.ATTR_GAINCEILING #connect signals signals = { @@ -90,6 +95,7 @@ class OMVGtk: "on_save_file" : self.save_file, "on_save_file_as" : self.save_file_as, "on_save_template_activate" : self.save_template, + "on_ctrl_scale_value_changed" : self.on_ctrl_scale_value_changed, } self.builder.connect_signals(signals) @@ -153,6 +159,10 @@ class OMVGtk: # reschedule callback gobject.idle_add(omvgtk.update_drawing); + + def on_ctrl_scale_value_changed(self, adjust): + openmv.set_attr(adjust.attr, int(adjust.value)) + def open_file(self, widget): dialog = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) diff --git a/usr/openmv.py b/usr/openmv.py index 36d47761d..f77945cb8 100755 --- a/usr/openmv.py +++ b/usr/openmv.py @@ -26,6 +26,13 @@ __USBDBG_READ_SCRIPT=4 __USBDBG_WRITE_SCRIPT=5 __USBDBG_STOP_SCRIPT=6 __USBDBG_SAVE_TEMPLATE=7 +__USBDBG_SET_ATTR=8 +__USBDBG_GET_ATTR=9 + +ATTR_CONTRAST=0 +ATTR_BRIGHTNESS=1 +ATTR_SATURATION=2 +ATTR_GAINCEILING=3 def init(): global __dev @@ -95,6 +102,13 @@ def save_template(x, y, w, h, name): __dev.ctrl_transfer(0x41, __USBDBG_SAVE_TEMPLATE, len(buf), __INTERFACE, None, __TIMEOUT) __dev.write(__OUT_EP, buf, __INTERFACE, __TIMEOUT) +def set_attr(attr, value): + buf = struct.unpack(">H", struct.pack("bb", attr, value))[0] + __dev.ctrl_transfer(0x41, __USBDBG_SET_ATTR, buf, __INTERFACE, None, __TIMEOUT) + +def get_attr(attr): + return 0 + if __name__ == '__main__': if len(sys.argv)!= 2: print 'usage: openmv.py