/** * @brief Camera error callback. * @param None * @retval None */ void BSP_CAMERA_ErrorCallback(void) { if( CameraError != CAMERA_ERROR) { BSP_CAMERA_Resume(); } }
/** * @brief Resume the camera capture. * @param None * @retval None */ void CAMERA_Resume(void) { if( CameraError != CAMERA_ERROR) { /* Resume the CAMERA capture */ BSP_CAMERA_Resume(); } }
/** * @brief Frame Event callback. * @param None * @retval None */ void BSP_CAMERA_FrameEventCallback(void) { uint32_t xsizeLCD, ysizeLCD; uint32_t xsizeCamera, ysizeCamera; uint32_t xoffset, yoffset; uint32_t line, column, i, j; uint16_t *ptrCamera, *ptrCameraCrop; xsizeLCD = BSP_LCD_GetXSize(); ysizeLCD = BSP_LCD_GetYSize(); BSP_CAMERA_Suspend(); /* Display on LCD */ switch (CameraResIndex) { case CAMERA_R160x120: xsizeCamera = CAMERA_QQVGA_RES_X; ysizeCamera = CAMERA_QQVGA_RES_Y; xoffset = 80; yoffset = 105; break; case CAMERA_R320x240: default: xsizeCamera = CAMERA_QVGA_RES_X; ysizeCamera = CAMERA_QVGA_RES_Y; xoffset = 0; yoffset = 0; break; } if ((xsizeCamera > xsizeLCD) || (ysizeCamera > ysizeLCD)) { /* As the camera output resolution is greater than display resolution, a cropped image has to be generated */ ptrCamera = (uint16_t *)(CAMERA_FRAME_BUFFER); ptrCameraCrop = (uint16_t *)(CAMERA_FRAME_BUFFER_CROP); xoffset = (xsizeCamera - xsizeLCD) / 2; yoffset = (ysizeCamera - ysizeLCD) / 2; i=0; j=xoffset; for (line = 0; line < ysizeLCD; line ++) { for (column = 0; column < xsizeLCD; column ++) { ptrCameraCrop[i++] = ptrCamera[j++]; } j += xsizeCamera - xsizeLCD; } BSP_LCD_DrawRGBImage(0, 0, xsizeLCD , ysizeLCD, (uint8_t *)ptrCameraCrop); } else { BSP_LCD_DrawRGBImage(xoffset, yoffset, xsizeCamera , ysizeCamera, (uint8_t *)CAMERA_FRAME_BUFFER); } BSP_CAMERA_Resume(); }
/** * @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; }
/** * @brief Main routine for Camera capture * @param None * @retval None */ static void CAMERA_Capture(void) { while(1) { if(BSP_PB_GetState(BUTTON_TAMPER) != GPIO_PIN_RESET) { if(BSP_PB_GetState(BUTTON_TAMPER) != GPIO_PIN_SET) { SavePicture(); 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]; /* 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); } } }