HOme Sheriff And Lamp
Dependencies: CameraC328 HCSR04 SDFileSystem WIZnetInterface mbed
Fork of HoSAL by
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "SDFileSystem.h" 00004 #include <stdio.h> 00005 #include <string.h> 00006 00007 #define DEBUG_TYPE 1 00008 #define P_ uart.printf 00009 #include "rev_config.h" 00010 00011 #include "rev_Camera.h" 00012 #include "rev_httpFile.h" 00013 #include "rev_Hcsr04.h" 00014 00015 00016 #define MAC "\x00\x08\xDC\x11\x34\x78" 00017 #define IP "192.168.5.5" 00018 #define MASK "255.255.255.0" 00019 #define GATEWAY "192.168.5.1" 00020 00021 #define HTTPD_SERVER_PORT 80 00022 00023 00024 Serial uart(USBTX, USBRX); // tx, rx 00025 00026 #if defined(USE_SDCARD) 00027 SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500 00028 #endif // defined(USE_SDCARD) 00029 00030 #if defined(USE_HTTP_FILE_SERVER) 00031 EthernetInterface eth; 00032 TCPSocketServer server; 00033 TCPSocketConnection client; 00034 #endif // defined(USE_HTTP_FILE_SERVER) 00035 00036 #if defined(USE_CAMERA) 00037 //CameraC328 cam(PA_14, PA_13, CameraC328::Baud14400); 00038 CameraC328 *g_pCam; 00039 #endif // defined(USE_CAMERA) 00040 00041 #if defined(USE_MEASURE_DISTANCE) 00042 //HCSR04 sensor(D12, D11); 00043 HCSR04 *g_pHcsr; 00044 #define CHECK_DISTANCE 50 00045 #endif // defined(USE_MEASURE_DISTANCE) 00046 00047 00048 DigitalOut led1(LED1); //server listning status 00049 DigitalOut led2(LED2); //socket connecting status 00050 00051 DigitalOut myled_R(D7); 00052 DigitalOut myled_G(D6); 00053 DigitalOut myled_B(D5); 00054 00055 ////////////////////////////////////////////////////////////////////////// 00056 Ticker tickLed; 00057 00058 ////////////////////////////////////////////////////////////////////////// 00059 void ledTickfunc() 00060 { 00061 led1 = !led1; 00062 } 00063 00064 void LedSet(int nSet) 00065 { 00066 myled_R = nSet; 00067 myled_G = nSet; 00068 myled_B = nSet; 00069 } 00070 00071 ////////////////////////////////////////////////////////////////////////// 00072 int main() 00073 { 00074 Timer tm1; 00075 char strFile[32]; 00076 uint32_t cntImage=1; 00077 00078 tickLed.attach(&ledTickfunc,0.5); 00079 //ledTickfunc(); 00080 00081 uart.baud(115200); 00082 00083 DM_fLN("INIT DEVICE"); 00084 LedSet(0); 00085 #if defined(USE_SDCARD) 00086 // Check File System 00087 DM_fLN("Checking File System"); 00088 DIR *d = opendir("/sd/"); 00089 if (d != NULL) { 00090 DM_fLN("SD Card Present"); 00091 } else { 00092 DM_fLN("SD Card Root Directory Not Found"); 00093 } 00094 #endif // defined(USE_SDCARD) 00095 00096 #if defined(USE_HTTP_FILE_SERVER) 00097 // EthernetInterface eth; 00098 DM_fLN("Init Ethernet"); 00099 //eth.init(); //Use DHCP 00100 eth.init((uint8_t*)MAC,IP,MASK,GATEWAY); //IP,mask,Gateway 00101 DM_fLN("Connecting"); 00102 eth.connect(); 00103 DM_fLN("IP Address is %s", eth.getIPAddress()); 00104 00105 // TCPSocketServer server; 00106 server.bind(HTTPD_SERVER_PORT); 00107 server.listen(); 00108 DM_fLN("Server Listening"); 00109 00110 // FIXME: no work - non-block mode 00111 server.set_blocking(false, 1000); 00112 #endif // defined(USE_HTTP_FILE_SERVER) 00113 00114 #if defined(USE_CAMERA) 00115 DM_fLN("Init camera C328"); 00116 g_pCam = new CameraC328(PA_13, PA_14, CameraC328::Baud14400); 00117 //g_pCam = new CameraC328(PA_13, PA_14, CameraC328::Baud38400); 00118 revSync(g_pCam); 00119 #if 0 00120 tm1.reset(); 00121 tm1.start(); 00122 revJpeg_snapshot(g_pCam, "/sd/test_shoot.jpg", CameraC328::JpegResolution640x480); 00123 tm1.stop(); 00124 DM_fLN("time of capture: %d", tm1.read_ms()); 00125 #endif 00126 #endif // defined(USE_CAMERA) 00127 #if defined(USE_MEASURE_DISTANCE) 00128 g_pHcsr = new HCSR04(D12, D11); 00129 #endif // defined(USE_MEASURE_DISTANCE) 00130 00131 //tickLed.attach(&fileServer,1.2); 00132 00133 DM_fLN("start main loop"); 00134 while(1) { 00135 int dist_cm = 0; 00136 #if defined(USE_MEASURE_DISTANCE) 00137 if( (dist_cm = get_distance(g_pHcsr)) < CHECK_DISTANCE ) 00138 #endif // defined(USE_MEASURE_DISTANCE) 00139 { 00140 DM_fLN("capture image: %d", dist_cm); 00141 #if defined(USE_CAMERA) 00142 memset(strFile, 0, 32); 00143 sprintf(strFile, "/sd/file_%03d.jpg", cntImage++); 00144 LedSet(1); 00145 revJpeg_snapshot(g_pCam, strFile, CameraC328::JpegResolution640x480); 00146 LedSet(0); 00147 #endif // defined(USE_CAMERA) 00148 } 00149 #if 1 00150 fileServer(); 00151 #else 00152 wait_ms(1000); 00153 #endif 00154 } 00155 //return 0; 00156 }
Generated on Mon Jul 18 2022 23:38:57 by
1.7.2
