KSM edits to RA8875

Dependents:   Liz_Test_Code

Revision:
100:0b084475d5a9
Parent:
98:ecebed9b80b2
Child:
101:e0aad446094a
--- a/RA8875.cpp	Thu Dec 17 12:19:01 2015 +0000
+++ b/RA8875.cpp	Sat Dec 19 15:55:09 2015 +0000
@@ -146,6 +146,8 @@
     WriteCommand(0x1e, 0x06);                   //VSTR1 //VSYNC Start Position[8]
     WriteCommand(0x1f, 0x01);                   //VPWR  //VSYNC Polarity ,VSYNC Pulse Width[6:0]
 
+    portraitmode = false;
+    
     if (width >= 800 && height >= 480 && color_bpp > 8) {
         WriteCommand(0x20, 0x00);               // DPCR - 1-layer mode when the resolution is too high
     } else {
@@ -386,9 +388,13 @@
 #ifdef PERF_METRICS
 void RA8875::ClearPerformance()
 {
-    for (int i=0; i<METRICCOUNT; i++)
+    int i;
+    
+    for (i=0; i<METRICCOUNT; i++)
         metrics[i] = 0;
     idletime_usec = 0;
+    for (i=0; i<256; i++)
+        commandsUsed[i] = 0;
 }
 
 
@@ -409,14 +415,16 @@
 
 void RA8875::ReportPerformance(Serial & pc)
 {
+    int i;
+    
     pc.printf("\r\nPerformance Metrics\r\n");
-    for (int i=0; i<METRICCOUNT; i++) {
+    for (i=0; i<METRICCOUNT; i++) {
         pc.printf("%10d uS %s\r\n", metrics[i], metricsName[i]);
     }
     pc.printf("%10d uS Idle time polling display for ready.\r\n", idletime_usec);
     for (i=0; i<256; i++) {
         if (commandsUsed[i])
-            pc.printf("Command %02X used %5d times.\r\n", i, commandsUsed[i])
+            pc.printf("Command %02X used %5d times.\r\n", i, commandsUsed[i]);
     }
 }
 #endif
@@ -738,6 +746,7 @@
         default:
             return bad_parameter;
     }
+    INFO("Orientation: %d, %d", angle, portraitmode);
     WriteCommand(0x22, fncr1Val);
     return WriteCommand(0x20, dpcrVal);
 }
@@ -882,14 +891,8 @@
 
 void RA8875::puts(const char * string)
 {
-    unsigned char mwcr0 = ReadCommand(0x40);
-
     if (font == NULL) {
-        if ((mwcr0 & 0x80) == 0x00) {
-            WriteCommand(0x40,0x80);    // Put in Text mode if not already
-        }
-    //} else {
-    //    _StartGraphicsStream();
+        WriteCommand(0x40,0x80);    // Put in Text mode if internal font
     }
     if (*string != '\0') {
 #if 1
@@ -907,8 +910,6 @@
         _select(false);
 #endif
     }
-    //if (font)
-    //    _EndGraphicsStream();
 }
 
 
@@ -1162,9 +1163,9 @@
     PERFORMANCE_RESET;
     // check for bad_parameter
     if (x1 < 0 || x1 >= width() || x2 < 0 || x2 >= width() 
-    || y1 < 0 || y1 >= height() || y2 < 0 || y2 >= height())
+    || y1 < 0 || y1 >= height() || y2 < 0 || y2 >= height()) {
         ret = bad_parameter;
-    else {
+    } else {
         if (x1 == x2 && y1 == y2) {
             pixel(x1, y1);
         } else if (x1 == x2) {
@@ -1476,15 +1477,6 @@
     return (float)(GetBacklight_u8())/255;
 }
 
-RetCode_t RA8875::set_font(const unsigned char * _font)
-{
-    if (font && ! _font) {
-        SetTextCursor(cursor_x, cursor_y);  // soft-font cursor -> hw cursor
-    }
-    font = _font;
-    return GraphicsDisplay::set_font(_font);    // trusting them, but it might be good to put some checks in here...
-}
-
 RetCode_t RA8875::SelectUserFont(const uint8_t * _font)
 {
     INFO("Cursor(%d,%d)  %p", cursor_x, cursor_y, _font);
@@ -1716,8 +1708,6 @@
             if (pixelBuffer)
                 free(pixelBuffer);
             free(lineBuffer);
-            if (pixelBuffer)
-                free(pixelBuffer);
             return(not_enough_ram);
         }
 
@@ -1812,8 +1802,6 @@
         if (pixelBuffer)
             free(pixelBuffer);
         free(lineBuffer);
-        if (pixelBuffer)
-            free(pixelBuffer);
         INFO("Image closed");
         return noerror;
     } else {
@@ -1883,8 +1871,6 @@
             if (pixelBuffer)
                 free(pixelBuffer);
             free(lineBuffer);
-            if (pixelBuffer)
-                free(pixelBuffer);
             return(not_enough_ram);
         }
 
@@ -1898,8 +1884,6 @@
             if (pixelBuffer)
                 free(pixelBuffer);
             free(lineBuffer);
-            if (pixelBuffer)
-                free(pixelBuffer);
             return(file_not_found);
         }
 
@@ -1986,8 +1970,6 @@
         if (pixelBuffer)
             free(pixelBuffer);
         free(lineBuffer);
-        if (pixelBuffer)
-            free(pixelBuffer);
         INFO("Image closed");
         return noerror;
     } else {
@@ -2026,7 +2008,7 @@
     display.foreground(Blue);
     display.cls();
     display.Backlight_u8(255);
-    display.puts(0,0, "Text Wrap Test.\r\n");
+    display.puts("Text Wrap Test.\r\n");
     for (int i=1; i<60; i++) {
         display.printf("L%2d\n", i % 17);
         if (!SuppressSlowStuff)
@@ -2080,7 +2062,7 @@
     display.foreground(Blue);
     display.cls();
     display.Backlight_u8(255);
-    display.puts(0,0, "KeyPad Test. Touch the keypad...");
+    display.puts("KeyPad Test. Touch the keypad...");
     pc.printf("\r\n"
               "Raw KeyPad Test. Keypad returns the key-number.\r\n"
               "Press [most] any PC keyboard key to advance to next test.\r\n");
@@ -2129,7 +2111,7 @@
     const char * bCursor  = "The Block cursor should be visible for this text.\r\n";
     const char * bbCursor = "The Blinking Block cursor should be visible for this text.\r\n";
     const char * p;
-    int delay = 100;
+    int delay = 60;
 
     if (!SuppressSlowStuff)
         pc.printf("Text Cursor Test\r\n");
@@ -2139,7 +2121,7 @@
     display.foreground(Blue);
     display.cls();
     display.Backlight_u8(255);
-    display.puts(0,0, "Text Cursor Test.");
+    display.puts("Text Cursor Test.");
 
     // visible, non-blinking
     display.SetTextCursor(0,20);
@@ -2191,8 +2173,8 @@
     display.background(White);
     display.foreground(Blue);
     display.cls();
+    display.puts("RA8875 Backlight Test - Ramp up.");
     wait_ms(delay);
-    display.puts(0,0, "RA8875 Backlight Test - Ramp up.");
     for (int i=0; i <= 255; i++) {
         sprintf(buf, "%3d, %4d", i, w);
         display.puts(100,100,buf);
@@ -2230,8 +2212,8 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
+    display.puts("External Font Test.");
     display.Backlight(1);
-    display.puts(0,0, "External Font Test.");
 
     display.SelectUserFont(BPG_Arial08x08);
     display.puts(0,30, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n");
@@ -2240,7 +2222,6 @@
     display.puts("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n");
     
     display.SelectUserFont();
-    //display.set_font();     // restore to internal
 
     display.puts("Normal font again.");
     //display.window(0,0, display.width(), display.height());
@@ -2254,7 +2235,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "DOS Colors - Fore");
+    display.puts("DOS Colors - Fore");
     display.puts(280,0, "Back");
     display.background(Gray);
     for (int i=0; i<16; i++) {
@@ -2306,7 +2287,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Pixel Test");
+    display.puts("Pixel Test");
     for (i=0; i<1000; i++) {
         x = rand() % 480;
         y = 16 + rand() % (272-16);
@@ -2326,7 +2307,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Line Test");
+    display.puts("Line Test");
     for (i=0; i<16; i++) {
         // Lines
         x = rand() % 480;
@@ -2379,7 +2360,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Rectangle Test");
+    display.puts("Rectangle Test");
     for (i=0; i<16; i++) {
         x1 = rand() % 240;
         y1 = 50 + rand() % 200;
@@ -2407,7 +2388,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Layer 0");
+    display.puts("Layer 0");
     for (i=0; i<16; i++) {
         x1 = rand() % 240;
         y1 = 50 + rand() % 200;
@@ -2467,7 +2448,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Rounded Rectangle Test");
+    display.puts("Rounded Rectangle Test");
 
     for (i=0; i<16; i++) {
         x1 = rand() % 240;
@@ -2560,7 +2541,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Circle Test");
+    display.puts("Circle Test");
     for (i=0; i<16; i++) {
         x = 100 + rand() % 100;
         y = 70 + rand() % 200;
@@ -2586,7 +2567,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Ellipse Test");
+    display.puts("Ellipse Test");
     for (i=0; i<16; i++) {
         x = 100 + rand() % 100;
         y = 70 + rand() % 200;
@@ -2611,7 +2592,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Graphics Test, loading /local/TestPat.bmp");
+    display.puts("Graphics Test, loading /local/TestPat.bmp");
     wait(3);
 
     int r = display.RenderBitmapFile(0,0, "/local/TestPat.bmp");
@@ -2629,7 +2610,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Touch Panel Test\r\n");
+    display.puts("Touch Panel Test\r\n");
     pc.printf("Touch Panel Test\r\n");
     display.TouchPanelInit();
     pc.printf("  TP: c - calibrate, r - restore, t - test\r\n");