C++ file for display control
Dependencies: 4DGL mbed ConfigFile
Fork of 4DGLtest by
display.cpp@3:f7bce78b04c1, 2014-06-26 (annotated)
- Committer:
- WillemBraat
- Date:
- Thu Jun 26 11:41:45 2014 +0000
- Revision:
- 3:f7bce78b04c1
- Child:
- 6:904d00252480
CDU Display code file
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
WillemBraat | 3:f7bce78b04c1 | 1 | //Display control functions -- |
WillemBraat | 3:f7bce78b04c1 | 2 | |
WillemBraat | 3:f7bce78b04c1 | 3 | #include "mbed.h" |
WillemBraat | 3:f7bce78b04c1 | 4 | #include "TFT_4DGL.h" |
WillemBraat | 3:f7bce78b04c1 | 5 | #include "display.h" |
WillemBraat | 3:f7bce78b04c1 | 6 | #include <string> |
WillemBraat | 3:f7bce78b04c1 | 7 | using namespace std; |
WillemBraat | 3:f7bce78b04c1 | 8 | |
WillemBraat | 3:f7bce78b04c1 | 9 | /* |
WillemBraat | 3:f7bce78b04c1 | 10 | ===================================================== |
WillemBraat | 3:f7bce78b04c1 | 11 | SGC (Serial Graphics Controller) PLATFORM OUTPUT FILE |
WillemBraat | 3:f7bce78b04c1 | 12 | ===================================================== |
WillemBraat | 3:f7bce78b04c1 | 13 | |
WillemBraat | 3:f7bce78b04c1 | 14 | ******************************************************* |
WillemBraat | 3:f7bce78b04c1 | 15 | * Must set 'New image format' for usage on Picaso SGC * |
WillemBraat | 3:f7bce78b04c1 | 16 | * Data: * |
WillemBraat | 3:f7bce78b04c1 | 17 | * 0x59, 0x06, 0x00 * |
WillemBraat | 3:f7bce78b04c1 | 18 | * 4DSL command: * |
WillemBraat | 3:f7bce78b04c1 | 19 | * Control(6,0) * |
WillemBraat | 3:f7bce78b04c1 | 20 | ******************************************************* |
WillemBraat | 3:f7bce78b04c1 | 21 | |
WillemBraat | 3:f7bce78b04c1 | 22 | --------------------------------------------------------------------------------------- |
WillemBraat | 3:f7bce78b04c1 | 23 | File "logo_flyengravity.jpg" (logo_flyengravity.jpg) |
WillemBraat | 3:f7bce78b04c1 | 24 | Sector Address 0x000000 |
WillemBraat | 3:f7bce78b04c1 | 25 | X = 0 Y = 135 Width = 640 Height = 215 Bits = 16 |
WillemBraat | 3:f7bce78b04c1 | 26 | |
WillemBraat | 3:f7bce78b04c1 | 27 | Display Image from Memory Card (Serial Command): |
WillemBraat | 3:f7bce78b04c1 | 28 | Syntax: |
WillemBraat | 3:f7bce78b04c1 | 29 | @, I, x, y, SectorAdd(hi), SectorAdd(mid), SectorAdd(lo) |
WillemBraat | 3:f7bce78b04c1 | 30 | Picaso Data: |
WillemBraat | 3:f7bce78b04c1 | 31 | 0x40, 0x49, 0x00, 0x00, 0x00, 0x87, 0x00, 0x00, 0x00 |
WillemBraat | 3:f7bce78b04c1 | 32 | 4DSL command: |
WillemBraat | 3:f7bce78b04c1 | 33 | NewUSDImage(0, 135, 0x000000) |
WillemBraat | 3:f7bce78b04c1 | 34 | |
WillemBraat | 3:f7bce78b04c1 | 35 | --------------------------------------------------------------------------------------- |
WillemBraat | 3:f7bce78b04c1 | 36 | File "Testscreen.png" (Testscreen.png) |
WillemBraat | 3:f7bce78b04c1 | 37 | Sector Address 0x00021A |
WillemBraat | 3:f7bce78b04c1 | 38 | X = 0 Y = 0 Width = 640 Height = 480 Bits = 16 |
WillemBraat | 3:f7bce78b04c1 | 39 | |
WillemBraat | 3:f7bce78b04c1 | 40 | Display Image from Memory Card (Serial Command): |
WillemBraat | 3:f7bce78b04c1 | 41 | Syntax: |
WillemBraat | 3:f7bce78b04c1 | 42 | @, I, x, y, SectorAdd(hi), SectorAdd(mid), SectorAdd(lo) |
WillemBraat | 3:f7bce78b04c1 | 43 | Picaso Data: |
WillemBraat | 3:f7bce78b04c1 | 44 | 0x40, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1A |
WillemBraat | 3:f7bce78b04c1 | 45 | 4DSL command: |
WillemBraat | 3:f7bce78b04c1 | 46 | NewUSDImage(0, 0, 0x00021A) |
WillemBraat | 3:f7bce78b04c1 | 47 | |
WillemBraat | 3:f7bce78b04c1 | 48 | */ |
WillemBraat | 3:f7bce78b04c1 | 49 | |
WillemBraat | 3:f7bce78b04c1 | 50 | /*Display Commands |
WillemBraat | 3:f7bce78b04c1 | 51 | |
WillemBraat | 3:f7bce78b04c1 | 52 | $PCDUCLS Erase to active background colour (default black) or white |
WillemBraat | 3:f7bce78b04c1 | 53 | =================================================================== |
WillemBraat | 3:f7bce78b04c1 | 54 | Syntax: $PCDUCLS, <mode>*<checksum>CRLF |
WillemBraat | 3:f7bce78b04c1 | 55 | <mode>=0 : Clear screen to current background colour (default=black) |
WillemBraat | 3:f7bce78b04c1 | 56 | <mode>=1 : Clear screen to white |
WillemBraat | 3:f7bce78b04c1 | 57 | |
WillemBraat | 3:f7bce78b04c1 | 58 | $PCDUSBC Set Background Color |
WillemBraat | 3:f7bce78b04c1 | 59 | ==================================================================== |
WillemBraat | 3:f7bce78b04c1 | 60 | Syntax: $PCDUSBC,<Rcolour>,<Gcolour>,<Bcolour>*<checksum>CRLF |
WillemBraat | 3:f7bce78b04c1 | 61 | < Rcolour > : RED (000‐255) |
WillemBraat | 3:f7bce78b04c1 | 62 | < Gcolour > : GREEN (000‐255) |
WillemBraat | 3:f7bce78b04c1 | 63 | < Bcolour > : BLUE (000‐255) |
WillemBraat | 3:f7bce78b04c1 | 64 | Set background colour to RGB as defined in the three data fields. |
WillemBraat | 3:f7bce78b04c1 | 65 | |
WillemBraat | 3:f7bce78b04c1 | 66 | $PCDUWTX WTX=WRITE TEXT Write text on any X,Y position on the screen. |
WillemBraat | 3:f7bce78b04c1 | 67 | ===================================================================== |
WillemBraat | 3:f7bce78b04c1 | 68 | Syntax: $PCDUWTX,<Fsize>,<Fstyle>,<Rcolour>,<Gcolour>,<Bcolour>,<Text><Col>,<Row>*<checksum>CRLF |
WillemBraat | 3:f7bce78b04c1 | 69 | <Fsize> : Font size (F0..F9). Currently F0 and F1 are implemented. |
WillemBraat | 3:f7bce78b04c1 | 70 | <Fstyle> : Font style (S=Standard, B=Bold, I=Italic, U=Underline, N=Negative) |
WillemBraat | 3:f7bce78b04c1 | 71 | < Rcolour > : RED (000‐255) |
WillemBraat | 3:f7bce78b04c1 | 72 | < Gcolour > : GREEN (000‐255) |
WillemBraat | 3:f7bce78b04c1 | 73 | < Bcolour > : BLUE (000‐255) |
WillemBraat | 3:f7bce78b04c1 | 74 | <Text> : Any printable ASCII character except the * character as this is used as the text field delimiter. |
WillemBraat | 3:f7bce78b04c1 | 75 | Maximum length is 24 characters, minimum length is 1 character for font F0. |
WillemBraat | 3:f7bce78b04c1 | 76 | Maximum length is 48 characters, minumum length is 1 character for font F1. |
WillemBraat | 3:f7bce78b04c1 | 77 | <Col> : Horizontal position of the first character (1..24) |
WillemBraat | 3:f7bce78b04c1 | 78 | <Row> : Vertical position of the line (1..14) |
WillemBraat | 3:f7bce78b04c1 | 79 | |
WillemBraat | 3:f7bce78b04c1 | 80 | $PCDUETX ETX=ERASE TEXT |
WillemBraat | 3:f7bce78b04c1 | 81 | ============================================================= |
WillemBraat | 3:f7bce78b04c1 | 82 | Syntax: $PCDUETX, <Col>,<Row>,<n>*<checksum>CRLF |
WillemBraat | 3:f7bce78b04c1 | 83 | <Col> : Horizontal position of the first character (1..24 for font F0 or 1..48 for font F1) |
WillemBraat | 3:f7bce78b04c1 | 84 | <Row> : Vertical position of the line (1‐14) |
WillemBraat | 3:f7bce78b04c1 | 85 | <n> : number of characters to be erased (1..24 for font F0 or 1..48 for font F1) |
WillemBraat | 3:f7bce78b04c1 | 86 | |
WillemBraat | 3:f7bce78b04c1 | 87 | $PCDUKTX Write text attached to a Select Key |
WillemBraat | 3:f7bce78b04c1 | 88 | =========================================================== |
WillemBraat | 3:f7bce78b04c1 | 89 | Syntax: $PCDUKTX,<KeyID>,<Texttype>,<Fsize>,<Fstyle>,<Rcolour>,<Gcolour>,<Bcolour>,<Text>*< checksum>CRLF |
WillemBraat | 3:f7bce78b04c1 | 90 | <KeyID> : Numbering is 00 – 49 for left keys and 50 – 99 for right keys. Top keys are 00 and 50. |
WillemBraat | 3:f7bce78b04c1 | 91 | <Texttype> : M or S, meaning Main text or Subtext. |
WillemBraat | 3:f7bce78b04c1 | 92 | <Fsize> : Font size (F0..F9). Currently F0 and F1 are implemented. |
WillemBraat | 3:f7bce78b04c1 | 93 | <Fstyle> : Font style (S=Standard, B=Bold, I=Italic, U=Underline, N=Negative) |
WillemBraat | 3:f7bce78b04c1 | 94 | < Rcolour > : RED (000‐255) |
WillemBraat | 3:f7bce78b04c1 | 95 | < Gcolour > : GREEN (000‐255) |
WillemBraat | 3:f7bce78b04c1 | 96 | < Bcolour > : BLUE (000‐255) |
WillemBraat | 3:f7bce78b04c1 | 97 | <Text> : Any printable ASCII character within the character set.except the * character as this is used as the text field delimiter. |
WillemBraat | 3:f7bce78b04c1 | 98 | Maximum length is 24 characters, minimum length is 1 character for font F0 |
WillemBraat | 3:f7bce78b04c1 | 99 | Maximum length is 48 characters, minumum length is 1 character for font F1. |
WillemBraat | 3:f7bce78b04c1 | 100 | */ |
WillemBraat | 3:f7bce78b04c1 | 101 | |
WillemBraat | 3:f7bce78b04c1 | 102 | |
WillemBraat | 3:f7bce78b04c1 | 103 | DigitalOut VGA_SOURCE( p7 ); // control line for video switch between internal and external video |
WillemBraat | 3:f7bce78b04c1 | 104 | DigitalOut VGA_SELECT( p8 ); // select or deselect video switch |
WillemBraat | 3:f7bce78b04c1 | 105 | |
WillemBraat | 3:f7bce78b04c1 | 106 | //Control lines for VGA driver board |
WillemBraat | 3:f7bce78b04c1 | 107 | TFT_4DGL display(p13,p14,p15); // serial tx, serial rx, reset pin |
WillemBraat | 3:f7bce78b04c1 | 108 | |
WillemBraat | 3:f7bce78b04c1 | 109 | //Character & String functions |
WillemBraat | 3:f7bce78b04c1 | 110 | |
WillemBraat | 3:f7bce78b04c1 | 111 | char* str2char( string cString ) //convert a string to a character array |
WillemBraat | 3:f7bce78b04c1 | 112 | { |
WillemBraat | 3:f7bce78b04c1 | 113 | int nStrLen=cString.size(); |
WillemBraat | 3:f7bce78b04c1 | 114 | std::string cInput( cString ); |
WillemBraat | 3:f7bce78b04c1 | 115 | char* cText = new char[nStrLen+1]; |
WillemBraat | 3:f7bce78b04c1 | 116 | strncpy(cText, cInput.c_str(), nStrLen); |
WillemBraat | 3:f7bce78b04c1 | 117 | cText[nStrLen+1] = '\0'; |
WillemBraat | 3:f7bce78b04c1 | 118 | return cText; |
WillemBraat | 3:f7bce78b04c1 | 119 | } |
WillemBraat | 3:f7bce78b04c1 | 120 | |
WillemBraat | 3:f7bce78b04c1 | 121 | int centertext( string cString, int nChars, int nCharWidth ) |
WillemBraat | 3:f7bce78b04c1 | 122 | //calculates the startposition on the screen to center the text |
WillemBraat | 3:f7bce78b04c1 | 123 | //needs the actual string (cString), screenwidth in characters (nChars) and the character width (nCharWidth) |
WillemBraat | 3:f7bce78b04c1 | 124 | { |
WillemBraat | 3:f7bce78b04c1 | 125 | int nStart; |
WillemBraat | 3:f7bce78b04c1 | 126 | nStart = nCharWidth*( nChars/2-( cString.size()/2 )); |
WillemBraat | 3:f7bce78b04c1 | 127 | return nStart; |
WillemBraat | 3:f7bce78b04c1 | 128 | } |
WillemBraat | 3:f7bce78b04c1 | 129 | |
WillemBraat | 3:f7bce78b04c1 | 130 | int righttext( string cString, int nChars, int nCharWidth ) |
WillemBraat | 3:f7bce78b04c1 | 131 | //calculates the startposition on the screen to right-align the text |
WillemBraat | 3:f7bce78b04c1 | 132 | //needs the actual string (cString), screenwidth in characters (nChars) and the character width (nCharWidth) |
WillemBraat | 3:f7bce78b04c1 | 133 | { |
WillemBraat | 3:f7bce78b04c1 | 134 | int nStart; |
WillemBraat | 3:f7bce78b04c1 | 135 | nStart = nCharWidth*( nChars - cString.size()); |
WillemBraat | 3:f7bce78b04c1 | 136 | return nStart; |
WillemBraat | 3:f7bce78b04c1 | 137 | } |
WillemBraat | 3:f7bce78b04c1 | 138 | |
WillemBraat | 3:f7bce78b04c1 | 139 | void CDU_StartScreen() |
WillemBraat | 3:f7bce78b04c1 | 140 | { |
WillemBraat | 3:f7bce78b04c1 | 141 | string cTitle1="ENGRAVITY"; |
WillemBraat | 3:f7bce78b04c1 | 142 | string cTitle2="CONTROL & DISPLAY UNIT"; |
WillemBraat | 3:f7bce78b04c1 | 143 | display.cls(); |
WillemBraat | 3:f7bce78b04c1 | 144 | |
WillemBraat | 3:f7bce78b04c1 | 145 | display.graphic_string( str2char( cTitle1 ), centertext( cTitle1, 24, LARGECHAR), LINE6, FONT_24X34, WHITE, 1, 1 ); |
WillemBraat | 3:f7bce78b04c1 | 146 | wait_ms(2000); |
WillemBraat | 3:f7bce78b04c1 | 147 | display.graphic_string( str2char( cTitle2 ), centertext( cTitle2, 24, LARGECHAR), LINE8, FONT_24X34, RED, 1, 1 ); |
WillemBraat | 3:f7bce78b04c1 | 148 | wait_ms(2000); |
WillemBraat | 3:f7bce78b04c1 | 149 | display.graphic_string( str2char( cTitle2 ), centertext( cTitle2, 24, LARGECHAR), LINE8, FONT_24X34, GREEN, 1, 1 ); |
WillemBraat | 3:f7bce78b04c1 | 150 | wait_ms(2000); |
WillemBraat | 3:f7bce78b04c1 | 151 | display.graphic_string( str2char( cTitle2) , centertext( cTitle2, 24, LARGECHAR), LINE8, FONT_24X34, BLUE, 1, 1 ); |
WillemBraat | 3:f7bce78b04c1 | 152 | wait_ms(2000); |
WillemBraat | 3:f7bce78b04c1 | 153 | display.graphic_string( str2char( cTitle2) , centertext( cTitle2, 24, LARGECHAR), LINE8, FONT_24X34, WHITE, 1, 1 ); |
WillemBraat | 3:f7bce78b04c1 | 154 | wait_ms(2000); |
WillemBraat | 3:f7bce78b04c1 | 155 | } |
WillemBraat | 3:f7bce78b04c1 | 156 | |
WillemBraat | 3:f7bce78b04c1 | 157 | void CDU_ScreenAlign() |
WillemBraat | 3:f7bce78b04c1 | 158 | { |
WillemBraat | 3:f7bce78b04c1 | 159 | display.cls(); |
WillemBraat | 3:f7bce78b04c1 | 160 | |
WillemBraat | 3:f7bce78b04c1 | 161 | display.pen_size(WIREFRAME); |
WillemBraat | 3:f7bce78b04c1 | 162 | display.rectangle(XMIN,YMIN,XMAX,YMAX, WHITE); |
WillemBraat | 3:f7bce78b04c1 | 163 | display.line(XMIN,LINE2,XMAX,LINE2, WHITE); |
WillemBraat | 3:f7bce78b04c1 | 164 | display.line(XMIN,LINE3,XMAX,LINE3, WHITE); |
WillemBraat | 3:f7bce78b04c1 | 165 | display.line(XMIN,LINE4,XMAX,LINE4, WHITE); |
WillemBraat | 3:f7bce78b04c1 | 166 | display.line(XMIN,LINE5,XMAX,LINE5, WHITE); |
WillemBraat | 3:f7bce78b04c1 | 167 | display.line(XMIN,LINE6,XMAX,LINE6, WHITE); |
WillemBraat | 3:f7bce78b04c1 | 168 | display.line(XMIN,LINE7,XMAX,LINE7, WHITE); |
WillemBraat | 3:f7bce78b04c1 | 169 | display.line(XMIN,LINE8,XMAX,LINE8, WHITE); |
WillemBraat | 3:f7bce78b04c1 | 170 | display.line(XMIN,LINE9,XMAX,LINE9, WHITE); |
WillemBraat | 3:f7bce78b04c1 | 171 | display.line(XMIN,LINE10,XMAX,LINE10, WHITE); |
WillemBraat | 3:f7bce78b04c1 | 172 | display.line(XMIN,LINE11,XMAX,LINE11, WHITE); |
WillemBraat | 3:f7bce78b04c1 | 173 | display.line(XMIN,LINE12,XMAX,LINE12, WHITE); |
WillemBraat | 3:f7bce78b04c1 | 174 | display.line(XMIN,LINE13,XMAX,LINE13, WHITE); |
WillemBraat | 3:f7bce78b04c1 | 175 | display.line(XMIN,LINE14,XMAX,LINE14, WHITE); |
WillemBraat | 3:f7bce78b04c1 | 176 | |
WillemBraat | 3:f7bce78b04c1 | 177 | } |