CVD 0.8
cvd/Linux/v4lcontrol.h
00001 #ifndef CVD_V4LCONTROL_H
00002 #define CVD_V4LCONTROL_H
00003 
00004 #include <string>
00005 #include <map>
00006 #include <vector>
00007 
00008 #include <linux/videodev2.h>
00009 
00010 #include <cvd/exceptions.h>
00011 
00012 namespace CVD {
00013 
00014 namespace Exceptions
00015 {
00017     namespace V4LControl
00018     {
00020     struct All: public CVD::Exceptions::All
00021     {
00022     };
00025     struct DeviceOpen: public All {DeviceOpen(std::string dev); 
00026     };
00027 
00030     struct ParameterNotSupported: public All {
00031         ParameterNotSupported(std::string);  
00032         ParameterNotSupported(unsigned int); 
00033     };
00034 
00037     struct GetValue: public All {GetValue(std::string); 
00038     };
00039 
00042     struct SetValue: public All {SetValue(std::string); 
00043     };
00044 
00047     struct QueryParameters: public All {QueryParameters(std::string); 
00048     };
00049 
00050     }
00051 }
00052 
00053 
00064 class V4LControl {
00065 public:
00066     V4LControl( int fd, bool report = true );
00067     V4LControl( const std::string & name, bool report = true );
00068 
00076 
00077     void exposure( int );
00078     int  exposure(void);
00079 
00080     void autoexposure(bool);
00081     bool autoexposure();
00082 
00083     void gain( double );
00084     double gain(void);
00085 
00086     void autogain(bool);
00087     bool autogain(void);
00088 
00089     void brightness(double);
00090     double brightness(void);
00091 
00092     void contrast(double);
00093     double contrast(void);
00094 
00095     void saturation(double);
00096     double saturation(void);
00098 
00101 
00102     unsigned int getId( const std::string & name ) const;
00103     std::string getName( unsigned int id ) const;
00104     std::vector<unsigned int> supportedParameters(void) const;
00105     std::vector<std::string> supportedParameterNames(void) const;
00106 
00107     inline bool isSupported( const std::string & name ) const {
00108         return (controlNames.find(name) != controlNames.end());
00109     }
00110     inline void set( const std::string & name, int value ){
00111         set(getId(name), value);
00112     }
00113     inline int get( const std::string & name ){
00114         return get(getId(name));
00115     }
00116     inline int type( const std::string & name ){
00117         return type(getId(name));
00118     }
00119     inline std::map<unsigned int, std::string> menuValues( const std::string & name ){
00120         return menuValues(getId(name));
00121     }
00122     inline int defaultValue( const std::string & name ){
00123         return defaultValue(getId(name));
00124     }
00125     inline int min( const std::string & name ){
00126         return min(getId(name));
00127     }
00128     inline int max( const std::string & name ){
00129         return max(getId(name));
00130     }
00131     inline int step( const std::string & name ){
00132         return step(getId(name));
00133     }
00134 
00135     inline bool isSupported( unsigned int id ) const {
00136         return (controlData.find(id) != controlData.end());
00137     }
00138     void set( unsigned int id, int value);
00139     int get( unsigned int id );
00140     int type( unsigned int id );
00141     std::map<unsigned int, std::string> menuValues( unsigned int id ) const ;
00142     int defaultValue( unsigned int id ) const;
00143     int min( unsigned int id ) const;
00144     int max( unsigned int id ) const;
00145     int step( unsigned int id ) const;
00147 
00150 
00151     int getQueryStruct( v4l2_queryctrl & query ) const;
00152     void getMenuStruct( unsigned int id, std::vector<v4l2_querymenu> & menu ) const;
00153     int setControlStruct( v4l2_control & value );
00154     int getControlStruct( v4l2_control & value ) const;
00156 
00158     inline int getFile(void) const { return device; }
00159 
00161     inline const std::string & getDevice(void) const { return deviceName; }
00162 
00164     inline void setReportErrors( bool report ) { reportErrors = report; }
00165     inline bool getReportErrors(void) const { return reportErrors; }
00166 
00167 protected:
00168     int device;
00169     std::string deviceName;
00170     struct v4l2_control control;
00171     bool reportErrors;
00172 
00173     void queryControls(void);
00174 
00175     std::map<std::string, unsigned int> controlNames;
00176     std::map<unsigned int, v4l2_queryctrl> controlData;
00177     std::map<unsigned int, std::vector<v4l2_querymenu> >  menuData;
00178 };
00179 
00180 } // namespace CVD
00181 
00182 #endif