mirror of
https://github.com/EyeTrackVR/OpenIris.git
synced 2025-11-04 15:39:42 +08:00
Initial implementation of API/user config controlled auto exposure and gain settings
This commit is contained in:
parent
7e8aab2ed3
commit
cf0b395fd9
@ -30,8 +30,14 @@ build_flags =
|
||||
-DADHOC_CHANNEL=${wifi.adhocchannel}
|
||||
-DWIFI_CHANNEL=${wifi.channel}
|
||||
-DDEBUG_ESP_PORT=Serial
|
||||
'-DVERSION=""' ; set the debug port
|
||||
'-DMDNS_HOSTNAME=${wifi.mdnsname}' ; Set the OTA password
|
||||
'-DVERSION=""'
|
||||
'-DMDNS_HOSTNAME=${wifi.mdnsname}'
|
||||
-DSIMPLE_AUTO_EXPOSURE_ON=${autoexposure.simple_auto_exposure_on}
|
||||
-DFANCY_AUTO_EXPOSURE_ON=${autoexposure.fancy_auto_exposure_on}
|
||||
-DAE_LEVEL=${autoexposure.ae_level}
|
||||
-DAEC_VALUE=${autoexposure.aec_value}
|
||||
-DAUTO_GAIN_ON=${autoexposure.auto_gain_on}
|
||||
-DBRIGHTNESS=${autoexposure.brightness}
|
||||
'-DWIFI_SSID=${wifi.ssid}'
|
||||
'-DWIFI_PASSWORD=${wifi.password}'
|
||||
'-DWIFI_AP_SSID=${wifi.ap_ssid}'
|
||||
|
||||
@ -17,3 +17,14 @@ otaserverip = "openiristracker.local"
|
||||
otalogin = "openiris"
|
||||
otapassword = "12345678"
|
||||
otaserverport = 3232
|
||||
|
||||
[autoexposure]
|
||||
simple_auto_exposure_on = 0 ; should the auto exposure be enabled, 0 - off, 1 - on
|
||||
fancy_auto_exposure_on = 0 ; should the more advanced auto exposure be enabled, 0 - on, 1 - off
|
||||
|
||||
ae_level = 0 ; auto exposure level, -2 to 2, 0 is the default
|
||||
aec_value = 300 ; auto exposure control, a sort of brightness, 0 - 1200
|
||||
|
||||
auto_gain_on = 0 ; should the auto gain be enabled, 0 - off, 1 - on
|
||||
|
||||
brightness = 2 ; controls the brightness, -2 to 2, to is the default
|
||||
@ -55,7 +55,12 @@ void ProjectConfig::initConfig() {
|
||||
.href = 0,
|
||||
.framesize = 4,
|
||||
.quality = 7,
|
||||
.brightness = 2,
|
||||
.brightness = BRIGHTNESS,
|
||||
.simple_auto_exposure_on = SIMPLE_AUTO_EXPOSURE_ON,
|
||||
.fancy_auto_exposure_on = FANCY_AUTO_EXPOSURE_ON,
|
||||
.ae_level = AE_LEVEL,
|
||||
.aec_value = AEC_VALUE,
|
||||
.auto_gain_on = AUTO_GAIN_ON,
|
||||
};
|
||||
}
|
||||
|
||||
@ -132,6 +137,12 @@ void ProjectConfig::cameraConfigSave() {
|
||||
putInt("framesize", this->config.camera.framesize);
|
||||
putInt("quality", this->config.camera.quality);
|
||||
putInt("brightness", this->config.camera.brightness);
|
||||
putInt("brightness", this->config.camera.brightness);
|
||||
putInt("simple_auto_exposure_on", this->config.camera.fancy_auto_exposure_on);
|
||||
putInt("fancy_auto_exposure_on", this->config.camera.fancy_auto_exposure_on);
|
||||
putInt("ae_level", this->config.camera.ae_level);
|
||||
putInt("aec_value", this->config.camera.aec_value);
|
||||
putInt("auto_gain_on ", this->config.camera.auto_gain_on);
|
||||
}
|
||||
|
||||
bool ProjectConfig::reset() {
|
||||
@ -198,7 +209,12 @@ void ProjectConfig::load() {
|
||||
this->config.camera.href = getInt("href", 0);
|
||||
this->config.camera.framesize = getInt("framesize", 4);
|
||||
this->config.camera.quality = getInt("quality", 7);
|
||||
this->config.camera.brightness = getInt("brightness", 2);
|
||||
this->config.camera.brightness = getInt("brightness", BRIGHTNESS);
|
||||
this->config.camera.fancy_auto_exposure_on = getInt("simple_auto_exposure_on", SIMPLE_AUTO_EXPOSURE_ON);
|
||||
this->config.camera.fancy_auto_exposure_on = getInt("fancy_auto_exposure_on", FANCY_AUTO_EXPOSURE_ON);
|
||||
this->config.camera.ae_level = getInt("ae_level", AE_LEVEL);
|
||||
this->config.camera.aec_value = getInt("aec_value", AEC_VALUE);
|
||||
this->config.camera.auto_gain_on = getInt("auto_gain_on ", AUTO_GAIN_ON);
|
||||
|
||||
this->_already_loaded = true;
|
||||
this->notifyAll(ConfigState_e::configLoaded);
|
||||
@ -238,6 +254,11 @@ void ProjectConfig::setCameraConfig(uint8_t vflip,
|
||||
uint8_t href,
|
||||
uint8_t quality,
|
||||
uint8_t brightness,
|
||||
bool simple_auto_exposure_on,
|
||||
bool fancy_auto_exposure_on,
|
||||
int ae_level,
|
||||
unsigned int aec_value,
|
||||
bool auto_gain_on,
|
||||
bool shouldNotify) {
|
||||
log_d("Updating camera config");
|
||||
this->config.camera.vflip = vflip;
|
||||
@ -245,6 +266,11 @@ void ProjectConfig::setCameraConfig(uint8_t vflip,
|
||||
this->config.camera.framesize = framesize;
|
||||
this->config.camera.quality = quality;
|
||||
this->config.camera.brightness = brightness;
|
||||
this->config.camera.simple_auto_exposure_on = simple_auto_exposure_on;
|
||||
this->config.camera.fancy_auto_exposure_on = fancy_auto_exposure_on;
|
||||
this->config.camera.ae_level = ae_level;
|
||||
this->config.camera.aec_value = aec_value;
|
||||
this->config.camera.auto_gain_on = auto_gain_on;
|
||||
|
||||
log_d("Updating Camera config");
|
||||
if (shouldNotify)
|
||||
@ -384,9 +410,10 @@ std::string ProjectConfig::MDNSConfig_t::toRepresentation() {
|
||||
std::string ProjectConfig::CameraConfig_t::toRepresentation() {
|
||||
std::string json = Helpers::format_string(
|
||||
"\"camera_config\": {\"vflip\": %d,\"framesize\": %d,\"href\": "
|
||||
"%d,\"quality\": %d,\"brightness\": %d}",
|
||||
"%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 }",
|
||||
this->vflip, this->framesize, this->href, this->quality,
|
||||
this->brightness);
|
||||
this->brightness, this->simple_auto_exposure_on, this->fancy_auto_exposure_on,
|
||||
this->aec_value, this->ae_level, this->auto_gain_on);
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
@ -47,6 +47,11 @@ class ProjectConfig : public Preferences, public ISubject<ConfigState_e> {
|
||||
uint8_t framesize;
|
||||
uint8_t quality;
|
||||
uint8_t brightness;
|
||||
bool simple_auto_exposure_on;
|
||||
bool fancy_auto_exposure_on;
|
||||
int ae_level;
|
||||
int aec_value;
|
||||
bool auto_gain_on;
|
||||
|
||||
std::string toRepresentation();
|
||||
};
|
||||
@ -116,6 +121,11 @@ class ProjectConfig : public Preferences, public ISubject<ConfigState_e> {
|
||||
uint8_t href,
|
||||
uint8_t quality,
|
||||
uint8_t brightness,
|
||||
bool simple_auto_exposure_on,
|
||||
bool fancy_auto_exposure_on,
|
||||
int ae_level,
|
||||
unsigned int aec_value,
|
||||
bool auto_gain_on,
|
||||
bool shouldNotify);
|
||||
void setWifiConfig(const std::string& networkName,
|
||||
const std::string& ssid,
|
||||
|
||||
@ -89,7 +89,7 @@ void CameraHandler::setupCameraSensor() {
|
||||
0x00); // banksel, here we're directly writing to the registers.
|
||||
// 0xFF==0x00 is the first bank, there's also 0xFF==0x01
|
||||
camera_sensor->set_reg(camera_sensor, 0xd3, 0xff, 5); // clock
|
||||
camera_sensor->set_brightness(camera_sensor, 2); // -2 to 2
|
||||
camera_sensor->set_brightness(camera_sensor, cameraConfig->brightness); // -2 to 2
|
||||
camera_sensor->set_contrast(camera_sensor, 2); // -2 to 2
|
||||
camera_sensor->set_saturation(camera_sensor, -2); // -2 to 2
|
||||
|
||||
@ -101,14 +101,13 @@ void CameraHandler::setupCameraSensor() {
|
||||
// Sunny, 2 - Cloudy, 3 - Office, 4 - Home)
|
||||
|
||||
// controls the exposure
|
||||
camera_sensor->set_exposure_ctrl(camera_sensor,
|
||||
0); // 0 = disable , 1 = enable
|
||||
camera_sensor->set_aec2(camera_sensor, 0); // 0 = disable , 1 = enable
|
||||
camera_sensor->set_ae_level(camera_sensor, 0); // -2 to 2
|
||||
camera_sensor->set_aec_value(camera_sensor, 300); // 0 to 1200
|
||||
camera_sensor->set_exposure_ctrl(camera_sensor, cameraConfig->simple_auto_exposure_on); // 0 = disable , 1 = enable
|
||||
camera_sensor->set_aec2(camera_sensor, cameraConfig->fancy_auto_exposure_on); // 0 = disable , 1 = enable
|
||||
camera_sensor->set_ae_level(camera_sensor, cameraConfig->ae_level); // -2 to 2
|
||||
camera_sensor->set_aec_value(camera_sensor, cameraConfig->aec_value); // 0 to 1200
|
||||
|
||||
// controls the gain
|
||||
camera_sensor->set_gain_ctrl(camera_sensor, 0); // 0 = disable , 1 = enable
|
||||
camera_sensor->set_gain_ctrl(camera_sensor, cameraConfig->auto_gain_on); // 0 = disable , 1 = enable
|
||||
|
||||
// automatic gain control gain, controls by how much the resulting image
|
||||
// should be amplified
|
||||
@ -186,13 +185,6 @@ int CameraHandler::setHFlip(int direction) {
|
||||
return camera_sensor->set_hmirror(camera_sensor, direction);
|
||||
}
|
||||
|
||||
int CameraHandler::setVieWindow(int offsetX,
|
||||
int offsetY,
|
||||
int outputX,
|
||||
int outputY) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//! either hardware(1) or software(0)
|
||||
void CameraHandler::resetCamera(bool type) {
|
||||
if (type) {
|
||||
|
||||
@ -286,8 +286,17 @@ void BaseAPI::setCamera(AsyncWebServerRequest* request) {
|
||||
uint8_t temp_camera_hflip = 0;
|
||||
uint8_t temp_camera_quality = 0;
|
||||
uint8_t temp_camera_brightness = 0;
|
||||
uint8_t temp_simple_auto_exposure_on = SIMPLE_AUTO_EXPOSURE_ON;
|
||||
uint8_t temp_fancy_auto_exposure_on = FANCY_AUTO_EXPOSURE_ON;
|
||||
int temp_ae_level = AE_LEVEL;
|
||||
unsigned int temp_aec_value = AEC_VALUE;
|
||||
uint8_t temp_auto_gain_on = AUTO_GAIN_ON;
|
||||
|
||||
|
||||
int params = request->params();
|
||||
// TODO we probably should refactor this at some point, maybe some serialization of sorts, or direct mapping of
|
||||
// TODO get parameters? Can we even do that?
|
||||
|
||||
//! Using the else if statements to ensure that the values do not need to
|
||||
//! be set in a specific order This means the order of the URL params does
|
||||
//! not matter
|
||||
@ -303,13 +312,25 @@ void BaseAPI::setCamera(AsyncWebServerRequest* request) {
|
||||
temp_camera_quality = (uint8_t)param->value().toInt();
|
||||
} else if (param->name() == "brightness") {
|
||||
temp_camera_brightness = (uint8_t)param->value().toInt();
|
||||
} else if (param->name() == "simple_auto_exposure_on") {
|
||||
temp_simple_auto_exposure_on = (uint8_t)param->value().toInt();
|
||||
} else if (param->name() == "fancy_auto_exposure_on") {
|
||||
temp_fancy_auto_exposure_on = (uint8_t)param->value().toInt();
|
||||
} else if (param->name() == "ae_level") {
|
||||
temp_ae_level = param->value().toInt();
|
||||
} else if (param->name() == "aec_value") {
|
||||
temp_aec_value = (uint8_t)param->value().toInt();
|
||||
} else if (param->name() == "auto_gain_on") {
|
||||
temp_auto_gain_on = (uint8_t)param->value().toInt();
|
||||
}
|
||||
}
|
||||
// note: We're passing empty params by design, this is done to reset
|
||||
// specific fields
|
||||
projectConfig.setCameraConfig(temp_camera_vflip, temp_camera_framesize,
|
||||
temp_camera_hflip, temp_camera_quality,
|
||||
temp_camera_brightness, true);
|
||||
temp_camera_brightness, temp_simple_auto_exposure_on,
|
||||
temp_fancy_auto_exposure_on, temp_ae_level,
|
||||
temp_aec_value, temp_auto_gain_on, true);
|
||||
|
||||
request->send(200, MIMETYPE_JSON,
|
||||
"{\"msg\":\"Done. Camera Settings have been set.\"}");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user