HOme Sheriff And Lamp

Dependencies:   CameraC328 HCSR04 SDFileSystem WIZnetInterface mbed

Fork of HoSAL by pi bae

Files at this revision

API Documentation at this revision

Comitter:
uasonice
Date:
Thu Aug 13 19:35:01 2015 +0000
Parent:
12:974f7a96d6ab
Commit message:
update: web server image view

Changed in this revision

html/image.html Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
rev_Camera.cpp Show annotated file Show diff for this revision Revisions of this file
rev_httpFile.cpp Show annotated file Show diff for this revision Revisions of this file
rev_httpFile.h Show annotated file Show diff for this revision Revisions of this file
diff -r 974f7a96d6ab -r cefc034543a5 html/image.html
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/html/image.html	Thu Aug 13 19:35:01 2015 +0000
@@ -0,0 +1,80 @@
+<!DOCTYPE html>
+<html xmlns='http://www.w3.org/1999/xhtml'>
+<head>
+<title>image</title>
+<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
+<meta http-equiv='pragma' content='no-cache' />
+<meta http-equiv='content-type' content='no-cache, must-revalidate' />
+<style>
+body{background-color:transparent;}
+</style>
+
+<script>
+function AJAX(url, callback)
+{
+	var req = AJAX_init();
+	req.onreadystatechange = AJAX_processRequest;
+
+	function AJAX_init() {
+		if (window.XMLHttpRequest) {
+			return new XMLHttpRequest();
+		} else if (window.ActiveXObject) {
+			return new ActiveXObject('Microsoft.XMLHTTP');
+		}
+	};
+
+	function AJAX_processRequest() {
+		if(req.readyState == 4) {
+			if(req.status == 200) {
+			if(callback)
+				callback(req.responseText);
+			}
+		}
+	};
+
+	this.doGet = function() {
+		req.open('GET', url, true);
+		req.send(null);
+	};
+
+	this.doPost = function(body) {
+		req.open('POST', url, true);
+		req.setRequestHeader('Content-Type',
+		'application/x-www-form-urlencoded');
+		req.setRequestHeader('ISAJAX','yes');
+		req.send(body);
+	};
+};
+
+function $(id){return document.getElementById(id);}
+function $$(id){return document.getElementsByName(id);}
+function $$_ie(tag, name){
+	if(!tag){tag='*';}
+	var elems=document.getElementsByTagName(tag);
+	var res=[];
+	for(var i=0;i<elems.length;i++){
+		att=elems[i].getAttribute('name');
+		if(att==name){
+			res.push(elems[i]);
+		}
+	}
+	return res;
+}
+
+</script>
+
+<script>
+function load() {
+	strFile= window.location.search.substring(1);
+	$('imgFile').src = strFile;
+}
+</script>
+
+
+</head>
+<body onload="load()">
+	<img id='imgFile'>
+
+</body>
+</html>
+
diff -r 974f7a96d6ab -r cefc034543a5 main.cpp
--- a/main.cpp	Thu Aug 13 18:35:55 2015 +0000
+++ b/main.cpp	Thu Aug 13 19:35:01 2015 +0000
@@ -53,7 +53,7 @@
 DigitalOut myled_B(D5);
 
 //////////////////////////////////////////////////////////////////////////
-Ticker ledTick;
+Ticker tickLed;
 
 //////////////////////////////////////////////////////////////////////////
 void ledTickfunc()
@@ -75,7 +75,8 @@
     char strFile[32];
     uint32_t cntImage=1;
 
-    ledTick.attach(&ledTickfunc,0.5);
+    tickLed.attach(&ledTickfunc,0.5);
+    //ledTickfunc();
 
     uart.baud(115200);
     
@@ -127,6 +128,7 @@
     g_pHcsr = new HCSR04(D12, D11);
 #endif // defined(USE_MEASURE_DISTANCE)
 
+    //tickLed.attach(&fileServer,1.2);
 
     DM_fLN("start main loop");
     while(1) {
@@ -145,7 +147,7 @@
 #endif // defined(USE_CAMERA)
         }
 #if 1
-        fileServer(NULL);
+        fileServer();
 #else   
         wait_ms(1000);
 #endif
diff -r 974f7a96d6ab -r cefc034543a5 rev_Camera.cpp
--- a/rev_Camera.cpp	Thu Aug 13 18:35:55 2015 +0000
+++ b/rev_Camera.cpp	Thu Aug 13 19:35:01 2015 +0000
@@ -96,7 +96,8 @@
 
     fp_jpeg = fopen(strFile, "w");
 
-    err = pH->getJpegPreviewPicture(cb_jpeg);
+    //err = pH->getJpegPreviewPicture(cb_jpeg);
+    err = pH->getJpegSnapshotPicture(cb_jpeg);
     if (CameraC328::NoError == err) {
         DM_fLN("[ OK ] : CameraC328::getJpegPreview");
     } else {
diff -r 974f7a96d6ab -r cefc034543a5 rev_httpFile.cpp
--- a/rev_httpFile.cpp	Thu Aug 13 18:35:55 2015 +0000
+++ b/rev_httpFile.cpp	Thu Aug 13 19:35:01 2015 +0000
@@ -60,9 +60,7 @@
                 if (subDir != NULL) {
                     sprintf(httpHeader,"<li><a href=\"./%s/\">%s/</a></li>", p->d_name, p->d_name);
                 } else {
-                    //strlen(p->d_name);
-                    sprintf(httpHeader,"<li><a href=\"./%s\">%s</a></li>", p->d_name, p->d_name);
-                    //sprintf(httpHeader,"<li><img width=50 height=50 src=\"./%s\">%s</li>", p->d_name, p->d_name); 
+                    sprintf(httpHeader,"<li><a href=\"./image.html?%s\">%s</a></li>", p->d_name, p->d_name);
                 }
                 client.send(httpHeader,strlen(httpHeader));
             }
@@ -72,7 +70,9 @@
         sprintf(httpHeader,"</ul></body></html>");
         client.send(httpHeader,strlen(httpHeader));
     } else {
+        char *strFind;
         sprintf(fileName, "/sd%s", uri);
+        if((strFind = strstr(fileName, "?")) != NULL) *strFind = NULL; // remove parameter
         fp = fopen(fileName, "r");
         if (fp == NULL) {
             DM_FLN("File not found");
@@ -95,7 +95,7 @@
     }
 }
 
-void fileServer(void const *data)
+void fileServer(/*void const *data*/)
 {
     int ret;
 
diff -r 974f7a96d6ab -r cefc034543a5 rev_httpFile.h
--- a/rev_httpFile.h	Thu Aug 13 18:35:55 2015 +0000
+++ b/rev_httpFile.h	Thu Aug 13 19:35:01 2015 +0000
@@ -27,7 +27,7 @@
 extern DigitalOut led2; //socket connecting status
 
 void get_file(char* uri);
-void fileServer(void const *data);
+void fileServer(/*void const *data*/);
 
 #endif // __REV_HTTPFILE_H__