Skip to content

Commit

Permalink
refactor(source code): Refactor complete source code with clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
Slider0007 committed Nov 29, 2024
1 parent 53fd0f5 commit 4f01e7e
Show file tree
Hide file tree
Showing 98 changed files with 6,456 additions and 5,409 deletions.
45 changes: 45 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: true
AlignTrailingComments: true
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
BreakAfterReturnType: Automatic
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Never
AfterEnum: false
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBraces: Custom
ColumnLimit: 140
#IndentAccessModifiers: true # If activated struct content is indented twice
IndentCaseLabels: true
IndentWidth: 4
InsertBraces: true
InsertNewlineAtEOF: true
MaxEmptyLinesToKeep: 2
PenaltyBreakAssignment : 60
PenaltyReturnTypeOnItsOwnLine: 200
SortIncludes: Never
341 changes: 185 additions & 156 deletions code/components/camera_ctrl/ClassControlCamera.cpp

Large diffs are not rendered by default.

118 changes: 59 additions & 59 deletions code/components/camera_ctrl/ClassControlCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,67 +19,67 @@ typedef struct {

class ClassControlCamera
{
protected:
CfgData::SectionTakeImage::Camera paramCameraInternal;
CfgData::SectionTakeImage::Flashlight paramFlashlightInternal;
bool cameraInitSuccessful;
uint16_t sensorFrameSizeWidth, sensorFrameSizeHeight;
uint16_t outputFrameSizeWidth, outputFrameSizeHeight;

bool demoMode;
std::vector<std::string> demoFiles;

void setStatusLed(bool status);
bool loadNextDemoImage(camera_fb_t *_fb);

public:
ClassControlCamera();
~ClassControlCamera();
void powerResetCamera();
esp_err_t initCam();
esp_err_t deinitCam();

bool testCamera(void);
void printCamInfo(void);
void printCamConfig(void);

esp_err_t setCameraParameter(const CfgData::SectionTakeImage::Camera *paramCamera);
void setCameraFrequency(int _frequency);
void setImageQuality(int _qual);
void setImageSize(int _zoomFactor, int _zoomOffsetX, int _zoomOffsetY);
bool setImageManipulation(int _brightness, int _contrast, int _saturation, int _sharpness, int _exposureControlMode,
int _autoExposureLevel, int _manualExposureValue, int _gainControlMode, int _manualGainValue,
int _specialEffect, bool _mirror, bool _flip);
bool setMirrorFlip(bool _mirror, bool _flip);

bool getCameraInitSuccessful();
camera_model_t getCamModel(void);
std::string getCamType(void);
std::string getCamPID(void);
std::string getCamVersion(void);
int getCamFrequencyMhz(void);
void getOutputFrameSize(int &width, int &height);

esp_err_t captureToBasisImage(CImageBasis *_Image);
esp_err_t captureToFile(std::string _nm);
esp_err_t captureToHTTP(httpd_req_t *_req);
esp_err_t captureToStream(httpd_req_t *_req, bool _flashlightOn);

#ifdef GPIO_FLASHLIGHT_DEFAULT_USE_PWM
void ledcInitFlashlightDefault(void);
#endif
esp_err_t setFlashlightParameter(const CfgData::SectionTakeImage::Flashlight *paramFlashlight);
void setFlashIntensity(int _flashIntensity);
void setFlashTime(int _flashTime);
int getFlashTime();
void setFlashlight(bool _status);

void enableDemoMode(void);
void disableDemoMode(void);
void freeDemoMemoryOnly();
protected:
CfgData::SectionTakeImage::Camera paramCameraInternal;
CfgData::SectionTakeImage::Flashlight paramFlashlightInternal;
bool cameraInitSuccessful;
uint16_t sensorFrameSizeWidth, sensorFrameSizeHeight;
uint16_t outputFrameSizeWidth, outputFrameSizeHeight;

bool demoMode;
std::vector<std::string> demoFiles;

void setStatusLed(bool status);
bool loadNextDemoImage(camera_fb_t *_fb);

public:
ClassControlCamera();
~ClassControlCamera();
void powerResetCamera();
esp_err_t initCam();
esp_err_t deinitCam();

bool testCamera(void);
void printCamInfo(void);
void printCamConfig(void);

esp_err_t setCameraParameter(const CfgData::SectionTakeImage::Camera *paramCamera);
void setCameraFrequency(int _frequency);
void setImageQuality(int _qual);
void setImageSize(int _zoomFactor, int _zoomOffsetX, int _zoomOffsetY);
bool setImageManipulation(int _brightness, int _contrast, int _saturation, int _sharpness, int _exposureControlMode,
int _autoExposureLevel, int _manualExposureValue, int _gainControlMode, int _manualGainValue,
int _specialEffect, bool _mirror, bool _flip);
bool setMirrorFlip(bool _mirror, bool _flip);

bool getCameraInitSuccessful();
camera_model_t getCamModel(void);
std::string getCamType(void);
std::string getCamPID(void);
std::string getCamVersion(void);
int getCamFrequencyMhz(void);
void getOutputFrameSize(int &width, int &height);

esp_err_t captureToBasisImage(CImageBasis *_Image);
esp_err_t captureToFile(std::string _nm);
esp_err_t captureToHTTP(httpd_req_t *_req);
esp_err_t captureToStream(httpd_req_t *_req, bool _flashlightOn);

#ifdef GPIO_FLASHLIGHT_DEFAULT_USE_PWM
void ledcInitFlashlightDefault(void);
#endif
esp_err_t setFlashlightParameter(const CfgData::SectionTakeImage::Flashlight *paramFlashlight);
void setFlashIntensity(int _flashIntensity);
void setFlashTime(int _flashTime);
int getFlashTime();
void setFlashlight(bool _status);

void enableDemoMode(void);
void disableDemoMode(void);
void freeDemoMemoryOnly();
};


extern ClassControlCamera cameraCtrl;

#endif
#endif
112 changes: 22 additions & 90 deletions code/components/camera_ctrl/ov2640_sharpness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,108 +5,39 @@

#define OV2640_MAXLEVEL_SHARPNESS 6

const static uint8_t OV2640_SHARPNESS_AUTO[]=
{
0xFF, 0x00, 0xff,
0x92, 0x01, 0xff,
0x93, 0x20, 0x20,
0x00, 0x00, 0x00
};

const static uint8_t OV2640_SHARPNESS_MANUAL[]=
{
0xFF, 0x00, 0xff,
0x92, 0x01, 0xff,
0x93, 0x00, 0x20,
0x00, 0x00, 0x00
};

const static uint8_t OV2640_SHARPNESS_LEVEL0[]=
{
0xFF, 0x00, 0xff,
0x92, 0x01, 0xff,
0x93, 0xc0, 0x1f,
0x00, 0x00, 0x00
};

const static uint8_t OV2640_SHARPNESS_LEVEL1[]=
{
0xFF, 0x00, 0xff,
0x92, 0x01, 0xff,
0x93, 0xc1, 0x1f,
0x00, 0x00, 0x00
};

const static uint8_t OV2640_SHARPNESS_LEVEL2[]=
{
0xFF, 0x00, 0xff,
0x92, 0x01, 0xff,
0x93, 0xc2, 0x1f,
0x00, 0x00, 0x00
};

const static uint8_t OV2640_SHARPNESS_LEVEL3[]=
{
0xFF, 0x00, 0xff,
0x92, 0x01, 0xff,
0x93, 0xc4, 0x1f,
0x00, 0x00, 0x00
};

const static uint8_t OV2640_SHARPNESS_LEVEL4[]=
{
0xFF, 0x00, 0xff,
0x92, 0x01, 0xff,
0x93, 0xc8, 0x1f,
0x00, 0x00, 0x00
};

const static uint8_t OV2640_SHARPNESS_LEVEL5[]=
{
0xFF, 0x00, 0xff,
0x92, 0x01, 0xff,
0x93, 0xd0, 0x1f,
0x00, 0x00, 0x00
};

const static uint8_t OV2640_SHARPNESS_LEVEL6[]=
{
0xFF, 0x00, 0xff,
0x92, 0x01, 0xff,
0x93, 0xdf, 0x1f,
0x00, 0x00, 0x00
};

const static uint8_t *OV2640_SETTING_SHARPNESS[]=
{
OV2640_SHARPNESS_LEVEL0, // -3 sharpness
OV2640_SHARPNESS_LEVEL1,
OV2640_SHARPNESS_LEVEL2,
OV2640_SHARPNESS_LEVEL3,
OV2640_SHARPNESS_LEVEL4,
OV2640_SHARPNESS_LEVEL5,
OV2640_SHARPNESS_LEVEL6 // +3 sharpness
};


static bool table_mask_write(sensor_t *_sensor, const uint8_t* _ptab)
const static uint8_t OV2640_SHARPNESS_AUTO[] = {0xFF, 0x00, 0xff, 0x92, 0x01, 0xff, 0x93, 0x20, 0x20, 0x00, 0x00, 0x00};
const static uint8_t OV2640_SHARPNESS_MANUAL[] = {0xFF, 0x00, 0xff, 0x92, 0x01, 0xff, 0x93, 0x00, 0x20, 0x00, 0x00, 0x00};
const static uint8_t OV2640_SHARPNESS_LEVEL0[] = {0xFF, 0x00, 0xff, 0x92, 0x01, 0xff, 0x93, 0xc0, 0x1f, 0x00, 0x00, 0x00};
const static uint8_t OV2640_SHARPNESS_LEVEL1[] = {0xFF, 0x00, 0xff, 0x92, 0x01, 0xff, 0x93, 0xc1, 0x1f, 0x00, 0x00, 0x00};
const static uint8_t OV2640_SHARPNESS_LEVEL2[] = {0xFF, 0x00, 0xff, 0x92, 0x01, 0xff, 0x93, 0xc2, 0x1f, 0x00, 0x00, 0x00};
const static uint8_t OV2640_SHARPNESS_LEVEL3[] = {0xFF, 0x00, 0xff, 0x92, 0x01, 0xff, 0x93, 0xc4, 0x1f, 0x00, 0x00, 0x00};
const static uint8_t OV2640_SHARPNESS_LEVEL4[] = {0xFF, 0x00, 0xff, 0x92, 0x01, 0xff, 0x93, 0xc8, 0x1f, 0x00, 0x00, 0x00};
const static uint8_t OV2640_SHARPNESS_LEVEL5[] = {0xFF, 0x00, 0xff, 0x92, 0x01, 0xff, 0x93, 0xd0, 0x1f, 0x00, 0x00, 0x00};
const static uint8_t OV2640_SHARPNESS_LEVEL6[] = {0xFF, 0x00, 0xff, 0x92, 0x01, 0xff, 0x93, 0xdf, 0x1f, 0x00, 0x00, 0x00};
const static uint8_t *OV2640_SETTING_SHARPNESS[] = {OV2640_SHARPNESS_LEVEL0, OV2640_SHARPNESS_LEVEL1, OV2640_SHARPNESS_LEVEL2,
OV2640_SHARPNESS_LEVEL3, OV2640_SHARPNESS_LEVEL4, OV2640_SHARPNESS_LEVEL5,
OV2640_SHARPNESS_LEVEL6}; // [-3 .. 3]


static bool table_mask_write(sensor_t *_sensor, const uint8_t *_ptab)
{
uint8_t address;
uint8_t value;
uint8_t orgval;
uint8_t mask;
const uint8_t *pdata = _ptab;

if (pdata == NULL)
if (pdata == NULL) {
return false;
}

while (1)
{
while (1) {
address = *pdata++;
value = *pdata++;
mask = *pdata++;
if ((address == 0) && (value == 0) && (mask == 0))
if ((address == 0) && (value == 0) && (mask == 0)) {
break;
}
_sensor->set_reg(_sensor, address, mask, value);
}

Expand All @@ -122,8 +53,9 @@ bool ov2640_enable_auto_sharpness(sensor_t *_sensor)

bool ov2640_set_sharpness(sensor_t *_sensor, int _sharpness)
{
if ((_sharpness < -3) || (_sharpness > OV2640_MAXLEVEL_SHARPNESS - 3))
if ((_sharpness < -3) || (_sharpness > OV2640_MAXLEVEL_SHARPNESS - 3)) {
return false;
}

bool retval = false;
retval = table_mask_write(_sensor, OV2640_SHARPNESS_MANUAL);
Expand Down
Loading

0 comments on commit 4f01e7e

Please sign in to comment.