Digital Photo Frame using FTP Client
Dependencies: FTPClient SDFileSystem SeeedStudioTFTv2 TFT_fonts WIZnetInterface mbed
Overview
This program is smart Digital Photo Frame remotely controlled by FTP protocol.
Demo
<iframe src="https://player.vimeo.com/video/137345478" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <p><a href="https://vimeo.com/137345478">Digital Photo Frame controlled remotely by using FTP protocol.</a> from <a href="https://vimeo.com/midnightcow">MidnightCow</a> on <a href="https://vimeo.com">Vimeo</a>.</p>
For more detail
http://midnightcow.tistory.com/entry/Digital-Photo-Frame-controlled-remotely-by-using-FTP-protocol
MySeeedStudioTFTv2.cpp@2:c069ab35d315, 2015-08-26 (annotated)
- Committer:
- MidnightCow
- Date:
- Wed Aug 26 13:55:29 2015 +0000
- Revision:
- 2:c069ab35d315
- Parent:
- 0:583a42b8d940
Replace FTPClient
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MidnightCow | 0:583a42b8d940 | 1 | /* mbed library for resistive touch pads |
MidnightCow | 0:583a42b8d940 | 2 | * uses 4 pins - 2 IO and 2 Analog |
MidnightCow | 0:583a42b8d940 | 3 | |
MidnightCow | 0:583a42b8d940 | 4 | * c 2011 Peter Drescher - DC2PD |
MidnightCow | 0:583a42b8d940 | 5 | * |
MidnightCow | 0:583a42b8d940 | 6 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
MidnightCow | 0:583a42b8d940 | 7 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
MidnightCow | 0:583a42b8d940 | 8 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
MidnightCow | 0:583a42b8d940 | 9 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
MidnightCow | 0:583a42b8d940 | 10 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
MidnightCow | 0:583a42b8d940 | 11 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
MidnightCow | 0:583a42b8d940 | 12 | * THE SOFTWARE. |
MidnightCow | 0:583a42b8d940 | 13 | */ |
MidnightCow | 0:583a42b8d940 | 14 | |
MidnightCow | 0:583a42b8d940 | 15 | |
MidnightCow | 0:583a42b8d940 | 16 | #include "mbed.h" |
MidnightCow | 0:583a42b8d940 | 17 | #include "MySeeedStudioTFTv2.h" |
MidnightCow | 0:583a42b8d940 | 18 | |
MidnightCow | 0:583a42b8d940 | 19 | #define TFT_DEBUG |
MidnightCow | 0:583a42b8d940 | 20 | |
MidnightCow | 0:583a42b8d940 | 21 | #ifdef TFT_DEBUG |
MidnightCow | 0:583a42b8d940 | 22 | extern Serial uart; |
MidnightCow | 0:583a42b8d940 | 23 | #endif |
MidnightCow | 0:583a42b8d940 | 24 | |
MidnightCow | 0:583a42b8d940 | 25 | |
MidnightCow | 0:583a42b8d940 | 26 | MySeeedStudioTFTv2::MySeeedStudioTFTv2(PinName xp, PinName xm, PinName yp, PinName ym, |
MidnightCow | 0:583a42b8d940 | 27 | PinName mosi, PinName miso, PinName sclk, |
MidnightCow | 0:583a42b8d940 | 28 | PinName csTft, PinName dcTft, PinName blTft, |
MidnightCow | 0:583a42b8d940 | 29 | PinName csSd) : SeeedStudioTFTv2(xp,xm,yp,ym,mosi,miso,sclk,csTft,dcTft,blTft,csSd) |
MidnightCow | 0:583a42b8d940 | 30 | { |
MidnightCow | 0:583a42b8d940 | 31 | SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.frequency(18000000); |
MidnightCow | 0:583a42b8d940 | 32 | SeeedStudioTFTv2::SDFileSystem::_spi.frequency(24000000); |
MidnightCow | 0:583a42b8d940 | 33 | } |
MidnightCow | 0:583a42b8d940 | 34 | |
MidnightCow | 0:583a42b8d940 | 35 | int MySeeedStudioTFTv2::DrawBitmapFile(FILE * fp) |
MidnightCow | 0:583a42b8d940 | 36 | { |
MidnightCow | 0:583a42b8d940 | 37 | |
MidnightCow | 0:583a42b8d940 | 38 | char img[3*240]; |
MidnightCow | 0:583a42b8d940 | 39 | uint32_t imgsize = 0; |
MidnightCow | 0:583a42b8d940 | 40 | uint32_t offset = 0; |
MidnightCow | 0:583a42b8d940 | 41 | uint32_t imgw = 0; |
MidnightCow | 0:583a42b8d940 | 42 | uint32_t imgh = 0; |
MidnightCow | 0:583a42b8d940 | 43 | char colbits = 0; |
MidnightCow | 0:583a42b8d940 | 44 | char compress = 0; |
MidnightCow | 0:583a42b8d940 | 45 | uint16_t col; |
MidnightCow | 0:583a42b8d940 | 46 | |
MidnightCow | 0:583a42b8d940 | 47 | int i, j; |
MidnightCow | 0:583a42b8d940 | 48 | |
MidnightCow | 0:583a42b8d940 | 49 | if(fp == NULL) return -1; |
MidnightCow | 0:583a42b8d940 | 50 | if(fgetc(fp) != 0x42) return -2; |
MidnightCow | 0:583a42b8d940 | 51 | if(fgetc(fp) != 0x4D) return -2; |
MidnightCow | 0:583a42b8d940 | 52 | |
MidnightCow | 0:583a42b8d940 | 53 | for(i = 0; i < 4; i++) |
MidnightCow | 0:583a42b8d940 | 54 | { |
MidnightCow | 0:583a42b8d940 | 55 | imgsize += (((uint32_t)fgetc(fp)) << i*8); |
MidnightCow | 0:583a42b8d940 | 56 | } |
MidnightCow | 0:583a42b8d940 | 57 | #ifdef TFT_DEBUG |
MidnightCow | 0:583a42b8d940 | 58 | uart.printf("BMP SIZE:%d\r\n",imgsize); |
MidnightCow | 0:583a42b8d940 | 59 | #endif |
MidnightCow | 0:583a42b8d940 | 60 | fseek(fp,4,SEEK_CUR); |
MidnightCow | 0:583a42b8d940 | 61 | for(i = 0; i < 4; i++) |
MidnightCow | 0:583a42b8d940 | 62 | { |
MidnightCow | 0:583a42b8d940 | 63 | offset += (((uint32_t)fgetc(fp)) << i*8); |
MidnightCow | 0:583a42b8d940 | 64 | } |
MidnightCow | 0:583a42b8d940 | 65 | #ifdef TFT_DEBUG |
MidnightCow | 0:583a42b8d940 | 66 | uart.printf("BMP OFFSET:%d\r\n",offset); |
MidnightCow | 0:583a42b8d940 | 67 | #endif |
MidnightCow | 0:583a42b8d940 | 68 | fseek(fp,4,SEEK_CUR); |
MidnightCow | 0:583a42b8d940 | 69 | for(i = 0; i < 4; i++) |
MidnightCow | 0:583a42b8d940 | 70 | { |
MidnightCow | 0:583a42b8d940 | 71 | imgw += (((uint32_t)fgetc(fp)) << i*8); |
MidnightCow | 0:583a42b8d940 | 72 | } |
MidnightCow | 0:583a42b8d940 | 73 | if(imgw > 240) return -3; |
MidnightCow | 0:583a42b8d940 | 74 | |
MidnightCow | 0:583a42b8d940 | 75 | for(i = 0; i < 4; i++) |
MidnightCow | 0:583a42b8d940 | 76 | { |
MidnightCow | 0:583a42b8d940 | 77 | imgh += (((uint32_t)fgetc(fp)) << i*8); |
MidnightCow | 0:583a42b8d940 | 78 | } |
MidnightCow | 0:583a42b8d940 | 79 | if(imgh > 320) return -3; |
MidnightCow | 0:583a42b8d940 | 80 | |
MidnightCow | 0:583a42b8d940 | 81 | fseek(fp,2,SEEK_CUR); |
MidnightCow | 0:583a42b8d940 | 82 | colbits = fgetc(fp); |
MidnightCow | 0:583a42b8d940 | 83 | //if(colbits != 16 || colbits != 24) return -4; |
MidnightCow | 0:583a42b8d940 | 84 | fgetc(fp); |
MidnightCow | 0:583a42b8d940 | 85 | if((compress=fgetc(fp)) != 0) |
MidnightCow | 0:583a42b8d940 | 86 | { |
MidnightCow | 0:583a42b8d940 | 87 | #ifdef TFT_DEBUG |
MidnightCow | 0:583a42b8d940 | 88 | uart.printf("Not supported compress : %d\r\n",compress); |
MidnightCow | 0:583a42b8d940 | 89 | #endif |
MidnightCow | 0:583a42b8d940 | 90 | return -4; |
MidnightCow | 0:583a42b8d940 | 91 | } |
MidnightCow | 0:583a42b8d940 | 92 | |
MidnightCow | 0:583a42b8d940 | 93 | |
MidnightCow | 0:583a42b8d940 | 94 | #ifdef TFT_DEBUG |
MidnightCow | 0:583a42b8d940 | 95 | uart.printf("RESOL : %d col, %d X %d",colbits,imgw,imgh); |
MidnightCow | 0:583a42b8d940 | 96 | #endif |
MidnightCow | 0:583a42b8d940 | 97 | |
MidnightCow | 0:583a42b8d940 | 98 | fseek(fp, offset, SEEK_SET); |
MidnightCow | 0:583a42b8d940 | 99 | for (j = imgh-1; j >= 0; j--) //Lines |
MidnightCow | 0:583a42b8d940 | 100 | { |
MidnightCow | 0:583a42b8d940 | 101 | fread(img,sizeof(char),imgw*3,fp); |
MidnightCow | 0:583a42b8d940 | 102 | window(0, j, imgw, 1); |
MidnightCow | 0:583a42b8d940 | 103 | wr_cmd(0x2C); // send pixel |
MidnightCow | 0:583a42b8d940 | 104 | #ifndef TARGET_KL25Z // 16 Bit SPI |
MidnightCow | 0:583a42b8d940 | 105 | SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.format(16,3); |
MidnightCow | 0:583a42b8d940 | 106 | #endif // switch to 16 bit Mode 3 |
MidnightCow | 0:583a42b8d940 | 107 | |
MidnightCow | 0:583a42b8d940 | 108 | for(i = 0; i < imgw; i++) |
MidnightCow | 0:583a42b8d940 | 109 | { |
MidnightCow | 0:583a42b8d940 | 110 | /* if(colbits == 16) |
MidnightCow | 0:583a42b8d940 | 111 | { |
MidnightCow | 0:583a42b8d940 | 112 | col = (uint16_t)img[2*i+1]; |
MidnightCow | 0:583a42b8d940 | 113 | col <<= 8; |
MidnightCow | 0:583a42b8d940 | 114 | col += (uint16_t)img[2*i]; |
MidnightCow | 0:583a42b8d940 | 115 | } |
MidnightCow | 0:583a42b8d940 | 116 | else if(colbits == 24) */ |
MidnightCow | 0:583a42b8d940 | 117 | { |
MidnightCow | 0:583a42b8d940 | 118 | col = RGB((uint16_t)img[3*i+2],(uint16_t)img[3*i+1], (uint16_t)img[3*i]); |
MidnightCow | 0:583a42b8d940 | 119 | } |
MidnightCow | 0:583a42b8d940 | 120 | #ifdef TFT_DEBUG |
MidnightCow | 0:583a42b8d940 | 121 | //uart.printf("RGB(%d): (%d,%d,%d) -> %04X\r\n ",i,img[3*i+2],img[3*i+1],img[3*i],col); |
MidnightCow | 0:583a42b8d940 | 122 | #endif |
MidnightCow | 0:583a42b8d940 | 123 | |
MidnightCow | 0:583a42b8d940 | 124 | #ifdef TAGET_KL25Z |
MidnightCow | 0:583a42b8d940 | 125 | SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.write((char)(col>>8)); |
MidnightCow | 0:583a42b8d940 | 126 | SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.write((char)col); |
MidnightCow | 0:583a42b8d940 | 127 | #else |
MidnightCow | 0:583a42b8d940 | 128 | SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.write(col); |
MidnightCow | 0:583a42b8d940 | 129 | #endif |
MidnightCow | 0:583a42b8d940 | 130 | } |
MidnightCow | 0:583a42b8d940 | 131 | SeeedStudioTFTv2::SPI_TFT_ILI9341::_cs = 1; |
MidnightCow | 0:583a42b8d940 | 132 | #ifndef TARGET_KL25Z // 16 Bit SPI |
MidnightCow | 0:583a42b8d940 | 133 | SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.format(8,3); |
MidnightCow | 0:583a42b8d940 | 134 | #endif |
MidnightCow | 0:583a42b8d940 | 135 | |
MidnightCow | 0:583a42b8d940 | 136 | } |
MidnightCow | 0:583a42b8d940 | 137 | WindowMax(); |
MidnightCow | 0:583a42b8d940 | 138 | |
MidnightCow | 0:583a42b8d940 | 139 | return 0; |
MidnightCow | 0:583a42b8d940 | 140 | } |