HOme Sheriff And Lamp
Dependencies: CameraC328 HCSR04 SDFileSystem WIZnetInterface mbed
Fork of HoSAL by
main.cpp@5:217f40f0a415, 2015-08-11 (annotated)
- Committer:
- uasonice
- Date:
- Tue Aug 11 17:52:59 2015 +0000
- Revision:
- 5:217f40f0a415
- Parent:
- 4:ca368c50f8c9
- Child:
- 7:58b14840531c
update httpFile debug code
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:8c4e0e7c8cea | 63 | |
uasonice | 0:35211a622a44 | 64 | ledTick.attach(&ledTickfunc,0.5); |
uasonice | 0:35211a622a44 | 65 | |
uasonice | 0:35211a622a44 | 66 | uart.baud(115200); |
uasonice | 3:8c4e0e7c8cea | 67 | |
uasonice | 3:8c4e0e7c8cea | 68 | DM_fLN("INIT DEVICE"); |
uasonice | 4:ca368c50f8c9 | 69 | #if defined(USE_SDCARD) |
uasonice | 4:ca368c50f8c9 | 70 | // Check File System |
uasonice | 4:ca368c50f8c9 | 71 | DM_fLN("Checking File System"); |
uasonice | 4:ca368c50f8c9 | 72 | DIR *d = opendir("/sd/"); |
uasonice | 4:ca368c50f8c9 | 73 | if (d != NULL) { |
uasonice | 4:ca368c50f8c9 | 74 | DM_fLN("SD Card Present"); |
uasonice | 4:ca368c50f8c9 | 75 | } else { |
uasonice | 4:ca368c50f8c9 | 76 | DM_fLN("SD Card Root Directory Not Found"); |
uasonice | 4:ca368c50f8c9 | 77 | } |
uasonice | 4:ca368c50f8c9 | 78 | #endif // defined(USE_SDCARD) |
uasonice | 4:ca368c50f8c9 | 79 | |
uasonice | 4:ca368c50f8c9 | 80 | #if defined(USE_HTTP_FILE_SERVER) |
uasonice | 4:ca368c50f8c9 | 81 | // EthernetInterface eth; |
uasonice | 4:ca368c50f8c9 | 82 | DM_fLN("Init Ethernet"); |
uasonice | 4:ca368c50f8c9 | 83 | //eth.init(); //Use DHCP |
uasonice | 4:ca368c50f8c9 | 84 | eth.init((uint8_t*)MAC,IP,MASK,GATEWAY); //IP,mask,Gateway |
uasonice | 4:ca368c50f8c9 | 85 | DM_fLN("Connecting"); |
uasonice | 4:ca368c50f8c9 | 86 | eth.connect(); |
uasonice | 4:ca368c50f8c9 | 87 | DM_fLN("IP Address is %s", eth.getIPAddress()); |
uasonice | 4:ca368c50f8c9 | 88 | |
uasonice | 4:ca368c50f8c9 | 89 | // TCPSocketServer server; |
uasonice | 4:ca368c50f8c9 | 90 | server.bind(HTTPD_SERVER_PORT); |
uasonice | 4:ca368c50f8c9 | 91 | server.listen(); |
uasonice | 4:ca368c50f8c9 | 92 | DM_fLN("Server Listening"); |
uasonice | 4:ca368c50f8c9 | 93 | |
uasonice | 4:ca368c50f8c9 | 94 | // FIXME: no work - non-block mode |
uasonice | 4:ca368c50f8c9 | 95 | server.set_blocking(false, 1000); |
uasonice | 4:ca368c50f8c9 | 96 | #endif // defined(USE_HTTP_FILE_SERVER) |
uasonice | 4:ca368c50f8c9 | 97 | |
uasonice | 3:8c4e0e7c8cea | 98 | #if defined(USE_CAMERA) |
uasonice | 3:8c4e0e7c8cea | 99 | DM_fLN("Init camera C328"); |
uasonice | 3:8c4e0e7c8cea | 100 | g_pCam = new CameraC328(PA_14, PA_13, CameraC328::Baud14400); |
uasonice | 3:8c4e0e7c8cea | 101 | revSync(g_pCam); |
uasonice | 3:8c4e0e7c8cea | 102 | tm1.reset(); |
uasonice | 3:8c4e0e7c8cea | 103 | tm1.start(); |
uasonice | 3:8c4e0e7c8cea | 104 | //revJpeg_snapshot(g_pCam, "/sd/file05.jpg", CameraC328::JpegResolution640x480); |
uasonice | 3:8c4e0e7c8cea | 105 | tm1.stop(); |
uasonice | 3:8c4e0e7c8cea | 106 | DM_fLN("time of capture: %d", tm1.read_ms()); |
uasonice | 3:8c4e0e7c8cea | 107 | #endif // defined(USE_CAMERA) |
uasonice | 3:8c4e0e7c8cea | 108 | #if defined(USE_MEASURE_DISTANCE) |
uasonice | 4:ca368c50f8c9 | 109 | g_pHcsr = new HCSR04(D12, D11); |
uasonice | 3:8c4e0e7c8cea | 110 | #endif // defined(USE_MEASURE_DISTANCE) |
uasonice | 3:8c4e0e7c8cea | 111 | |
uasonice | 3:8c4e0e7c8cea | 112 | DM_fLN("start main loop"); |
uasonice | 0:35211a622a44 | 113 | while(1) { |
uasonice | 4:ca368c50f8c9 | 114 | int dist_cm = 0; |
uasonice | 4:ca368c50f8c9 | 115 | tm1.reset(); |
uasonice | 4:ca368c50f8c9 | 116 | tm1.start(); |
uasonice | 3:8c4e0e7c8cea | 117 | #if defined(USE_MEASURE_DISTANCE) |
uasonice | 4:ca368c50f8c9 | 118 | if( (dist_cm = get_distance(g_pHcsr)) < CHECK_DISTANCE ) |
uasonice | 3:8c4e0e7c8cea | 119 | #endif // defined(USE_MEASURE_DISTANCE) |
uasonice | 4:ca368c50f8c9 | 120 | { |
uasonice | 4:ca368c50f8c9 | 121 | DM_fLN("capture image: %d", dist_cm); |
uasonice | 4:ca368c50f8c9 | 122 | #if defined(USE_CAMERA) |
uasonice | 4:ca368c50f8c9 | 123 | //revJpeg_snapshot("/sd/file02.jpg", CameraC328::JpegResolution640x480); |
uasonice | 4:ca368c50f8c9 | 124 | #endif // defined(USE_CAMERA) |
uasonice | 4:ca368c50f8c9 | 125 | |
uasonice | 4:ca368c50f8c9 | 126 | } |
uasonice | 4:ca368c50f8c9 | 127 | fileServer(); |
uasonice | 4:ca368c50f8c9 | 128 | |
uasonice | 4:ca368c50f8c9 | 129 | //wait_ms(1000); |
uasonice | 4:ca368c50f8c9 | 130 | tm1.stop(); |
uasonice | 5:217f40f0a415 | 131 | //DM_fLN("time: %d", tm1.read_ms()); |
uasonice | 0:35211a622a44 | 132 | } |
uasonice | 4:ca368c50f8c9 | 133 | //return 0; |
uasonice | 0:35211a622a44 | 134 | } |