core/vidl/vidl_v4l2_control.h

Go to the documentation of this file.
00001 // This is core/vidl/vidl_v4l2_control.h
00002 #ifndef vidl_v4l2_control_h_
00003 #define vidl_v4l2_control_h_
00004 //:
00005 // \file
00006 // \brief A base control class for user controls
00007 //
00008 // \author Antonio Garrido
00009 // \verbatim
00010 //  Modifications
00011 //     10 Nov 2008 Created (A. Garrido)
00012 //\endverbatim
00013 
00014 #include <vcl_string.h>
00015 #include <vcl_vector.h>
00016 
00017 extern "C" {
00018 #include <asm/types.h>          /* for videodev2.h */
00019 #include <linux/videodev2.h>
00020 };
00021 
00022 //: A base class for handle a control.
00023 class vidl_v4l2_control
00024 {
00025   protected:
00026     int fd;
00027     struct v4l2_queryctrl ctrl_;
00028     vidl_v4l2_control(const v4l2_queryctrl& ctr, int f):  fd(f), ctrl_(ctr) {}
00029     void set_value(int v) const;
00030     int get_value() const;
00031   public:
00032     virtual ~vidl_v4l2_control() {}
00033     //: Factory method to create new controls
00034     // \param ctr details from VIDIOC_QUERYCTRL
00035     // \param f associated file descriptor
00036     // \return pointer to base class of new control
00037     static vidl_v4l2_control * new_control(const v4l2_queryctrl& ctr, int f);
00038     //: Type of control
00039     // \return type as indicated in v4l2 specification
00040     v4l2_ctrl_type type() const { return ctrl_.type; }
00041     //: Name of control
00042     // \return name the driver assign to the control
00043     vcl_string name() const { return  (const char *) ctrl_.name; }
00044     //: A 1-line brief description
00045     virtual vcl_string description() const= 0;
00046     //: Id of control
00047     // \return ID (for example, V4L2_CID_BRIGHTNESS corresponds to brightness)
00048     int id() const { return ctrl_.id; }
00049     //: Control is read only
00050     bool read_only() const 
00051     { 
00052 #ifdef V4L2_CTRL_FLAG_READ_ONLY
00053       return ctrl_.flags & V4L2_CTRL_FLAG_READ_ONLY; 
00054 #else
00055       return false;    
00056 #endif
00057     }
00058     //: Control can change value of other controls
00059     bool affect_other_controls() const
00060     { 
00061 #ifdef V4L2_CTRL_FLAG_UPDATE
00062       return ctrl_.flags & V4L2_CTRL_FLAG_UPDATE;
00063 #else
00064       return false;
00065 #endif
00066      }
00067     //: Reset control
00068     // \note no-op fot button controls
00069     virtual void reset() const {}
00070 };
00071 
00072 //: A class for handle a control of type integer
00073 class vidl_v4l2_control_integer: public vidl_v4l2_control
00074 {
00075   public:
00076     vidl_v4l2_control_integer(const v4l2_queryctrl& ctr, int f): vidl_v4l2_control(ctr,f) {}
00077     //: Minimum value of the control
00078     int minimum() const { return ctrl_.minimum; }
00079     //: Maximum value of the control
00080     int maximum() const { return ctrl_.maximum; }
00081     //: Step size
00082     // Indicates the increment between values which are actually different on the hardware
00083     int step() const { return ctrl_.step; }
00084     //: Default value of this control
00085     int default_value() const { return ctrl_.default_value; }
00086     //: Set the value of the control 
00087     // \param value to be set in range determined by driver
00088     void set(int value) const;
00089     //: Change control 
00090     // \param value to be set in range 0-100
00091     void set_100 ( int value) const;
00092     //: Get the value of the control 
00093     // \return value in range determined by driver
00094     int get() const { return get_value(); }
00095     //: Get the value of the control 
00096     // \return value in range 0-100
00097     int get_100() const { return (get_value()-ctrl_.minimum)*100/(ctrl_.maximum-ctrl_.minimum); }
00098     //: A 1-line brief description
00099     virtual vcl_string description() const;
00100     //: Reset control
00101     virtual void reset() const { set(default_value()); }
00102 };
00103 
00104 //: A class for handle a control of type menu
00105 class vidl_v4l2_control_menu: public vidl_v4l2_control
00106 {
00107     vcl_vector<vcl_string> items;
00108   public:
00109     vidl_v4l2_control_menu(const v4l2_queryctrl& ctr, int f);
00110     //: Number of items
00111     // \return number of entries in the menu
00112     unsigned int n_items() const { return items.size();}
00113     //: Item i
00114     // \return string assigned to item i
00115     vcl_string get(unsigned int i) const { return items[i]; }
00116     //: Select item i
00117     void set(unsigned int i) const { if (i<n_items()) set_value((int) i); }
00118     //: Get the value of the control 
00119     // \return index in the menu
00120     unsigned int get() const { return (unsigned int) get_value(); }
00121     //: Default value of this control
00122     unsigned int default_value() const { return ctrl_.default_value; }
00123     //: A 1-line brief description
00124     virtual vcl_string description() const;
00125     //: Reset control
00126     virtual void reset() const { set(default_value()); }
00127 };
00128 
00129 //: A class for handle a control of type boolean
00130 class vidl_v4l2_control_boolean: public vidl_v4l2_control
00131 {
00132   public:
00133     vidl_v4l2_control_boolean(const v4l2_queryctrl& ctr, int f): vidl_v4l2_control(ctr,f) {}
00134     //: Set the value of the control 
00135     void set(bool v) const { set_value(v?1:0); }
00136     //: Get the value of the control 
00137     bool get() const { return get_value(); }
00138     //: Default value of this control
00139     bool default_value() const { return ctrl_.default_value; }
00140     //: A 1-line brief description
00141     virtual vcl_string description() const 
00142        { return "Control \""+name()+"\": boolean (default: "+(default_value()?"true":"false")+")"; }
00143     //: Reset control
00144     virtual void reset() const { set(default_value()); }
00145 };
00146 
00147 //: A class for handle a control of type button
00148 class vidl_v4l2_control_button: public vidl_v4l2_control
00149 {
00150   public:
00151     vidl_v4l2_control_button(const v4l2_queryctrl& ctr, int f): vidl_v4l2_control(ctr,f) {}
00152     //: Push button
00153     void push() const { set_value(1); }
00154     //: A 1-line brief description
00155     virtual vcl_string description() const { return "Control \""+name()+"\": button"; }
00156 };
00157 
00158 #endif // vidl_v4l2_control_h_

Generated on Mon Mar 8 05:10:34 2010 for core/vidl by  doxygen 1.5.1