C++ file for display control

Dependencies:   4DGL mbed ConfigFile

Fork of 4DGLtest by Stephane ROCHON

Revision:
3:f7bce78b04c1
Child:
6:904d00252480
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/display.cpp	Thu Jun 26 11:41:45 2014 +0000
@@ -0,0 +1,177 @@
+//Display control functions --
+
+#include "mbed.h"
+#include "TFT_4DGL.h"
+#include "display.h"
+#include <string> 
+using namespace std;
+
+/*
+=====================================================
+SGC (Serial Graphics Controller) PLATFORM OUTPUT FILE
+=====================================================
+
+*******************************************************
+* Must set 'New image format' for usage on Picaso SGC *
+* Data:                                               *
+*  0x59, 0x06, 0x00                                   *
+* 4DSL command:                                       *
+*  Control(6,0)                                       *
+*******************************************************
+
+---------------------------------------------------------------------------------------
+File "logo_flyengravity.jpg" (logo_flyengravity.jpg)
+Sector Address 0x000000
+X = 0 Y = 135 Width = 640 Height = 215 Bits = 16
+
+Display Image from Memory Card (Serial Command):
+Syntax:
+@, I, x, y, SectorAdd(hi), SectorAdd(mid), SectorAdd(lo)
+Picaso Data:
+0x40, 0x49, 0x00, 0x00, 0x00, 0x87, 0x00, 0x00, 0x00
+4DSL command:
+NewUSDImage(0, 135, 0x000000)
+
+---------------------------------------------------------------------------------------
+File "Testscreen.png" (Testscreen.png)
+Sector Address 0x00021A
+X = 0 Y = 0 Width = 640 Height = 480 Bits = 16
+
+Display Image from Memory Card (Serial Command):
+Syntax:
+@, I, x, y, SectorAdd(hi), SectorAdd(mid), SectorAdd(lo)
+Picaso Data:
+0x40, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1A
+4DSL command:
+NewUSDImage(0, 0, 0x00021A)
+
+*/
+
+/*Display Commands
+
+$PCDUCLS Erase to active background colour (default black) or white
+===================================================================
+Syntax: $PCDUCLS, <mode>*<checksum>CRLF
+ <mode>=0 : Clear screen to current background colour (default=black)
+ <mode>=1 : Clear screen to white
+
+$PCDUSBC Set Background Color
+====================================================================
+Syntax: $PCDUSBC,<Rcolour>,<Gcolour>,<Bcolour>*<checksum>CRLF
+ < Rcolour > : RED (000‐255)
+ < Gcolour > : GREEN (000‐255)
+ < Bcolour > : BLUE (000‐255)
+ Set background colour to RGB as defined in the three data fields.
+
+$PCDUWTX WTX=WRITE TEXT Write text on any X,Y position on the screen.
+=====================================================================
+Syntax: $PCDUWTX,<Fsize>,<Fstyle>,<Rcolour>,<Gcolour>,<Bcolour>,<Text><Col>,<Row>*<checksum>CRLF
+ <Fsize> : Font size (F0..F9). Currently F0 and F1 are implemented.
+ <Fstyle> : Font style (S=Standard, B=Bold, I=Italic, U=Underline, N=Negative)
+ < Rcolour > : RED (000‐255)
+ < Gcolour > : GREEN (000‐255)
+ < Bcolour > : BLUE (000‐255)
+ <Text> : Any printable ASCII character except the * character as this is used as the text field delimiter. 
+  Maximum length is 24 characters, minimum length is 1 character for font F0.
+  Maximum length is 48 characters, minumum length is 1 character for font F1.
+ <Col> : Horizontal position of the first character (1..24)
+ <Row> : Vertical position of the line (1..14)
+
+$PCDUETX ETX=ERASE TEXT
+============================================================= 
+Syntax: $PCDUETX, <Col>,<Row>,<n>*<checksum>CRLF
+ <Col> : Horizontal position of the first character (1..24 for font F0 or 1..48 for font F1)
+ <Row> : Vertical position of the line (1‐14)
+ <n> : number of characters to be erased (1..24 for font F0 or 1..48 for font F1)
+
+$PCDUKTX                Write text attached to a Select Key
+===========================================================
+Syntax: $PCDUKTX,<KeyID>,<Texttype>,<Fsize>,<Fstyle>,<Rcolour>,<Gcolour>,<Bcolour>,<Text>*< checksum>CRLF
+ <KeyID> : Numbering is 00 – 49 for left keys and 50 – 99 for right keys. Top keys are 00 and 50.
+ <Texttype> : M or S, meaning Main text or Subtext.
+ <Fsize> : Font size (F0..F9). Currently F0 and F1 are implemented.
+ <Fstyle> : Font style (S=Standard, B=Bold, I=Italic, U=Underline, N=Negative)
+ < Rcolour > : RED (000‐255)
+ < Gcolour > : GREEN (000‐255)
+ < Bcolour > : BLUE (000‐255)
+ <Text> : Any printable ASCII character within the character set.except the * character as this is used as the text field delimiter. 
+ Maximum length is 24 characters, minimum length is 1 character for font F0
+ Maximum length is 48 characters, minumum length is 1 character for font F1.
+*/
+
+
+DigitalOut VGA_SOURCE( p7 ); // control line for video switch between internal and external video
+DigitalOut VGA_SELECT( p8 ); // select or deselect video switch
+
+//Control lines for VGA driver board
+TFT_4DGL display(p13,p14,p15); // serial tx, serial rx, reset pin
+
+//Character & String functions
+
+char* str2char( string cString ) //convert a string to a character array
+    {
+    int nStrLen=cString.size();
+    std::string cInput( cString );
+    char* cText = new char[nStrLen+1];
+    strncpy(cText, cInput.c_str(), nStrLen);
+    cText[nStrLen+1] = '\0';
+    return cText;
+    }
+    
+int centertext( string cString, int nChars, int nCharWidth )
+    //calculates the startposition on the screen to center the text
+    //needs the actual string (cString), screenwidth in characters (nChars) and the character width (nCharWidth)
+    {
+    int nStart;
+    nStart = nCharWidth*( nChars/2-( cString.size()/2 ));
+    return nStart;
+    }
+    
+int righttext( string cString, int nChars, int nCharWidth )
+    //calculates the startposition on the screen to right-align the text
+    //needs the actual string (cString), screenwidth in characters (nChars) and the character width (nCharWidth)
+    {
+    int nStart;
+    nStart = nCharWidth*( nChars - cString.size());
+    return nStart;
+    }
+
+void CDU_StartScreen()
+ {
+    string cTitle1="ENGRAVITY";
+    string cTitle2="CONTROL & DISPLAY UNIT";
+    display.cls();   
+    
+    display.graphic_string( str2char( cTitle1 ), centertext( cTitle1, 24, LARGECHAR), LINE6, FONT_24X34, WHITE, 1, 1 );
+    wait_ms(2000);
+    display.graphic_string( str2char( cTitle2 ), centertext( cTitle2, 24, LARGECHAR), LINE8, FONT_24X34, RED, 1, 1 );
+    wait_ms(2000);
+    display.graphic_string( str2char( cTitle2 ), centertext( cTitle2, 24, LARGECHAR), LINE8, FONT_24X34, GREEN, 1, 1 );
+    wait_ms(2000);
+    display.graphic_string( str2char( cTitle2) , centertext( cTitle2, 24, LARGECHAR), LINE8, FONT_24X34, BLUE, 1, 1 );
+    wait_ms(2000);
+    display.graphic_string( str2char( cTitle2) , centertext( cTitle2, 24, LARGECHAR), LINE8, FONT_24X34, WHITE, 1, 1 );
+    wait_ms(2000);
+ }
+
+void CDU_ScreenAlign()
+{
+    display.cls();
+    
+    display.pen_size(WIREFRAME);
+    display.rectangle(XMIN,YMIN,XMAX,YMAX, WHITE);
+    display.line(XMIN,LINE2,XMAX,LINE2, WHITE);
+    display.line(XMIN,LINE3,XMAX,LINE3, WHITE);
+    display.line(XMIN,LINE4,XMAX,LINE4, WHITE);
+    display.line(XMIN,LINE5,XMAX,LINE5, WHITE);
+    display.line(XMIN,LINE6,XMAX,LINE6, WHITE);
+    display.line(XMIN,LINE7,XMAX,LINE7, WHITE);
+    display.line(XMIN,LINE8,XMAX,LINE8, WHITE);
+    display.line(XMIN,LINE9,XMAX,LINE9, WHITE);
+    display.line(XMIN,LINE10,XMAX,LINE10, WHITE);
+    display.line(XMIN,LINE11,XMAX,LINE11, WHITE);
+    display.line(XMIN,LINE12,XMAX,LINE12, WHITE);
+    display.line(XMIN,LINE13,XMAX,LINE13, WHITE);
+    display.line(XMIN,LINE14,XMAX,LINE14, WHITE);
+
+}
\ No newline at end of file