From 71dd634be893e26766b13ccb9df655375403e635 Mon Sep 17 00:00:00 2001 From: Owen Carter Date: Thu, 10 Sep 2020 19:54:00 +0200 Subject: [PATCH] Mini viewer (#34) fixes #25 --- app_httpd.cpp | 21 ++ camera_index_ov2640.h | 3 + camera_index_ov3660.h | 3 + miniviewer.h | 629 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 656 insertions(+) create mode 100644 miniviewer.h diff --git a/app_httpd.cpp b/app_httpd.cpp index 3f13615..59d9e24 100644 --- a/app_httpd.cpp +++ b/app_httpd.cpp @@ -19,6 +19,7 @@ #include "camera_index_ov2640.h" #include "camera_index_ov3660.h" +#include "miniviewer.h" #include "favicon/favicons.h" //#define DEBUG_STREAM_DATA // Debug: dump info for each stream frame on serial port @@ -570,6 +571,9 @@ static esp_err_t cmd_handler(httpd_req_t *req){ lampVal = constrain(val,0,100); setLamp(lampVal); } + else if(!strcmp(variable, "rotate")) { + sprintf(myRotation, "%i", val); + } else { res = -1; } @@ -660,6 +664,15 @@ static esp_err_t favicon_ico_handler(httpd_req_t *req){ return httpd_resp_send(req, (const char *)favicon_ico, favicon_ico_len); } +static esp_err_t miniviewer_handler(httpd_req_t *req){ + flashLED(75); // a little feedback to user + delay(75); + flashLED(75); + httpd_resp_set_type(req, "text/html"); + httpd_resp_set_hdr(req, "Content-Encoding", "identity"); + return httpd_resp_send(req, (const char *)miniviewer_html, miniviewer_html_len); +} + static esp_err_t index_handler(httpd_req_t *req){ flashLED(75); // a little feedback to user delay(75); @@ -704,6 +717,13 @@ void startCameraServer(int hPort, int sPort){ .user_ctx = NULL }; + httpd_uri_t miniviewer_uri = { + .uri = "/view", + .method = HTTP_GET, + .handler = miniviewer_handler, + .user_ctx = NULL + }; + httpd_uri_t favicon_16x16_uri = { .uri = "/favicon-16x16.png", .method = HTTP_GET, @@ -759,6 +779,7 @@ void startCameraServer(int hPort, int sPort){ httpd_register_uri_handler(camera_httpd, &cmd_uri); httpd_register_uri_handler(camera_httpd, &status_uri); httpd_register_uri_handler(camera_httpd, &capture_uri); + httpd_register_uri_handler(camera_httpd, &miniviewer_uri); httpd_register_uri_handler(camera_httpd, &favicon_16x16_uri); httpd_register_uri_handler(camera_httpd, &favicon_32x32_uri); httpd_register_uri_handler(camera_httpd, &favicon_ico_uri); diff --git a/camera_index_ov2640.h b/camera_index_ov2640.h index 634d8b6..7a71e34 100644 --- a/camera_index_ov2640.h +++ b/camera_index_ov2640.h @@ -684,6 +684,7 @@ document.addEventListener('DOMContentLoaded', function (event) { } else if(el.id === "cam_name"){ camName.innerHTML = value; window.document.title = value; + console.log('Name set to: ' + value); } else if(el.id === "code_ver"){ codeVer.innerHTML = value; } else if(el.id === "rotate"){ @@ -698,6 +699,7 @@ document.addEventListener('DOMContentLoaded', function (event) { streamURL = value; streamButton.setAttribute("title", `You can also browse to '${streamURL}' for a raw stream`); show(streamGroup) + console.log('Stream set to:' + value); } } } @@ -836,6 +838,7 @@ document.addEventListener('DOMContentLoaded', function (event) { // Detection and framesize rotate.onchange = () => { + updateConfig(rotate); rot = rotate.value; if (rot == -90) { viewContainer.style.transform = `rotate(-90deg) translate(-100%)`; diff --git a/camera_index_ov3660.h b/camera_index_ov3660.h index 7cfd418..73ea8a7 100644 --- a/camera_index_ov3660.h +++ b/camera_index_ov3660.h @@ -695,6 +695,7 @@ document.addEventListener('DOMContentLoaded', function (event) { } else if(el.id === "cam_name"){ camName.innerHTML = value; window.document.title = value; + console.log('Name set to: ' + value); } else if(el.id === "code_ver"){ codeVer.innerHTML = value; } else if(el.id === "rotate"){ @@ -709,6 +710,7 @@ document.addEventListener('DOMContentLoaded', function (event) { streamURL = value; streamButton.setAttribute("title", `You can also browse to '${streamURL}' for a raw stream`); show(streamGroup) + console.log('Stream set to:' + value); } } } @@ -844,6 +846,7 @@ document.addEventListener('DOMContentLoaded', function (event) { // Detection and framesize rotate.onchange = () => { + updateConfig(rotate); rot = rotate.value; if (rot == -90) { viewContainer.style.transform = `rotate(-90deg) translate(-100%)`; diff --git a/miniviewer.h b/miniviewer.h new file mode 100644 index 0000000..f62198a --- /dev/null +++ b/miniviewer.h @@ -0,0 +1,629 @@ +//File: index_ov2640.html +const uint8_t miniviewer_html[] = R"=====( + + + + + + ESP32-CAM MiniViewer + + + + + + +
+ +
+ +
+ +
+
+
+ + + + +)====="; +size_t miniviewer_html_len = sizeof(miniviewer_html);