HOme Sheriff And Lamp

Dependencies:   CameraC328 HCSR04 SDFileSystem WIZnetInterface mbed

Fork of HoSAL by pi bae

Committer:
uasonice
Date:
Tue Aug 11 19:07:44 2015 +0000
Revision:
7:58b14840531c
Parent:
5:217f40f0a415
Child:
8:28f7b30c1ae4
all component - OK

Who changed what in which revision?

UserRevisionLine numberNew contents of line
uasonice 0:35211a622a44 1 #include "mbed.h"
uasonice 4:ca368c50f8c9 2 #include "EthernetInterface.h"
uasonice 4:ca368c50f8c9 3 #include "SDFileSystem.h"
uasonice 4:ca368c50f8c9 4 #include <stdio.h>
uasonice 4:ca368c50f8c9 5 #include <string.h>
uasonice 0:35211a622a44 6
uasonice 0:35211a622a44 7 #define DEBUG_TYPE 1
uasonice 0:35211a622a44 8 #define P_ uart.printf
uasonice 0:35211a622a44 9 #include "rev_config.h"
uasonice 0:35211a622a44 10
uasonice 3:8c4e0e7c8cea 11 #include "rev_Camera.h"
uasonice 4:ca368c50f8c9 12 #include "rev_httpFile.h"
uasonice 3:8c4e0e7c8cea 13 #include "rev_Hcsr04.h"
uasonice 0:35211a622a44 14
uasonice 0:35211a622a44 15
uasonice 3:8c4e0e7c8cea 16 #define MAC "\x00\x08\xDC\x11\x34\x78"
uasonice 3:8c4e0e7c8cea 17 #define IP "192.168.5.5"
uasonice 3:8c4e0e7c8cea 18 #define MASK "255.255.255.0"
uasonice 3:8c4e0e7c8cea 19 #define GATEWAY "192.168.5.1"
uasonice 3:8c4e0e7c8cea 20
uasonice 3:8c4e0e7c8cea 21 #define HTTPD_SERVER_PORT 80
uasonice 0:35211a622a44 22
uasonice 0:35211a622a44 23 Serial uart(USBTX, USBRX); // tx, rx
uasonice 0:35211a622a44 24
uasonice 4:ca368c50f8c9 25
uasonice 4:ca368c50f8c9 26 #if defined(USE_SDCARD)
uasonice 4:ca368c50f8c9 27 SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500
uasonice 4:ca368c50f8c9 28 #endif // defined(USE_SDCARD)
uasonice 4:ca368c50f8c9 29
uasonice 4:ca368c50f8c9 30 #if defined(USE_HTTP_FILE_SERVER)
uasonice 4:ca368c50f8c9 31 EthernetInterface eth;
uasonice 4:ca368c50f8c9 32 TCPSocketServer server;
uasonice 4:ca368c50f8c9 33 TCPSocketConnection client;
uasonice 4:ca368c50f8c9 34 #endif // defined(USE_HTTP_FILE_SERVER)
uasonice 4:ca368c50f8c9 35
uasonice 3:8c4e0e7c8cea 36 #if defined(USE_CAMERA)
uasonice 3:8c4e0e7c8cea 37 //CameraC328 cam(PA_14, PA_13, CameraC328::Baud14400);
uasonice 3:8c4e0e7c8cea 38 CameraC328 *g_pCam;
uasonice 3:8c4e0e7c8cea 39 #endif // defined(USE_CAMERA)
uasonice 3:8c4e0e7c8cea 40
uasonice 3:8c4e0e7c8cea 41 #if defined(USE_MEASURE_DISTANCE)
uasonice 2:3c7526a1893a 42 //HCSR04 sensor(D12, D11);
uasonice 4:ca368c50f8c9 43 HCSR04 *g_pHcsr;
uasonice 3:8c4e0e7c8cea 44 #define CHECK_DISTANCE 50
uasonice 3:8c4e0e7c8cea 45 #endif // defined(USE_MEASURE_DISTANCE)
uasonice 0:35211a622a44 46
uasonice 0:35211a622a44 47 DigitalOut led1(LED1); //server listning status
uasonice 0:35211a622a44 48 DigitalOut led2(LED2); //socket connecting status
uasonice 0:35211a622a44 49
uasonice 0:35211a622a44 50 //////////////////////////////////////////////////////////////////////////
uasonice 0:35211a622a44 51 Ticker ledTick;
uasonice 0:35211a622a44 52
uasonice 0:35211a622a44 53 //////////////////////////////////////////////////////////////////////////
uasonice 0:35211a622a44 54 void ledTickfunc()
uasonice 0:35211a622a44 55 {
uasonice 0:35211a622a44 56 led1 = !led1;
uasonice 0:35211a622a44 57 }
uasonice 0:35211a622a44 58
uasonice 0:35211a622a44 59 //////////////////////////////////////////////////////////////////////////
uasonice 0:35211a622a44 60 int main()
uasonice 0:35211a622a44 61 {
uasonice 3:8c4e0e7c8cea 62 Timer tm1;
uasonice 7:58b14840531c 63 char strFile[32];
uasonice 7:58b14840531c 64 uint32_t cntImage=1;
uasonice 3:8c4e0e7c8cea 65
uasonice 0:35211a622a44 66 ledTick.attach(&ledTickfunc,0.5);
uasonice 0:35211a622a44 67
uasonice 0:35211a622a44 68 uart.baud(115200);
uasonice 3:8c4e0e7c8cea 69
uasonice 3:8c4e0e7c8cea 70 DM_fLN("INIT DEVICE");
uasonice 4:ca368c50f8c9 71 #if defined(USE_SDCARD)
uasonice 4:ca368c50f8c9 72 // Check File System
uasonice 4:ca368c50f8c9 73 DM_fLN("Checking File System");
uasonice 4:ca368c50f8c9 74 DIR *d = opendir("/sd/");
uasonice 4:ca368c50f8c9 75 if (d != NULL) {
uasonice 4:ca368c50f8c9 76 DM_fLN("SD Card Present");
uasonice 4:ca368c50f8c9 77 } else {
uasonice 4:ca368c50f8c9 78 DM_fLN("SD Card Root Directory Not Found");
uasonice 4:ca368c50f8c9 79 }
uasonice 4:ca368c50f8c9 80 #endif // defined(USE_SDCARD)
uasonice 4:ca368c50f8c9 81
uasonice 4:ca368c50f8c9 82 #if defined(USE_HTTP_FILE_SERVER)
uasonice 4:ca368c50f8c9 83 // EthernetInterface eth;
uasonice 4:ca368c50f8c9 84 DM_fLN("Init Ethernet");
uasonice 4:ca368c50f8c9 85 //eth.init(); //Use DHCP
uasonice 4:ca368c50f8c9 86 eth.init((uint8_t*)MAC,IP,MASK,GATEWAY); //IP,mask,Gateway
uasonice 4:ca368c50f8c9 87 DM_fLN("Connecting");
uasonice 4:ca368c50f8c9 88 eth.connect();
uasonice 4:ca368c50f8c9 89 DM_fLN("IP Address is %s", eth.getIPAddress());
uasonice 4:ca368c50f8c9 90
uasonice 4:ca368c50f8c9 91 // TCPSocketServer server;
uasonice 4:ca368c50f8c9 92 server.bind(HTTPD_SERVER_PORT);
uasonice 4:ca368c50f8c9 93 server.listen();
uasonice 4:ca368c50f8c9 94 DM_fLN("Server Listening");
uasonice 4:ca368c50f8c9 95
uasonice 4:ca368c50f8c9 96 // FIXME: no work - non-block mode
uasonice 4:ca368c50f8c9 97 server.set_blocking(false, 1000);
uasonice 4:ca368c50f8c9 98 #endif // defined(USE_HTTP_FILE_SERVER)
uasonice 4:ca368c50f8c9 99
uasonice 3:8c4e0e7c8cea 100 #if defined(USE_CAMERA)
uasonice 3:8c4e0e7c8cea 101 DM_fLN("Init camera C328");
uasonice 7:58b14840531c 102 g_pCam = new CameraC328(PA_13, PA_14, CameraC328::Baud14400);
uasonice 3:8c4e0e7c8cea 103 revSync(g_pCam);
uasonice 7:58b14840531c 104 #if 0
uasonice 3:8c4e0e7c8cea 105 tm1.reset();
uasonice 3:8c4e0e7c8cea 106 tm1.start();
uasonice 7:58b14840531c 107 revJpeg_snapshot(g_pCam, "/sd/test_shoot.jpg", CameraC328::JpegResolution640x480);
uasonice 3:8c4e0e7c8cea 108 tm1.stop();
uasonice 3:8c4e0e7c8cea 109 DM_fLN("time of capture: %d", tm1.read_ms());
uasonice 7:58b14840531c 110 #endif
uasonice 3:8c4e0e7c8cea 111 #endif // defined(USE_CAMERA)
uasonice 3:8c4e0e7c8cea 112 #if defined(USE_MEASURE_DISTANCE)
uasonice 4:ca368c50f8c9 113 g_pHcsr = new HCSR04(D12, D11);
uasonice 3:8c4e0e7c8cea 114 #endif // defined(USE_MEASURE_DISTANCE)
uasonice 3:8c4e0e7c8cea 115
uasonice 3:8c4e0e7c8cea 116 DM_fLN("start main loop");
uasonice 0:35211a622a44 117 while(1) {
uasonice 4:ca368c50f8c9 118 int dist_cm = 0;
uasonice 4:ca368c50f8c9 119 tm1.reset();
uasonice 4:ca368c50f8c9 120 tm1.start();
uasonice 3:8c4e0e7c8cea 121 #if defined(USE_MEASURE_DISTANCE)
uasonice 4:ca368c50f8c9 122 if( (dist_cm = get_distance(g_pHcsr)) < CHECK_DISTANCE )
uasonice 3:8c4e0e7c8cea 123 #endif // defined(USE_MEASURE_DISTANCE)
uasonice 4:ca368c50f8c9 124 {
uasonice 4:ca368c50f8c9 125 DM_fLN("capture image: %d", dist_cm);
uasonice 4:ca368c50f8c9 126 #if defined(USE_CAMERA)
uasonice 7:58b14840531c 127 memset(strFile, 0, 32);
uasonice 7:58b14840531c 128 sprintf(strFile, "/sd/file_%03d.jpg", cntImage++);
uasonice 7:58b14840531c 129 revJpeg_snapshot(g_pCam, strFile, CameraC328::JpegResolution640x480);
uasonice 4:ca368c50f8c9 130 #endif // defined(USE_CAMERA)
uasonice 4:ca368c50f8c9 131
uasonice 4:ca368c50f8c9 132 }
uasonice 4:ca368c50f8c9 133 fileServer();
uasonice 4:ca368c50f8c9 134
uasonice 4:ca368c50f8c9 135 //wait_ms(1000);
uasonice 4:ca368c50f8c9 136 tm1.stop();
uasonice 5:217f40f0a415 137 //DM_fLN("time: %d", tm1.read_ms());
uasonice 0:35211a622a44 138 }
uasonice 4:ca368c50f8c9 139 //return 0;
uasonice 0:35211a622a44 140 }