|
|
|
|
@ -7,6 +7,7 @@
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include "configuration.h"
|
|
|
|
|
@ -53,6 +54,14 @@ static void *thread_video(void *ignored_argument) {
|
|
|
|
|
timeval tv_fps;
|
|
|
|
|
time_t time_fps, time_refreshctls;
|
|
|
|
|
float current_brightness = 0.5;
|
|
|
|
|
float brightness_error_sum = 0.0f;
|
|
|
|
|
float brightness_error_integral = 0.0f;
|
|
|
|
|
int brightness_sample_count = 0;
|
|
|
|
|
const int brightness_settle_frames = 5;
|
|
|
|
|
const float brightness_deadband = 0.01f;
|
|
|
|
|
const float brightness_kp = 0.10f;
|
|
|
|
|
const float brightness_ki = 0.01f;
|
|
|
|
|
const float brightness_integral_limit = 2.0f;
|
|
|
|
|
|
|
|
|
|
time_fps = time(NULL);
|
|
|
|
|
time_refreshctls = time(NULL);
|
|
|
|
|
@ -96,6 +105,7 @@ static void *thread_video(void *ignored_argument) {
|
|
|
|
|
debug ("Brightness: %f", current_brightness);
|
|
|
|
|
}
|
|
|
|
|
Lock();
|
|
|
|
|
current_brightness = 0.0f;
|
|
|
|
|
inputimage.CopyTo(¤timage, config.web_width, config.web_height, ¤t_brightness);
|
|
|
|
|
if (inputfloatfilter.AddScaledImage(&inputfloat, config.filter_ratio) == 0)
|
|
|
|
|
inputfloat.CopyTo(&inputfloatfilter);
|
|
|
|
|
@ -119,17 +129,47 @@ static void *thread_video(void *ignored_argument) {
|
|
|
|
|
config.auto_brightness = 0; // disable auto brightness if control not found
|
|
|
|
|
}
|
|
|
|
|
if (found) {
|
|
|
|
|
int new_ctrl_value = it->value;
|
|
|
|
|
|
|
|
|
|
if (config.auto_brightness_target < 0.0f) config.auto_brightness_target = 0.0f;
|
|
|
|
|
if (config.auto_brightness_target > 1.0f) config.auto_brightness_target = 1.0f;
|
|
|
|
|
|
|
|
|
|
if (current_brightness < config.auto_brightness_target) {
|
|
|
|
|
new_ctrl_value += 1; // increase brightness
|
|
|
|
|
} else if (current_brightness > config.auto_brightness_target) {
|
|
|
|
|
new_ctrl_value -= 1; // decrease brightness
|
|
|
|
|
brightness_error_sum += config.auto_brightness_target - current_brightness;
|
|
|
|
|
if (++brightness_sample_count >= brightness_settle_frames) {
|
|
|
|
|
float error = brightness_error_sum / brightness_sample_count;
|
|
|
|
|
int control_range = it->max - it->min;
|
|
|
|
|
brightness_error_sum = 0.0f;
|
|
|
|
|
brightness_sample_count = 0;
|
|
|
|
|
|
|
|
|
|
if (std::fabs(error) <= brightness_deadband) {
|
|
|
|
|
brightness_error_integral = 0.0f;
|
|
|
|
|
} else if (control_range > 0) {
|
|
|
|
|
if (!((it->value <= it->min && error < 0.0f) ||
|
|
|
|
|
(it->value >= it->max && error > 0.0f))) {
|
|
|
|
|
brightness_error_integral += error;
|
|
|
|
|
if (brightness_error_integral > brightness_integral_limit)
|
|
|
|
|
brightness_error_integral = brightness_integral_limit;
|
|
|
|
|
if (brightness_error_integral < -brightness_integral_limit)
|
|
|
|
|
brightness_error_integral = -brightness_integral_limit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float adjustment = (brightness_kp * error + brightness_ki * brightness_error_integral) * control_range;
|
|
|
|
|
int max_step = control_range / 32;
|
|
|
|
|
if (max_step < 1) max_step = 1;
|
|
|
|
|
if (adjustment > max_step) adjustment = max_step;
|
|
|
|
|
if (adjustment < -max_step) adjustment = -max_step;
|
|
|
|
|
|
|
|
|
|
int change = static_cast<int>(std::lround(adjustment));
|
|
|
|
|
if (change == 0) change = error > 0.0f ? 1 : -1;
|
|
|
|
|
|
|
|
|
|
int new_ctrl_value = it->value + change;
|
|
|
|
|
if (new_ctrl_value < it->min) new_ctrl_value = it->min;
|
|
|
|
|
if (new_ctrl_value > it->max) new_ctrl_value = it->max;
|
|
|
|
|
|
|
|
|
|
debug("Auto Brightness: current=%f, target=%f, error=%f, new_ctrl_value=%d",
|
|
|
|
|
current_brightness, config.auto_brightness_target, error, new_ctrl_value);
|
|
|
|
|
if (new_ctrl_value != it->value)
|
|
|
|
|
vdev->SetDevCtrl(config.auto_brightness, new_ctrl_value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
vdev->SetDevCtrl(config.auto_brightness, new_ctrl_value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|