Add sensor controls

This commit is contained in:
iabdalkader 2014-06-21 09:41:27 +02:00
parent aaa51cfdf6
commit b5587adc65
5 changed files with 410 additions and 42 deletions

View File

@ -483,6 +483,14 @@ int sensor_set_framerate(enum sensor_framerate framerate)
return 0; 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) int sensor_set_brightness(int level)
{ {
if (sensor.set_brightness != NULL) { if (sensor.set_brightness != NULL) {
@ -491,10 +499,10 @@ int sensor_set_brightness(int level)
return -1; return -1;
} }
int sensor_set_contrast(int level) int sensor_set_saturation(int level)
{ {
if (sensor.set_contrast != NULL) { if (sensor.set_saturation != NULL) {
return sensor.set_contrast(level); return sensor.set_saturation(level);
} }
return -1; return -1;
} }

View File

@ -44,24 +44,11 @@ enum sensor_gainceiling {
GAINCEILING_128X, GAINCEILING_128X,
}; };
enum sensor_command { enum sensor_attr {
CMD_RESET_SENSOR=1, ATTR_CONTRAST=0,
CMD_SET_PIXFORMAT, ATTR_BRIGHTNESS,
CMD_SET_FRAMERATE, ATTR_SATURATION,
CMD_SET_FRAMESIZE, ATTR_GAINCEILING,
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 reset_polarity { enum reset_polarity {
@ -87,8 +74,9 @@ struct sensor_dev {
int (*set_pixformat) (enum sensor_pixformat pixformat); int (*set_pixformat) (enum sensor_pixformat pixformat);
int (*set_framesize) (enum sensor_framesize framesize); int (*set_framesize) (enum sensor_framesize framesize);
int (*set_framerate) (enum sensor_framerate framerate); int (*set_framerate) (enum sensor_framerate framerate);
int (*set_brightness) (int level);
int (*set_contrast) (int level); int (*set_contrast) (int level);
int (*set_brightness) (int level);
int (*set_saturation) (int level);
int (*set_exposure) (int exposure); int (*set_exposure) (int exposure);
int (*set_gainceiling) (enum sensor_gainceiling gainceiling); 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. * @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); 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. * Set the sensor brightness level.
* *
@ -169,13 +165,13 @@ int sensor_set_framerate(enum sensor_framerate framerate);
*/ */
int sensor_set_brightness(int level); 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 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. * @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 * Set the sensor exposure level. This function has no
* effect when AEC (Automatic Exposure Control) is enabled. * effect when AEC (Automatic Exposure Control) is enabled.

View File

@ -4,6 +4,20 @@
<!-- interface-requires gtksourceview 0.0 --> <!-- interface-requires gtksourceview 0.0 -->
<!-- interface-requires vte 0.0 --> <!-- interface-requires vte 0.0 -->
<!-- interface-naming-policy project-wide --> <!-- interface-naming-policy project-wide -->
<object class="GtkAdjustment" id="brightness_adjust">
<property name="lower">-2</property>
<property name="upper">2</property>
<property name="step_increment">1</property>
<property name="page_increment">1</property>
<signal name="value-changed" handler="on_ctrl_scale_value_changed" swapped="no"/>
</object>
<object class="GtkAdjustment" id="contrast_adjust">
<property name="lower">-2</property>
<property name="upper">2</property>
<property name="step_increment">1</property>
<property name="page_increment">1</property>
<signal name="value-changed" handler="on_ctrl_scale_value_changed" swapped="no"/>
</object>
<object class="GtkMenu" id="da_menu"> <object class="GtkMenu" id="da_menu">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -27,6 +41,18 @@
</object> </object>
</child> </child>
</object> </object>
<object class="GtkAdjustment" id="gainceiling_adjust">
<property name="upper">6</property>
<property name="step_increment">1</property>
<signal name="value-changed" handler="on_ctrl_scale_value_changed" swapped="no"/>
</object>
<object class="GtkAdjustment" id="saturation_adjust">
<property name="lower">-2</property>
<property name="upper">2</property>
<property name="step_increment">1</property>
<property name="page_increment">1</property>
<signal name="value-changed" handler="on_ctrl_scale_value_changed" swapped="no"/>
</object>
<object class="GtkDialog" id="save_template_dialog"> <object class="GtkDialog" id="save_template_dialog">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="border_width">5</property> <property name="border_width">5</property>
@ -467,11 +493,19 @@
<object class="GtkVBox" id="vbox2"> <object class="GtkVBox" id="vbox2">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="homogeneous">True</property>
<child> <child>
<object class="GtkHBox" id="hbox1"> <object class="GtkFrame" id="frame1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="border_width">2</property>
<property name="label_xalign">0</property>
<property name="label_yalign">0</property>
<property name="shadow_type">etched-out</property>
<child>
<object class="GtkAlignment" id="alignment2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<child> <child>
<object class="GtkDrawingArea" id="drawingarea"> <object class="GtkDrawingArea" id="drawingarea">
<property name="width_request">200</property> <property name="width_request">200</property>
@ -483,17 +517,323 @@
<signal name="button-release-event" handler="on_button_release" swapped="no"/> <signal name="button-release-event" handler="on_button_release" swapped="no"/>
<signal name="motion-notify-event" handler="on_motion_notify" swapped="no"/> <signal name="motion-notify-event" handler="on_motion_notify" swapped="no"/>
</object> </object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">&lt;b&gt;Framebuffer&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkFrame" id="frame2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">2</property>
<property name="label_xalign">0</property>
<property name="label_yalign">0</property>
<property name="shadow_type">etched-out</property>
<child>
<object class="GtkAlignment" id="alignment3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_rows">4</property>
<property name="n_columns">2</property>
<property name="column_spacing">12</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Contrast</property>
</object>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Brightness</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Saturation</property>
</object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkHScale" id="hscale1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="update_policy">delayed</property>
<property name="adjustment">contrast_adjust</property>
<property name="show_fill_level">True</property>
<property name="round_digits">0</property>
<property name="digits">0</property>
<property name="value_pos">right</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<object class="GtkHScale" id="hscale2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="update_policy">delayed</property>
<property name="adjustment">brightness_adjust</property>
<property name="round_digits">0</property>
<property name="digits">0</property>
<property name="value_pos">right</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="GtkHScale" id="hscale3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="update_policy">delayed</property>
<property name="adjustment">saturation_adjust</property>
<property name="lower_stepper_sensitivity">off</property>
<property name="upper_stepper_sensitivity">off</property>
<property name="round_digits">0</property>
<property name="digits">0</property>
<property name="value_pos">right</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Gain Ceiling</property>
</object>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbox3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkHScale" id="hscale5">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="update_policy">delayed</property>
<property name="adjustment">gainceiling_adjust</property>
<property name="lower_stepper_sensitivity">off</property>
<property name="upper_stepper_sensitivity">off</property>
<property name="round_digits">0</property>
<property name="digits">0</property>
<property name="value_pos">right</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkLabel" id="label7">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">2x</property>
<attributes>
<attribute name="foreground" value="#b7bdb7bdb7bd"/>
</attributes>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label8">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">4x</property>
<attributes>
<attribute name="foreground" value="#b7bdb7bdb7bd"/>
</attributes>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label9">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">8x</property>
<attributes>
<attribute name="foreground" value="#b7bdb7bdb7bd"/>
</attributes>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label10">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">16x</property>
<attributes>
<attribute name="foreground" value="#b7bdb7bdb7bd"/>
</attributes>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label11">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">32x</property>
<attributes>
<attribute name="foreground" value="#b7bdb7bdb7bd"/>
</attributes>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label12">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">64x</property>
<attributes>
<attribute name="foreground" value="#b7bdb7bdb7bd"/>
</attributes>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label13">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">128x</property>
<attributes>
<attribute name="foreground" value="#b7bdb7bdb7bd"/>
</attributes>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">6</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">True</property>
<property name="position">0</property> <property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="y_options"></property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">&lt;b&gt;Controls&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing> </packing>
</child> </child>
</object> </object>
@ -526,7 +866,7 @@
</object> </object>
<packing> <packing>
<property name="resize">False</property> <property name="resize">False</property>
<property name="shrink">False</property> <property name="shrink">True</property>
</packing> </packing>
</child> </child>
</object> </object>

View File

@ -77,6 +77,11 @@ class OMVGtk:
self.selection_started=False self.selection_started=False
self.sel_ended=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 #connect signals
signals = { signals = {
@ -90,6 +95,7 @@ class OMVGtk:
"on_save_file" : self.save_file, "on_save_file" : self.save_file,
"on_save_file_as" : self.save_file_as, "on_save_file_as" : self.save_file_as,
"on_save_template_activate" : self.save_template, "on_save_template_activate" : self.save_template,
"on_ctrl_scale_value_changed" : self.on_ctrl_scale_value_changed,
} }
self.builder.connect_signals(signals) self.builder.connect_signals(signals)
@ -153,6 +159,10 @@ class OMVGtk:
# reschedule callback # reschedule callback
gobject.idle_add(omvgtk.update_drawing); 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): def open_file(self, widget):
dialog = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_OPEN, dialog = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))

View File

@ -26,6 +26,13 @@ __USBDBG_READ_SCRIPT=4
__USBDBG_WRITE_SCRIPT=5 __USBDBG_WRITE_SCRIPT=5
__USBDBG_STOP_SCRIPT=6 __USBDBG_STOP_SCRIPT=6
__USBDBG_SAVE_TEMPLATE=7 __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(): def init():
global __dev 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.ctrl_transfer(0x41, __USBDBG_SAVE_TEMPLATE, len(buf), __INTERFACE, None, __TIMEOUT)
__dev.write(__OUT_EP, buf, __INTERFACE, __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 __name__ == '__main__':
if len(sys.argv)!= 2: if len(sys.argv)!= 2:
print 'usage: openmv.py <script>' print 'usage: openmv.py <script>'