Skip to content

Commit db4ba4e

Browse files
committed
Light working better, notification LED
1 parent 882858e commit db4ba4e

File tree

7 files changed

+2459
-327
lines changed

7 files changed

+2459
-327
lines changed

app_httpd.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
#include "camera_index_ov2640.h"
2121
#include "camera_index_ov3660.h"
2222

23-
// Globals needed to set led levels
24-
extern long int ledVal;
25-
extern int ledChannel;
23+
// Globals (from main .ino) needed to set Led and Lamp levels
24+
extern long int lampVal;
25+
extern int lampChannel;
26+
void flashLED(int flashtime);
2627

2728
#include "fb_gfx.h"
2829
#include "fd_forward.h"
@@ -530,23 +531,26 @@ static esp_err_t cmd_handler(httpd_req_t *req){
530531
detection_enabled = val;
531532
}
532533
}
533-
else if(!strcmp(variable, "led")) {
534-
Serial.print("LED");
535-
ledVal = (val * 2.55); //Gets the value of the query parameter (0-100) and converts to pwm value
536-
if (ledVal > 255) ledVal = 255; // normalise 0-255 (pwm range) just in case..
537-
if (ledVal < 0 ) ledVal = 0;
538-
ledcWrite(ledChannel, ledVal);
539-
Serial.println(ledVal);
540-
res = true;
534+
else if(!strcmp(variable, "lamp")) {
535+
Serial.print("Lamp: ");
536+
lampVal = val;
537+
if (lampVal > 100) lampVal = 100; // normalise 0-255 (pwm range) just in case..
538+
if (lampVal < 0 ) lampVal = 0;
539+
ledcWrite(lampChannel, lampVal * 2.55); // Add s exponential map for 0-100 vs pwm value here.
540+
Serial.print(lampVal);
541+
Serial.println("%");
541542
}
542543
else {
543544
res = -1;
544545
}
545546

547+
546548
if(res){
547549
return httpd_resp_send_500(req);
548550
}
549551

552+
flashLED(75); // little flash of status LED
553+
550554
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
551555
return httpd_resp_send(req, NULL, 0);
552556
}
@@ -558,6 +562,7 @@ static esp_err_t status_handler(httpd_req_t *req){
558562
char * p = json_response;
559563
*p++ = '{';
560564

565+
p+=sprintf(p, "\"Lamp\":%u", lampVal);
561566
p+=sprintf(p, "\"framesize\":%u,", s->status.framesize);
562567
p+=sprintf(p, "\"quality\":%u,", s->status.quality);
563568
p+=sprintf(p, "\"brightness\":%d,", s->status.brightness);
@@ -594,14 +599,14 @@ static esp_err_t status_handler(httpd_req_t *req){
594599
}
595600

596601
static esp_err_t index_handler(httpd_req_t *req){
602+
flashLED(75); // a little feedback to user
597603
httpd_resp_set_type(req, "text/html");
598-
// httpd_resp_set_hdr(req, "Content-Encoding", "gzip");
599604
httpd_resp_set_hdr(req, "Content-Encoding", "identity");
600605
sensor_t * s = esp_camera_sensor_get();
601606
if (s->id.PID == OV3660_PID) {
602-
return httpd_resp_send(req, (const char *)index_ov3660_html_gz, index_ov3660_html_gz_len);
607+
return httpd_resp_send(req, (const char *)index_ov3660_html, index_ov3660_html_len);
603608
}
604-
return httpd_resp_send(req, (const char *)index_ov2640_html_gz, index_ov2640_html_gz_len);
609+
return httpd_resp_send(req, (const char *)index_ov2640_html, index_ov2640_html_len);
605610
}
606611

607612
void startCameraServer(){

camera_index_ov2640.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
21
//File: index_ov2640.html
3-
const uint8_t index_ov2640_html_gz[] PROGMEM = R"=====(
2+
const uint8_t index_ov2640_html[] PROGMEM = R"=====(
43
<!doctype html>
54
<html>
65
<head>
76
<meta charset="utf-8">
87
<meta name="viewport" content="width=device-width,initial-scale=1">
9-
<title>Owens Camera 1</title>
8+
<title>ESP32 OV2640</title>
109
<style>
1110
body {
1211
font-family: Arial,Helvetica,sans-serif;
@@ -349,10 +348,10 @@ const uint8_t index_ov2640_html_gz[] PROGMEM = R"=====(
349348
<input type="checkbox" id="nav-toggle-cb" checked="checked">
350349
<nav id="menu">
351350

352-
<div class="input-group" id="led-group">
353-
<label for="led">Light</label>
351+
<div class="input-group" id="lamp-group">
352+
<label for="lamp">Light</label>
354353
<div class="range-min">0%</div>
355-
<input type="range" id="led" min="0" max="100" value="10" class="default-action">
354+
<input type="range" id="lamp" min="0" max="100" value="0" class="default-action">
356355
<div class="range-max">100%</div>
357356
</div>
358357

@@ -791,4 +790,4 @@ document.addEventListener('DOMContentLoaded', function (event) {
791790
</html>
792791
)=====";
793792

794-
size_t index_ov2640_html_gz_len = sizeof(index_ov2640_html_gz);
793+
size_t index_ov2640_html_len = sizeof(index_ov2640_html);

0 commit comments

Comments
 (0)