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.

/media/uploads/MidnightCow/dpf_logo.jpg


Demo

https://vimeo.com/137345478

<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

Files at this revision

API Documentation at this revision

Comitter:
MidnightCow
Date:
Sat Aug 15 08:45:28 2015 +0000
Child:
1:72700c87f8d5
Commit message:
Just Test version

Changed in this revision

FTPClient.lib Show annotated file Show diff for this revision Revisions of this file
MySeeedStudioTFTv2.cpp Show annotated file Show diff for this revision Revisions of this file
MySeeedStudioTFTv2.h Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
SeeedStudioTFTv2.lib Show annotated file Show diff for this revision Revisions of this file
TFT_fonts.lib Show annotated file Show diff for this revision Revisions of this file
WIZnetInterface.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FTPClient.lib	Sat Aug 15 08:45:28 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/MidnightCow/code/FTPClient/#4bef734cc93e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MySeeedStudioTFTv2.cpp	Sat Aug 15 08:45:28 2015 +0000
@@ -0,0 +1,140 @@
+/* mbed library for resistive touch pads
+ * uses 4 pins - 2 IO and 2 Analog
+
+ * c 2011 Peter Drescher - DC2PD
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+#include "mbed.h"
+#include "MySeeedStudioTFTv2.h"
+
+#define TFT_DEBUG
+
+#ifdef TFT_DEBUG
+extern Serial uart;
+#endif
+
+
+MySeeedStudioTFTv2::MySeeedStudioTFTv2(PinName xp, PinName xm, PinName yp, PinName ym,
+                     PinName mosi, PinName miso, PinName sclk,
+                     PinName csTft, PinName dcTft, PinName blTft,
+                     PinName csSd) : SeeedStudioTFTv2(xp,xm,yp,ym,mosi,miso,sclk,csTft,dcTft,blTft,csSd)
+{
+    SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.frequency(18000000);
+    SeeedStudioTFTv2::SDFileSystem::_spi.frequency(24000000);     
+}
+
+int MySeeedStudioTFTv2::DrawBitmapFile(FILE * fp)
+{
+   
+    char img[3*240];
+    uint32_t imgsize = 0;
+    uint32_t offset = 0;
+    uint32_t imgw = 0;
+    uint32_t imgh = 0;
+    char colbits = 0;
+    char compress = 0;
+    uint16_t col;
+
+    int i, j;
+ 
+    if(fp == NULL) return -1;
+    if(fgetc(fp) != 0x42) return -2;
+    if(fgetc(fp) != 0x4D) return -2;
+
+    for(i = 0; i < 4; i++)
+    {
+        imgsize += (((uint32_t)fgetc(fp)) << i*8);
+    }
+#ifdef TFT_DEBUG
+    uart.printf("BMP SIZE:%d\r\n",imgsize);
+#endif
+    fseek(fp,4,SEEK_CUR);
+    for(i = 0; i < 4; i++)
+    {
+        offset += (((uint32_t)fgetc(fp)) << i*8);
+    }
+#ifdef TFT_DEBUG    
+    uart.printf("BMP OFFSET:%d\r\n",offset);
+#endif
+    fseek(fp,4,SEEK_CUR);
+    for(i = 0; i < 4; i++)
+    {
+        imgw += (((uint32_t)fgetc(fp)) << i*8);
+    }
+    if(imgw > 240) return -3;
+    
+    for(i = 0; i < 4; i++)
+    {
+        imgh += (((uint32_t)fgetc(fp)) << i*8);
+    }
+    if(imgh > 320) return -3;
+    
+    fseek(fp,2,SEEK_CUR);
+    colbits = fgetc(fp);
+    //if(colbits != 16 || colbits != 24) return -4;
+    fgetc(fp);
+    if((compress=fgetc(fp)) != 0)
+    {
+    #ifdef TFT_DEBUG    
+        uart.printf("Not supported compress : %d\r\n",compress);
+    #endif
+        return -4;    
+    }
+    
+
+#ifdef TFT_DEBUG    
+    uart.printf("RESOL : %d col, %d X %d",colbits,imgw,imgh);
+#endif    
+    
+    fseek(fp, offset, SEEK_SET);
+    for (j = imgh-1; j >= 0; j--)        //Lines
+    {  
+        fread(img,sizeof(char),imgw*3,fp);
+        window(0, j, imgw, 1);    
+        wr_cmd(0x2C);  // send pixel
+    #ifndef TARGET_KL25Z  // 16 Bit SPI 
+        SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.format(16,3);
+    #endif                            // switch to 16 bit Mode 3
+
+        for(i = 0; i < imgw; i++)
+        {
+/*            if(colbits == 16)
+            {
+                col = (uint16_t)img[2*i+1];
+                col <<= 8;
+                col += (uint16_t)img[2*i];
+            }
+            else if(colbits == 24) */
+            {
+                col = RGB((uint16_t)img[3*i+2],(uint16_t)img[3*i+1], (uint16_t)img[3*i]);
+            }
+        #ifdef TFT_DEBUG    
+            //uart.printf("RGB(%d): (%d,%d,%d) -> %04X\r\n ",i,img[3*i+2],img[3*i+1],img[3*i],col);
+        #endif    
+
+        #ifdef TAGET_KL25Z
+            SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.write((char)(col>>8));
+            SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.write((char)col);
+        #else
+           SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.write(col);
+        #endif
+        }
+        SeeedStudioTFTv2::SPI_TFT_ILI9341::_cs = 1;
+        #ifndef TARGET_KL25Z  // 16 Bit SPI 
+            SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.format(8,3);
+        #endif
+ 
+    }
+    WindowMax();
+    
+    return 0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MySeeedStudioTFTv2.h	Sat Aug 15 08:45:28 2015 +0000
@@ -0,0 +1,47 @@
+/* mbed library for touchscreen connected to 4 mbed pins
+ * derive from SPI_TFT lib
+ * Copyright (c) 2011 Peter Drescher - DC2PD
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MYMBED_TOUCH_H
+#define MYMBED_TOUCH_H
+
+#include "mbed.h"
+
+#include "SeeedStudioTFTv2.h"
+#ifndef USE_SDCARD
+#error "Shoud be defined USE_SDCARD in SeeedStudioTFTv2.0.h
+#endif
+
+
+class MySeeedStudioTFTv2 : public SeeedStudioTFTv2
+{
+public:
+    /** create a TFT with touch object connected to the pins:
+     *
+     * @param pin xp resistiv touch x+
+     * @param pin xm resistiv touch x-
+     * @param pin yp resistiv touch y+
+     * @param pin ym resistiv touch y-
+     * @param mosi,miso,sclk SPI connection to TFT
+     * @param cs pin connected to CS of display
+     * @param reset pin connected to RESET of display
+     * based on my SPI_TFT lib
+     */
+    MySeeedStudioTFTv2(PinName xp, PinName xm, PinName yp, PinName ym,
+                     PinName mosi, PinName miso, PinName sclk,
+                     PinName csTft, PinName dcTft, PinName blTft,
+                     PinName csSd);
+
+    int DrawBitmapFile(FILE * fp);
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Sat Aug 15 08:45:28 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/SDFileSystem/#7b35d1709458
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SeeedStudioTFTv2.lib	Sat Aug 15 08:45:28 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/MidnightCow/code/SeeedStudioTFTv2/#1ed8ed0c17cd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TFT_fonts.lib	Sat Aug 15 08:45:28 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/dreschpe/code/TFT_fonts/#76774250fcec
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WIZnetInterface.lib	Sat Aug 15 08:45:28 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/WIZnet/code/WIZnetInterface/#3b64df29662f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Aug 15 08:45:28 2015 +0000
@@ -0,0 +1,190 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "SDFileSystem.h"
+#include <stdio.h>
+#include <string.h>
+
+#include "FTPClient.h"
+#include "MySeeedStudioTFTv2.h"
+#include "Arial12x12.h"
+#include "Arial24x23.h"
+#include "Arial28x28.h"
+#include "font_big.h"
+
+#define PIN_XP          A3
+#define PIN_XM          A1
+#define PIN_YP          A2
+#define PIN_YM          A0
+#define PIN_MOSI        D11
+#define PIN_MISO        D12
+#define PIN_SCLK        D13
+#define PIN_CS_TFT      D5
+#define PIN_DC_TFT      D6
+#define PIN_BL_TFT      D7
+#define PIN_CS_SD       D4
+
+#define MAC     "\x00\x08\xDC\x11\x34\x78"
+#define IP      "192.168.77.100"
+#define MASK    "255.255.255.0"
+#define GATEWAY "192.168.77.1"
+
+#define HTTPD_SERVER_PORT   80
+#define HTTPD_MAX_REQ_LENGTH   1023
+#define HTTPD_MAX_HDR_LENGTH   255
+#define HTTPD_MAX_FNAME_LENGTH   127
+#define HTTPD_MAX_DNAME_LENGTH   127
+
+Serial uart(USBTX, USBRX);
+
+//SDFileSystem sd(p5, p6, p7, p8, "sd"); // LPC1768 MBD2PMD
+//SDFileSystem sd(P0_18, P0_17, P0_15, P0_16, "sd"); // Seeeduino Arch Pro SPI2SD
+//SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // K64F
+//SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500 
+
+EthernetInterface eth;
+
+/*
+char buffer[HTTPD_MAX_REQ_LENGTH+1];
+char httpHeader[HTTPD_MAX_HDR_LENGTH+1];
+char fileName[HTTPD_MAX_FNAME_LENGTH+1];
+char dirName[HTTPD_MAX_DNAME_LENGTH+1];
+char *uristr;
+char *eou;
+char *qrystr;
+
+FILE *fp;
+int rdCnt;
+*/
+
+DigitalOut led1(LED1); //server listning status
+DigitalOut led2(LED2); //socket connecting status
+
+
+
+MySeeedStudioTFTv2 TFT(PIN_XP, PIN_XM, PIN_YP, PIN_YM, PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_DC_TFT, PIN_BL_TFT, PIN_CS_SD);
+
+
+FTPClient myFTP("/sdc");  // mountname in MySeeedStudioTFTv2
+
+Ticker ledTick;
+
+
+char myfilelist[MAX_SS] = {0,};
+
+void ledTickfunc()
+{
+    led1 = !led1;
+}
+
+
+int main (void)
+{
+    int ret;
+    char* tok = NULL;
+    char* lasts = NULL;
+    char filename[20];
+    FILE* fp;
+    
+    
+    ledTick.attach(&ledTickfunc,0.5);
+
+//    Serial Interface eth;
+    uart.baud(115200);
+    uart.printf("Initializing\n");
+
+//    Check File System
+    uart.printf("Checking File System\n");
+    DIR *d = opendir("/sdc/");
+    if (d != NULL) {
+        uart.printf("SD Card Present\n");
+    } else {
+        uart.printf("SD Card Root Directory Not Found\n");
+    }
+
+//    EthernetInterface eth;
+    uart.printf("Initializing Ethernet\n");
+    //eth.init(); //Use DHCP
+    eth.init((uint8_t*)MAC,IP,MASK,GATEWAY);  //IP,mask,Gateway
+    uart.printf("Connecting\n");
+    eth.connect();
+    uart.printf("IP Address is %s\n", eth.getIPAddress());
+
+    //Configure the display driver
+    TFT.background(Black);
+    TFT.foreground(White);
+    TFT.set_font((unsigned char*) Arial12x12);    
+    TFT.cls();
+
+
+    if(myFTP.open("192.168.77.210", 21, "user", "pass"))
+    {
+        printf("Connect Success to FTPServer\r\n");
+    }
+    myFTP.ls(myfilelist);
+   
+
+    if(*myfilelist !=0)
+    {
+        tok = myfilelist;
+        while(tok)
+        {
+            tok = strtok_r(tok,"\r\n",&lasts);
+            if(tok != NULL)
+            {
+                printf("tok=%s\r\n",tok);
+                if(strstr(tok,"bmp"))
+                {
+                    sprintf(filename,"/sdc/%s",tok);
+                    fp = fopen(filename, "r");
+                    printf("fp=%d\r\n",fp);
+                    if(fp==NULL)
+                    {
+                        myFTP.getfile(tok);
+                        printf("Get File : %s\r\n",tok);
+                    }
+                    else fclose(fp);
+                }
+                tok = lasts; 
+            }
+            
+        }
+    }
+    myFTP.quit();
+
+/*
+            struct dirent *p;
+            while((p = readdir(d)) != NULL) {
+                sprintf(dirName, "%s/%s", fileName, p->d_name);
+                uart.printf("%s\n", dirName);
+                DIR *subDir = opendir(dirName);
+                if (subDir != NULL) {
+                    sprintf(httpHeader,"<li><a href=\"./%s/\">%s/</a></li>", p->d_name, p->d_name);
+                } else {
+                    sprintf(httpHeader,"<li><a href=\"./%s\">%s</a></li>", p->d_name, p->d_name);
+                }
+                client.send(httpHeader,strlen(httpHeader));
+            }
+*/
+
+    for(int i=0; i < 4; i++)
+    {
+    TFT.set_orientation(i);
+    fp = fopen("/sdc/island.bmp", "r");
+    if((ret = TFT.DrawBitmapFile(fp)) < 0)
+    {
+        printf("error : %d\r\n",ret);
+    }
+    fclose(fp);
+    TFT.locate(120-6*strlen("islasn.bmp"),308);
+    TFT.printf("red24.bmp");
+    fp = fopen("/sdc/tiger24.bmp", "r");
+    if((ret = TFT.DrawBitmapFile(fp)) < 0)
+    {
+        printf("error : %d\r\n",ret);
+    }
+    fclose(fp);
+    TFT.locate(120-6*strlen("tiger24.bmp"),308);
+    TFT.printf("tiger24.bmp");
+    printf("press key");getchar();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Aug 15 08:45:28 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/bad568076d81
\ No newline at end of file