test

Dependencies:   mbed Prelude_OV5642 Arducam_UTFT_SPI Arducam_OV5642 Arduino WIZnetInterface_Ricky

Revision:
2:3a12c5e8b030
Parent:
1:3a14a4c84db2
Child:
3:23d439c8526b
--- a/main.cpp	Thu Oct 29 06:58:08 2015 +0000
+++ b/main.cpp	Thu Oct 29 07:57:09 2015 +0000
@@ -1,52 +1,15 @@
 #include "mbed.h"
-
 #include "UTFT_SPI.h"
 #include "OV5642.h"
 #include "OV5642_regs.h"
-#include "SDFileSystem.h"
 #include "Arduino.h"
 
 void setup();
 void loop();
-void GrabImage(char* str);
-void dispBitmap();
-void Playback();
-void dispBitmap(FILE* fname);
-/* itoa:  convert n to characters in s */
-void itoa( unsigned long long int value, char *str)
-{   
-   int i,j;
-   char temp[30];
-   for(i=0; value > 0; i++){    
-       str[i] = value%10+'0';
-       value=value/10;
-    }
-    for(j=0;i>=0;j++,i--){
-        temp[j]=str[i-1];
-    }
-    for(i=0;i<j;i++){
-        str[i]=temp[i];
-    }   
-}
-
-#define BMPIMAGEOFFSET 66
-static FILE *outFile;
-static FILE *inFile;
-
-const char bmp_header[BMPIMAGEOFFSET] =
-{
-      0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00, 
-      0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00, 
-      0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00, 
-      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00,
-      0x00, 0x00
-};
 
 ArduCAM myCAM(D11, D12, D13, D10, D14, D15);
 ArduLCD myGLCD(D11, D12, D13, D10);
-SDFileSystem SD(PB_3, PB_2, PB_1, PB_0, "sd");
 Serial pc(USBTX, USBRX);
-bool isShowFlag = true;
 
 int main()
 {
@@ -101,15 +64,11 @@
   else
     pc.printf("OV5642 detected\r\n");
     
-  myCAM.set_format(BMP);
   myCAM.InitCAM();
 }
   
 void loop()
 {
-  char str[8];
-  unsigned long previous_time = 0;
-  static int k = 0;
   myCAM.set_mode(CAM2LCD_MODE);             //Switch to CAM
   
   while(1)
@@ -121,138 +80,6 @@
        myGLCD.resetXY();
        myCAM.set_mode(CAM2LCD_MODE);        //Switch to CAM
        while(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK));     //Wait for VSYNC is gone
-       pc.printf("VSYNC\r\n");
-    }
-    else if(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK))
-    {       
-       pc.printf("SHUTTER\r\n");
-       previous_time = millis();
-       while(myCAM.get_bit(ARDUCHIP_TRIG,SHUTTER_MASK))
-       {
-         if((millis() - previous_time) > 1500)
-         {
-           Playback();
-           pc.printf("playback\r\n");
-         }
-       }
-       if((millis() - previous_time) < 1500)
-       {
-         k = k + 1;
-         itoa(k, str);
-         strcat(str,".bmp");                //Generate file name
-         myCAM.set_mode(MCU2LCD_MODE);      //Switch to MCU, freeze the screen 
-         GrabImage(str);
-         pc.printf("GrabImage\r\n");
-       }
     }
   }
 }
-
-
-void GrabImage(char* str)
-{
-  char VH,VL;
-  uint8_t buf[256];
-  static int k = 0;  
-  int i,j = 0;
-  outFile = fopen("preview.jpg", "w");
-  if (!outFile) 
-  {
-    pc.printf("Open File Error\r\n");
-    return;
-  }
-    
-  //Switch to FIFO Mode
-  myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK);
-  //Flush the FIFO 
-  myCAM.flush_fifo();        
-  //Start capture
-  myCAM.start_capture();
-  pc.printf("Start Capture\r\n");   
-
-  //Polling the capture done flag
-  while(!myCAM.get_bit(ARDUCHIP_TRIG,CAP_DONE_MASK));
-  pc.printf("Capture Done!\r\n");  
-
-  k = 0;
-  //Write the BMP header
-  for( i = 0; i < BMPIMAGEOFFSET; i++)
-  {
-    char ch = pgm_read_byte(&bmp_header[i]);
-    buf[k++] = ch;
-  }
-  fwrite(buf,256,1,outFile);
-  //Read the first dummy byte
-  //myCAM.read_fifo();
-  
-  k = 0;
-  //Read 320x240x2 byte from FIFO
-  //Save as RGB565 bmp format
-  for(i = 0; i < 240; i++)
-    for(j = 0; j < 320; j++)
-  {
-      VH = myCAM.read_fifo();
-      VL = myCAM.read_fifo();
-      buf[k++] = VL;
-      buf[k++] = VH;
-      //Write image data to bufer if not full
-      if(k >= 256)
-      {
-        //Write 256 bytes image data to file from buffer
-        fwrite(buf,256,1,outFile);
-        k = 0;
-      }
-  }
-  //Close the file  
-  fclose(outFile); 
-
-  //Clear the capture done flag 
-  myCAM.clear_fifo_flag();
-  
-  //Switch to LCD Mode
-  myCAM.write_reg(ARDUCHIP_TIM, 0);
-  return;
-}
-
-void Playback()
-{  
-  char str[8];
-  int k = 0;
-  myCAM.set_mode(MCU2LCD_MODE);         //Switch to MCU
-  myGLCD.InitLCD(PORTRAIT);
-  
-  while(1)
-  {
-      k = k + 1;
-      itoa(k, str); 
-      strcat(str,".bmp");
-      inFile = fopen("preview","r");
-      if (! inFile) 
-        return;
-      myGLCD.clrScr();
-      myGLCD.resetXY();
-      dispBitmap(inFile);
-      fclose(inFile);
-      wait_ms(2000);
-  }
-}
-
-//Only support RGB565 bmp format
-void dispBitmap(FILE* fname)
-{
-    uint8_t buf[256];
-    char VH,VL;
-    int i,j = 0;
-    for(i = 0 ;i < BMPIMAGEOFFSET; i++)
-        fread(buf,256,1,fname);
-    for(i = 0; i < 320; i++)
-    for(j = 0; j < 240; j++)
-    {
-        VL = fread(buf,256,1,fname);
-        //Serial.write(VL);
-        VH = fread(buf,256,1,fname);
-        //Serial.write(VH);
-        myGLCD.LCD_Write_DATA(VH,VL);
-    }
-    myGLCD.clrXY();
-}