Skip to content

Commit 7f217b3

Browse files
committed
Added static member functions to control camera sensor properties
fixed code style
1 parent 6d67fb1 commit 7f217b3

File tree

4 files changed

+329
-9
lines changed

4 files changed

+329
-9
lines changed

src/esp32cam.cpp

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,218 @@ CameraClass::changeResolution(const Resolution& resolution, int sleepFor)
4242
return true;
4343
}
4444

45+
bool
46+
CameraClass::changeContrast(int ilevel)
47+
{
48+
sensor_t* sensor = esp_camera_sensor_get();
49+
if (sensor == nullptr) {
50+
return false;
51+
}
52+
53+
if (sensor->set_contrast(sensor, ilevel) == 0) {
54+
return true;
55+
} else
56+
return false;
57+
}
58+
59+
bool
60+
CameraClass::changeBrightness(int ilevel)
61+
{
62+
sensor_t* sensor = esp_camera_sensor_get();
63+
if (sensor == nullptr) {
64+
return false;
65+
}
66+
67+
if (sensor->set_brightness(sensor, ilevel) == 0) {
68+
return true;
69+
} else
70+
return false;
71+
}
72+
73+
bool
74+
CameraClass::changeSaturation(int ilevel)
75+
{
76+
sensor_t* sensor = esp_camera_sensor_get();
77+
if (sensor == nullptr) {
78+
return false;
79+
}
80+
81+
if (sensor->set_saturation(sensor, ilevel) == 0) {
82+
return true;
83+
} else
84+
return false;
85+
}
86+
87+
bool
88+
CameraClass::changeSpecialEffect(int ilevel)
89+
{
90+
sensor_t* sensor = esp_camera_sensor_get();
91+
if (sensor == nullptr) {
92+
return false;
93+
}
94+
95+
if (sensor->set_special_effect(sensor, ilevel) == 0) {
96+
return true;
97+
} else
98+
return false;
99+
}
100+
101+
bool
102+
CameraClass::changeWbMode(int ilevel)
103+
{
104+
sensor_t* sensor = esp_camera_sensor_get();
105+
if (sensor == nullptr) {
106+
return false;
107+
}
108+
109+
if (sensor->set_wb_mode(sensor, ilevel) == 0) {
110+
return true;
111+
} else
112+
return false;
113+
}
114+
115+
bool
116+
CameraClass::changeAeLevels(int ilevel)
117+
{
118+
sensor_t* sensor = esp_camera_sensor_get();
119+
if (sensor == nullptr) {
120+
return false;
121+
}
122+
123+
if (sensor->set_ae_level(sensor, ilevel)) {
124+
return true;
125+
} else
126+
return false;
127+
}
128+
129+
bool
130+
CameraClass::changAgcGain(int ilevel)
131+
{
132+
sensor_t* sensor = esp_camera_sensor_get();
133+
if (sensor == nullptr) {
134+
return false;
135+
}
136+
137+
if (sensor->set_agc_gain(sensor, ilevel) == 0) {
138+
return true;
139+
} else
140+
return false;
141+
}
142+
143+
bool
144+
CameraClass::changGainceilingSensor(int iGainCeiling)
145+
{
146+
sensor_t* sensor = esp_camera_sensor_get();
147+
if (sensor == nullptr) {
148+
return false;
149+
}
150+
151+
if ((gainceiling_t)iGainCeiling < GAINCEILING_2X ||
152+
(gainceiling_t)iGainCeiling > GAINCEILING_128X) {
153+
return false;
154+
}
155+
156+
if (sensor->set_gainceiling(sensor, (gainceiling_t)iGainCeiling) == 0) {
157+
return true;
158+
} else
159+
return false;
160+
}
161+
162+
bool
163+
CameraClass::changeGaincontrol(int iEnable)
164+
{
165+
sensor_t* sensor = esp_camera_sensor_get();
166+
if (sensor == nullptr) {
167+
return false;
168+
}
169+
170+
if (sensor->set_gain_ctrl(sensor, iEnable) == 0) {
171+
return true;
172+
} else
173+
return false;
174+
}
175+
176+
bool
177+
CameraClass::changeColorbar(int iEnable)
178+
{
179+
sensor_t* sensor = esp_camera_sensor_get();
180+
if (sensor == nullptr) {
181+
return false;
182+
}
183+
184+
if (sensor->set_colorbar(sensor, iEnable) == 0) {
185+
return true;
186+
} else
187+
return false;
188+
}
189+
190+
bool
191+
CameraClass::changeWhitebalance(int iEnable)
192+
{
193+
sensor_t* sensor = esp_camera_sensor_get();
194+
if (sensor == nullptr) {
195+
return false;
196+
}
197+
198+
if (sensor->set_whitebal(sensor, iEnable) == 0) {
199+
return true;
200+
} else
201+
return false;
202+
}
203+
204+
bool
205+
CameraClass::changeQuality(int iQuality)
206+
{
207+
sensor_t* sensor = esp_camera_sensor_get();
208+
if (sensor == nullptr) {
209+
return false;
210+
}
211+
212+
if (iQuality < 0 ||
213+
iQuality > 63) {
214+
return false;
215+
}
216+
217+
if (sensor->set_quality(sensor, iQuality) == 0) {
218+
return true;
219+
} else
220+
return false;
221+
}
222+
223+
bool
224+
CameraClass::changAec2(int iEnable)
225+
{
226+
sensor_t* sensor = esp_camera_sensor_get();
227+
if (sensor == nullptr) {
228+
return false;
229+
}
230+
231+
if (sensor->set_aec2(sensor, iEnable) == 0) {
232+
return true;
233+
} else
234+
return false;
235+
}
236+
237+
bool
238+
CameraClass::changeAecValue(int iValue)
239+
{
240+
sensor_t* sensor = esp_camera_sensor_get();
241+
if (sensor == nullptr) {
242+
return false;
243+
}
244+
245+
if (iValue < 0 ||
246+
iValue > 1200) {
247+
return false;
248+
}
249+
250+
if (sensor->set_agc_gain(sensor, iValue) == 0) {
251+
return true;
252+
} else
253+
return false;
254+
}
255+
256+
45257
std::unique_ptr<Frame>
46258
CameraClass::capture()
47259
{

src/esp32cam.h

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,101 @@ class CameraClass
2929
bool
3030
changeResolution(const Resolution& resolution, int sleepFor = 500);
3131

32+
/** \brief Change Sensor Contrast level
33+
* must be -2 to +2, default 0
34+
*/
35+
bool
36+
changeContrast(int ilevel);
37+
38+
/** \brief Change Brightness level
39+
* \param ilevel must be -2 to +2, default 0
40+
*/
41+
bool
42+
changeBrightness(int ilevel);
43+
44+
/** \brief Change Saturation level
45+
* \param ilevel must be -2 to +2, default 0
46+
*/
47+
bool
48+
changeSaturation(int ilevel);
49+
50+
/** \brief Change SpecialEffect
51+
* \param ilevel must be > 0 && <= NUM_SPECIAL_EFFECTS, default 0
52+
* \ 1 = no effect
53+
* \ 2 = negative
54+
* \ 3 = black and white
55+
* \ 4 = reddish
56+
* \ 5 = greenish
57+
* \ 6 = blue
58+
* \ 7 = retro
59+
*/
60+
bool
61+
changeSpecialEffect(int ilevel);
62+
63+
/** \brief Change WbMode
64+
* \param ilevel must be > 0 && <= NUM_WB_MODES, default 0
65+
* \ 0 = default
66+
* \ 1 = sunny
67+
* \ 2 = cloudy
68+
* \ 3 = office
69+
* \ 4 = home
70+
*/
71+
bool
72+
changeWbMode(int ilevel);
73+
74+
/** \brief Change AE Levels
75+
* \param ilevel must be -2 to +2, default 0
76+
*/
77+
bool
78+
changeAeLevels(int ilevel);
79+
80+
/** \brief Change AGC Gain
81+
* \param ilevel must be >= 0 and <= 30, default 30
82+
*/
83+
bool
84+
changAgcGain(int ilevel);
85+
86+
/** \brief Change Gainceiling
87+
* \param ilevel must be within ENUM gainceiling_t
88+
*/
89+
bool
90+
changGainceilingSensor(int iGainCeiling);
91+
92+
/** \brief Enable/Disable Gaincontrol
93+
* \param iGainCeiling must be between GAINCEILING_2X and GAINCEILING_128X
94+
*/
95+
bool
96+
changeGaincontrol(int iEnable);
97+
98+
/** \brief Enable/Disable Testing Colorbar
99+
* \param iEnable must be 0(disable) or 1 (enable)
100+
*/
101+
bool
102+
changeColorbar(int iEnable);
103+
104+
/** \brief Enable/Disable Whitebalance
105+
* \param iEnable must be 0(disable) or 1 (enable)
106+
*/
107+
bool
108+
changeWhitebalance(int iEnable);
109+
110+
/** \brief Change JPEG Quality
111+
* \param iEnable iQuality must be within 0 and 63
112+
*/
113+
bool changeQuality(int iQuality);
114+
115+
/** \brief Change AEC Value
116+
* \param iEnable iValue must be 0 to 1200, default 0
117+
*/
118+
bool
119+
changeAecValue(int iValue);
120+
121+
/** \brief Enable/Disable Auto/Manual Exposure control
122+
* \param iEnable must be 0(disable) or 1 (enable)
123+
*/
124+
bool
125+
changAec2(int iEnable);
126+
32127
/** \brief Capture a frame of picture.
33128
*/
34129
std::unique_ptr<Frame>

src/internal/frame.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,23 @@ Frame::releaseFb()
4040
}
4141
}
4242

43-
bool Frame::writeTo(Print& os, int timeout) {
43+
bool
44+
Frame::writeTo(Print& os, int timeout) {
4445
return writeToImpl(os, timeout, nullptr);
4546
}
4647

47-
bool Frame::writeTo(Client& os, int timeout) {
48+
bool
49+
Frame::writeTo(Client& os, int timeout) {
4850
return writeToImpl(os, timeout, &os);
4951
}
5052

51-
bool Frame::writeTo(AsyncClient& os, int timeout) {
53+
bool
54+
Frame::writeTo(AsyncClient& os, int timeout) {
5255
return writeToImpl(timeout, &os);
5356
}
5457

55-
bool Frame::writeToImpl(Print& os, int timeout, Client* client) {
58+
bool
59+
Frame::writeToImpl(Print& os, int timeout, Client* client) {
5660
auto startTime = millis();
5761
for (size_t i = 0; i < m_size; i += os.write(&m_data[i], m_size - i)) {
5862
if (millis() - startTime > static_cast<unsigned long>(timeout) ||
@@ -64,7 +68,8 @@ bool Frame::writeToImpl(Print& os, int timeout, Client* client) {
6468
return true;
6569
}
6670

67-
bool Frame::writeToImpl(int timeout, AsyncClient* client) {
71+
bool
72+
Frame::writeToImpl(int timeout, AsyncClient* client) {
6873
auto startTime = millis();
6974
for (size_t i = 0; i < m_size; i += client->write((const char*) &m_data[i], m_size - i)) {
7075
if (millis() - startTime > static_cast<unsigned long>(timeout) ||

src/internal/frame.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,26 @@ class Frame
5555
* \retval true writing completed.
5656
* \retval false writing disrupted by timeout.
5757
*/
58-
bool writeTo(Print& os, int timeout = 10000);
58+
bool
59+
writeTo(Print& os, int timeout = 10000);
5960

6061
/** \brief Write frame buffer to \p os .
6162
* \param os output socket.
6263
* \param timeout total time limit in millis.
6364
* \retval true writing completed.
6465
* \retval false writing disrupted by timeout or socket error.
6566
*/
66-
bool writeTo(Client& os, int timeout = 10000);
67-
67+
bool
68+
writeTo(Client& os, int timeout = 10000);
6869

69-
bool writeTo(AsyncClient& os, int timeout = 10000);
70+
/** \brief Write frame buffer to \p os .
71+
* \param os output socket.
72+
* \param timeout total time limit in millis.
73+
* \retval true writing completed.
74+
* \retval false writing disrupted by timeout or socket error.
75+
*/
76+
bool
77+
writeTo(AsyncClient& os, int timeout = 10000);
7078

7179
public: // conversion
7280
bool

0 commit comments

Comments
 (0)