Extract set_variable() from cmd_handler()

pull/171/head
Michael Ludvig 2021-02-03 20:58:19 +13:00
parent b34eb8f7d4
commit d021b14e42
1 changed files with 104 additions and 92 deletions

View File

@ -294,6 +294,108 @@ void enable_led(bool en)
} }
#endif #endif
static esp_err_t set_variable(const char *variable, int val, sensor_t *s, bool ignore_unknown)
{
int res = 0;
ESP_LOGI(TAG, "%s = %d", variable, val);
if (!strcmp(variable, "framesize")) {
if (s->pixformat == PIXFORMAT_JPEG) {
res = s->set_framesize(s, (framesize_t)val);
if (res == 0) {
app_mdns_update_framesize(val);
}
}
}
else if (!strcmp(variable, "fps_max")) {
fps_max = val;
fps_period_us = FPS_TO_PERIOD(fps_max);
}
else if (!strcmp(variable, "quality"))
res = s->set_quality(s, val);
else if (!strcmp(variable, "contrast"))
res = s->set_contrast(s, val);
else if (!strcmp(variable, "brightness"))
res = s->set_brightness(s, val);
else if (!strcmp(variable, "saturation"))
res = s->set_saturation(s, val);
else if (!strcmp(variable, "gainceiling"))
res = s->set_gainceiling(s, (gainceiling_t)val);
else if (!strcmp(variable, "colorbar"))
res = s->set_colorbar(s, val);
else if (!strcmp(variable, "awb"))
res = s->set_whitebal(s, val);
else if (!strcmp(variable, "agc"))
res = s->set_gain_ctrl(s, val);
else if (!strcmp(variable, "aec"))
res = s->set_exposure_ctrl(s, val);
else if (!strcmp(variable, "hmirror"))
res = s->set_hmirror(s, val);
else if (!strcmp(variable, "vflip"))
res = s->set_vflip(s, val);
else if (!strcmp(variable, "awb_gain"))
res = s->set_awb_gain(s, val);
else if (!strcmp(variable, "agc_gain"))
res = s->set_agc_gain(s, val);
else if (!strcmp(variable, "aec_value"))
res = s->set_aec_value(s, val);
else if (!strcmp(variable, "aec2"))
res = s->set_aec2(s, val);
else if (!strcmp(variable, "dcw"))
res = s->set_dcw(s, val);
else if (!strcmp(variable, "bpc"))
res = s->set_bpc(s, val);
else if (!strcmp(variable, "wpc"))
res = s->set_wpc(s, val);
else if (!strcmp(variable, "raw_gma"))
res = s->set_raw_gma(s, val);
else if (!strcmp(variable, "lenc"))
res = s->set_lenc(s, val);
else if (!strcmp(variable, "special_effect"))
res = s->set_special_effect(s, val);
else if (!strcmp(variable, "wb_mode"))
res = s->set_wb_mode(s, val);
else if (!strcmp(variable, "ae_level"))
res = s->set_ae_level(s, val);
#ifdef CONFIG_LED_ILLUMINATOR_ENABLED
else if (!strcmp(variable, "led_intensity")) {
led_duty = val;
if (isStreaming)
enable_led(true);
}
#endif
#if CONFIG_ESP_FACE_DETECT_ENABLED
else if (!strcmp(variable, "face_detect")) {
detection_enabled = val;
#if CONFIG_ESP_FACE_RECOGNITION_ENABLED
if (!detection_enabled) {
recognition_enabled = 0;
}
#endif
}
#if CONFIG_ESP_FACE_RECOGNITION_ENABLED
else if (!strcmp(variable, "face_enroll"))
is_enrolling = val;
else if (!strcmp(variable, "face_recognize")) {
recognition_enabled = val;
if (recognition_enabled) {
detection_enabled = val;
}
}
#endif
#endif
else {
ESP_LOGI(TAG, "Unknown variable: %s = %d", variable, val);
if (!ignore_unknown) {
res = -1;
}
}
return res;
}
static esp_err_t bmp_handler(httpd_req_t *req) static esp_err_t bmp_handler(httpd_req_t *req)
{ {
camera_fb_t *fb = NULL; camera_fb_t *fb = NULL;
@ -714,6 +816,7 @@ static esp_err_t cmd_handler(httpd_req_t *req)
char *buf = NULL; char *buf = NULL;
char variable[32]; char variable[32];
char value[32]; char value[32];
esp_err_t res;
if (parse_get(req, &buf) != ESP_OK) { if (parse_get(req, &buf) != ESP_OK) {
return ESP_FAIL; return ESP_FAIL;
@ -727,100 +830,9 @@ static esp_err_t cmd_handler(httpd_req_t *req)
free(buf); free(buf);
int val = atoi(value); int val = atoi(value);
ESP_LOGI(TAG, "%s = %d", variable, val);
sensor_t *s = esp_camera_sensor_get(); sensor_t *s = esp_camera_sensor_get();
int res = 0;
if (!strcmp(variable, "framesize")) { res = set_variable(variable, val, s, false);
if (s->pixformat == PIXFORMAT_JPEG) {
res = s->set_framesize(s, (framesize_t)val);
if (res == 0) {
app_mdns_update_framesize(val);
}
}
}
else if (!strcmp(variable, "fps_max")) {
fps_max = val;
fps_period_us = FPS_TO_PERIOD(fps_max);
}
else if (!strcmp(variable, "quality"))
res = s->set_quality(s, val);
else if (!strcmp(variable, "contrast"))
res = s->set_contrast(s, val);
else if (!strcmp(variable, "brightness"))
res = s->set_brightness(s, val);
else if (!strcmp(variable, "saturation"))
res = s->set_saturation(s, val);
else if (!strcmp(variable, "gainceiling"))
res = s->set_gainceiling(s, (gainceiling_t)val);
else if (!strcmp(variable, "colorbar"))
res = s->set_colorbar(s, val);
else if (!strcmp(variable, "awb"))
res = s->set_whitebal(s, val);
else if (!strcmp(variable, "agc"))
res = s->set_gain_ctrl(s, val);
else if (!strcmp(variable, "aec"))
res = s->set_exposure_ctrl(s, val);
else if (!strcmp(variable, "hmirror"))
res = s->set_hmirror(s, val);
else if (!strcmp(variable, "vflip"))
res = s->set_vflip(s, val);
else if (!strcmp(variable, "awb_gain"))
res = s->set_awb_gain(s, val);
else if (!strcmp(variable, "agc_gain"))
res = s->set_agc_gain(s, val);
else if (!strcmp(variable, "aec_value"))
res = s->set_aec_value(s, val);
else if (!strcmp(variable, "aec2"))
res = s->set_aec2(s, val);
else if (!strcmp(variable, "dcw"))
res = s->set_dcw(s, val);
else if (!strcmp(variable, "bpc"))
res = s->set_bpc(s, val);
else if (!strcmp(variable, "wpc"))
res = s->set_wpc(s, val);
else if (!strcmp(variable, "raw_gma"))
res = s->set_raw_gma(s, val);
else if (!strcmp(variable, "lenc"))
res = s->set_lenc(s, val);
else if (!strcmp(variable, "special_effect"))
res = s->set_special_effect(s, val);
else if (!strcmp(variable, "wb_mode"))
res = s->set_wb_mode(s, val);
else if (!strcmp(variable, "ae_level"))
res = s->set_ae_level(s, val);
#ifdef CONFIG_LED_ILLUMINATOR_ENABLED
else if (!strcmp(variable, "led_intensity")) {
led_duty = val;
if (isStreaming)
enable_led(true);
}
#endif
#if CONFIG_ESP_FACE_DETECT_ENABLED
else if (!strcmp(variable, "face_detect")) {
detection_enabled = val;
#if CONFIG_ESP_FACE_RECOGNITION_ENABLED
if (!detection_enabled) {
recognition_enabled = 0;
}
#endif
}
#if CONFIG_ESP_FACE_RECOGNITION_ENABLED
else if (!strcmp(variable, "face_enroll"))
is_enrolling = val;
else if (!strcmp(variable, "face_recognize")) {
recognition_enabled = val;
if (recognition_enabled) {
detection_enabled = val;
}
}
#endif
#endif
else {
ESP_LOGI(TAG, "Unknown command: %s", variable);
res = -1;
}
if (res < 0) { if (res < 0) {
return httpd_resp_send_500(req); return httpd_resp_send_500(req);