added camera module info

pull/21/merge
Miroslav Pivovarsky 2024-06-01 14:38:31 +02:00
parent 55caed062c
commit cee7ebc8ae
3 changed files with 54 additions and 9 deletions

View File

@ -6,6 +6,9 @@
@author Miroslav Pivovarsky @author Miroslav Pivovarsky
Contact: miroslav.pivovarsky@gmail.com Contact: miroslav.pivovarsky@gmail.com
https://github.com/espressif/esp32-camera
@bug: no know bug @bug: no know bug
*/ */
#include "camera.h" #include "camera.h"
@ -49,6 +52,7 @@ void Camera::Init() {
InitCameraModule(); InitCameraModule();
ApplyCameraCfg(); ApplyCameraCfg();
GetCameraModel();
} }
/** /**
@ -80,7 +84,7 @@ void Camera::InitCameraModule() {
CameraConfig.pin_sccb_scl = SIOC_GPIO_NUM; CameraConfig.pin_sccb_scl = SIOC_GPIO_NUM;
CameraConfig.pin_pwdn = PWDN_GPIO_NUM; CameraConfig.pin_pwdn = PWDN_GPIO_NUM;
CameraConfig.pin_reset = RESET_GPIO_NUM; CameraConfig.pin_reset = RESET_GPIO_NUM;
CameraConfig.xclk_freq_hz = 16500000; // or 3000000; 16500000; 20000000 CameraConfig.xclk_freq_hz = 20000000; // or 3000000; 16500000; 20000000
CameraConfig.pixel_format = PIXFORMAT_JPEG; /* YUV422,GRAYSCALE,RGB565,JPEG */ CameraConfig.pixel_format = PIXFORMAT_JPEG; /* YUV422,GRAYSCALE,RGB565,JPEG */
/* OV2640 /* OV2640
@ -91,13 +95,17 @@ void Camera::InitCameraModule() {
FRAMESIZE_XGA (1024 x 768) FRAMESIZE_XGA (1024 x 768)
FRAMESIZE_SXGA (1280 x 1024) FRAMESIZE_SXGA (1280 x 1024)
FRAMESIZE_UXGA (1600 x 1200) FRAMESIZE_UXGA (1600 x 1200)
CAMERA_GRAB_WHEN_EMPTY - Fills buffers when they are empty. Less resources but first 'fb_count' frames might be old
CAMERA_GRAB_LATEST - Except when 1 frame buffer is used, queue will always contain the last 'fb_count' frames
*/ */
CameraConfig.frame_size = TFrameSize; /* FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA */ CameraConfig.frame_size = TFrameSize; /* FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA */
CameraConfig.jpeg_quality = PhotoQuality; /* 10-63 lower number means higher quality */ CameraConfig.jpeg_quality = PhotoQuality; /* 10-63 lower number means higher quality */
CameraConfig.fb_count = 1; /* picture frame buffer alocation */ CameraConfig.fb_count = 1; /* picture frame buffer alocation */
CameraConfig.grab_mode = CAMERA_GRAB_LATEST; /* CAMERA_GRAB_WHEN_EMPTY or CAMERA_GRAB_LATEST */ CameraConfig.grab_mode = CAMERA_GRAB_LATEST; /* CAMERA_GRAB_WHEN_EMPTY or CAMERA_GRAB_LATEST */
//CameraConfig.fb_location = CAMERA_FB_IN_PSRAM; /* CAMERA_FB_IN_PSRAM or CAMERA_FB_IN_DRAM */
if (CameraConfig.fb_location == CAMERA_FB_IN_DRAM) { if (CameraConfig.fb_location == CAMERA_FB_IN_DRAM) {
log->AddEvent(LogLevel_Verbose, F("Camera frame buffer location: DRAM")); log->AddEvent(LogLevel_Verbose, F("Camera frame buffer location: DRAM"));
} else if (CameraConfig.fb_location == CAMERA_FB_IN_PSRAM) { } else if (CameraConfig.fb_location == CAMERA_FB_IN_PSRAM) {
@ -113,7 +121,7 @@ void Camera::InitCameraModule() {
log->AddEvent(LogLevel_Warning, F("Camera init failed. Error: "), String(err, HEX)); log->AddEvent(LogLevel_Warning, F("Camera init failed. Error: "), String(err, HEX));
log->AddEvent(LogLevel_Warning, F("Reset ESP32-cam!")); log->AddEvent(LogLevel_Warning, F("Reset ESP32-cam!"));
ESP.restart(); ESP.restart();
} }
} }
/** /**
@ -187,6 +195,11 @@ framesize_t Camera::TransformFrameSizeDataType(uint8_t i_data) {
return ret; return ret;
} }
/**
@brief Function set photo sending status
@param bool i_data - true = on, false = off
@return none
*/
void Camera::SetPhotoSending(bool i_data) { void Camera::SetPhotoSending(bool i_data) {
PhotoSending = i_data; PhotoSending = i_data;
} }
@ -228,7 +241,7 @@ void Camera::ApplyCameraCfg() {
log->AddEvent(LogLevel_Info, F("Set camera CFG")); log->AddEvent(LogLevel_Info, F("Set camera CFG"));
/* sensor configuration */ /* sensor configuration */
sensor_t* sensor = esp_camera_sensor_get(); sensor = esp_camera_sensor_get();
sensor->set_brightness(sensor, brightness); // -2 to 2 sensor->set_brightness(sensor, brightness); // -2 to 2
sensor->set_contrast(sensor, contrast); // -2 to 2 sensor->set_contrast(sensor, contrast); // -2 to 2
sensor->set_saturation(sensor, saturation); // -2 to 2 sensor->set_saturation(sensor, saturation); // -2 to 2
@ -268,6 +281,34 @@ void Camera::ReinitCameraModule() {
ApplyCameraCfg(); ApplyCameraCfg();
} }
/**
@brief Function for get camera model and type
@param void
@return none
*/
void Camera::GetCameraModel() {
log->AddEvent(LogLevel_Info, F("Get camera model and type"));
if (sensor == NULL) {
log->AddEvent(LogLevel_Error, F("Camera sensor is NULL"));
return;
}
camera_sensor_info_t *info = esp_camera_sensor_get_info(&sensor->id);
if (info == NULL) {
log->AddEvent(LogLevel_Error, F("Camera sensor info is NULL"));
return;
}
CameraType = (camera_pid_t) sensor->id.PID;
CameraName = info->name;
log->AddEvent(LogLevel_Info, F("Camera type: "), String(CameraType));
log->AddEvent(LogLevel_Info, F("Camera name: "), String(CameraName));
log->AddEvent(LogLevel_Info, F("Camera model: "), String(info->model));
log->AddEvent(LogLevel_Info, F("Camera PID: "), String(info->pid));
log->AddEvent(LogLevel_Info, F("Camera MAX framesize: "), String(info->max_size));
log->AddEvent(LogLevel_Info, F("Camera support jpeg: "), String(info->support_jpeg));
}
/** /**
@brief Capture Photo and Save it to string array @brief Capture Photo and Save it to string array
@param none @param none

View File

@ -68,6 +68,7 @@ private:
/* OV2640 camera module pinout and cfg*/ /* OV2640 camera module pinout and cfg*/
camera_config_t CameraConfig; ///< camera configuration camera_config_t CameraConfig; ///< camera configuration
camera_fb_t *FrameBuffer; ///< frame buffer camera_fb_t *FrameBuffer; ///< frame buffer
sensor_t* sensor; ///< sensor
String Photo; ///< photo in string format String Photo; ///< photo in string format
bool StreamOnOff; ///< stream on/off bool StreamOnOff; ///< stream on/off
SemaphoreHandle_t frameBufferSemaphore; ///< semaphore for frame buffer SemaphoreHandle_t frameBufferSemaphore; ///< semaphore for frame buffer
@ -75,6 +76,8 @@ private:
uint16_t StreamAverageSize; ///< stream average size uint16_t StreamAverageSize; ///< stream average size
PhotoExifData_t PhotoExifData; ///< photo exif data PhotoExifData_t PhotoExifData; ///< photo exif data
uint8_t CameraCaptureFailedCounter; ///< camera capture failed counter uint8_t CameraCaptureFailedCounter; ///< camera capture failed counter
camera_pid_t CameraType; ///< camera type
String CameraName; ///< camera name
Configuration *config; ///< pointer to Configuration object Configuration *config; ///< pointer to Configuration object
Logs *log; ///< pointer to Logs object Logs *log; ///< pointer to Logs object
@ -88,6 +91,7 @@ public:
void ApplyCameraCfg(); void ApplyCameraCfg();
void LoadCameraCfgFromEeprom(); void LoadCameraCfgFromEeprom();
void ReinitCameraModule(); void ReinitCameraModule();
void GetCameraModel();
void CapturePhoto(); void CapturePhoto();
void CaptureStream(camera_fb_t *); void CaptureStream(camera_fb_t *);
void CaptureReturnFrameBuffer(); void CaptureReturnFrameBuffer();

View File

@ -14,7 +14,7 @@
#define _MCU_CFG_H_ #define _MCU_CFG_H_
/* ---------------- BASIC MCU CFG --------------*/ /* ---------------- BASIC MCU CFG --------------*/
#define SW_VERSION "1.0.3-rc2" ///< SW version #define SW_VERSION "1.0.3" ///< SW version
#define SW_BUILD __DATE__ " " __TIME__ ///< build number #define SW_BUILD __DATE__ " " __TIME__ ///< build number
#define CONSOLE_VERBOSE_DEBUG false ///< enable/disable verbose debug log level for console #define CONSOLE_VERBOSE_DEBUG false ///< enable/disable verbose debug log level for console
#define DEVICE_HOSTNAME "Prusa-ESP32cam" ///< device hostname #define DEVICE_HOSTNAME "Prusa-ESP32cam" ///< device hostname