Skip to content

Commit

Permalink
Less flashy notification LED, face recognition stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
easytarget committed Sep 28, 2020
1 parent 25d5c86 commit a35817e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 35 deletions.
37 changes: 7 additions & 30 deletions app_httpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ static esp_err_t cmd_handler(httpd_req_t *req){
httpd_resp_send_404(req);
return ESP_FAIL;
}

int val = atoi(value);
sensor_t * s = esp_camera_sensor_get();
int res = 0;
Expand Down Expand Up @@ -577,6 +577,12 @@ static esp_err_t cmd_handler(httpd_req_t *req){
lampVal = constrain(val,0,100);
setLamp(lampVal);
}
else if(!strcmp(variable, "save_face")) {
if (filesystem) saveFaceDB(SPIFFS);
}
else if(!strcmp(variable, "clear_face")) {
if (filesystem) removeFaceDB(SPIFFS);
}
else if(!strcmp(variable, "save_prefs")) {
if (filesystem) savePrefs(SPIFFS);
}
Expand Down Expand Up @@ -607,7 +613,6 @@ static esp_err_t status_handler(httpd_req_t *req){
static char json_response[1024];
sensor_t * s = esp_camera_sensor_get();
char * p = json_response;
flashLED(75);
*p++ = '{';
p+=sprintf(p, "\"lamp\":%d,", lampVal);
p+=sprintf(p, "\"framesize\":%u,", s->status.framesize);
Expand Down Expand Up @@ -650,7 +655,6 @@ static esp_err_t status_handler(httpd_req_t *req){
}

static esp_err_t info_handler(httpd_req_t *req){
flashLED(75);
static char json_response[256];
char * p = json_response;
*p++ = '{';
Expand All @@ -666,49 +670,23 @@ static esp_err_t info_handler(httpd_req_t *req){
}

static esp_err_t favicon_16x16_handler(httpd_req_t *req){
flashLED(75);
httpd_resp_set_type(req, "image/png");
httpd_resp_set_hdr(req, "Content-Encoding", "identity");
return httpd_resp_send(req, (const char *)favicon_16x16_png, favicon_16x16_png_len);
}

static esp_err_t favicon_32x32_handler(httpd_req_t *req){

httpd_resp_set_type(req, "image/png");
httpd_resp_set_hdr(req, "Content-Encoding", "identity");
return httpd_resp_send(req, (const char *)favicon_32x32_png, favicon_32x32_png_len);
}

static esp_err_t favicon_ico_handler(httpd_req_t *req){
flashLED(75);
httpd_resp_set_type(req, "image/x-icon");
httpd_resp_set_hdr(req, "Content-Encoding", "identity");
return httpd_resp_send(req, (const char *)favicon_ico, favicon_ico_len);
}

static esp_err_t save_prefs_handler(httpd_req_t *req){
flashLED(75);
savePrefs(SPIFFS);
httpd_resp_set_type(req, "text/css");
httpd_resp_set_hdr(req, "Content-Encoding", "identity");
char resp[] = "Preferences saved";
return httpd_resp_send(req, resp, strlen(resp));
}

static esp_err_t remove_prefs_handler(httpd_req_t *req){
flashLED(75);
httpd_resp_set_type(req, "text/css");
httpd_resp_set_hdr(req, "Content-Encoding", "identity");
if (filesystem) {
removePrefs(SPIFFS);
char resp[] = "Preferences file removed, reboot will revert to default settings";
return httpd_resp_send(req, resp, strlen(resp));
} else {
char resp[] = "No internal filesystem; save/restore functions disabled";
return httpd_resp_send(req, resp, strlen(resp));
}
}

// DEBUG
extern void dumpPrefs(fs::FS &fs);
static esp_err_t dump_prefs_handler(httpd_req_t *req){
Expand All @@ -724,7 +702,6 @@ static esp_err_t dump_prefs_handler(httpd_req_t *req){


static esp_err_t style_handler(httpd_req_t *req){
flashLED(75);
httpd_resp_set_type(req, "text/css");
httpd_resp_set_hdr(req, "Content-Encoding", "identity");
return httpd_resp_send(req, (const char *)style_css, style_css_len);
Expand Down
1 change: 1 addition & 0 deletions esp32-cam-webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ void setup() {
if (filesystem) {
filesystemStart();
loadPrefs(SPIFFS);
loadFaceDB(SPIFFS);
} else {
Serial.println("No Internal Filesystem, cannot save preferences or face DB");
}
Expand Down
4 changes: 2 additions & 2 deletions index_ov2640.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ const uint8_t index_ov2640_html[] = R"=====(
const recognize = document.getElementById('face_recognize')
const framesize = document.getElementById('framesize')
const swapButton = document.getElementById('swap-viewer')
const saveFaceButton = document.getElementById('save_face')
const clearFaceButton = document.getElementById('clear_face')
// const saveFaceButton = document.getElementById('save_face')
// const clearFaceButton = document.getElementById('clear_face')
const savePrefsButton = document.getElementById('save_prefs')
const clearPrefsButton = document.getElementById('clear_prefs')
const rebootButton = document.getElementById('reboot')
Expand Down
55 changes: 52 additions & 3 deletions index_ov3660.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,20 @@ const uint8_t index_ov3660_html[] = R"=====(
<label class="slider" for="face_recognize"></label>
</div>
</div>
<section id="buttons">
<button id="face_enroll" class="disabled" disabled="disabled">Enroll Face</button>
</section>
<div class="input-group" id="facedb-group">
<label for="face_enroll" style="line-height: 2em;">Face Database</label>
<button id="face_enroll" class="disabled" disabled="disabled" title="Enroll Faces in Database">Enroll</button>
<!--
<button id="save_face" title="Save Database on camera module">Save</button>
<button id="clear_face" title="Erase saved Database on camera module">Erase</button>
-->
</div>
<div class="input-group" id="preferences-group">
<label for="reboot" style="line-height: 2em;">Preferences</label>
<button id="reboot" title="Reboot the camera module">Reboot</button>
<button id="save_prefs" title="Save Preferences on camera module">Save</button>
<button id="clear_prefs" title="Erase saved Preferences on camera module">Erase</button>
</div>
<div class="input-group" id="cam_name-group">
<label for="cam_name">Name:</label>
<div id="cam_name" class="default-action"></div>
Expand Down Expand Up @@ -324,6 +335,11 @@ const uint8_t index_ov3660_html[] = R"=====(
const recognize = document.getElementById('face_recognize')
const framesize = document.getElementById('framesize')
const swapButton = document.getElementById('swap-viewer')
// const saveFaceButton = document.getElementById('save_face')
// const clearFaceButton = document.getElementById('clear_face')
const savePrefsButton = document.getElementById('save_prefs')
const clearPrefsButton = document.getElementById('clear_prefs')
const rebootButton = document.getElementById('reboot')

const hide = el => {
el.classList.add('hidden')
Expand Down Expand Up @@ -489,6 +505,7 @@ const uint8_t index_ov3660_html[] = R"=====(
// Attach actions to controls

streamLink.onclick = () => {
stopStream();
window.open(streamURL + "view", "_blank");
}

Expand Down Expand Up @@ -598,6 +615,38 @@ const uint8_t index_ov3660_html[] = R"=====(
swapButton.onclick = () => {
window.open('/view','_self');
}

// saveFaceButton.onclick = () => {
// if (confirm("Saving the current face database?")) {
// updateConfig(saveFaceButton);
// }
// }

// clearFaceButton.onclick = () => {
// if (confirm("Removing the face database?")) {
// updateConfig(clearFaceButton);
// }
// }

savePrefsButton.onclick = () => {
if (confirm("Save the current preferences?")) {
updateConfig(savePrefsButton);
}
}

clearPrefsButton.onclick = () => {
if (confirm("Remove the saved preferences?")) {
updateConfig(clearPrefsButton);
}
}

rebootButton.onclick = () => {
if (confirm("Reboot the Camera Module?")) {
updateConfig(rebootButton);
// Some sort of countdown here?
location.reload();
}
}

})
</script>
Expand Down
13 changes: 13 additions & 0 deletions storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ void removePrefs(fs::FS &fs) {
}
}

void saveFaceDB(fs::FS &fs) {
// Stub!
return;
}
void loadFaceDB(fs::FS &fs) {
// Stub!
return;
}
void removeFaceDB(fs::FS &fs) {
// Stub!
return;
}

void filesystemStart(){
while ( !SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED) ) {
// if we sit in this loop something is wrong;
Expand Down
4 changes: 4 additions & 0 deletions storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@
extern void loadPrefs(fs::FS &fs);
extern void removePrefs(fs::FS &fs);
extern void savePrefs(fs::FS &fs);
extern void loadFaceDB(fs::FS &fs);
extern void removeFaceDB(fs::FS &fs);
extern void saveFaceDB(fs::FS &fs);

extern void filesystemStart();

0 comments on commit a35817e

Please sign in to comment.