HOme Sheriff And Lamp
Dependencies: CameraC328 HCSR04 SDFileSystem WIZnetInterface mbed
Fork of HoSAL by
Diff: main.cpp
- Revision:
- 4:ca368c50f8c9
- Parent:
- 3:8c4e0e7c8cea
- Child:
- 5:217f40f0a415
--- a/main.cpp Tue Aug 11 17:35:33 2015 +0000
+++ b/main.cpp Tue Aug 11 17:46:53 2015 +0000
@@ -1,11 +1,15 @@
#include "mbed.h"
+#include "EthernetInterface.h"
+#include "SDFileSystem.h"
+#include <stdio.h>
+#include <string.h>
#define DEBUG_TYPE 1
#define P_ uart.printf
#include "rev_config.h"
#include "rev_Camera.h"
-//#include "rev_httpFile.h"
+#include "rev_httpFile.h"
#include "rev_Hcsr04.h"
@@ -18,6 +22,17 @@
Serial uart(USBTX, USBRX); // tx, rx
+
+#if defined(USE_SDCARD)
+SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500
+#endif // defined(USE_SDCARD)
+
+#if defined(USE_HTTP_FILE_SERVER)
+EthernetInterface eth;
+TCPSocketServer server;
+TCPSocketConnection client;
+#endif // defined(USE_HTTP_FILE_SERVER)
+
#if defined(USE_CAMERA)
//CameraC328 cam(PA_14, PA_13, CameraC328::Baud14400);
CameraC328 *g_pCam;
@@ -25,7 +40,7 @@
#if defined(USE_MEASURE_DISTANCE)
//HCSR04 sensor(D12, D11);
-HCSR04 *g_pHcrs;
+HCSR04 *g_pHcsr;
#define CHECK_DISTANCE 50
#endif // defined(USE_MEASURE_DISTANCE)
@@ -51,6 +66,35 @@
uart.baud(115200);
DM_fLN("INIT DEVICE");
+#if defined(USE_SDCARD)
+ // Check File System
+ DM_fLN("Checking File System");
+ DIR *d = opendir("/sd/");
+ if (d != NULL) {
+ DM_fLN("SD Card Present");
+ } else {
+ DM_fLN("SD Card Root Directory Not Found");
+ }
+#endif // defined(USE_SDCARD)
+
+#if defined(USE_HTTP_FILE_SERVER)
+ // EthernetInterface eth;
+ DM_fLN("Init Ethernet");
+ //eth.init(); //Use DHCP
+ eth.init((uint8_t*)MAC,IP,MASK,GATEWAY); //IP,mask,Gateway
+ DM_fLN("Connecting");
+ eth.connect();
+ DM_fLN("IP Address is %s", eth.getIPAddress());
+
+ // TCPSocketServer server;
+ server.bind(HTTPD_SERVER_PORT);
+ server.listen();
+ DM_fLN("Server Listening");
+
+ // FIXME: no work - non-block mode
+ server.set_blocking(false, 1000);
+#endif // defined(USE_HTTP_FILE_SERVER)
+
#if defined(USE_CAMERA)
DM_fLN("Init camera C328");
g_pCam = new CameraC328(PA_14, PA_13, CameraC328::Baud14400);
@@ -62,14 +106,29 @@
DM_fLN("time of capture: %d", tm1.read_ms());
#endif // defined(USE_CAMERA)
#if defined(USE_MEASURE_DISTANCE)
- g_pHcrs = new HCSR04(D12, D11);
+ g_pHcsr = new HCSR04(D12, D11);
#endif // defined(USE_MEASURE_DISTANCE)
DM_fLN("start main loop");
while(1) {
+ int dist_cm = 0;
+ tm1.reset();
+ tm1.start();
#if defined(USE_MEASURE_DISTANCE)
- get_distance(g_pHcrs);
+ if( (dist_cm = get_distance(g_pHcsr)) < CHECK_DISTANCE )
#endif // defined(USE_MEASURE_DISTANCE)
- wait_ms(1000);
+ {
+ DM_fLN("capture image: %d", dist_cm);
+#if defined(USE_CAMERA)
+ //revJpeg_snapshot("/sd/file02.jpg", CameraC328::JpegResolution640x480);
+#endif // defined(USE_CAMERA)
+
+ }
+ fileServer();
+
+ //wait_ms(1000);
+ tm1.stop();
+ DM_fLN("time: %d", tm1.read_ms());
}
+ //return 0;
}
