Skip to content

Commit

Permalink
Added static member functions to control camera sensor properties
Browse files Browse the repository at this point in the history
fixed code style
  • Loading branch information
alorbach committed Oct 30, 2019
1 parent 6d67fb1 commit 7f217b3
Show file tree
Hide file tree
Showing 4 changed files with 329 additions and 9 deletions.
212 changes: 212 additions & 0 deletions src/esp32cam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,218 @@ CameraClass::changeResolution(const Resolution& resolution, int sleepFor)
return true;
}

bool
CameraClass::changeContrast(int ilevel)
{
sensor_t* sensor = esp_camera_sensor_get();
if (sensor == nullptr) {
return false;
}

if (sensor->set_contrast(sensor, ilevel) == 0) {
return true;
} else
return false;
}

bool
CameraClass::changeBrightness(int ilevel)
{
sensor_t* sensor = esp_camera_sensor_get();
if (sensor == nullptr) {
return false;
}

if (sensor->set_brightness(sensor, ilevel) == 0) {
return true;
} else
return false;
}

bool
CameraClass::changeSaturation(int ilevel)
{
sensor_t* sensor = esp_camera_sensor_get();
if (sensor == nullptr) {
return false;
}

if (sensor->set_saturation(sensor, ilevel) == 0) {
return true;
} else
return false;
}

bool
CameraClass::changeSpecialEffect(int ilevel)
{
sensor_t* sensor = esp_camera_sensor_get();
if (sensor == nullptr) {
return false;
}

if (sensor->set_special_effect(sensor, ilevel) == 0) {
return true;
} else
return false;
}

bool
CameraClass::changeWbMode(int ilevel)
{
sensor_t* sensor = esp_camera_sensor_get();
if (sensor == nullptr) {
return false;
}

if (sensor->set_wb_mode(sensor, ilevel) == 0) {
return true;
} else
return false;
}

bool
CameraClass::changeAeLevels(int ilevel)
{
sensor_t* sensor = esp_camera_sensor_get();
if (sensor == nullptr) {
return false;
}

if (sensor->set_ae_level(sensor, ilevel)) {
return true;
} else
return false;
}

bool
CameraClass::changAgcGain(int ilevel)
{
sensor_t* sensor = esp_camera_sensor_get();
if (sensor == nullptr) {
return false;
}

if (sensor->set_agc_gain(sensor, ilevel) == 0) {
return true;
} else
return false;
}

bool
CameraClass::changGainceilingSensor(int iGainCeiling)
{
sensor_t* sensor = esp_camera_sensor_get();
if (sensor == nullptr) {
return false;
}

if ((gainceiling_t)iGainCeiling < GAINCEILING_2X ||
(gainceiling_t)iGainCeiling > GAINCEILING_128X) {
return false;
}

if (sensor->set_gainceiling(sensor, (gainceiling_t)iGainCeiling) == 0) {
return true;
} else
return false;
}

bool
CameraClass::changeGaincontrol(int iEnable)
{
sensor_t* sensor = esp_camera_sensor_get();
if (sensor == nullptr) {
return false;
}

if (sensor->set_gain_ctrl(sensor, iEnable) == 0) {
return true;
} else
return false;
}

bool
CameraClass::changeColorbar(int iEnable)
{
sensor_t* sensor = esp_camera_sensor_get();
if (sensor == nullptr) {
return false;
}

if (sensor->set_colorbar(sensor, iEnable) == 0) {
return true;
} else
return false;
}

bool
CameraClass::changeWhitebalance(int iEnable)
{
sensor_t* sensor = esp_camera_sensor_get();
if (sensor == nullptr) {
return false;
}

if (sensor->set_whitebal(sensor, iEnable) == 0) {
return true;
} else
return false;
}

bool
CameraClass::changeQuality(int iQuality)
{
sensor_t* sensor = esp_camera_sensor_get();
if (sensor == nullptr) {
return false;
}

if (iQuality < 0 ||
iQuality > 63) {
return false;
}

if (sensor->set_quality(sensor, iQuality) == 0) {
return true;
} else
return false;
}

bool
CameraClass::changAec2(int iEnable)
{
sensor_t* sensor = esp_camera_sensor_get();
if (sensor == nullptr) {
return false;
}

if (sensor->set_aec2(sensor, iEnable) == 0) {
return true;
} else
return false;
}

bool
CameraClass::changeAecValue(int iValue)
{
sensor_t* sensor = esp_camera_sensor_get();
if (sensor == nullptr) {
return false;
}

if (iValue < 0 ||
iValue > 1200) {
return false;
}

if (sensor->set_agc_gain(sensor, iValue) == 0) {
return true;
} else
return false;
}


std::unique_ptr<Frame>
CameraClass::capture()
{
Expand Down
95 changes: 95 additions & 0 deletions src/esp32cam.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,101 @@ class CameraClass
bool
changeResolution(const Resolution& resolution, int sleepFor = 500);

/** \brief Change Sensor Contrast level
* must be -2 to +2, default 0
*/
bool
changeContrast(int ilevel);

/** \brief Change Brightness level
* \param ilevel must be -2 to +2, default 0
*/
bool
changeBrightness(int ilevel);

/** \brief Change Saturation level
* \param ilevel must be -2 to +2, default 0
*/
bool
changeSaturation(int ilevel);

/** \brief Change SpecialEffect
* \param ilevel must be > 0 && <= NUM_SPECIAL_EFFECTS, default 0
* \ 1 = no effect
* \ 2 = negative
* \ 3 = black and white
* \ 4 = reddish
* \ 5 = greenish
* \ 6 = blue
* \ 7 = retro
*/
bool
changeSpecialEffect(int ilevel);

/** \brief Change WbMode
* \param ilevel must be > 0 && <= NUM_WB_MODES, default 0
* \ 0 = default
* \ 1 = sunny
* \ 2 = cloudy
* \ 3 = office
* \ 4 = home
*/
bool
changeWbMode(int ilevel);

/** \brief Change AE Levels
* \param ilevel must be -2 to +2, default 0
*/
bool
changeAeLevels(int ilevel);

/** \brief Change AGC Gain
* \param ilevel must be >= 0 and <= 30, default 30
*/
bool
changAgcGain(int ilevel);

/** \brief Change Gainceiling
* \param ilevel must be within ENUM gainceiling_t
*/
bool
changGainceilingSensor(int iGainCeiling);

/** \brief Enable/Disable Gaincontrol
* \param iGainCeiling must be between GAINCEILING_2X and GAINCEILING_128X
*/
bool
changeGaincontrol(int iEnable);

/** \brief Enable/Disable Testing Colorbar
* \param iEnable must be 0(disable) or 1 (enable)
*/
bool
changeColorbar(int iEnable);

/** \brief Enable/Disable Whitebalance
* \param iEnable must be 0(disable) or 1 (enable)
*/
bool
changeWhitebalance(int iEnable);

/** \brief Change JPEG Quality
* \param iEnable iQuality must be within 0 and 63
*/
bool changeQuality(int iQuality);

/** \brief Change AEC Value
* \param iEnable iValue must be 0 to 1200, default 0
*/
bool
changeAecValue(int iValue);

/** \brief Enable/Disable Auto/Manual Exposure control
* \param iEnable must be 0(disable) or 1 (enable)
*/
bool
changAec2(int iEnable);

/** \brief Capture a frame of picture.
*/
std::unique_ptr<Frame>
Expand Down
15 changes: 10 additions & 5 deletions src/internal/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,23 @@ Frame::releaseFb()
}
}

bool Frame::writeTo(Print& os, int timeout) {
bool
Frame::writeTo(Print& os, int timeout) {
return writeToImpl(os, timeout, nullptr);
}

bool Frame::writeTo(Client& os, int timeout) {
bool
Frame::writeTo(Client& os, int timeout) {
return writeToImpl(os, timeout, &os);
}

bool Frame::writeTo(AsyncClient& os, int timeout) {
bool
Frame::writeTo(AsyncClient& os, int timeout) {
return writeToImpl(timeout, &os);
}

bool Frame::writeToImpl(Print& os, int timeout, Client* client) {
bool
Frame::writeToImpl(Print& os, int timeout, Client* client) {
auto startTime = millis();
for (size_t i = 0; i < m_size; i += os.write(&m_data[i], m_size - i)) {
if (millis() - startTime > static_cast<unsigned long>(timeout) ||
Expand All @@ -64,7 +68,8 @@ bool Frame::writeToImpl(Print& os, int timeout, Client* client) {
return true;
}

bool Frame::writeToImpl(int timeout, AsyncClient* client) {
bool
Frame::writeToImpl(int timeout, AsyncClient* client) {
auto startTime = millis();
for (size_t i = 0; i < m_size; i += client->write((const char*) &m_data[i], m_size - i)) {
if (millis() - startTime > static_cast<unsigned long>(timeout) ||
Expand Down
16 changes: 12 additions & 4 deletions src/internal/frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,26 @@ class Frame
* \retval true writing completed.
* \retval false writing disrupted by timeout.
*/
bool writeTo(Print& os, int timeout = 10000);
bool
writeTo(Print& os, int timeout = 10000);

/** \brief Write frame buffer to \p os .
* \param os output socket.
* \param timeout total time limit in millis.
* \retval true writing completed.
* \retval false writing disrupted by timeout or socket error.
*/
bool writeTo(Client& os, int timeout = 10000);

bool
writeTo(Client& os, int timeout = 10000);

bool writeTo(AsyncClient& os, int timeout = 10000);
/** \brief Write frame buffer to \p os .
* \param os output socket.
* \param timeout total time limit in millis.
* \retval true writing completed.
* \retval false writing disrupted by timeout or socket error.
*/
bool
writeTo(AsyncClient& os, int timeout = 10000);

public: // conversion
bool
Expand Down

0 comments on commit 7f217b3

Please sign in to comment.