/** * @brief Main routine for Mass Storage Class * @param None * @retval None */ static void SavePicture(void) { FRESULT res1, res2; /* FatFs function common result code */ uint32_t byteswritten; /* File write count */ static uint32_t counter = 0; uint8_t str[30]; /* Suspend the camera capture */ BSP_CAMERA_Suspend(); /* Prepare the image to be saved */ PicturePrepare(); /* Format the string */ sprintf((char *)str, "image_%lu.bmp", counter); /* Create and Open a new file object with write access */ if(f_open(&MyFile, (const char*)str, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { Error_Handler(); } else { /* Write data to the BMP file */ res1 = f_write(&MyFile, (uint32_t *)aBMPHeader, 54, (void *)&byteswritten); res2 = f_write(&MyFile, (uint16_t *)SRAM_DEVICE_ADDR, (BSP_LCD_GetYSize()*BSP_LCD_GetXSize()*sizeof(uint32_t)), (void *)&byteswritten); if((res1 != FR_OK) || (res2 != FR_OK) || (byteswritten == 0)) { Error_Handler(); } else { /* Close the open BMP file */ f_close(&MyFile); /* Success of the demo: no error occurrence */ BSP_LED_On(LED1); /* Wait for 2s */ HAL_Delay(2000); counter++; BSP_LED_Off(LED1); } } }
/** * @brief Saves Picture into USB disk. * @param None * @retval None */ static void SavePicture(void) { FRESULT res1, res2; /* FatFs function common result code */ uint32_t byteswritten; /* File write count */ static uint32_t counter = 0; uint8_t str[30]; /* Suspend the camera capture */ BSP_CAMERA_Suspend(); /* Prepare the image to be saved */ PicturePrepare(); /* Set foreground Layer */ BSP_LCD_SetLayerVisible(1, ENABLE); BSP_LCD_SetColorKeying(1, LCD_COLOR_WHITE); BSP_LCD_SelectLayer(1); BSP_LCD_SetTextColor(LCD_COLOR_DARKRED); BSP_LCD_SetFont(&Font24); /* Format the string */ sprintf((char *)str,"image_%d.bmp", (int)counter); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)"Saving ..", RIGHT_MODE); /* Create and Open a new text file object with write access */ if(f_open(&MyFile, (const char*)str, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { Error_Handler(); } else { /* Write data to the BMP file */ res1 = f_write(&MyFile, (uint32_t *)aBMPHeader, 54, (void *)&byteswritten); res2 = f_write(&MyFile, (uint32_t *)CONVERTED_FRAME_BUFFER, (BSP_LCD_GetXSize()*BSP_LCD_GetYSize()*3), (void *)&byteswritten); if((res1 != FR_OK) || (res2 != FR_OK) || (byteswritten == 0)) { Error_Handler(); } else { /* Close the open BMP file */ f_close(&MyFile); /* Success of the demo: no error occurrence */ BSP_LED_On(LED1); BSP_LCD_SetTextColor(LCD_COLOR_DARKGREEN); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize()-24), (uint8_t *)" Saved ", RIGHT_MODE); /* Wait for 2s */ HAL_Delay(2000); /* Disable the Layer 2 */ BSP_LCD_SetLayerVisible(1, DISABLE); /* Select Layer 1 */ BSP_LCD_SelectLayer(0); counter++; BSP_LED_Off(LED1); /* Resume the camera capture */ BSP_CAMERA_Resume(); } } }
/** * @brief Saves Picture into USB disk. * @param None * @retval None */ static void SavePicture(void) { FRESULT res1, res2; /* FatFs function common result code */ uint32_t byteswritten; /* File write count */ static uint32_t counter = 0; uint8_t str[30]; uint8_t str_display[50]; /* Suspend the camera capture */ BSP_CAMERA_Suspend(); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" ", RIGHT_MODE); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)"Camera stopped...", RIGHT_MODE); /* Prepare the image to be saved */ PicturePrepare(); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" ", RIGHT_MODE); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" Picture Prepared...", RIGHT_MODE); HAL_Delay(1000); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" ", RIGHT_MODE); /* Set foreground Layer as visible */ BSP_LCD_SetLayerVisible(LTDC_ACTIVE_LAYER_FOREGROUND, ENABLE); BSP_LCD_SetColorKeying(LTDC_ACTIVE_LAYER_FOREGROUND, LCD_COLOR_WHITE); BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER_FOREGROUND); BSP_LCD_SetTextColor(LCD_COLOR_DARKRED); BSP_LCD_SetFont(&Font24); /* Format the string */ sprintf((char *)str,"image_%d.bmp", (int)counter); sprintf((char *)str_display," Saving picture in file %s ..", str); /* Display text on LTDC layer foreground */ BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), str_display, RIGHT_MODE); /* Create and Open a new text file object with write access */ if(f_open(&MyFile, (const char*)str, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { Error_Handler(); } else { /* Write data to the BMP file */ res1 = f_write(&MyFile, (uint32_t *)aBMPHeader, 54, (void *)&byteswritten); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" ", RIGHT_MODE); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" Header BMP written...", RIGHT_MODE); HAL_Delay(1000); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" ", RIGHT_MODE); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" BMP pixel data save ongoing...", RIGHT_MODE); res2 = f_write(&MyFile, (uint8_t *)p_bmp_converted_pixel_data, (CameraResX * CameraResY * RGB888_BYTE_PER_PIXEL), (void *)&byteswritten); if((res1 != FR_OK) || (res2 != FR_OK) || (byteswritten == 0)) { Error_Handler(); } else { /* Close the open BMP file */ f_close(&MyFile); /* Success of the demo: no error occurrence */ BSP_LED_On(LED1); BSP_LCD_SetTextColor(LCD_COLOR_DARKGREEN); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" ", RIGHT_MODE); sprintf((char *)str_display,"File %s saved on USB disk ..", str); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize()-24), str_display, RIGHT_MODE); /* Wait for 2s */ HAL_Delay(2000); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" ", RIGHT_MODE); /* Disable the Layer Foreground */ BSP_LCD_SetLayerVisible(LTDC_ACTIVE_LAYER_FOREGROUND, DISABLE); /* Select Layer Background */ BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER_BACKGROUND); counter++; BSP_LED_Off(LED1); /* Resume the camera capture */ BSP_CAMERA_Resume(); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize()-24), (uint8_t *)"Camera Play ", RIGHT_MODE); } } }