HOme Sheriff And Lamp

Dependencies:   CameraC328 HCSR04 SDFileSystem WIZnetInterface mbed

Fork of HoSAL by pi bae

Committer:
uasonice
Date:
Thu Aug 13 18:35:55 2015 +0000
Revision:
12:974f7a96d6ab
Parent:
11:7db34a66a751
Child:
13:cefc034543a5
update LED control

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 12:974f7a96d6ab 23
uasonice 0:35211a622a44 24 Serial uart(USBTX, USBRX); // tx, rx
uasonice 0:35211a622a44 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 12:974f7a96d6ab 47
uasonice 0:35211a622a44 48 DigitalOut led1(LED1); //server listning status
uasonice 0:35211a622a44 49 DigitalOut led2(LED2); //socket connecting status
uasonice 0:35211a622a44 50
galucpia 11:7db34a66a751 51 DigitalOut myled_R(D7);
galucpia 11:7db34a66a751 52 DigitalOut myled_G(D6);
galucpia 11:7db34a66a751 53 DigitalOut myled_B(D5);
galucpia 11:7db34a66a751 54
uasonice 0:35211a622a44 55 //////////////////////////////////////////////////////////////////////////
uasonice 0:35211a622a44 56 Ticker ledTick;
uasonice 0:35211a622a44 57
uasonice 0:35211a622a44 58 //////////////////////////////////////////////////////////////////////////
uasonice 0:35211a622a44 59 void ledTickfunc()
uasonice 0:35211a622a44 60 {
uasonice 0:35211a622a44 61 led1 = !led1;
uasonice 0:35211a622a44 62 }
uasonice 0:35211a622a44 63
uasonice 12:974f7a96d6ab 64 void LedSet(int nSet)
uasonice 12:974f7a96d6ab 65 {
uasonice 12:974f7a96d6ab 66 myled_R = nSet;
uasonice 12:974f7a96d6ab 67 myled_G = nSet;
uasonice 12:974f7a96d6ab 68 myled_B = nSet;
uasonice 12:974f7a96d6ab 69 }
uasonice 12:974f7a96d6ab 70
uasonice 0:35211a622a44 71 //////////////////////////////////////////////////////////////////////////
uasonice 0:35211a622a44 72 int main()
uasonice 0:35211a622a44 73 {
uasonice 3:8c4e0e7c8cea 74 Timer tm1;
uasonice 7:58b14840531c 75 char strFile[32];
uasonice 7:58b14840531c 76 uint32_t cntImage=1;
uasonice 3:8c4e0e7c8cea 77
uasonice 0:35211a622a44 78 ledTick.attach(&ledTickfunc,0.5);
uasonice 0:35211a622a44 79
uasonice 0:35211a622a44 80 uart.baud(115200);
galucpia 11:7db34a66a751 81
uasonice 3:8c4e0e7c8cea 82 DM_fLN("INIT DEVICE");
uasonice 12:974f7a96d6ab 83 LedSet(0);
uasonice 4:ca368c50f8c9 84 #if defined(USE_SDCARD)
uasonice 4:ca368c50f8c9 85 // Check File System
uasonice 4:ca368c50f8c9 86 DM_fLN("Checking File System");
uasonice 4:ca368c50f8c9 87 DIR *d = opendir("/sd/");
uasonice 4:ca368c50f8c9 88 if (d != NULL) {
uasonice 4:ca368c50f8c9 89 DM_fLN("SD Card Present");
uasonice 4:ca368c50f8c9 90 } else {
uasonice 4:ca368c50f8c9 91 DM_fLN("SD Card Root Directory Not Found");
uasonice 4:ca368c50f8c9 92 }
uasonice 4:ca368c50f8c9 93 #endif // defined(USE_SDCARD)
uasonice 4:ca368c50f8c9 94
uasonice 4:ca368c50f8c9 95 #if defined(USE_HTTP_FILE_SERVER)
uasonice 4:ca368c50f8c9 96 // EthernetInterface eth;
uasonice 4:ca368c50f8c9 97 DM_fLN("Init Ethernet");
uasonice 4:ca368c50f8c9 98 //eth.init(); //Use DHCP
uasonice 4:ca368c50f8c9 99 eth.init((uint8_t*)MAC,IP,MASK,GATEWAY); //IP,mask,Gateway
uasonice 4:ca368c50f8c9 100 DM_fLN("Connecting");
uasonice 4:ca368c50f8c9 101 eth.connect();
uasonice 4:ca368c50f8c9 102 DM_fLN("IP Address is %s", eth.getIPAddress());
uasonice 4:ca368c50f8c9 103
uasonice 4:ca368c50f8c9 104 // TCPSocketServer server;
uasonice 4:ca368c50f8c9 105 server.bind(HTTPD_SERVER_PORT);
uasonice 4:ca368c50f8c9 106 server.listen();
uasonice 4:ca368c50f8c9 107 DM_fLN("Server Listening");
uasonice 4:ca368c50f8c9 108
uasonice 4:ca368c50f8c9 109 // FIXME: no work - non-block mode
uasonice 4:ca368c50f8c9 110 server.set_blocking(false, 1000);
uasonice 4:ca368c50f8c9 111 #endif // defined(USE_HTTP_FILE_SERVER)
uasonice 4:ca368c50f8c9 112
uasonice 3:8c4e0e7c8cea 113 #if defined(USE_CAMERA)
uasonice 3:8c4e0e7c8cea 114 DM_fLN("Init camera C328");
uasonice 9:416cbcabbddd 115 g_pCam = new CameraC328(PA_13, PA_14, CameraC328::Baud14400);
uasonice 9:416cbcabbddd 116 //g_pCam = new CameraC328(PA_13, PA_14, CameraC328::Baud38400);
uasonice 3:8c4e0e7c8cea 117 revSync(g_pCam);
uasonice 7:58b14840531c 118 #if 0
uasonice 3:8c4e0e7c8cea 119 tm1.reset();
uasonice 3:8c4e0e7c8cea 120 tm1.start();
uasonice 7:58b14840531c 121 revJpeg_snapshot(g_pCam, "/sd/test_shoot.jpg", CameraC328::JpegResolution640x480);
uasonice 3:8c4e0e7c8cea 122 tm1.stop();
uasonice 3:8c4e0e7c8cea 123 DM_fLN("time of capture: %d", tm1.read_ms());
uasonice 7:58b14840531c 124 #endif
uasonice 3:8c4e0e7c8cea 125 #endif // defined(USE_CAMERA)
uasonice 3:8c4e0e7c8cea 126 #if defined(USE_MEASURE_DISTANCE)
uasonice 4:ca368c50f8c9 127 g_pHcsr = new HCSR04(D12, D11);
uasonice 3:8c4e0e7c8cea 128 #endif // defined(USE_MEASURE_DISTANCE)
uasonice 3:8c4e0e7c8cea 129
uasonice 12:974f7a96d6ab 130
uasonice 3:8c4e0e7c8cea 131 DM_fLN("start main loop");
uasonice 0:35211a622a44 132 while(1) {
uasonice 4:ca368c50f8c9 133 int dist_cm = 0;
uasonice 3:8c4e0e7c8cea 134 #if defined(USE_MEASURE_DISTANCE)
uasonice 4:ca368c50f8c9 135 if( (dist_cm = get_distance(g_pHcsr)) < CHECK_DISTANCE )
uasonice 3:8c4e0e7c8cea 136 #endif // defined(USE_MEASURE_DISTANCE)
uasonice 4:ca368c50f8c9 137 {
uasonice 4:ca368c50f8c9 138 DM_fLN("capture image: %d", dist_cm);
uasonice 4:ca368c50f8c9 139 #if defined(USE_CAMERA)
uasonice 7:58b14840531c 140 memset(strFile, 0, 32);
uasonice 7:58b14840531c 141 sprintf(strFile, "/sd/file_%03d.jpg", cntImage++);
uasonice 12:974f7a96d6ab 142 LedSet(1);
uasonice 7:58b14840531c 143 revJpeg_snapshot(g_pCam, strFile, CameraC328::JpegResolution640x480);
uasonice 12:974f7a96d6ab 144 LedSet(0);
uasonice 4:ca368c50f8c9 145 #endif // defined(USE_CAMERA)
uasonice 4:ca368c50f8c9 146 }
uasonice 12:974f7a96d6ab 147 #if 1
uasonice 12:974f7a96d6ab 148 fileServer(NULL);
uasonice 12:974f7a96d6ab 149 #else
uasonice 12:974f7a96d6ab 150 wait_ms(1000);
uasonice 12:974f7a96d6ab 151 #endif
uasonice 0:35211a622a44 152 }
uasonice 4:ca368c50f8c9 153 //return 0;
uasonice 0:35211a622a44 154 }