see: http://mbed.org/users/okini3939/notebook/wifi_webcam/
Dependencies: GSwifiInterface_ap_webcam USBHost mbed
main.cpp
00001 /* 00002 * see: http://mbed.org/users/okini3939/notebook/wifi_webcam/ 00003 * 00004 * using: http://mbed.org/users/va009039/code/USBHostC270_example/ 00005 * using: http://mbed.org/users/gsfan/code/GSwifiInterface/ 00006 */ 00007 00008 #include "mbed.h" 00009 #include "GSwifiInterface.h" 00010 #include "USBHostC270.h" 00011 00012 #define SEC GSwifi::SEC_OPEN 00013 #define SSID "MBED" 00014 #define PASS "1234567890" 00015 #define MODE GSwifi::WM_LIMITEDAP 00016 00017 DigitalOut led1(LED1), led2(LED2), led3(LED3); 00018 Serial pc(USBTX, USBRX); 00019 LocalFileSystem local("local"); 00020 GSwifiInterface *gs; 00021 00022 int main() { 00023 Timer t; 00024 00025 pc.baud(115200); 00026 pc.printf("GSwifi_ap_webcam\r\n"); 00027 00028 gs = new GSwifiInterface(p13, p14, p12, P0_22, p20, NC, 115200); 00029 wait_ms(300); 00030 // gs->init(); //Use DHCP 00031 gs->init("192.168.1.1", "255.255.255.0", "192.168.1.1", "192.168.1.1", "www.mbed"); 00032 if (gs->connect(SEC, SSID, PASS, MODE)) return -1; // join the network 00033 NVIC_SetPriority(UART1_IRQn, 1); 00034 printf("IP Address is %s\r\n", gs->getIPAddress()); 00035 00036 gs->httpd(); 00037 gs->httpdAttach("/", "/local/"); 00038 00039 USBHostC270* cam = new USBHostC270(C270_MJPEG, C270_160x120, _10FPS); // Logitech C270 00040 // USBHostC270* cam = new USBHostC270(C270_MJPEG, C270_320x240, _5FPS); // Logitech C270 00041 00042 t.start(); 00043 led1 = 1; 00044 for (;;) { 00045 gs->poll(); 00046 00047 if (!cam->connected()) { 00048 led2 = 1; 00049 if (t.read() > 0.5) { 00050 cam->connect(); 00051 if (cam->connected()) printf("webcam has detected\r\n"); 00052 t.reset(); 00053 } 00054 } else { 00055 led2 = 0; 00056 cam->poll(); 00057 if (t.read() > 10) { 00058 led3 = 1; 00059 uint8_t buf[1024*8]; 00060 int r = cam->readJPEG(buf, sizeof(buf)); 00061 if (r) { 00062 FILE* fp = fopen("/local/photo.jpg", "wb"); 00063 if (fp) { 00064 fwrite(buf, r, 1, fp); 00065 fclose(fp); 00066 } 00067 printf("took a picture\r\n"); 00068 } 00069 t.reset(); 00070 led3 = 0; 00071 } 00072 } 00073 } 00074 }
Generated on Sat Jul 16 2022 21:04:03 by 1.7.2