/**
  * @brief  Save the data to specified file.
  * @param  path: pointer to the saving path
  * @retval File saved
  */
uint8_t  CAMERA_SaveToFile(uint8_t *path)
{
  RTC_TimeTypeDef   Time;
  RTC_DateTypeDef   Date;
  FIL               file;
  uint32_t  NumWrittenData;
  uint8_t ret = 1;

  char filename[FILEMGR_FILE_NAME_SIZE];
  char fullpath[FILEMGR_FILE_NAME_SIZE];

    /* Create filename */
    k_GetTime(&Time);
    k_GetDate(&Date);
    sprintf((char *)filename, "/Camera_%02d%02d%04d_%02d%02d%02d.bmp",
            Date.Date,
            Date.Month,
            Date.Year + 2015,
            Time.Hours,
            Time.Minutes,
            Time.Seconds);
    strcpy((char *)fullpath, (char *)path);
    strcat ((char *)fullpath, (char *)filename);

    BSP_CAMERA_Suspend();

    BSP_SD_Init();


    /* Can not create file */
    if (f_open(&file, (char *)fullpath, FA_CREATE_NEW | FA_WRITE) == FR_OK)
    {
      /* Write the received data into the file */
      if (f_write(&file, (char *)BMPHeader_QQVGA24Bit, RGB_HEADER_SIZE, (UINT *)&NumWrittenData) == FR_OK)
      {
        f_sync(&file);
        /* Convert RGB16 image to RGB24 */
        RGB16toRGB24((uint8_t *)CAMERA_CVRT_BUFFER, (uint8_t *)&buffer_camera);

        if (f_write(&file, (char *)CAMERA_CVRT_BUFFER, MAX_IMAGE_SIZE, (UINT*)&NumWrittenData)== FR_OK)
        {
          /*File Written correctly */
          ret = 0;
        }

      }
      f_close(&file);
    }

    BSP_CAMERA_Init(RESOLUTION_R160x120);
    CAMERA_Configured = 1;
    BSP_CAMERA_Resume();
    return ret;
}
Exemplo n.º 2
0
/**
  * @brief  Save the image frame into a file
  * @param  Storage path
  * @param  file_name: Jpeg file name
  * @retval Status 
  */
static uint8_t Save_Jpg_To_File (uint8_t *path , uint8_t *file_name)
{
  RTC_TimeTypeDef   RTC_TimeStructure;
  RTC_DateTypeDef   RTC_DateStructure;
  FIL file;

  /* Update file name */
  strcpy((char *)ImageBuffer.ImageName , (char *)path),
  strcat ((char *)ImageBuffer.ImageName, "/");

  if ( RTC_Error == 0)
  {
    RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
    RTC_GetDate(RTC_Format_BIN, &RTC_DateStructure);

    sprintf((char *)file_name, "Camera_%02d%02d%d%02d%02d%02d.jpg", RTC_DateStructure.RTC_Date,
            RTC_DateStructure.RTC_Month,
            RTC_DateStructure.RTC_Year + 2000,
            RTC_TimeStructure.RTC_Hours,
            RTC_TimeStructure.RTC_Minutes,
            RTC_TimeStructure.RTC_Seconds);
  }
  else
  {
    sprintf((char *)file_name, "Camera_%08d.jpg", (int)(RecoveryImageCounter++));
  }

  strcat ((char *)ImageBuffer.ImageName, (char *)file_name);
  /* Can not create file */
  if (f_open(&file, (char *)ImageBuffer.ImageName, FA_CREATE_NEW | FA_WRITE) != FR_OK)
  {
    return 0;
  }

  /* Convert RGB16 image to RGB24 */
  RGB16toRGB24(ImageBuffer.DestData, ImageBuffer.RawData , 1);

  /* Set compression parameters */

  jpeg_params.in_buff = (uint8_t *)ImageBuffer.DestData;
  jpeg_params.in_length = IMAGE_COLUMN_SIZE * IMAGE_LINE_SIZE * 3;
  jpeg_params.in_width = IMAGE_LINE_SIZE;
  jpeg_params.in_height = IMAGE_COLUMN_SIZE;
  jpeg_params.in_bpp = 3;
  jpeg_params.in_colorspace = JCS_RGB;
  jpeg_params.in_imagequality = 100;

  jpeg_compress(&file, &jpeg_params);

  /* Close file */
  f_close(&file);
  return 1 ;
}
Exemplo n.º 3
0
/**
  * @brief  Save the image frame into a file
  * @param  Storage path
  * @param  file_name 
  * @retval Status 0 = Sucess, !0 :error
  */
static uint8_t Save_Bmp_To_File (uint8_t *path , uint8_t *file_name)
{
  RTC_TimeTypeDef   RTC_TimeStructure;
  RTC_DateTypeDef   RTC_DateStructure;
  uint32_t i = 0 ,j = 0 , Index;

  FIL file;

  for ( i = 0 ; i < IMAGE_COLUMN_SIZE; i++)
  {
    for ( j= 0 ; j < 2 * IMAGE_LINE_SIZE; j++)
    {
      ImageBuffer.SrcData[j + (2 * IMAGE_LINE_SIZE * i)] = ImageBuffer.RawData[j + (2 * IMAGE_LINE_SIZE * ( IMAGE_COLUMN_SIZE- 1 - i))];
    }
  }


  /* Convert RGB16 image to RGB24 */
  RGB16toRGB24(ImageBuffer.DestData, ImageBuffer.SrcData, 1);

  /* Update file name */
  strcpy((char *)ImageBuffer.ImageName , (char *)path),
  strcat ((char *)ImageBuffer.ImageName, "/");

  if ( RTC_Error == 0)
  {
    RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
    RTC_GetDate(RTC_Format_BIN, &RTC_DateStructure);

    sprintf((char *)file_name, "Camera_%02d%02d%d%02d%02d%02d.bmp", RTC_DateStructure.RTC_Date,
            RTC_DateStructure.RTC_Month,
            RTC_DateStructure.RTC_Year + 2000,
            RTC_TimeStructure.RTC_Hours,
            RTC_TimeStructure.RTC_Minutes,
            RTC_TimeStructure.RTC_Seconds);
  }
  else
  {
    /* Wait until one RNG number is ready */
    while(RNG_GetFlagStatus(RNG_FLAG_DRDY)== RESET)
    {
    }
    RecoveryImageCounter = (uint32_t )(RNG_GetRandomNumber() & 0x7FFFFFFF) ;
    sprintf((char *)file_name, "Camera_%014d.bmp", (int)RecoveryImageCounter);
  }

  strcat ((char *)ImageBuffer.ImageName, (char *)file_name);


  /* Can not create file */
  if (f_open(&file, (char *)ImageBuffer.ImageName, FA_CREATE_NEW | FA_WRITE) != FR_OK)
  {
    return 0;
  }

  /* Write the received data into the file */
  if (f_write(&file, (char*)ImageBuffer.ImageHeader, RGB_HEADER_SIZE, (UINT*)&Index))
  {
    f_close(&file);
    return 0;
  }

  if (f_write(&file, (char*)ImageBuffer.DestData, MAX_IMAGE_SIZE, (UINT*)&Index))
  {
    f_close(&file);
    return 0;
  }
  /* Close file */
  f_close(&file);
  return 1 ;
}