camera, web: Refresh Snapshot captured by the photo task

release/1.1.3
Miroslav Pivovarsky 2026-11-02 13:15:33 +01:00
parent cbe39aa9c7
commit 0c78dd54e4
7 changed files with 40 additions and 8 deletions

View File

@ -69,7 +69,7 @@ const char index_html[] PROGMEM = R"rawliteral(
<div class="container_right-half">
<article>
<p class="p1">Trigger interval: <b><span id="refreshInterval"></span><b>s</p><br><br>
<button class="btn" onclick="actionButton('/action_capture',true,'')">Refresh Snapshot</button> <br><br>
<button class="btn" onclick="actionButton('/action_capture',true,'',1500)">Refresh Snapshot</button> <br><br>
<button class="btn" onclick="actionButton('/action_send',false,'Sending snapshot...')">Send snapshot</button><br><br><br>
<button class="btn" onclick="window.open('saved-photo.jpg')">Download snapshot</button><br><br>
<button class="btn" onclick="window.open('stream.mjpg')">Start stream</button><br><br>
@ -1117,7 +1117,7 @@ function openImage() {
OpenImageclickCount++;
}
function actionButton(url, reload, msg) {
function actionButton(url, reload, msg, delay = 200) {
var xhr = new XMLHttpRequest();
if (msg != '') {
@ -1127,9 +1127,10 @@ function actionButton(url, reload, msg) {
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
if (reload == true) {
/* delay [ms] before the reload. Refresh Snapshot: the photo task captures the photo up to ~1 s after the request */
setTimeout(function() {
location.reload();
}, 200);
}, delay);
}
}
};

View File

@ -452,7 +452,8 @@ void Server_InitWebServer_Actions() {
SystemLog.AddEvent(LogLevel_Verbose, F("WEB server: /action_capture Take photo"));
if (Server_CheckBasicAuth(request) == false)
return;
SystemCamera.CapturePhoto();
/* the photo task captures the photo, the page loads it later (actionButton() in scripts.js) */
SystemCamera.SetCaptureRequest();
request->send(200, "text/plain", "Take Photo");
});

View File

@ -55,6 +55,7 @@ Camera::Camera(Configuration* i_conf, Logs* i_log, int8_t i_FlashPin) {
PhotoExifData.offset = 0;
PhotoSending = false;
ReinitRequest = false;
CaptureRequest = false;
CameraCaptureFailedCounter = 0;
}
@ -471,6 +472,30 @@ void Camera::ProcessReinitRequest() {
}
}
/**
@brief Request the photo from the web (Refresh Snapshot), the photo task captures it (ProcessCaptureRequest()).
The capture in the web server (async_tcp) during sending the photo of the photo task cleared CameraCaptureSuccess (the photo was not sent),
and the reinit after the failed captures released the frame buffer used by the photo task
@param none
@return none
*/
void Camera::SetCaptureRequest() {
CaptureRequest = true;
}
/**
@brief Capture the photo requested from the web. Called by the photo task, not during sending and saving the photo
@param none
@return none
*/
void Camera::ProcessCaptureRequest() {
if (true == CaptureRequest) {
CaptureRequest = false;
log->AddEvent(LogLevel_Verbose, F("Capture photo requested from the web"));
CapturePhoto();
}
}
/**
@brief Function for get camera model and type
@param void

View File

@ -64,6 +64,7 @@ private:
bool CameraCaptureSuccess; ///< camera capture success
bool PhotoSending; ///< photo sending
bool ReinitRequest; ///< reinit of the camera module requested (frame size, photo quality), done by the photo task
bool CaptureRequest; ///< photo requested from the web (Refresh Snapshot), captured by the photo task
/* OV2640 camera module pinout and cfg*/
camera_config_t CameraConfig; ///< camera configuration
@ -100,6 +101,8 @@ public:
void LoadCameraCfgFromEeprom();
void ReinitCameraModule();
void ProcessReinitRequest();
void SetCaptureRequest();
void ProcessCaptureRequest();
void GetCameraModel();
void CapturePhoto();
bool CaptureStream(camera_fb_t *);

View File

@ -595,8 +595,9 @@ void System_TaskCaptureAndSendPhoto(void *pvParameters) {
TickType_t xLastWakeTime = xTaskGetTickCount();
while (1) {
/* reinit camera module after the change of the frame size or the photo quality. Here, not during sending and saving the photo */
/* reinit camera module after the change of the frame size or the photo quality, and the photo requested from the web. Here, not during sending and saving the photo */
SystemCamera.ProcessReinitRequest();
SystemCamera.ProcessCaptureRequest();
if (Connect.CheckSendingIntervalExpired()) {
Connect.SetSendingIntervalCounter(0);

View File

@ -43,7 +43,7 @@
<div class="container_right-half">
<article>
<p class="p1">Trigger interval: <b><span id="refreshInterval"></span><b>s</p><br><br>
<button class="btn" onclick="actionButton('/action_capture',true,'')">Refresh Snapshot</button> <br><br>
<button class="btn" onclick="actionButton('/action_capture',true,'',1500)">Refresh Snapshot</button> <br><br>
<button class="btn" onclick="actionButton('/action_send',false,'Sending snapshot...')">Send snapshot</button><br><br><br>
<button class="btn" onclick="window.open('saved-photo.jpg')">Download snapshot</button><br><br>
<button class="btn" onclick="window.open('stream.mjpg')">Start stream</button><br><br>

View File

@ -197,7 +197,7 @@ function openImage() {
OpenImageclickCount++;
}
function actionButton(url, reload, msg) {
function actionButton(url, reload, msg, delay = 200) {
var xhr = new XMLHttpRequest();
if (msg != '') {
@ -207,9 +207,10 @@ function actionButton(url, reload, msg) {
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
if (reload == true) {
/* delay [ms] before the reload. Refresh Snapshot: the photo task captures the photo up to ~1 s after the request */
setTimeout(function() {
location.reload();
}, 200);
}, delay);
}
}
};