Go to the documentation of this file.00001
00002 #ifndef vidl_v4l2_control_h_
00003 #define vidl_v4l2_control_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <vcl_string.h>
00015 #include <vcl_vector.h>
00016
00017 extern "C" {
00018
00019 #include <sys/time.h>
00020 #include <linux/videodev2.h>
00021 };
00022
00023
00024 class vidl_v4l2_control
00025 {
00026 protected:
00027 int fd;
00028 struct v4l2_queryctrl ctrl_;
00029 vidl_v4l2_control(const v4l2_queryctrl& ctr, int f): fd(f), ctrl_(ctr) {}
00030 void set_value(int v) const;
00031 int get_value() const;
00032 public:
00033 virtual ~vidl_v4l2_control() {}
00034
00035
00036
00037
00038 static vidl_v4l2_control * new_control(const v4l2_queryctrl& ctr, int f);
00039
00040
00041 v4l2_ctrl_type type() const { return ctrl_.type; }
00042
00043
00044 vcl_string name() const { return (const char *) ctrl_.name; }
00045
00046 virtual vcl_string description() const= 0;
00047
00048
00049 int id() const { return ctrl_.id; }
00050
00051 bool read_only() const
00052 {
00053 #ifdef V4L2_CTRL_FLAG_READ_ONLY
00054 return ctrl_.flags & V4L2_CTRL_FLAG_READ_ONLY;
00055 #else
00056 return false;
00057 #endif
00058 }
00059
00060 bool affect_other_controls() const
00061 {
00062 #ifdef V4L2_CTRL_FLAG_UPDATE
00063 return ctrl_.flags & V4L2_CTRL_FLAG_UPDATE;
00064 #else
00065 return false;
00066 #endif
00067 }
00068
00069
00070 virtual void reset() const {}
00071 };
00072
00073
00074 class vidl_v4l2_control_integer: public vidl_v4l2_control
00075 {
00076 public:
00077 vidl_v4l2_control_integer(const v4l2_queryctrl& ctr, int f): vidl_v4l2_control(ctr,f) {}
00078
00079 int minimum() const { return ctrl_.minimum; }
00080
00081 int maximum() const { return ctrl_.maximum; }
00082
00083
00084 int step() const { return ctrl_.step; }
00085
00086 int default_value() const { return ctrl_.default_value; }
00087
00088
00089 void set(int value) const;
00090
00091
00092 void set_100 ( int value) const;
00093
00094
00095 int get() const { return get_value(); }
00096
00097
00098 int get_100() const { return (get_value()-ctrl_.minimum)*100/(ctrl_.maximum-ctrl_.minimum); }
00099
00100 virtual vcl_string description() const;
00101
00102 virtual void reset() const { set(default_value()); }
00103 };
00104
00105
00106 class vidl_v4l2_control_menu: public vidl_v4l2_control
00107 {
00108 vcl_vector<vcl_string> items;
00109 public:
00110 vidl_v4l2_control_menu(const v4l2_queryctrl& ctr, int f);
00111
00112
00113 unsigned int n_items() const { return items.size();}
00114
00115
00116 vcl_string get(unsigned int i) const { return items[i]; }
00117
00118 void set(unsigned int i) const { if (i<n_items()) set_value((int) i); }
00119
00120
00121 unsigned int get() const { return (unsigned int) get_value(); }
00122
00123 unsigned int default_value() const { return ctrl_.default_value; }
00124
00125 virtual vcl_string description() const;
00126
00127 virtual void reset() const { set(default_value()); }
00128 };
00129
00130
00131 class vidl_v4l2_control_boolean: public vidl_v4l2_control
00132 {
00133 public:
00134 vidl_v4l2_control_boolean(const v4l2_queryctrl& ctr, int f): vidl_v4l2_control(ctr,f) {}
00135
00136 void set(bool v) const { set_value(v?1:0); }
00137
00138 bool get() const { return get_value(); }
00139
00140 bool default_value() const { return ctrl_.default_value; }
00141
00142 virtual vcl_string description() const
00143 { return "Control \""+name()+"\": boolean (default: "+(default_value()?"true":"false")+")"; }
00144
00145 virtual void reset() const { set(default_value()); }
00146 };
00147
00148
00149 class vidl_v4l2_control_button: public vidl_v4l2_control
00150 {
00151 public:
00152 vidl_v4l2_control_button(const v4l2_queryctrl& ctr, int f): vidl_v4l2_control(ctr,f) {}
00153
00154 void push() const { set_value(1); }
00155
00156 virtual vcl_string description() const { return "Control \""+name()+"\": button"; }
00157 };
00158
00159 #endif // vidl_v4l2_control_h_