|
19 | 19 | #include "esp32-hal-ledc.h"
|
20 | 20 | #include "sdkconfig.h"
|
21 | 21 | #include "camera_index.h"
|
| 22 | +#include "board_config.h" |
22 | 23 |
|
23 | 24 | #if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
|
24 | 25 | #include "esp32-hal-log.h"
|
25 | 26 | #endif
|
26 | 27 |
|
27 |
| -// Enable LED FLASH setting |
28 |
| -#define CONFIG_LED_ILLUMINATOR_ENABLED 1 |
29 |
| - |
30 | 28 | // LED FLASH setup
|
31 |
| -#if CONFIG_LED_ILLUMINATOR_ENABLED |
32 |
| - |
| 29 | +#if defined(LED_GPIO_NUM) |
33 | 30 | #define CONFIG_LED_MAX_INTENSITY 255
|
34 | 31 |
|
35 |
| -int led_pin = 22; // Store the actual LED pin used |
36 | 32 | int led_duty = 0;
|
37 | 33 | bool isStreaming = false;
|
38 | 34 |
|
@@ -91,13 +87,13 @@ static int ra_filter_run(ra_filter_t *filter, int value) {
|
91 | 87 | }
|
92 | 88 | #endif
|
93 | 89 |
|
94 |
| -#if CONFIG_LED_ILLUMINATOR_ENABLED |
| 90 | +#if defined(LED_GPIO_NUM) |
95 | 91 | void enable_led(bool en) { // Turn LED On or Off
|
96 | 92 | int duty = en ? led_duty : 0;
|
97 | 93 | if (en && isStreaming && (led_duty > CONFIG_LED_MAX_INTENSITY)) {
|
98 | 94 | duty = CONFIG_LED_MAX_INTENSITY;
|
99 | 95 | }
|
100 |
| - ledcWrite(led_pin, duty); |
| 96 | + ledcWrite(LED_GPIO_NUM, duty); |
101 | 97 | //ledc_set_duty(CONFIG_LED_LEDC_SPEED_MODE, CONFIG_LED_LEDC_CHANNEL, duty);
|
102 | 98 | //ledc_update_duty(CONFIG_LED_LEDC_SPEED_MODE, CONFIG_LED_LEDC_CHANNEL);
|
103 | 99 | log_i("Set LED intensity to %d", duty);
|
@@ -162,7 +158,7 @@ static esp_err_t capture_handler(httpd_req_t *req) {
|
162 | 158 | int64_t fr_start = esp_timer_get_time();
|
163 | 159 | #endif
|
164 | 160 |
|
165 |
| -#if CONFIG_LED_ILLUMINATOR_ENABLED |
| 161 | +#if defined(LED_GPIO_NUM) |
166 | 162 | enable_led(true);
|
167 | 163 | vTaskDelay(150 / portTICK_PERIOD_MS); // The LED needs to be turned on ~150ms before the call to esp_camera_fb_get()
|
168 | 164 | fb = esp_camera_fb_get(); // or it won't be visible in the frame. A better way to do this is needed.
|
@@ -230,7 +226,7 @@ static esp_err_t stream_handler(httpd_req_t *req) {
|
230 | 226 | httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
231 | 227 | httpd_resp_set_hdr(req, "X-Framerate", "60");
|
232 | 228 |
|
233 |
| -#if CONFIG_LED_ILLUMINATOR_ENABLED |
| 229 | +#if defined(LED_GPIO_NUM) |
234 | 230 | isStreaming = true;
|
235 | 231 | enable_led(true);
|
236 | 232 | #endif
|
@@ -293,7 +289,7 @@ static esp_err_t stream_handler(httpd_req_t *req) {
|
293 | 289 | );
|
294 | 290 | }
|
295 | 291 |
|
296 |
| -#if CONFIG_LED_ILLUMINATOR_ENABLED |
| 292 | +#if defined(LED_GPIO_NUM) |
297 | 293 | isStreaming = false;
|
298 | 294 | enable_led(false);
|
299 | 295 | #endif
|
@@ -393,7 +389,7 @@ static esp_err_t cmd_handler(httpd_req_t *req) {
|
393 | 389 | } else if (!strcmp(variable, "ae_level")) {
|
394 | 390 | res = s->set_ae_level(s, val);
|
395 | 391 | }
|
396 |
| -#if CONFIG_LED_ILLUMINATOR_ENABLED |
| 392 | +#if defined(LED_GPIO_NUM) |
397 | 393 | else if (!strcmp(variable, "led_intensity")) {
|
398 | 394 | led_duty = val;
|
399 | 395 | if (isStreaming) {
|
@@ -481,7 +477,7 @@ static esp_err_t status_handler(httpd_req_t *req) {
|
481 | 477 | p += sprintf(p, "\"vflip\":%u,", s->status.vflip);
|
482 | 478 | p += sprintf(p, "\"dcw\":%u,", s->status.dcw);
|
483 | 479 | p += sprintf(p, "\"colorbar\":%u", s->status.colorbar);
|
484 |
| -#if CONFIG_LED_ILLUMINATOR_ENABLED |
| 480 | +#if defined(LED_GPIO_NUM) |
485 | 481 | p += sprintf(p, ",\"led_intensity\":%u", led_duty);
|
486 | 482 | #else
|
487 | 483 | p += sprintf(p, ",\"led_intensity\":%d", -1);
|
@@ -843,11 +839,10 @@ void startCameraServer() {
|
843 | 839 | }
|
844 | 840 | }
|
845 | 841 |
|
846 |
| -void setupLedFlash(int pin) { |
847 |
| -#if CONFIG_LED_ILLUMINATOR_ENABLED |
848 |
| - led_pin = pin; // Store the actual LED pin used |
849 |
| - ledcAttach(pin, 5000, 8); |
| 842 | +void setupLedFlash() { |
| 843 | +#if defined(LED_GPIO_NUM) |
| 844 | + ledcAttach(LED_GPIO_NUM, 5000, 8); |
850 | 845 | #else
|
851 |
| - log_i("LED flash is disabled -> CONFIG_LED_ILLUMINATOR_ENABLED = 0"); |
| 846 | + log_i("LED flash is disabled -> LED_GPIO_NUM undefined"); |
852 | 847 | #endif
|
853 | 848 | }
|
0 commit comments