From 50ada0a5a8576b578ae8d79ae3d81f9a3bac814d Mon Sep 17 00:00:00 2001 From: SybexX Date: Wed, 4 Dec 2024 22:57:43 +0100 Subject: [PATCH] fix (#3418) --- .../jomjol_controlcamera/ClassControllCamera.cpp | 16 ++++++++-------- .../jomjol_controlcamera/ClassControllCamera.h | 4 +++- .../jomjol_controlcamera/server_camera.cpp | 3 +++ .../jomjol_flowcontroll/ClassFlowTakeImage.cpp | 5 +++-- .../jomjol_flowcontroll/MainFlowControl.cpp | 5 ++--- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/code/components/jomjol_controlcamera/ClassControllCamera.cpp b/code/components/jomjol_controlcamera/ClassControllCamera.cpp index 84b5a887a..cfc62a88b 100644 --- a/code/components/jomjol_controlcamera/ClassControllCamera.cpp +++ b/code/components/jomjol_controlcamera/ClassControllCamera.cpp @@ -229,13 +229,12 @@ void CCamera::ledc_init(void) #endif } -void CCamera::SetLEDIntensity(float _intrel) +int CCamera::SetLEDIntensity(int _intrel) { - _intrel = min(_intrel, (float)100); - _intrel = max(_intrel, (float)0); - _intrel = _intrel / 100; - CCstatus.ImageLedIntensity = (int)(_intrel * 8191); - ESP_LOGD(TAG, "Set led_intensity to %d of 8191", CCstatus.ImageLedIntensity); + // CCstatus.ImageLedIntensity = (int)(std::min(std::max((float)0, _intrel), (float)100) / 100 * 8191) + Camera.LedIntensity = (int)((float)(std::min(std::max(0, _intrel), 100)) / 100 * 8191); + ESP_LOGD(TAG, "Set led_intensity to %i of 8191", Camera.LedIntensity); + return Camera.LedIntensity; } bool CCamera::getCameraInitSuccessful(void) @@ -944,6 +943,7 @@ esp_err_t CCamera::CaptureToStream(httpd_req_t *req, bool FlashlightOn) { Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip); + Camera.LedIntensity = CCstatus.ImageLedIntensity; CFstatus.changedCameraSettings = false; } @@ -1034,8 +1034,8 @@ void CCamera::LightOnOff(bool status) #ifdef USE_PWM_LEDFLASH if (status) { - ESP_LOGD(TAG, "Internal Flash-LED turn on with PWM %d", CCstatus.ImageLedIntensity); - ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, CCstatus.ImageLedIntensity)); + ESP_LOGD(TAG, "Internal Flash-LED turn on with PWM %d", Camera.LedIntensity); + ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, Camera.LedIntensity)); // Update duty to apply the new value ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL)); } diff --git a/code/components/jomjol_controlcamera/ClassControllCamera.h b/code/components/jomjol_controlcamera/ClassControllCamera.h index b3afbc38b..51e091912 100644 --- a/code/components/jomjol_controlcamera/ClassControllCamera.h +++ b/code/components/jomjol_controlcamera/ClassControllCamera.h @@ -80,6 +80,8 @@ class CCamera void SanitizeZoomParams(int imageSize, int frameSizeX, int frameSizeY, int &imageWidth, int &imageHeight, int &zoomOffsetX, int &zoomOffsetY); public: + int LedIntensity = 4096; + CCamera(void); esp_err_t InitCam(void); @@ -100,7 +102,7 @@ class CCamera void SetQualityZoomSize(int qual, framesize_t resol, bool zoomEnabled, int zoomOffsetX, int zoomOffsetY, int imageSize, int imageVflip); void SetZoomSize(bool zoomEnabled, int zoomOffsetX, int zoomOffsetY, int imageSize, int imageVflip); - void SetLEDIntensity(float _intrel); + int SetLEDIntensity(int _intrel); bool testCamera(void); bool getCameraInitSuccessful(void); void useDemoMode(void); diff --git a/code/components/jomjol_controlcamera/server_camera.cpp b/code/components/jomjol_controlcamera/server_camera.cpp index fc8fd4bc1..71eeba471 100644 --- a/code/components/jomjol_controlcamera/server_camera.cpp +++ b/code/components/jomjol_controlcamera/server_camera.cpp @@ -101,6 +101,7 @@ esp_err_t handler_capture(httpd_req_t *req) { Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip); + Camera.LedIntensity = CCstatus.ImageLedIntensity; CFstatus.changedCameraSettings = false; } @@ -159,6 +160,7 @@ esp_err_t handler_capture_with_light(httpd_req_t *req) { Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip); + Camera.LedIntensity = CCstatus.ImageLedIntensity; CFstatus.changedCameraSettings = false; } @@ -241,6 +243,7 @@ esp_err_t handler_capture_save_to_file(httpd_req_t *req) { Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip); + Camera.LedIntensity = CCstatus.ImageLedIntensity; CFstatus.changedCameraSettings = false; } diff --git a/code/components/jomjol_flowcontroll/ClassFlowTakeImage.cpp b/code/components/jomjol_flowcontroll/ClassFlowTakeImage.cpp index f83829064..4ab50ecf4 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowTakeImage.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowTakeImage.cpp @@ -499,8 +499,8 @@ bool ClassFlowTakeImage::ReadParameter(FILE *pfile, string &aktparamgraph) { if (isStringNumeric(splitted[1])) { - float ledintensity = std::stof(splitted[1]); - Camera.SetLEDIntensity(ledintensity); + int ledintensity = std::stoi(splitted[1]); + CCstatus.ImageLedIntensity = Camera.SetLEDIntensity(ledintensity); } } @@ -559,6 +559,7 @@ bool ClassFlowTakeImage::doFlow(string zwtime) { Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip); + Camera.LedIntensity = CCstatus.ImageLedIntensity; CFstatus.changedCameraSettings = false; } diff --git a/code/components/jomjol_flowcontroll/MainFlowControl.cpp b/code/components/jomjol_flowcontroll/MainFlowControl.cpp index 107663ac2..a71c7e663 100644 --- a/code/components/jomjol_flowcontroll/MainFlowControl.cpp +++ b/code/components/jomjol_flowcontroll/MainFlowControl.cpp @@ -1364,9 +1364,8 @@ esp_err_t handler_editflow(httpd_req_t *req) std::string _ledi = std::string(_valuechar); if (isStringNumeric(_ledi)) { - float _ImageLedIntensity = std::stof(_valuechar); - Camera.SetLEDIntensity(_ImageLedIntensity); - CFstatus.ImageLedIntensity = CCstatus.ImageLedIntensity; + int _ImageLedIntensity = std::stoi(_valuechar); + CFstatus.ImageLedIntensity = Camera.SetLEDIntensity(_ImageLedIntensity); } }