Skip to content

Commit 6a0f318

Browse files
committed
Initial implementation of API/user config controlled auto exposure and gain settings
1 parent dfcb17e commit 6a0f318

File tree

5 files changed

+63
-5
lines changed

5 files changed

+63
-5
lines changed

ESP/ini/dev_config.ini

+7-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ build_flags =
2828
-DENABLE_ADHOC=${wifi.enableadhoc}
2929
-DADHOC_CHANNEL=${wifi.adhocchannel}
3030
-DWIFI_CHANNEL=${wifi.channel}
31-
-DDEBUG_ESP_PORT=Serial
32-
'-DMDNS_HOSTNAME=${wifi.mdnsname}'
31+
-DSIMPLE_AUTO_EXPOSURE_ON=${autoexposure.simple_auto_exposure_on}
32+
-DFANCY_AUTO_EXPOSURE_ON=${autoexposure.fancy_auto_exposure_on}
33+
-DAE_LEVEL=${autoexposure.ae_level}
34+
-DAEC_VALUE=${autoexposure.aec_value}
35+
-DAUTO_GAIN_ON=${autoexposure.auto_gain_on}
36+
-DDEBUG_ESP_PORT=Serial ; set the debug port
37+
'-DMDNS_HOSTNAME=${wifi.mdnsname}' ; Set the OTA password
3338
'-DWIFI_SSID=${wifi.ssid}'
3439
'-DWIFI_PASSWORD=${wifi.password}'
3540
'-DWIFI_AP_SSID=${wifi.ap_ssid}'

ESP/ini/user_config.ini

+11
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,14 @@ otaserverip = "openiristracker.local"
1717
otalogin = "openiris"
1818
otapassword = "12345678"
1919
otaserverport = 3232
20+
21+
[autoexposure]
22+
simple_auto_exposure_on = 0 ; should the auto exposure be enabled, 0 - off, 1 - on
23+
fancy_auto_exposure_on = 0 ; should the more advanced auto exposure be enabled, 0 - on, 1 - off
24+
25+
ae_level = 0 ; auto exposure level, -2 to 2, 0 is the default
26+
aec_value = 300 ; auto exposure control, a sort of brightness, 0 - 1200
27+
28+
auto_gain_on = 0 ; should the auto gain be enabled, 0 - off, 1 - on
29+
30+
brightness = 2 ; controls the brightness, -2 to 2, to is the default

ESP/lib/src/data/config/project_config.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,23 @@ void ProjectConfig::setCameraConfig(uint8_t* vflip,
238238
uint8_t* href,
239239
uint8_t* quality,
240240
uint8_t* brightness,
241+
bool simple_auto_exposure_on,
242+
bool fancy_auto_exposure_on,
243+
int ae_level,
244+
unsigned int aec_value,
245+
bool auto_gain_on,
241246
bool shouldNotify) {
242247
log_d("Updating camera config");
243248
this->config.camera.vflip = *vflip;
244249
this->config.camera.href = *href;
245250
this->config.camera.framesize = *framesize;
246251
this->config.camera.quality = *quality;
247252
this->config.camera.brightness = *brightness;
253+
this->config.camera.simple_auto_exposure_on = simple_auto_exposure_on;
254+
this->config.camera.fancy_auto_exposure_on = fancy_auto_exposure_on;
255+
this->config.camera.ae_level = ae_level;
256+
this->config.camera.aec_value = aec_value;
257+
this->config.camera.auto_gain_on = auto_gain_on;
248258

249259
log_d("Updating Camera config");
250260
if (shouldNotify)
@@ -372,9 +382,10 @@ std::string ProjectConfig::MDNSConfig_t::toRepresentation() {
372382
std::string ProjectConfig::CameraConfig_t::toRepresentation() {
373383
std::string json = Helpers::format_string(
374384
"\"camera_config\": {\"vflip\": %d,\"framesize\": %d,\"href\": "
375-
"%d,\"quality\": %d,\"brightness\": %d}",
385+
"%d,\"quality\": %d,\"brightness\": %d, \"simple_auto_exposure_on\": %d, \"fancy_auto_exposure_on\": %d,\"ae_level\": %d, \"aec_value\": %d, \"auto_gain_on\": %d }",
376386
this->vflip, this->framesize, this->href, this->quality,
377-
this->brightness);
387+
this->brightness, this->simple_auto_exposure_on, this->fancy_auto_exposure_on,
388+
this->aec_value, this->ae_level, this->auto_gain_on);
378389
return json;
379390
}
380391

ESP/lib/src/data/config/project_config.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class ProjectConfig : public Preferences, public ISubject {
4545
uint8_t framesize;
4646
uint8_t quality;
4747
uint8_t brightness;
48+
bool simple_auto_exposure_on;
49+
bool fancy_auto_exposure_on;
50+
int ae_level;
51+
unsigned int aec_value;
52+
bool auto_gain_on;
4853

4954
std::string toRepresentation();
5055
};
@@ -114,6 +119,11 @@ class ProjectConfig : public Preferences, public ISubject {
114119
uint8_t* href,
115120
uint8_t* quality,
116121
uint8_t* brightness,
122+
bool simple_auto_exposure_on,
123+
bool fancy_auto_exposure_on,
124+
int ae_level,
125+
unsigned int aec_value,
126+
bool auto_gain_on,
117127
bool shouldNotify);
118128
void setWifiConfig(const std::string& networkName,
119129
const std::string& ssid,

ESP/lib/src/network/api/baseAPI/baseAPI.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,17 @@ void BaseAPI::setCamera(AsyncWebServerRequest* request) {
284284
uint8_t temp_camera_hflip = 0;
285285
uint8_t temp_camera_quality = 0;
286286
uint8_t temp_camera_brightness = 0;
287+
uint8_t temp_simple_auto_exposure_on = SIMPLE_AUTO_EXPOSURE_ON;
288+
uint8_t temp_fancy_auto_exposure_on = FANCY_AUTO_EXPOSURE_ON;
289+
int temp_ae_level = AE_LEVEL;
290+
unsigned int temp_aec_value = AEC_VALUE;
291+
uint8_t temp_auto_gain_on = AUTO_GAIN_ON;
292+
287293

288294
int params = request->params();
295+
// TODO we probably should refactor this at some point, maybe some serialization of sorts, or direct mapping of
296+
// TODO get parameters? Can we even do that?
297+
289298
//! Using the else if statements to ensure that the values do not need to
290299
//! be set in a specific order This means the order of the URL params does
291300
//! not matter
@@ -301,13 +310,25 @@ void BaseAPI::setCamera(AsyncWebServerRequest* request) {
301310
temp_camera_quality = (uint8_t)param->value().toInt();
302311
} else if (param->name() == "brightness") {
303312
temp_camera_brightness = (uint8_t)param->value().toInt();
313+
} else if (param->name() == "simple_auto_exposure_on") {
314+
temp_simple_auto_exposure_on = (uint8_t)param->value().toInt();
315+
} else if (param->name() == "fancy_auto_exposure_on") {
316+
temp_fancy_auto_exposure_on = (uint8_t)param->value().toInt();
317+
} else if (param->name() == "ae_level") {
318+
temp_ae_level = param->value().toInt();
319+
} else if (param->name() == "aec_value") {
320+
temp_aec_value = (uint8_t)param->value().toInt();
321+
} else if (param->name() == "auto_gain_on") {
322+
temp_auto_gain_on = (uint8_t)param->value().toInt();
304323
}
305324
}
306325
// note: We're passing empty params by design, this is done to reset
307326
// specific fields
308327
projectConfig->setCameraConfig(&temp_camera_vflip, &temp_camera_framesize,
309328
&temp_camera_hflip, &temp_camera_quality,
310-
&temp_camera_brightness, true);
329+
&temp_camera_brightness, temp_simple_auto_exposure_on,
330+
temp_fancy_auto_exposure_on, temp_ae_level,
331+
temp_aec_value, temp_auto_gain_on, true);
311332

312333
request->send(200, MIMETYPE_JSON,
313334
"{\"msg\":\"Done. Camera Settings have been set.\"}");

0 commit comments

Comments
 (0)