Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5ae42fb

Browse files
add some config control to ESP32Camera
1 parent 0154915 commit 5ae42fb

File tree

4 files changed

+164
-4
lines changed

4 files changed

+164
-4
lines changed

‎library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "git",
77
"url": "https://github.com/eloquentarduino/EloquentArduino"
88
},
9-
"version": "1.1.12",
9+
"version": "1.1.13",
1010
"authors": {
1111
"name": "Simone Salerno",
1212
"url": "https://github.com/eloquentarduino"

‎library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=EloquentArduino
2-
version=1.1.12
2+
version=1.1.13
33
author=Simone Salerno <eloquentarduino@gmail.com>
44
maintainer=Simone Salerno <eloquentarduino@gmail.com>
55
sentence=An eloquent interface to common Arduino patterns, data structures and algorithms

‎src/eloquentarduino/vision/camera/ESP32Camera.h

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,85 @@ namespace Eloquent {
6161

6262
bool ok = esp_camera_init(&config) == ESP_OK;
6363

64-
sensor_t *sensor = esp_camera_sensor_get();
65-
sensor->set_framesize(sensor, frameSize);
64+
_sensor = esp_camera_sensor_get();
65+
_sensor->set_framesize(_sensor, frameSize);
6666

6767
return ok;
6868
}
6969

7070
/**
71+
* Capture image
7172
*
7273
* @return
7374
*/
7475
camera_fb_t *capture() {
7576
return (_frame = esp_camera_fb_get());
7677
}
7778

79+
/**
80+
* Enable manual exposure control
81+
*
82+
* @param exposure
83+
* @return
84+
*/
85+
int setExposure(uint16_t exposure) {
86+
return enableAutoExposure(false) && _sensor->set_aec_value(_sensor, exposure);
87+
}
88+
89+
/**
90+
* Set contrast
91+
*
92+
* @param contrast
93+
* @return
94+
*/
95+
int setContrast(int contrast) {
96+
return _sensor->set_contrast(_sensor, contrast);
97+
}
98+
99+
/**
100+
* Set brightness
101+
*
102+
* @param brightness
103+
* @return
104+
*/
105+
int setBrightness(int brightness) {
106+
return _sensor->set_brightness(_sensor, brightness);
107+
}
108+
109+
/**
110+
* Set saturation
111+
*
112+
* @param saturation
113+
* @return
114+
*/
115+
int setSaturation(int saturation) {
116+
return _sensor->set_saturation(_sensor, saturation);
117+
}
118+
119+
/**
120+
* Disable manual exposure control
121+
*
122+
* @param enable
123+
* @return
124+
*/
125+
int enableAutoExposure(bool enable = true) {
126+
return _sensor->set_exposure_ctrl(_sensor, enable);
127+
}
128+
129+
/**
130+
* Enable Automatic White Balancing
131+
*
132+
* @param enable
133+
* @return
134+
*/
135+
int enableAWB(bool enable = true) {
136+
return _sensor->set_whitebal(_sensor, enable);
137+
}
138+
78139
protected:
79140
pixformat_t _pixelFormat;
80141
camera_fb_t *_frame;
142+
sensor_t * _sensor;
81143
};
82144
}
83145
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#pragma once
2+
3+
#include <esp_http_server.h>
4+
5+
6+
namespace Eloquent {
7+
namespace Vision {
8+
namespace Camera {
9+
10+
class HTTPVideoStreamingServer {
11+
public:
12+
13+
/**
14+
*
15+
* @param port
16+
*/
17+
HTTPVideoStreamingServer(uint16_t port = 81) :
18+
_isPlaying(false) {
19+
_config = HTTPD_DEFAULT_CONFIG();
20+
_config.server_port = port;
21+
}
22+
23+
/**
24+
*
25+
* @return
26+
*/
27+
bool start() {
28+
if (_isPlaying)
29+
return true;
30+
31+
if (httpd_start(&_httpd, &_config) != ESP_OK)
32+
return false;
33+
34+
_isPlaying = true;
35+
36+
httpd_uri_t stream_uri = {
37+
.uri = "/",
38+
.method = HTTP_GET,
39+
.handler = [](httpd_req_t *req) {
40+
esp_err_t res = ESP_OK;
41+
char *part[64];
42+
43+
if (httpd_resp_set_type(req, "multipart/x-mixed-replace;boundary=123456789000000000000987654321") != ESP_OK)
44+
return ESP_FAIL;
45+
46+
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
47+
48+
while (true) {
49+
size_t contentTypeHeaderLength;
50+
camera_fb_t *fb = esp_camera_fb_get();
51+
52+
if (!fb)
53+
return ESP_FAIL;
54+
55+
contentTypeHeaderLength = snprintf((char *) part, 64,
56+
"Content-Type: image/jpeg\r\nContent-Length: %u\r\n\r\n", fb->len);
57+
58+
if (httpd_resp_send_chunk(req, (const char *) part, contentTypeHeaderLength) != ESP_OK)
59+
return ESP_FAIL;
60+
61+
if (httpd_resp_send_chunk(req, (const char *) fb->buf, fb->len) != ESP_OK) {
62+
esp_camera_fb_return(fb);
63+
64+
return ESP_FAIL;
65+
}
66+
67+
esp_camera_fb_return(fb);
68+
res = httpd_resp_send_chunk(req, "\r\n--123456789000000000000987654321\r\n", 37);
69+
fb = NULL;
70+
}
71+
72+
return ESP_OK;
73+
},
74+
.user_ctx = NULL
75+
};
76+
77+
httpd_register_uri_handler(_httpd, &stream_uri);
78+
79+
return true;
80+
}
81+
82+
/**
83+
* Stop the webserver
84+
*/
85+
void stop() {
86+
_isPlaying = false;
87+
httpd_unregister_uri(_httpd, "/");
88+
httpd_stop(_httpd);
89+
}
90+
91+
protected:
92+
bool _isPlaying;
93+
httpd_config_t _config;
94+
httpd_handle_t _httpd;
95+
};
96+
}
97+
}
98+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /