MY TRAIAL (1)

Dependencies:   FATFileSystem GR-PEACH_video GraphicsFramework LCD_shield_config R_BSP mbed-rtos mbed

Fork of GR-PEACH_NTSC_in_2ch_MOD_try by Hirofumi Inomata

I put an OVERVIEW in the blow URL. https://developer.mbed.org/users/digiponta/notebook/my-trial-ar--vr-2-eyes-display-goes-by-a-gr-peach/

Revision:
5:f6df6a4c32a7
Parent:
4:2bea25cf1883
Child:
6:3cb7758c3f17
--- a/main.cpp	Sun Sep 11 06:58:40 2016 +0000
+++ b/main.cpp	Sun Sep 11 13:38:32 2016 +0000
@@ -1,5 +1,6 @@
 #include "mbed.h"
 #include "SDFileSystem.h"
+#include "FATFileSystem.h"
 #include "JPEG_Converter.h"
 #include "DisplayBace.h"
 #include "rtos.h"
@@ -7,6 +8,11 @@
 DigitalOut led1(LED1);
 Serial pc(USBTX, USBRX);
 SDFileSystem sd(P8_5, P8_6, P8_3, P8_4, "sd");
+FILE *rd_fp = NULL;
+FILE *wr_fp = NULL;
+long fsize = 0;
+DIR *dir;
+struct dirent *dp;
 
 DigitalIn   sw0(USER_BUTTON0);
 // DigitalIn   sw1(P6_1);
@@ -329,9 +335,8 @@
     Thread::wait(200);
     lcd_cntrst.write(1.0);
 
-    DIR *dir = opendir( "/sd/" );
+    dir = opendir( "/sd" );
     for ( imgCnt=0; ; imgCnt++) {
-        struct dirent *dp;
         dp = readdir( dir );
         if ( dp == NULL) break;
     }
@@ -370,7 +375,7 @@
                                 
                 pc.printf("File write start\n");
                 sprintf( fname, "/sd/img_%04d.jpg", imgCnt++ );
-                FILE *wr_fp = fopen( fname, "w");
+                wr_fp = fopen( fname, "w");
                 for( long i=0; i < EncodeSize;i++) {
                     putc( user_frame_buffer1[i], wr_fp );
                 }
@@ -421,27 +426,31 @@
             sprintf( fname, "/sd/img_%04d.jpg", viewCnt++ );
             if ( viewCnt >= imgCnt ) viewCnt = 0;
             pc.printf("File read start %s v=%d, i=%d\n", fname, viewCnt, imgCnt );
-            FILE *rd_fp = fopen( fname, "r" );
-            if (rd_fp == NULL) {
+            rd_fp = fopen( fname, "r" );
+            if (rd_fp == NULL ) {
                 pc.printf("can't open the file\n" ); 
                 mode = 1;
                 continue;
             }
-            size_t fsize = ftell( rd_fp );
+            fseek( rd_fp, 0, SEEK_SET );
+#if 0
+            fsize = ftell( rd_fp );
              if (fsize == 0) {
-                pc.printf("fsize = 0\n" ); 
+                pc.printf("fsize = 0 error\n" ); 
                 mode = 1;
                 continue;                
-            }           
-            pc.printf("fsize=%d\n", fsize );
+            }
+            pc.printf("fsize = %d\n", fsize );
             fseek( rd_fp, 0, SEEK_SET );
             for( long i=0; i < fsize ;i++) {
                 char cc = getc( rd_fp );
                 // if ( cc == EOF ) break;
                 user_frame_buffer1[i] = (unsigned char)cc;
-                
-            //  size_t len = fread(user_frame_buffer1, sizeof(char), (LCD_PIXEL_WIDTH * LCD_PIXEL_HEIGHT * 4), rd_fp);
             }
+#else
+            size_t len = fread(user_frame_buffer1, sizeof(char), (LCD_PIXEL_WIDTH * LCD_PIXEL_HEIGHT * 4), rd_fp);  
+            pc.printf( "len = %d\n", len );
+#endif 
             fclose(rd_fp);
             pc.printf("File read done\n");