| 1 |
#ifndef CVD_V4LCONTROL_H |
| 2 |
#define CVD_V4LCONTROL_H |
| 3 |
|
| 4 |
#include <map> |
| 5 |
#include <string> |
| 6 |
#include <vector> |
| 7 |
|
| 8 |
#include <linux/videodev2.h> |
| 9 |
|
| 10 |
#include <cvd/exceptions.h> |
| 11 |
|
| 12 |
namespace CVD |
| 13 |
{ |
| 14 |
|
| 15 |
namespace Exceptions |
| 16 |
{ |
| 17 |
|
| 18 |
namespace V4LControl |
| 19 |
{ |
| 20 |
|
| 21 |
struct All : public CVD::Exceptions::All |
| 22 |
{ |
| 23 |
using CVD::Exceptions::All::All; |
| 24 |
}; |
| 25 |
|
| 26 |
|
| 27 |
struct DeviceOpen : public All |
| 28 |
{ |
| 29 |
DeviceOpen(std::string dev); |
| 30 |
}; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
struct ParameterNotSupported : public All |
| 35 |
{ |
| 36 |
ParameterNotSupported(std::string); |
| 37 |
ParameterNotSupported(unsigned int); |
| 38 |
}; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
struct GetValue : public All |
| 43 |
{ |
| 44 |
GetValue(std::string); |
| 45 |
}; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
struct SetValue : public All |
| 50 |
{ |
| 51 |
SetValue(std::string); |
| 52 |
}; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
struct QueryParameters : public All |
| 57 |
{ |
| 58 |
QueryParameters(std::string); |
| 59 |
}; |
| 60 |
|
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
class V4LControl |
| 75 |
{ |
| 76 |
public: |
| 77 |
V4LControl(int fd, bool report = true); |
| 78 |
V4LControl(const std::string& name, bool report = true); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
void exposure(int); |
| 89 |
int exposure(void); |
| 90 |
|
| 91 |
void autoexposure(bool); |
| 92 |
bool autoexposure(); |
| 93 |
|
| 94 |
void gain(double); |
| 95 |
double gain(void); |
| 96 |
|
| 97 |
void autogain(bool); |
| 98 |
bool autogain(void); |
| 99 |
|
| 100 |
void brightness(double); |
| 101 |
double brightness(void); |
| 102 |
|
| 103 |
void contrast(double); |
| 104 |
double contrast(void); |
| 105 |
|
| 106 |
void saturation(double); |
| 107 |
double saturation(void); |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
unsigned int getId(const std::string& name) const; |
| 114 |
std::string getName(unsigned int id) const; |
| 115 |
std::vector<unsigned int> supportedParameters(void) const; |
| 116 |
std::vector<std::string> supportedParameterNames(void) const; |
| 117 |
|
| 118 |
inline bool isSupported(const std::string& name) const |
| 119 |
{ |
| 120 |
return (controlNames.find(name) != controlNames.end()); |
| 121 |
} |
| 122 |
inline void set(const std::string& name, int value) |
| 123 |
{ |
| 124 |
set(getId(name), value); |
| 125 |
} |
| 126 |
inline int get(const std::string& name) |
| 127 |
{ |
| 128 |
return get(getId(name)); |
| 129 |
} |
| 130 |
inline int type(const std::string& name) |
| 131 |
{ |
| 132 |
return type(getId(name)); |
| 133 |
} |
| 134 |
inline std::map<unsigned int, std::string> menuValues(const std::string& name) |
| 135 |
{ |
| 136 |
return menuValues(getId(name)); |
| 137 |
} |
| 138 |
inline int defaultValue(const std::string& name) |
| 139 |
{ |
| 140 |
return defaultValue(getId(name)); |
| 141 |
} |
| 142 |
inline int min(const std::string& name) |
| 143 |
{ |
| 144 |
return min(getId(name)); |
| 145 |
} |
| 146 |
inline int max(const std::string& name) |
| 147 |
{ |
| 148 |
return max(getId(name)); |
| 149 |
} |
| 150 |
inline int step(const std::string& name) |
| 151 |
{ |
| 152 |
return step(getId(name)); |
| 153 |
} |
| 154 |
|
| 155 |
inline bool isSupported(unsigned int id) const |
| 156 |
{ |
| 157 |
return (controlData.find(id) != controlData.end()); |
| 158 |
} |
| 159 |
void set(unsigned int id, int value); |
| 160 |
int get(unsigned int id); |
| 161 |
int type(unsigned int id); |
| 162 |
std::map<unsigned int, std::string> menuValues(unsigned int id) const; |
| 163 |
int defaultValue(unsigned int id) const; |
| 164 |
int min(unsigned int id) const; |
| 165 |
int max(unsigned int id) const; |
| 166 |
int step(unsigned int id) const; |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
int getQueryStruct(v4l2_queryctrl& query) const; |
| 173 |
void getMenuStruct(unsigned int id, std::vector<v4l2_querymenu>& menu) const; |
| 174 |
int setControlStruct(v4l2_control& value); |
| 175 |
int getControlStruct(v4l2_control& value) const; |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
inline int getFile(void) const { return device; } |
| 180 |
|
| 181 |
|
| 182 |
inline const std::string& getDevice(void) const { return deviceName; } |
| 183 |
|
| 184 |
|
| 185 |
inline void setReportErrors(bool report) { reportErrors = report; } |
| 186 |
inline bool getReportErrors(void) const { return reportErrors; } |
| 187 |
|
| 188 |
protected: |
| 189 |
int device; |
| 190 |
std::string deviceName; |
| 191 |
struct v4l2_control control; |
| 192 |
bool reportErrors; |
| 193 |
|
| 194 |
void queryControls(void); |
| 195 |
|
| 196 |
std::map<std::string, unsigned int> controlNames; |
| 197 |
std::map<unsigned int, v4l2_queryctrl> controlData; |
| 198 |
std::map<unsigned int, std::vector<v4l2_querymenu>> menuData; |
| 199 |
}; |
| 200 |
|
| 201 |
} |
| 202 |
|
| 203 |
#endif |