Skip to content

Commit ac169f0

Browse files
committed
add functions to set new sensor features
- white pixel correction - black pixel correction - denoise control - lens correction - raw gamma - changeFrequence of Cam Sensor from 10 to 20 mhz - AutoExposurecontrol - Dcw - AsyncClient: Handle Client Disconnect from Outside - fix merge conflicts
1 parent 12370f5 commit ac169f0

File tree

5 files changed

+201
-25
lines changed

5 files changed

+201
-25
lines changed

src/esp32cam.cpp

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

45+
bool
46+
CameraClass::changeFrequence(int iMhz)
47+
{
48+
sensor_t* sensor = esp_camera_sensor_get();
49+
if (sensor == nullptr) {
50+
return false;
51+
}
52+
53+
int iLedTimer = 0;
54+
int ret = 0;
55+
sensor->xclk_freq_hz = iMhz * 1000000U;
56+
// ret = xclk_timer_conf(iLedTimer, sensor->xclk_freq_hz);
57+
// if (sensor->set_xclk(sensor, iLedTimer, iMhz) != 0) {
58+
if (ret != 0) {
59+
return false;
60+
} else
61+
return true;
62+
}
63+
4564
bool
4665
CameraClass::changeContrast(int ilevel)
4766
{
@@ -158,7 +177,7 @@ CameraClass::changGainceilingSensor(int iGainCeiling)
158177
} else
159178
return false;
160179
}
161-
180+
162181
bool
163182
CameraClass::changeAwbGainControl(int iEnable)
164183
{
@@ -262,7 +281,7 @@ CameraClass::changeAecValue(int iValue)
262281
return false;
263282
}
264283

265-
if (sensor->set_agc_gain(sensor, iValue) == 0) {
284+
if (sensor->set_aec_value(sensor, iValue) == 0) {
266285
return true;
267286
} else
268287
return false;
@@ -296,6 +315,105 @@ CameraClass::changVFlip(int iEnable)
296315
return false;
297316
}
298317

318+
bool
319+
CameraClass::changBPC(int iEnable)
320+
{
321+
sensor_t* sensor = esp_camera_sensor_get();
322+
if (sensor == nullptr) {
323+
return false;
324+
}
325+
326+
if (sensor->set_bpc(sensor, iEnable) == 0) {
327+
return true;
328+
} else
329+
return false;
330+
}
331+
332+
bool
333+
CameraClass::changWPC(int iEnable)
334+
{
335+
sensor_t* sensor = esp_camera_sensor_get();
336+
if (sensor == nullptr) {
337+
return false;
338+
}
339+
340+
if (sensor->set_wpc(sensor, iEnable) == 0) {
341+
return true;
342+
} else
343+
return false;
344+
}
345+
346+
bool
347+
CameraClass::changDenoise(int iEnable)
348+
{
349+
sensor_t* sensor = esp_camera_sensor_get();
350+
if (sensor == nullptr) {
351+
return false;
352+
}
353+
354+
if (sensor->set_denoise(sensor, iEnable) == 0) {
355+
return true;
356+
} else
357+
return false;
358+
}
359+
360+
bool
361+
CameraClass::changLenc(int iEnable)
362+
{
363+
sensor_t* sensor = esp_camera_sensor_get();
364+
if (sensor == nullptr) {
365+
return false;
366+
}
367+
368+
if (sensor->set_lenc(sensor, iEnable) == 0) {
369+
return true;
370+
} else
371+
return false;
372+
}
373+
374+
bool
375+
CameraClass::changRawGMA(int iEnable)
376+
{
377+
sensor_t* sensor = esp_camera_sensor_get();
378+
if (sensor == nullptr) {
379+
return false;
380+
}
381+
382+
if (sensor->set_raw_gma(sensor, iEnable) == 0) {
383+
return true;
384+
} else
385+
return false;
386+
}
387+
388+
bool
389+
CameraClass::changAutoExposurecontrol(int iEnable)
390+
{
391+
sensor_t* sensor = esp_camera_sensor_get();
392+
if (sensor == nullptr) {
393+
return false;
394+
}
395+
396+
if (sensor->set_exposure_ctrl(sensor, iEnable) == 0) {
397+
return true;
398+
} else
399+
return false;
400+
}
401+
402+
bool
403+
CameraClass::changDcw(int iEnable)
404+
{
405+
sensor_t* sensor = esp_camera_sensor_get();
406+
if (sensor == nullptr) {
407+
return false;
408+
}
409+
410+
if (sensor->set_dcw(sensor, iEnable) == 0) {
411+
return true;
412+
} else
413+
return false;
414+
}
415+
416+
299417
std::unique_ptr<Frame>
300418
CameraClass::capture()
301419
{
@@ -346,6 +464,7 @@ CameraClass::streamMjpeg(AsyncClient& client, const StreamMjpegConfig& cfg) {
346464
"\r\n");
347465
auto lastCapture = millis();
348466
int nFrames;
467+
int nNullFrames = 0;
349468
for (nFrames = 0; cfg.maxFrames < 0 || nFrames < cfg.maxFrames; ++nFrames) {
350469
auto now = millis();
351470
auto sinceLastCapture = now - lastCapture;
@@ -356,19 +475,31 @@ CameraClass::streamMjpeg(AsyncClient& client, const StreamMjpegConfig& cfg) {
356475

357476
auto frame = capture();
358477
if (frame == nullptr) {
359-
break;
360-
}
478+
nNullFrames++;
479+
if (nNullFrames > 10)
480+
break;
481+
else {
482+
// delay(100); // Delay short period!
483+
continue;
484+
}
485+
} else {
486+
nNullFrames = 0;
487+
}
361488

362489
char szTmp[256];
363490
size_t stLen = snprintf_P(szTmp, 256, PSTR(
364491
"Content-Type: image/jpeg\r\n"
365492
"Content-Length: %d\r\n"
366493
"\r\n"), static_cast<int>(frame->size())
367494
);
368-
client.write((const char*) szTmp, stLen);
369-
if (!frame->writeTo(client, cfg.frameTimeout)) {
370-
break;
371-
}
495+
if (!client.disconnected()) {
496+
client.write((const char*) szTmp, stLen);
497+
if (!frame->writeTo(client, cfg.frameTimeout)) {
498+
break;
499+
}
500+
} else {
501+
break;
502+
}
372503
client.write("\r\n--" BOUNDARY "\r\n");
373504
yield();
374505
}

src/esp32cam.h

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88

99
namespace esp32cam {
1010

11+
struct StreamMjpegConfig
12+
{
13+
/// minimum interval between frame captures.
14+
int minInterval = 0;
15+
/// maximum number of frames before disconnecting.
16+
int maxFrames = -1;
17+
/// time limit of writing one frame in millis.
18+
int frameTimeout = 10000;
19+
};
20+
1121
class CameraClass
1222
{
1323
public:
@@ -29,6 +39,13 @@ class CameraClass
2939
bool
3040
changeResolution(const Resolution& resolution, int sleepFor = 500);
3141

42+
/** \brief Change camera resolution.
43+
* \pre Change Camera Frequence Clock
44+
* \param iMhz new Frequence, must be in MHZ
45+
*/
46+
bool
47+
changeFrequence(int iMhz);
48+
3249
/** \brief Change Sensor Contrast level
3350
* must be -2 to +2, default 0
3451
*/
@@ -76,6 +93,12 @@ class CameraClass
7693
*/
7794
bool
7895
changeAeLevels(int ilevel);
96+
97+
/** \brief Enable/Disable AEC (Auto Exposure Control)
98+
* \param iEnable must be 0(disable) or 1 (enable)
99+
*/
100+
bool
101+
changAutoExposurecontrol(int iEnable);
79102

80103
/** \brief Change AGC Gain
81104
* \param ilevel must be >= 0 and <= 30, default 30
@@ -141,22 +164,48 @@ class CameraClass
141164
*/
142165
bool
143166
changVFlip(int iEnable);
167+
168+
/** \brief Enable/Disable black pixel correction
169+
* \param iEnable must be 0(disable) or 1 (enable)
170+
*/
171+
bool
172+
changBPC(int iEnable);
173+
174+
/** \brief Enable/Disable white pixel correction
175+
* \param iEnable must be 0(disable) or 1 (enable)
176+
*/
177+
bool
178+
changWPC(int iEnable);
179+
180+
/** \brief Enable/Disable Denoise Control
181+
* \param iEnable must be 0(disable) or 1 (enable)
182+
*/
183+
bool
184+
changDenoise(int iEnable);
185+
186+
/** \brief Enable/Disable Lenc Correction
187+
* \param iEnable must be 0(disable) or 1 (enable)
188+
*/
189+
bool
190+
changLenc(int iEnable);
191+
192+
/** \brief Enable/Disable RAW Gamma
193+
* \param iEnable must be 0(disable) or 1 (enable)
194+
*/
195+
bool
196+
changRawGMA(int iEnable);
197+
198+
/** \brief Enable/Disable DCW
199+
* \param iEnable must be 0(disable) or 1 (enable)
200+
*/
201+
bool
202+
changDcw(int iEnable);
144203

145204
/** \brief Capture a frame of picture.
146205
*/
147206
std::unique_ptr<Frame>
148207
capture();
149208

150-
struct StreamMjpegConfig
151-
{
152-
/// minimum interval between frame captures.
153-
int minInterval = 0;
154-
/// maximum number of frames before disconnecting.
155-
int maxFrames = -1;
156-
/// time limit of writing one frame in millis.
157-
int frameTimeout = 10000;
158-
};
159-
160209
/** \brief Stream Motion JPEG.
161210
* \pre The camera has been initialized to JPEG mode.
162211
* \return number of frames streamed.

src/internal/frame.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ class Frame
9393
/** \brief Convert frame to BMP.
9494
*/
9595
bool toBmp();
96-
/** \we converted the buffer ourself outside the lib and need to set it!
97-
*/
98-
void
99-
setData(uint8_t* newdata, size_t newsize, bool bIsBmp);
100-
96+
10197
/** \we converted the buffer ourself outside the lib and need to set it!
10298
*/
10399
void

src/internal/resolution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ Resolution::find(int minWidth, int minHeight)
4040
return res;
4141
}
4242

43-
} // namespace esp32cam
43+
} // namespace esp32cam

src/internal/resolution.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ class Resolution
3535

3636
} // namespace esp32cam
3737

38-
#endif // ESP32CAM_RESOLUTION_HPP
38+
#endif // ESP32CAM_RESOLUTION_HPP

0 commit comments

Comments
 (0)