|
|
@@ -407,10 +407,16 @@ void CCamera::ledc_init(void)
|
|
|
|
|
|
int CCamera::SetLEDIntensity(int _intrel)
|
|
|
{
|
|
|
- // 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;
|
|
|
+ ScopedCameraOperationLock operationLock(m_cameraOperationMutex);
|
|
|
+ if (!operationLock.acquired()) return LedIntensity;
|
|
|
+ ScopedCameraLock cameraLock(m_cameraMutex);
|
|
|
+ if (!cameraLock.acquired()) return LedIntensity;
|
|
|
+
|
|
|
+ LedIntensity = static_cast<int>(
|
|
|
+ static_cast<float>(std::min(std::max(0, _intrel), 100)) / 100.0f * 8191.0f);
|
|
|
+ UpdateFlashOutputLocked();
|
|
|
+ ESP_LOGD(TAG, "Set led_intensity to %i of 8191", LedIntensity);
|
|
|
+ return LedIntensity;
|
|
|
}
|
|
|
|
|
|
bool CCamera::getCameraInitSuccessful(void)
|
|
|
@@ -1350,56 +1356,92 @@ esp_err_t CCamera::CaptureToStream(httpd_req_t *req, bool FlashlightOn)
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
-void CCamera::LightOnOff(bool status)
|
|
|
+void CCamera::UpdateFlashOutputLocked(void)
|
|
|
+{
|
|
|
+ const bool active = m_manualFlashOn || m_captureFlashUsers > 0;
|
|
|
+#ifdef USE_PWM_LEDFLASH
|
|
|
+ const uint32_t duty = active ? static_cast<uint32_t>(LedIntensity) : 0U;
|
|
|
+ ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, duty));
|
|
|
+ ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
|
|
|
+#else
|
|
|
+ // The camera owns the board flash LED independently of the user GPIO handler.
|
|
|
+ gpio_pad_select_gpio(FLASH_GPIO);
|
|
|
+ gpio_set_direction(FLASH_GPIO, GPIO_MODE_OUTPUT);
|
|
|
+ gpio_set_level(FLASH_GPIO, active ? 1 : 0);
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
+void CCamera::UpdateStatusLedOutputLocked(void)
|
|
|
+{
|
|
|
+ if (xHandle_task_StatusLED != NULL) return;
|
|
|
+
|
|
|
+ const bool active = m_manualStatusLedOn || m_captureStatusLedUsers > 0;
|
|
|
+ gpio_pad_select_gpio(BLINK_GPIO);
|
|
|
+ gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
|
|
|
+ // The on-board status LED is active-low.
|
|
|
+ gpio_set_level(BLINK_GPIO, active ? 0 : 1);
|
|
|
+}
|
|
|
+
|
|
|
+void CCamera::SetCaptureFlashActive(bool active)
|
|
|
{
|
|
|
+ ScopedCameraOperationLock operationLock(m_cameraOperationMutex);
|
|
|
+ if (!operationLock.acquired()) return;
|
|
|
ScopedCameraLock cameraLock(m_cameraMutex);
|
|
|
- if (!cameraLock.acquired())
|
|
|
+ if (!cameraLock.acquired()) return;
|
|
|
+
|
|
|
+ if (active)
|
|
|
{
|
|
|
- ESP_LOGW(TAG, "LightOnOff: camera mutex unavailable");
|
|
|
- return;
|
|
|
+ if (m_captureFlashUsers < UINT32_MAX) ++m_captureFlashUsers;
|
|
|
+ }
|
|
|
+ else if (m_captureFlashUsers > 0)
|
|
|
+ {
|
|
|
+ --m_captureFlashUsers;
|
|
|
}
|
|
|
+ UpdateFlashOutputLocked();
|
|
|
+}
|
|
|
|
|
|
-#ifdef USE_PWM_LEDFLASH
|
|
|
- if (status)
|
|
|
+void CCamera::SetCaptureStatusLedActive(bool active)
|
|
|
+{
|
|
|
+ ScopedCameraOperationLock operationLock(m_cameraOperationMutex);
|
|
|
+ if (!operationLock.acquired()) return;
|
|
|
+ ScopedCameraLock cameraLock(m_cameraMutex);
|
|
|
+ if (!cameraLock.acquired()) return;
|
|
|
+
|
|
|
+ if (active)
|
|
|
{
|
|
|
- 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));
|
|
|
+ if (m_captureStatusLedUsers < UINT32_MAX) ++m_captureStatusLedUsers;
|
|
|
}
|
|
|
- else
|
|
|
+ else if (m_captureStatusLedUsers > 0)
|
|
|
{
|
|
|
- ESP_LOGD(TAG, "Internal Flash-LED turn off PWM");
|
|
|
- ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, 0));
|
|
|
- ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
|
|
|
+ --m_captureStatusLedUsers;
|
|
|
}
|
|
|
-#else
|
|
|
- // The camera owns the board flash LED. Keep it independent of the user
|
|
|
- // GPIO handler so an enabled user GPIO profile cannot disable camera light.
|
|
|
- gpio_pad_select_gpio(FLASH_GPIO);
|
|
|
- gpio_set_direction(FLASH_GPIO, GPIO_MODE_OUTPUT);
|
|
|
- gpio_set_level(FLASH_GPIO, status ? 1 : 0);
|
|
|
-#endif
|
|
|
+ UpdateStatusLedOutputLocked();
|
|
|
}
|
|
|
-void CCamera::LEDOnOff(bool status)
|
|
|
+
|
|
|
+void CCamera::LightOnOff(bool status)
|
|
|
{
|
|
|
- if (xHandle_task_StatusLED == NULL)
|
|
|
+ ScopedCameraOperationLock operationLock(m_cameraOperationMutex);
|
|
|
+ if (!operationLock.acquired()) return;
|
|
|
+ ScopedCameraLock cameraLock(m_cameraMutex);
|
|
|
+ if (!cameraLock.acquired())
|
|
|
{
|
|
|
- // Init the GPIO
|
|
|
- gpio_pad_select_gpio(BLINK_GPIO);
|
|
|
+ ESP_LOGW(TAG, "LightOnOff: camera mutex unavailable");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- /* Set the GPIO as a push/pull output */
|
|
|
- gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
|
|
|
+ m_manualFlashOn = status;
|
|
|
+ UpdateFlashOutputLocked();
|
|
|
+}
|
|
|
|
|
|
- if (!status)
|
|
|
- {
|
|
|
- gpio_set_level(BLINK_GPIO, 1);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- gpio_set_level(BLINK_GPIO, 0);
|
|
|
- }
|
|
|
- }
|
|
|
+void CCamera::LEDOnOff(bool status)
|
|
|
+{
|
|
|
+ ScopedCameraOperationLock operationLock(m_cameraOperationMutex);
|
|
|
+ if (!operationLock.acquired()) return;
|
|
|
+ ScopedCameraLock cameraLock(m_cameraMutex);
|
|
|
+ if (!cameraLock.acquired()) return;
|
|
|
+
|
|
|
+ m_manualStatusLedOn = status;
|
|
|
+ UpdateStatusLedOutputLocked();
|
|
|
}
|
|
|
|
|
|
void CCamera::SetImageWidthHeightFromResolution(CameraSettings &settings)
|
|
|
@@ -1428,6 +1470,9 @@ void CCamera::SetImageWidthHeightFromResolution(CameraSettings &settings)
|
|
|
|
|
|
void CCamera::useDemoMode(void)
|
|
|
{
|
|
|
+ ScopedCameraOperationLock operationLock(m_cameraOperationMutex);
|
|
|
+ if (!operationLock.acquired()) return;
|
|
|
+
|
|
|
char line[50];
|
|
|
m_demoFiles.clear();
|
|
|
FILE *fd = fopen("/sdcard/demo/files.txt", "r");
|