Skip to content

Commit 14c3e2e

Browse files
committed
fix(example): add camera_config.h and enable LED FLASH based on board model.
1 parent 02b2e28 commit 14c3e2e

File tree

3 files changed

+48
-51
lines changed

3 files changed

+48
-51
lines changed

libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,10 @@
11
#include "esp_camera.h"
22
#include <WiFi.h>
33

4-
//
5-
// WARNING!!! PSRAM IC required for UXGA resolution and high JPEG quality
6-
// Ensure ESP32 Wrover Module or other board with PSRAM is selected
7-
// Partial images will be transmitted if image exceeds buffer size
8-
//
9-
// You must select partition scheme from the board menu that has at least 3MB APP space.
10-
// Face Recognition is DISABLED for ESP32 and ESP32-S2, because it takes up from 15
11-
// seconds to process single frame. Face Detection is ENABLED if PSRAM is enabled as well
12-
13-
// ===================
14-
// Select camera model
15-
// ===================
16-
//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
17-
#define CAMERA_MODEL_ESP_EYE // Has PSRAM
18-
//#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM
19-
//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
20-
//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM
21-
//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
22-
//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM
23-
//#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM
24-
//#define CAMERA_MODEL_M5STACK_CAMS3_UNIT // Has PSRAM
25-
//#define CAMERA_MODEL_AI_THINKER // Has PSRAM
26-
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
27-
//#define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM
28-
// ** Espressif Internal Boards **
29-
//#define CAMERA_MODEL_ESP32_CAM_BOARD
30-
//#define CAMERA_MODEL_ESP32S2_CAM_BOARD
31-
//#define CAMERA_MODEL_ESP32S3_CAM_LCD
32-
//#define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM
33-
//#define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM
34-
#include "camera_pins.h"
4+
// ===========================
5+
// Select camera model in board_config.h
6+
// ===========================
7+
#include "board_config.h"
358

369
// ===========================
3710
// Enter your WiFi credentials
@@ -40,7 +13,7 @@ const char *ssid = "**********";
4013
const char *password = "**********";
4114

4215
void startCameraServer();
43-
void setupLedFlash(int pin);
16+
void setupLedFlash();
4417

4518
void setup() {
4619
Serial.begin(115200);
@@ -130,7 +103,7 @@ void setup() {
130103

131104
// Setup LED FLash if LED pin is defined in camera_pins.h
132105
#if defined(LED_GPIO_NUM)
133-
setupLedFlash(LED_GPIO_NUM);
106+
setupLedFlash();
134107
#endif
135108

136109
WiFi.begin(ssid, password);

libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,16 @@
1919
#include "esp32-hal-ledc.h"
2020
#include "sdkconfig.h"
2121
#include "camera_index.h"
22+
#include "board_config.h"
2223

2324
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
2425
#include "esp32-hal-log.h"
2526
#endif
2627

27-
// Enable LED FLASH setting
28-
#define CONFIG_LED_ILLUMINATOR_ENABLED 1
29-
3028
// LED FLASH setup
31-
#if CONFIG_LED_ILLUMINATOR_ENABLED
32-
29+
#if defined(LED_GPIO_NUM)
3330
#define CONFIG_LED_MAX_INTENSITY 255
3431

35-
int led_pin = 22; // Store the actual LED pin used
3632
int led_duty = 0;
3733
bool isStreaming = false;
3834

@@ -91,13 +87,13 @@ static int ra_filter_run(ra_filter_t *filter, int value) {
9187
}
9288
#endif
9389

94-
#if CONFIG_LED_ILLUMINATOR_ENABLED
90+
#if defined(LED_GPIO_NUM)
9591
void enable_led(bool en) { // Turn LED On or Off
9692
int duty = en ? led_duty : 0;
9793
if (en && isStreaming && (led_duty > CONFIG_LED_MAX_INTENSITY)) {
9894
duty = CONFIG_LED_MAX_INTENSITY;
9995
}
100-
ledcWrite(led_pin, duty);
96+
ledcWrite(LED_GPIO_NUM, duty);
10197
//ledc_set_duty(CONFIG_LED_LEDC_SPEED_MODE, CONFIG_LED_LEDC_CHANNEL, duty);
10298
//ledc_update_duty(CONFIG_LED_LEDC_SPEED_MODE, CONFIG_LED_LEDC_CHANNEL);
10399
log_i("Set LED intensity to %d", duty);
@@ -162,7 +158,7 @@ static esp_err_t capture_handler(httpd_req_t *req) {
162158
int64_t fr_start = esp_timer_get_time();
163159
#endif
164160

165-
#if CONFIG_LED_ILLUMINATOR_ENABLED
161+
#if defined(LED_GPIO_NUM)
166162
enable_led(true);
167163
vTaskDelay(150 / portTICK_PERIOD_MS); // The LED needs to be turned on ~150ms before the call to esp_camera_fb_get()
168164
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) {
230226
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
231227
httpd_resp_set_hdr(req, "X-Framerate", "60");
232228

233-
#if CONFIG_LED_ILLUMINATOR_ENABLED
229+
#if defined(LED_GPIO_NUM)
234230
isStreaming = true;
235231
enable_led(true);
236232
#endif
@@ -293,7 +289,7 @@ static esp_err_t stream_handler(httpd_req_t *req) {
293289
);
294290
}
295291

296-
#if CONFIG_LED_ILLUMINATOR_ENABLED
292+
#if defined(LED_GPIO_NUM)
297293
isStreaming = false;
298294
enable_led(false);
299295
#endif
@@ -393,7 +389,7 @@ static esp_err_t cmd_handler(httpd_req_t *req) {
393389
} else if (!strcmp(variable, "ae_level")) {
394390
res = s->set_ae_level(s, val);
395391
}
396-
#if CONFIG_LED_ILLUMINATOR_ENABLED
392+
#if defined(LED_GPIO_NUM)
397393
else if (!strcmp(variable, "led_intensity")) {
398394
led_duty = val;
399395
if (isStreaming) {
@@ -481,7 +477,7 @@ static esp_err_t status_handler(httpd_req_t *req) {
481477
p += sprintf(p, "\"vflip\":%u,", s->status.vflip);
482478
p += sprintf(p, "\"dcw\":%u,", s->status.dcw);
483479
p += sprintf(p, "\"colorbar\":%u", s->status.colorbar);
484-
#if CONFIG_LED_ILLUMINATOR_ENABLED
480+
#if defined(LED_GPIO_NUM)
485481
p += sprintf(p, ",\"led_intensity\":%u", led_duty);
486482
#else
487483
p += sprintf(p, ",\"led_intensity\":%d", -1);
@@ -843,11 +839,10 @@ void startCameraServer() {
843839
}
844840
}
845841

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);
850845
#else
851-
log_i("LED flash is disabled -> CONFIG_LED_ILLUMINATOR_ENABLED = 0");
846+
log_i("LED flash is disabled -> LED_GPIO_NUM undefined");
852847
#endif
853848
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// WARNING!!! PSRAM IC required for UXGA resolution and high JPEG quality
2+
// Ensure ESP32 Wrover Module or other board with PSRAM is selected
3+
// Partial images will be transmitted if image exceeds buffer size
4+
//
5+
// You must select partition scheme from the board menu that has at least 3MB APP space.
6+
// Face Recognition is DISABLED for ESP32 and ESP32-S2, because it takes up from 15
7+
// seconds to process single frame. Face Detection is ENABLED if PSRAM is enabled as well
8+
// ===================
9+
// Select camera model
10+
// ===================
11+
//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
12+
#define CAMERA_MODEL_ESP_EYE // Has PSRAM
13+
//#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM
14+
//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
15+
//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM
16+
//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
17+
//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM
18+
//#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM
19+
//#define CAMERA_MODEL_M5STACK_CAMS3_UNIT // Has PSRAM
20+
//#define CAMERA_MODEL_AI_THINKER // Has PSRAM
21+
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
22+
//#define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM
23+
// ** Espressif Internal Boards **
24+
//#define CAMERA_MODEL_ESP32_CAM_BOARD
25+
//#define CAMERA_MODEL_ESP32S2_CAM_BOARD
26+
//#define CAMERA_MODEL_ESP32S3_CAM_LCD
27+
//#define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM
28+
//#define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM
29+
#include "camera_pins.h"

0 commit comments

Comments
 (0)