Imrich Konkol / Mbed 2 deprecated lcd_tft_ssd2119

Dependencies:   EthernetNetIf mbed

Revision:
1:c9dad7bc0795
Parent:
0:d6b0747774da
Child:
2:456410210d03
--- a/main.cpp	Mon Nov 29 22:25:48 2010 +0000
+++ b/main.cpp	Wed Dec 01 21:01:31 2010 +0000
@@ -24,6 +24,8 @@
 // 29.11.2010 ZX Spectrum SCR viewer added
 //            - to show test.scr from internal mbed drive type \\ at
 //              PC terminal prompt
+// 01.12.2010 bright fixed, slideshow added, terminal session start
+//            after slideshow finish
 // *********************************************************************
 #include "mbed.h"
 
@@ -82,6 +84,9 @@
 static uint16_t yy=0;
 static uint16_t xx=0;
 
+static uint16_t BACKGROUND = WHITE;
+static uint16_t FOREGROUND = BLACK;
+
 // Essential display commands
 /*************************************************/
 void write_command(uint16_t command) {
@@ -303,10 +308,10 @@
         for ( j = 0; j < 8; j++ ) {
             if ( (c & 0x01) == 0x01 ) {
                 //printf("X");
-                write_data(BLACK);
+                write_data(FOREGROUND);
             } else {
                 //printf(".");
-                write_data(WHITE);
+                write_data(BACKGROUND);
             }
             //printf("\n");
             c >>= 1;
@@ -570,9 +575,13 @@
     unsigned char c,a,ink,pap;
     unsigned int x,y,i,j,k,l,m;
     unsigned char screen[6912];
-
-    printf("Opening File...\n"); // Drive should be marked as removed
-    FILE *fp = fopen("/local/test.scr", "r");
+    char fullpath[30];
+    
+    strcpy(fullpath,"/local/");
+    strcat(fullpath,scrfile);
+     
+    printf("Opening File %s...\n",fullpath); // Drive should be marked as removed
+    FILE *fp = fopen(fullpath, "r");
     if (!fp) {
         printf("File %s could not be opened!\n",scrfile);
         return(1);
@@ -602,10 +611,10 @@
                     for (m=0;m<8;m++) { // Pixel
                         a = screen[6144+ j * 256 + i * 32 + (l-1)];
                         ink = a & 0x07;
-                        pap = (a >>=3) & 0x07;
-                        if ( (a & 0x70) == 0x70 ) {  // Bright1
-                            if ( ink != 0 ) ink = ink+8;
-                            if ( pap != 0 ) pap = pap+8;
+                        pap = ( a >>=3 ) & 0x07;
+                        if ( (a & 0x08) == 0x08 ) {  // Bright1
+                            if ( ink != 0 ) ink += 7;
+                            if ( pap != 0 ) pap += 7;
                         }
 
                         if ( (c & 0x01) == 0x01 ) {
@@ -627,13 +636,50 @@
 
     return(0);
 }
+// List files on internal filesystem
+void Dir()
+{
+    unsigned int i=0, y=12;
+    char str[40];
+    
+    DIR *d = opendir("/local");               // Opens the root directory of the local file system
+    struct dirent *p;
+    while((p = readdir(d)) != NULL) {         // Print the names of the files in the local file system
+      //sprintf(str, "%s\n", p->d_name);        // to stdout.
+      LcdStr(p->d_name);
+      y++;
+      LcdGotoXY(0,y);
+      if ( strstr(p->d_name,".SCR") != NULL) {
+        i++;
+      }
+    }
+    closedir(d);
+    sprintf(str, "%d SCR files found!",i);
+    LcdStr(str);
+}
 
+// Slideshow - show all SCR files from mbed FS
+void SldShw()
+{
+    DIR *d = opendir("/local");               // Opens the root directory of the local file system
+    struct dirent *p;
+    while((p = readdir(d)) != NULL) {         // Print the names of the files in the local file system
+      if ( strstr(p->d_name,".SCR") != NULL) {
+        scr2lcd(p->d_name);                   // Display SCR files from listing
+        wait(3.0);
+      }
+    }
+    closedir(d);
+}
 
 // Main loop starts here
 int main() {
 
     uint8_t x,y;
     char c,xc=' ';
+    unsigned int i;
+    char str[40];
+    
     //Configure the Fastest Baud Rate
     pc.baud(115200);
 
@@ -678,16 +724,56 @@
         LcdChr('o');
 
         LcdStr(" World!");
-
-        LcdGotoXY(4,11);
+        
+        y = 11;
+        LcdGotoXY(0,y);
+        LcdStr("Local filesystem contains these files:");
+        y++;
+        LcdGotoXY(0,y);
+        Dir();
+       
+       for (i=5;i>0;i--)
+       {
+            LcdGotoXY(0,0);
+            sprintf(str, "Displaying images in %d seconds...", i);
+            switch (i) {
+                case 1:
+                    strcat(str,"/");
+                    break;
+                case 2:
+                    strcat(str,"|");
+                    break;
+                case 3:
+                    strcat(str,"\\");
+                    break;
+                case 4:
+                    strcat(str,"-");
+                    break;
+                default:
+                    break;
+              }
+                
+            LcdStr(str);
+            wait(1.0);
+        }
+        LCD_test();                                 // Restore rainbow background
+        SldShw();                                   // Slide show from ZX screens
+        
+        wait(5.0);
+        
+        
+        FOREGROUND = GREEN;
+        BACKGROUND = BLACK;
+        display_rgb(BACKGROUND);
+         
+        LcdGotoXY(4,1);
         LcdStr("Below you can see what you write");
-        LcdGotoXY(12,12);
+        LcdGotoXY(12,2);
         LcdStr("in your PC terminal");
 
-        wait(5.0);
-
+       
         x = 0;
-        y = 13;
+        y = 3;
         while (1) {
             LcdGotoXY(x,y);
             c = pc.getc();
@@ -702,7 +788,9 @@
             if (c > 31) {
                 LcdChr(c);
                 if ( (xc == '\\' ) && ( c == '\\' ) ) {
-                    scr2lcd("test.scr");
+                    //scr2lcd("test.scr");
+                    LCD_test();
+                    SldShw();
                 }
 
                 xc = c;