Simple program for the RETRO to compare the performance of the DisplayN18 and LCD_ST7735 libraries.

Dependencies:   LCD_ST7735 mbed

This is a very simple program for the RETRO to compare the performance of some of the primitives of the DisplayN18 and LCD_ST7735 libraries

WARNING - WARNING - WARNING

If you're sensitive to ugly coding techniques, lack of best practice, ignorance of proper design patterns, abuse of object orientation or to total disregards of any coding guidelines, then don't - I repeat - DON'T look at this code...

P.S. Regardless the performance, I do think the N18 library has a much nicer font!

Files at this revision

API Documentation at this revision

Comitter:
maxint
Date:
Fri Jan 16 21:41:09 2015 +0000
Parent:
1:e3193760dd98
Commit message:
Added bottomPrintf_xxx function to make the tests slightly more readable. Tiny bit of cleaning up the test functions.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r e3193760dd98 -r dcf8e6db342d main.cpp
--- a/main.cpp	Fri Jan 16 19:59:19 2015 +0000
+++ b/main.cpp	Fri Jan 16 21:41:09 2015 +0000
@@ -4,17 +4,29 @@
 //
 ///////////////////////
 
+#include <stdarg.h>
 #include "mbed.h"
 #include "DisplayN18.h"
 #include "Color565.h"
 #include "font_IBM.h"
 #include "LCD_ST7735.h"
 
+void bottomPrintf_N18(DisplayN18 &disp, const char *szFormat, ...)
+{
+    char szBuffer[256];
+    va_list args;
+
+    va_start(args, szFormat);
+    vsprintf(szBuffer, szFormat, args);
+    va_end(args);
+    disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(szBuffer) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT, szBuffer, DisplayN18::GREEN, DisplayN18::BLACK);
+}
+
 int testDisplayN18()
 {   // test N18 library functions
     DisplayN18 disp;
     Timer tPerformance;    // timer used for measuring performance
-    char buf[256];
+    char szTest[]="123TestText456";
     int iPerfMs=0;
     int iStartUs=0;
 
@@ -23,94 +35,93 @@
     // text
     iStartUs=tPerformance.read_us();
     disp.clear();
-    sprintf(buf,"drawString...");
+    bottomPrintf_N18(disp, "drawString...");
     for(int i=1; i<100; i++)
     {
-        disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, i, buf, DisplayN18::GREEN, DisplayN18::BLACK);
+        disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(szTest) / 2, i, szTest, DisplayN18::GREEN, DisplayN18::BLACK);
     }
-    sprintf(buf,"drawString:%u ", tPerformance.read_us()-iStartUs);
-    disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT, buf, DisplayN18::GREEN, DisplayN18::BLACK);
+    bottomPrintf_N18(disp, "drawString:%u ", tPerformance.read_us()-iStartUs);
     iPerfMs+=tPerformance.read_ms();
     wait(0.5);
 
     // rectangles
     iStartUs=tPerformance.read_us();
     disp.clear();
-    sprintf(buf,"drawRect...");
-    disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, 0, buf, DisplayN18::GREEN, DisplayN18::BLACK);
+    bottomPrintf_N18(disp, "drawRect...");
     for(int i=1; i<100; i++)
     {
         disp.drawRect(0, 0, i, i, DisplayN18::GREEN);
     }
-    sprintf(buf,"drawRect:%u ", tPerformance.read_us()-iStartUs);
-    disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT, buf, DisplayN18::GREEN, DisplayN18::BLACK);
+    bottomPrintf_N18(disp, "drawRect:%u ", tPerformance.read_us()-iStartUs);
     iPerfMs+=tPerformance.read_ms();
     wait(0.5);
 
     // filled rectangles
     iStartUs=tPerformance.read_us();
     disp.clear();
-    sprintf(buf,"fillRect...");
-    disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, 0, buf, DisplayN18::GREEN, DisplayN18::BLACK);
+    bottomPrintf_N18(disp, "fillRect...");
     for(int i=1; i<100; i+=2)
     {
         disp.fillRect(0, 0, i, i, DisplayN18::GREEN);
     }
-    sprintf(buf,"fillRect:%u ", tPerformance.read_us()-iStartUs);
-    disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT, buf, DisplayN18::GREEN, DisplayN18::BLACK);
+    bottomPrintf_N18(disp, "fillRect:%u ", tPerformance.read_us()-iStartUs);
     iPerfMs+=tPerformance.read_ms();
     wait(0.5);
 
     // circles
     iStartUs=tPerformance.read_us();
     disp.clear();
-    sprintf(buf,"drawCircle...");
-    disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, 0, buf, DisplayN18::GREEN, DisplayN18::BLACK);
+    bottomPrintf_N18(disp, "drawCircle...");
     for(int i=1; i<100; i++)
     {
         disp.drawCircle(i, i, i/2, DisplayN18::GREEN);
     }
-    sprintf(buf,"drawCircle:%u ", tPerformance.read_us()-iStartUs);
-    disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT, buf, DisplayN18::GREEN, DisplayN18::BLACK);
+    bottomPrintf_N18(disp, "drawCircle:%u ", tPerformance.read_us()-iStartUs);
     iPerfMs+=tPerformance.read_ms();
     wait(0.5);
 
     // filled circles
     iStartUs=tPerformance.read_us();
     disp.clear();
-    sprintf(buf,"fillCircle...");
-    disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, 0, buf, DisplayN18::GREEN, DisplayN18::BLACK);
+    bottomPrintf_N18(disp, "fillCircle...");
     for(int i=1; i<100; i+=2)
     {
         disp.fillCircle(i, i, i/2, DisplayN18::GREEN);
     }
-    sprintf(buf,"fillCircle:%u ", tPerformance.read_us()-iStartUs);
-    disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT, buf, DisplayN18::GREEN, DisplayN18::BLACK);
+    bottomPrintf_N18(disp, "fillCircle:%u ", tPerformance.read_us()-iStartUs);
     iPerfMs+=tPerformance.read_ms();
     wait(0.5);
 
     // lines
     iStartUs=tPerformance.read_us();
     disp.clear();
-    sprintf(buf,"drawLine...");
-    disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, 0, buf, DisplayN18::GREEN, DisplayN18::BLACK);
+    bottomPrintf_N18(disp, "drawLine...");
     for(int i=1; i<100; i++)
     {
         disp.drawLine(0, 0, i, 100, DisplayN18::GREEN);
     }
-    sprintf(buf,"drawLine:%u ", tPerformance.read_us()-iStartUs);
-    disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT, buf, DisplayN18::GREEN, DisplayN18::BLACK);
+    bottomPrintf_N18(disp, "drawLine:%u ", tPerformance.read_us()-iStartUs);
     iPerfMs+=tPerformance.read_ms();
     wait(0.5);
 
     disp.clear();
-    sprintf(buf,"Total:%u ms", iPerfMs);
-    disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT, buf, DisplayN18::GREEN, DisplayN18::BLACK);
+    bottomPrintf_N18(disp, "Total:%u ms", iPerfMs);
     wait(2);
 
     return(iPerfMs);
 }
 
+void bottomPrintf_ST7735(LCD_ST7735 &disp, const char *szFormat, ...)
+{
+    char szBuffer[256];
+    va_list args;
+
+    va_start(args, szFormat);
+    vsprintf(szBuffer, szFormat, args);
+    va_end(args);
+    disp.drawString(font_ibm, disp.getWidth() / 2 - (8 + 0) * strlen(szBuffer) / 2, disp.getHeight()-8, szBuffer);
+}
+
 int testDisplayST7735()
 {   // test ST7735 library functions
     LCD_ST7735 disp(
@@ -123,104 +134,91 @@
         P0_2,
         LCD_ST7735::RGB);
     Timer tPerformance;    // timer used for measuring performance
-    char buf[256];
+    char szTest[]="123TestText456";
     int iPerfMs=0;
     int iStartUs=0;
 
     tPerformance.start();      // start the timer
     disp.setOrientation(LCD_ST7735::Rotate270, false);
-    disp.setForegroundColor(Color565::White);
-    disp.setBackgroundColor(Color565::Blue);
+    disp.setForegroundColor(Color565::Blue);
+    disp.setBackgroundColor(Color565::Black);
     disp.clearScreen();
     
     // text
     iStartUs=tPerformance.read_us();
     disp.clearScreen();
-    sprintf(buf,"drawString...");
+    bottomPrintf_ST7735(disp, "drawString...");
     for(int i=1; i<100; i++)
     {
         //disp.drawString(font_ibm, disp.getWidth / 2 - (8 + 0) * strlen(buf) / 2, i, buf);
-        disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, i, buf);
+        disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(szTest) / 2, i, szTest);
     }
-    sprintf(buf,"drawString:%u ", tPerformance.read_us()-iStartUs);
-    //disp.drawString(font_ibm, disp.getWidth / 2 - (8 + 0) * strlen(buf) / 2, disp.getHeight-8, buf);
-    disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 128-8, buf);
+    bottomPrintf_ST7735(disp, "drawString:%u ", tPerformance.read_us()-iStartUs);
     iPerfMs+=tPerformance.read_ms();
     wait(0.5);
 
     // rectangles
     iStartUs=tPerformance.read_us();
     disp.clearScreen();
-    sprintf(buf,"drawRect...");
-    disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 0, buf);
+    bottomPrintf_ST7735(disp, "drawRect...");
     for(int i=1; i<100; i++)
     {
         disp.drawRect(0, 0, i, i, Color565::Blue);
     }
-    sprintf(buf,"drawRect:%u ", tPerformance.read_us()-iStartUs);
-    disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 128-8, buf);
+    bottomPrintf_ST7735(disp, "drawRect:%u ", tPerformance.read_us()-iStartUs);
     iPerfMs+=tPerformance.read_ms();
     wait(0.5);
 
     // filled rectangles
     iStartUs=tPerformance.read_us();
     disp.clearScreen();
-    sprintf(buf,"drawRect...");
-    disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 0, buf);
+    bottomPrintf_ST7735(disp, "fillRect...");
     for(int i=1; i<100; i+=2)
     {
         disp.fillRect(0, 0, i, i, Color565::Yellow, Color565::Blue);
     }
-    sprintf(buf,"drawRect:%u ", tPerformance.read_us()-iStartUs);
-    disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 128-8, buf);
+    bottomPrintf_ST7735(disp, "fillRect:%u ", tPerformance.read_us()-iStartUs);
     iPerfMs+=tPerformance.read_ms();
     wait(0.5);
 
     // circles
     iStartUs=tPerformance.read_us();
     disp.clearScreen();
-    sprintf(buf,"drawCircle...");
-    disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 0, buf);
+    bottomPrintf_ST7735(disp, "drawCircle...");
     for(int i=1; i<100; i++)
     {
         disp.drawCircle(i, i, i/2, Color565::Blue);
     }
-    sprintf(buf,"drawCircle:%u ", tPerformance.read_us()-iStartUs);
-    disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 128-8, buf);
+    bottomPrintf_ST7735(disp, "drawCircle:%u ", tPerformance.read_us()-iStartUs);
     iPerfMs+=tPerformance.read_ms();
     wait(0.5);
 
     // filled circles
     iStartUs=tPerformance.read_us();
     disp.clearScreen();
-    sprintf(buf,"fillCircle...");
-    disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 0, buf);
+    bottomPrintf_ST7735(disp, "fillCircle...");
     for(int i=1; i<100; i+=2)
     {
         disp.fillCircle(i, i, i/2, Color565::Yellow, Color565::Blue);
     }
-    sprintf(buf,"fillCircle:%u ", tPerformance.read_us()-iStartUs);
-    disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 128-8, buf);
+    bottomPrintf_ST7735(disp, "fillCircle:%u ", tPerformance.read_us()-iStartUs);
     iPerfMs+=tPerformance.read_ms();
     wait(0.5);
 
     // lines
     iStartUs=tPerformance.read_us();
     disp.clearScreen();
-    sprintf(buf,"drawLine...");
-    disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 0, buf);
+    bottomPrintf_ST7735(disp, "drawLine...");
     for(int i=1; i<100; i++)
     {
         disp.drawLine(0, 0, i, 100, Color565::Blue);
     }
-    sprintf(buf,"drawLine:%u ", tPerformance.read_us()-iStartUs);
-    disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 128-8, buf);
+    bottomPrintf_ST7735(disp, "drawLine:%u ", tPerformance.read_us()-iStartUs);
     iPerfMs+=tPerformance.read_ms();
     wait(0.5);
 
     disp.clearScreen();
-    sprintf(buf,"Total:%u ms", iPerfMs);
-    disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 128-8, buf);
+    bottomPrintf_ST7735(disp, "Total:%u ms", iPerfMs);
     wait(2);
 
     return(iPerfMs);