Wakeup Light with touch user interface, anti-aliased Font, SD card access and RTC usage on STM32F746NG-DISCO board
Dependencies: BSP_DISCO_F746NG_patch_fixed LCD_DISCO_F746NG TS_DISCO_F746NG FATFileSystem TinyJpgDec_interwork mbed-src
Diff: SD.cpp
- Revision:
- 12:a89096944f20
- Parent:
- 9:fe2c9b3a312b
--- a/SD.cpp Mon Nov 16 23:29:15 2015 +0000 +++ b/SD.cpp Sun Jan 31 01:02:36 2016 +0000 @@ -9,7 +9,7 @@ mySD(const char* name):FATFileSystem(name) { uint8_t result=BSP_SD_Init(); - DPrintf("BSP_SD_Init: %u.\r\n",result); + DPrintf_("BSP_SD_Init: %u.\r\n",result); BSP_SD_GetCardInfo(&CardInfo); DPrintf("BSP_SD_GetCardInfo: 0x%llX bytes / %u sector size.\r\n",CardInfo.CardCapacity,CardInfo.CardBlockSize); }; @@ -33,7 +33,6 @@ }; mySD sd("sd"); -bool mustSrand=true; FileHandle *fileHandle; uint8_t buffer[6000]; int16_t offsetX; @@ -104,13 +103,6 @@ BYTE scale; JPG_UINT pictureWidth; JPG_UINT pictureHeight; - AnalogIn analogIn(PA_0); - - if (mustSrand==true) - { - srand(time(NULL)+analogIn.read_u16()); - mustSrand=false; - } // // count all jpegs @@ -134,8 +126,8 @@ // // get random number // - count=(uint32_t)((uint64_t)rand()*(uint64_t)count/RAND_MAX); - DPrintf("SD_ShowRandomPicture: Take %u.\r\n",count); + count=(uint32_t)((uint64_t)TM_RNG_Get()*(uint64_t)count/0xFFFFFFFF); + DPrintf_("SD_ShowRandomPicture: Take %u.\r\n",count); // // find random jpeg @@ -144,7 +136,6 @@ dir=opendir("/sd/"); while ((dirEnt=readdir(dir))!=NULL) { -DPrintf("check %s.\r\n",dirEnt->d_name); extension=strrchr(dirEnt->d_name,'.'); if ((extension==NULL) || (strcmp(extension,".jpg"))!=0) continue; @@ -158,7 +149,6 @@ count--; } closedir(dir); -DPrintf("got %s.\r\n",file); if (file[0]=='\0') return false; @@ -166,7 +156,7 @@ // // load random jpeg // - DPrintf("SD_ShowRandomPicture: Open %s.\r\n",file); + DPrintf_("SD_ShowRandomPicture: Open %s.\r\n",file); if ((fileHandle=sd.open(file,O_RDONLY))==NULL) return false; @@ -178,6 +168,9 @@ pictureWidth=jdec.width; pictureHeight=jdec.height; scale=0; + + DPrintf("SD_ShowRandomPicture: Picture %ux%u, LCD: %ux%u.\r\n",pictureWidth,pictureHeight,uiLcd.GetXSize(),uiLcd.GetYSize()); + while ((pictureWidth>uiLcd.GetXSize()) || (pictureHeight>uiLcd.GetYSize())) { pictureWidth/=2; @@ -190,17 +183,18 @@ offsetX=(uiLcd.GetXSize()-pictureWidth)/2; offsetY=(uiLcd.GetYSize()-pictureHeight)/2; + DPrintf("SD_ShowRandomPicture: Scale %u.\r\n",scale); + jResult=jd_decomp(&jdec,jpeg_output_func,scale); if (jResult==JDR_OK) result=true; else - DPrintf("SD_ShowRandomPicture: jd_decomp: %u\r\n",jResult); + DPrintf("SD_ShowRandomPicture: jd_decomp: %u on %s\r\n",jResult,file); } else - DPrintf("SD_ShowRandomPicture: jd_prepare %u\r\n",jResult); + DPrintf("SD_ShowRandomPicture: jd_prepare %u on %s\r\n",jResult,file); fileHandle->close(); return result; } - \ No newline at end of file