This program show jpeg file in microSD card, run on Nucleo and Aitendo 2.4 inch TFT shield.
Dependencies: AitendoTFT SDFileSystem TinyJpgDec mbed
Fork of SDFileSystem_HelloWorld by
Revision 1:28ab8d9ab8e4, committed 2014-04-30
- Comitter:
- h_nari
- Date:
- Wed Apr 30 08:07:51 2014 +0000
- Parent:
- 0:bdbd3d6fc5d5
- Commit message:
- First Version
Changed in this revision
diff -r bdbd3d6fc5d5 -r 28ab8d9ab8e4 AitendoTFT.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AitendoTFT.lib Wed Apr 30 08:07:51 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/h_nari/code/AitendoTFT/#f53f19ac1457
diff -r bdbd3d6fc5d5 -r 28ab8d9ab8e4 SDFileSystem.lib --- a/SDFileSystem.lib Fri Dec 07 11:25:01 2012 +0000 +++ b/SDFileSystem.lib Wed Apr 30 08:07:51 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4 +http://mbed.org/users/mbed_official/code/SDFileSystem/#7b35d1709458
diff -r bdbd3d6fc5d5 -r 28ab8d9ab8e4 TinyJpgDec.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TinyJpgDec.lib Wed Apr 30 08:07:51 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/humlet/code/TinyJpgDec/#b6f284347a66
diff -r bdbd3d6fc5d5 -r 28ab8d9ab8e4 main.cpp --- a/main.cpp Fri Dec 07 11:25:01 2012 +0000 +++ b/main.cpp Wed Apr 30 08:07:51 2014 +0000 @@ -1,19 +1,88 @@ #include "mbed.h" #include "SDFileSystem.h" - -SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board - -int main() { - printf("Hello World!\n"); - - mkdir("/sd/mydir", 0777); - - FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); - if(fp == NULL) { - error("Could not open file for write\n"); +#include "AitendoTFT.h" +#include "TinyJpgDec.h" + +AitendoTFT tft; +SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd"); // the pinout on the mbed Cool Components workshop board + +JDEC jdec; +WORD work[3100/sizeof(WORD)]; +FileHandle *fh; + +UINT jpeg_input_func(JDEC *jd, BYTE *buff, UINT ndata) +{ + if(buff) { + size_t n = fh->read(buff, ndata); + return n == (size_t)-1 ? 0 : n; + } else { + off_t t = fh->lseek( ndata, SEEK_CUR); + return t == (off_t)-1 ? 0 : ndata; } - fprintf(fp, "Hello fun SD Card World!"); - fclose(fp); - - printf("Goodbye World!\n"); +} + +UINT jpeg_output_func(JDEC *jd, void *bitmap, JRECT *rect) +{ + WORD *src = (WORD *)bitmap; + int x0 = rect->left; + int x1 = rect->right; + int y0 = rect->top; + int y1 = rect->bottom; + int w = x1 - x0 + 1; + + if(y0 >= AitendoTFT::TFT_HEIGHT ||x0 >= AitendoTFT::TFT_WIDTH) + return 1; + + if(x1 > AitendoTFT::TFT_WIDTH-1) x1 = AitendoTFT::TFT_WIDTH - 1; + if(y1 > AitendoTFT::TFT_HEIGHT-1) y1 = AitendoTFT::TFT_HEIGHT - 1; + + if(x0 == 0) + printf("\r %d", y0); + + for(int y= y0; y <= y1; y++) { + tft.setPos(x0, y); + WORD *p = src + w * (y - y0); + for(int x=x0; x <= x1; x++) + tft.put(*p++); + } + return 1; } + +int main() +{ + JRESULT r; + int cFile; + char path[80]; + + + printf("Nucleo Picture Viewer\n"); + + while(1) { + cFile = 0; + DirHandle *dh = sd.opendir("/images"); + if(dh == NULL) + error("/images not found.\n"); + else { + while(1) { + struct dirent *de = dh->readdir(); + if(de == NULL) break; + char *ext = strrchr(de->d_name,'.'); + if(ext == NULL || strcmp(ext,".jpg")!=0) continue; + cFile++; + snprintf(path, sizeof path, "images/%s", de->d_name); + printf("\nshow %s\n", path); + fh = sd.open(path, 0); + if(fh == NULL) error("%s not found.",path); + + r = jd_prepare(&jdec, jpeg_input_func, work, sizeof work, fh); + if(r != JDR_OK) error("jd_prepare error:%d", r); + r = jd_decomp(&jdec, jpeg_output_func, 0); + fh->close(); + if( r != JDR_OK) error("jd_decomp error:%d", r); + wait(10); + } + dh->closedir(); + } + if(cFile == 0) error("no .jpg file found in /images"); + } +}
diff -r bdbd3d6fc5d5 -r 28ab8d9ab8e4 mbed.bld --- a/mbed.bld Fri Dec 07 11:25:01 2012 +0000 +++ b/mbed.bld Wed Apr 30 08:07:51 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/63cdd78b2dc1 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e \ No newline at end of file