Change to wifi AP mode. SSID "GR-PEACH_1", PSK "12345"

Dependencies:   DhcpServer EthernetInterface FATFileSystem GR-PEACH_WlanBP3595AP GR-PEACH_video GraphicsFramework HttpServer_snapshot R_BSP mbed-rpc mbed-rtos mbed

Fork of GR-Boards_WebCamera by Renesas

Revision:
1:ebff3aeb40a0
Parent:
0:c5448e500c90
Child:
2:82a6d79d05f0
--- a/main.cpp	Fri Aug 21 02:15:59 2015 +0000
+++ b/main.cpp	Fri Oct 09 08:26:51 2015 +0000
@@ -51,8 +51,20 @@
 static uint8_t FrameBuffer_Video[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(16)));  //16 bytes aligned!;
 static volatile int32_t vsync_count = 0;
 static volatile int32_t vfield_count = 1;
-static uint8_t JpegBuffer[1024 * 20]__attribute((section("NC_BSS"),aligned(8)));  //8 bytes aligned!;
+static uint8_t JpegBuffer[2][1024 * 50]__attribute((section("NC_BSS"),aligned(8)));  //8 bytes aligned!;
+static size_t jcu_encode_size[2];
 static int image_change = 0;
+JPEG_Converter Jcu;
+static int jcu_buf_index_write = 0;
+static int jcu_buf_index_write_done = 0;
+static int jcu_buf_index_read = 0;
+static int jcu_encoding = 0;
+
+static void JcuEncodeCallBackFunc(JPEG_Converter::jpeg_conv_error_t err_code) {
+    jcu_buf_index_write_done = jcu_buf_index_write;
+    image_change = 1;
+    jcu_encoding = 0;
+}
 
 static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type) {
     //Interrupt callback function
@@ -60,7 +72,31 @@
         vfield_count = 0;
     } else {
         vfield_count = 1;
-        image_change = 1;
+
+        JPEG_Converter::bitmap_buff_info_t bitmap_buff_info;
+        JPEG_Converter::encode_options_t   encode_options;
+
+        bitmap_buff_info.width          = PIXEL_HW;
+        bitmap_buff_info.height         = PIXEL_VW;
+        bitmap_buff_info.format         = JPEG_Converter::WR_RD_YCbCr422;
+        bitmap_buff_info.buffer_address = (void *)FrameBuffer_Video;
+
+        encode_options.encode_buff_size = sizeof(JpegBuffer[0]);
+        encode_options.p_EncodeCallBackFunc = &JcuEncodeCallBackFunc;
+
+        jcu_encoding = 1;
+        if (jcu_buf_index_read == jcu_buf_index_write) {
+            if (jcu_buf_index_write != 0) {
+                jcu_buf_index_write = 0;
+            } else {
+                jcu_buf_index_write = 1;
+            }
+        }
+        jcu_encode_size[jcu_buf_index_write] = 0;
+        if (Jcu.encode(&bitmap_buff_info, JpegBuffer[jcu_buf_index_write], &jcu_encode_size[jcu_buf_index_write], &encode_options) != JPEG_Converter::JPEG_CONV_OK) {
+            jcu_encode_size[jcu_buf_index_write] = 0;
+            jcu_encoding = 0;
+        }
     }
 }
 
@@ -209,31 +245,18 @@
 }
 
 static int snapshot_req(const char ** pp_data) {
-    JPEG_Converter                     Jcu;
-    size_t                             encode_size;
-    JPEG_Converter::bitmap_buff_info_t bitmap_buff_info;
-    JPEG_Converter::encode_options_t   encode_options;
+    int encode_size;
 
-    while ((vfield_count == 0) || (image_change == 0)) {
+    while ((jcu_encoding == 1) || (image_change == 0)) {
         Thread::wait(1);
     }
+    jcu_buf_index_read = jcu_buf_index_write_done;
     image_change = 0;
 
-    bitmap_buff_info.width          = PIXEL_HW;
-    bitmap_buff_info.height         = PIXEL_VW;
-    bitmap_buff_info.format         = JPEG_Converter::WR_RD_YCbCr422;
-    bitmap_buff_info.buffer_address = (void *)FrameBuffer_Video;
-
-    encode_options.encode_buff_size = sizeof(JpegBuffer);
+    *pp_data = (const char *)JpegBuffer[jcu_buf_index_read];
+    encode_size = (int)jcu_encode_size[jcu_buf_index_read];
 
-    if (Jcu.encode(&bitmap_buff_info, JpegBuffer, &encode_size, &encode_options) == JPEG_Converter::JPEG_CONV_OK) {
-        *pp_data = (const char *)JpegBuffer;
-    } else {
-        *pp_data = NULL;
-        encode_size = 0;
-    }
-
-    return (int)encode_size;
+    return encode_size;
 }
 
 static void TerminalWrite(Arguments* arg, Reply* r) {
@@ -279,8 +302,8 @@
     RPCFunction rpcFunc(TerminalWrite, "TerminalWrite");
 
     printf("EthernetInterface Setting up...\r\n");
-    if (eth.init() != 0) {                             //for DHCP Server
-//    if (eth.init("192.168.0.2","255.255.255.0","192.168.0.3") != 0) { //for Static IP Address (IPAddress, NetMasks, Gateway)
+//    if (eth.init() != 0) {                             //for DHCP Server
+    if (eth.init("192.168.0.2","255.255.255.0","192.168.0.3") != 0) { //for Static IP Address (IPAddress, NetMasks, Gateway)
         printf("EthernetInterface Initialize Error \r\n");
         return -1;
     }