C++ file for display control

Dependencies:   4DGL mbed ConfigFile

Fork of 4DGLtest by Stephane ROCHON

Committer:
WillemBraat
Date:
Wed Jul 16 19:15:40 2014 +0000
Revision:
11:a5b0d98794c0
Parent:
7:779c5b8d3b14
Rewritten function CDU_DSP_CSS()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WillemBraat 6:904d00252480 1 #include "mbed.h"
WillemBraat 6:904d00252480 2 #include "TFT_4DGL.h"
WillemBraat 6:904d00252480 3 #include "display.h"
WillemBraat 7:779c5b8d3b14 4 #include "fs_datastructures.h"
WillemBraat 7:779c5b8d3b14 5
WillemBraat 7:779c5b8d3b14 6 #include <string>
WillemBraat 7:779c5b8d3b14 7 using namespace std;
WillemBraat 6:904d00252480 8
WillemBraat 6:904d00252480 9
WillemBraat 6:904d00252480 10 // ---- FS-to-CDU data structures filled with received data ---------------------------------------
WillemBraat 6:904d00252480 11
WillemBraat 6:904d00252480 12 #define max_text0 48 // max text length font 0
WillemBraat 6:904d00252480 13 #define max_text1 24 // max text length font 1
WillemBraat 6:904d00252480 14 #define max_lines 14 // max nr of screen lines
WillemBraat 6:904d00252480 15 #define max_font 1 // possible fonts are 0 to max_font, so now 0 and 1 possible
WillemBraat 6:904d00252480 16 #define max_col_nr 255 // highest possible R,G, or B colour number
WillemBraat 6:904d00252480 17 #define fstyle_1 'S' // possible font style character 1
WillemBraat 6:904d00252480 18 #define fstyle_2 'N' // possible font style character 2
WillemBraat 6:904d00252480 19 #define max_keys 100 // max total nr of select keys 0 - 99
WillemBraat 6:904d00252480 20 #define max_leftkeys 6 // max nr of used LEFT select keys ( 0 - 49 )
WillemBraat 6:904d00252480 21 #define max_rightkeys 6 // max nr of used RIGHT select keys ( 50 - 99 )
WillemBraat 6:904d00252480 22
WillemBraat 7:779c5b8d3b14 23 extern int FSdata_received_flag; //Prototype of data flag (declared in main.cpp)
WillemBraat 7:779c5b8d3b14 24 extern TFT_4DGL display; //Prototype of Display Driver (declared in display.cpp)
WillemBraat 6:904d00252480 25
WillemBraat 7:779c5b8d3b14 26 //Prototype of indicators (declared in keyboard.cpp)
WillemBraat 7:779c5b8d3b14 27 extern DigitalOut EXEC;
WillemBraat 7:779c5b8d3b14 28 extern DigitalOut FAIL;
WillemBraat 7:779c5b8d3b14 29 extern DigitalOut DSPY;
WillemBraat 7:779c5b8d3b14 30 extern DigitalOut MSG;
WillemBraat 7:779c5b8d3b14 31 extern DigitalOut OFST;
WillemBraat 6:904d00252480 32
WillemBraat 7:779c5b8d3b14 33 extern void CDU_SET_BGL_INTENSITY( int nVal ); //Prototype of function controlling CDU backlight (declared in keyboard.cpp)
WillemBraat 7:779c5b8d3b14 34 extern int nFontSize( int nfont_number ); //Prototype of function for fontselection (declared in display.cpp)
WillemBraat 7:779c5b8d3b14 35 extern int nFontWidth (int nfont_number ); //Prototype of function to retrieve font width (declared in display.cpp)
WillemBraat 7:779c5b8d3b14 36 extern int nLine2Pixel( int nLine ); //Prototype of function to calculate vertical pixelposition from line number (declared in display.cpp)
WillemBraat 7:779c5b8d3b14 37 extern int LeftOrRight( int nTextLine, string cString, int nChars, int nCharWidth ); //declared in display.cpp
WillemBraat 11:a5b0d98794c0 38 extern unsigned int cRGB( char cRED, char cGREEN, char cBLUE ); //Prototype of function for assembly color word (declared in display.cpp)
WillemBraat 6:904d00252480 39
WillemBraat 7:779c5b8d3b14 40 // FS_data_update_ID:
WillemBraat 7:779c5b8d3b14 41 // These global flags indicate what data has been updated.
WillemBraat 7:779c5b8d3b14 42 // Should be tested when FS_DATA_EVENT occurs.
WillemBraat 7:779c5b8d3b14 43 extern int Background_Col_Update; // 1 when color was updated, must be reset to 0 when data has been read
WillemBraat 7:779c5b8d3b14 44 extern int CDU_Status_Update ; // 1 when status was updated, must be reset to 0 when data has been read
WillemBraat 7:779c5b8d3b14 45 extern int DO_CLR_SCREEN ; // 1 when screen should be cleared, must be reset to 0 when done
WillemBraat 7:779c5b8d3b14 46 extern int Text_Line_Update ; // equal to line number whose text was updated, must be reset to 0 when text has been read
WillemBraat 7:779c5b8d3b14 47 extern int Key_Maintext_Update ; // equal to keynumber whose main text line was updated, must be reset to -1 (!)when text has been read
WillemBraat 7:779c5b8d3b14 48 extern int Key_Subtext_Update ; // equal to keynumber whose sub text line was updated, must be reset to -1 (!) when text has been read
WillemBraat 6:904d00252480 49
WillemBraat 6:904d00252480 50 // Common flag to signal that one or more updates were performed:
WillemBraat 6:904d00252480 51 int FSdata_received_flag = false; // : true when one or more FS-to-CDU data structures were updated
WillemBraat 6:904d00252480 52
WillemBraat 6:904d00252480 53 // --------------------------------------------------------------------------------------------------
WillemBraat 6:904d00252480 54
WillemBraat 7:779c5b8d3b14 55 void CDU_DSP_CSS()
WillemBraat 7:779c5b8d3b14 56 /*Check flags to see if action is required
WillemBraat 7:779c5b8d3b14 57 Background_Col_Update; // : 1 when color was updated, must be reset to 0 when data has been read
WillemBraat 7:779c5b8d3b14 58 CDU_Status_Update ; // : 1 when status was updated, must be reset to 0 when data has been read
WillemBraat 7:779c5b8d3b14 59 DO_CLR_SCREEN ; // : 1 when screen should be cleared, must be reset to 0 when done
WillemBraat 7:779c5b8d3b14 60 Text_Line_Update ; // : equal to line number whose text was updated, must be reset to 0 when text has been read
WillemBraat 7:779c5b8d3b14 61 Key_Maintext_Update ; // : equal to keynumber whose main text line was updated, must be reset to -1 (!)when text has been read
WillemBraat 7:779c5b8d3b14 62 Key_Subtext_Update ; // : equal to keynumber whose sub text line was updated, must be reset to -1 (!) when text has been read
WillemBraat 7:779c5b8d3b14 63 */
WillemBraat 11:a5b0d98794c0 64
WillemBraat 6:904d00252480 65 {
WillemBraat 11:a5b0d98794c0 66 int nLine = 1; //default value
WillemBraat 6:904d00252480 67 //check common flag
WillemBraat 6:904d00252480 68 if ( FSdata_received_flag )
WillemBraat 7:779c5b8d3b14 69 //if set, check all structures and lock dynamic storage
WillemBraat 6:904d00252480 70 {
WillemBraat 7:779c5b8d3b14 71 if ( Background_Col_Update == 1)
WillemBraat 6:904d00252480 72 {
WillemBraat 6:904d00252480 73 display.background_color( cRGB( BACKGROUND_COL.BG_RED, BACKGROUND_COL.BG_GREEN, BACKGROUND_COL.BG_BLUE ) );
WillemBraat 7:779c5b8d3b14 74 Background_Col_Update = 0;
WillemBraat 6:904d00252480 75 }
WillemBraat 11:a5b0d98794c0 76
WillemBraat 7:779c5b8d3b14 77 if ( Key_Maintext_Update > -1 )
WillemBraat 7:779c5b8d3b14 78 //Key_Maintext_Update contains the line number 00-49 is LSK text, 50-99 is RSK text
WillemBraat 7:779c5b8d3b14 79 //Currently used:
WillemBraat 7:779c5b8d3b14 80 //00-14 left side of screen --> left adjust, horizontal position = 0
WillemBraat 7:779c5b8d3b14 81 //50-64 right side of screen --> right adjust, horizontal position calculated with righttext() (declared in display.cpp)
WillemBraat 11:a5b0d98794c0 82
WillemBraat 11:a5b0d98794c0 83 //00 = LSK1 50 = RSK1 Print on LINE 3
WillemBraat 11:a5b0d98794c0 84 //01 = LSK2 51 = RSK2 Print on LINE 5
WillemBraat 11:a5b0d98794c0 85 //02 = LSK3 52 = RSK3 Print on LINE 7
WillemBraat 11:a5b0d98794c0 86 //03 = LSK4 53 = RSK4 Print on LINE 9
WillemBraat 11:a5b0d98794c0 87 //04 = LSK5 54 = RSK5 Print on LINE 11
WillemBraat 11:a5b0d98794c0 88 //05 = LSK6 55 = RSK6 Print on LINE 13
WillemBraat 6:904d00252480 89 {
WillemBraat 11:a5b0d98794c0 90 switch ( Key_Maintext_Update )
WillemBraat 11:a5b0d98794c0 91 {
WillemBraat 11:a5b0d98794c0 92 case ( 00 ): nLine = 3; break;
WillemBraat 11:a5b0d98794c0 93 case ( 50 ): nLine = 3; break;
WillemBraat 11:a5b0d98794c0 94 case ( 01 ): nLine = 5; break;
WillemBraat 11:a5b0d98794c0 95 case ( 51 ): nLine = 5; break;
WillemBraat 11:a5b0d98794c0 96 case ( 02 ): nLine = 7; break;
WillemBraat 11:a5b0d98794c0 97 case ( 52 ): nLine = 7; break;
WillemBraat 11:a5b0d98794c0 98 case ( 03 ): nLine = 9; break;
WillemBraat 11:a5b0d98794c0 99 case ( 53 ): nLine = 9; break;
WillemBraat 11:a5b0d98794c0 100 case ( 04 ): nLine = 11; break;
WillemBraat 11:a5b0d98794c0 101 case ( 54 ): nLine = 11; break;
WillemBraat 11:a5b0d98794c0 102 case ( 05 ): nLine = 13; break;
WillemBraat 11:a5b0d98794c0 103 case ( 55 ): nLine = 13; break;
WillemBraat 11:a5b0d98794c0 104 }
WillemBraat 7:779c5b8d3b14 105 //display.graphic_string(char *s, int x, int y, char font, int color, char width multiplier, char height multiplier)
WillemBraat 7:779c5b8d3b14 106 display.graphic_string( SELKEY_MAINTEXT[Key_Maintext_Update].text , //Text to display
WillemBraat 7:779c5b8d3b14 107 LeftOrRight( Key_Maintext_Update, SELKEY_MAINTEXT[Key_Maintext_Update].text,24,24 )*nFontWidth( SELKEY_MAINTEXT[Key_Maintext_Update].font_size ) , //Horizontal position
WillemBraat 11:a5b0d98794c0 108 nLine2Pixel( nLine ), //Vertical position
WillemBraat 7:779c5b8d3b14 109 nFontSize( SELKEY_MAINTEXT[Key_Maintext_Update].font_size ), //Font
WillemBraat 7:779c5b8d3b14 110 cRGB( SELKEY_MAINTEXT[Key_Maintext_Update].text_RED ,SELKEY_MAINTEXT[Key_Maintext_Update].text_GREEN ,SELKEY_MAINTEXT[Key_Maintext_Update].text_BLUE ),
WillemBraat 7:779c5b8d3b14 111 1, 1 );
WillemBraat 7:779c5b8d3b14 112 Key_Maintext_Update = -1;
WillemBraat 6:904d00252480 113 }
WillemBraat 11:a5b0d98794c0 114
WillemBraat 7:779c5b8d3b14 115 if ( Key_Subtext_Update > -1 )
WillemBraat 7:779c5b8d3b14 116 //Key Subtext_Update contains the line number 00-49 is LSK subtext, 50-99 is RSK subtext
WillemBraat 7:779c5b8d3b14 117 //Currently used:
WillemBraat 7:779c5b8d3b14 118 //00-14 left side of screen --> left adjust, horizontal position = 0
WillemBraat 7:779c5b8d3b14 119 //50-64 right side of screen --> right adjust, horizontal position calculated with righttext() (declared in display.cpp)
WillemBraat 11:a5b0d98794c0 120 //00 = LSK1 50 = RSK1 Print on LINE 2
WillemBraat 11:a5b0d98794c0 121 //01 = LSK2 51 = RSK2 Print on LINE 4
WillemBraat 11:a5b0d98794c0 122 //02 = LSK3 52 = RSK3 Print on LINE 6
WillemBraat 11:a5b0d98794c0 123 //03 = LSK4 53 = RSK4 Print on LINE 8
WillemBraat 11:a5b0d98794c0 124 //04 = LSK5 54 = RSK5 Print on LINE 10
WillemBraat 11:a5b0d98794c0 125 //05 = LSK6 55 = RSK6 Print on LINE 12
WillemBraat 6:904d00252480 126 {
WillemBraat 11:a5b0d98794c0 127 switch ( Key_Maintext_Update )
WillemBraat 11:a5b0d98794c0 128 {
WillemBraat 11:a5b0d98794c0 129 case ( 00 ): nLine = 2; break;
WillemBraat 11:a5b0d98794c0 130 case ( 50 ): nLine = 2; break;
WillemBraat 11:a5b0d98794c0 131 case ( 01 ): nLine = 4; break;
WillemBraat 11:a5b0d98794c0 132 case ( 51 ): nLine = 4; break;
WillemBraat 11:a5b0d98794c0 133 case ( 02 ): nLine = 6; break;
WillemBraat 11:a5b0d98794c0 134 case ( 52 ): nLine = 6; break;
WillemBraat 11:a5b0d98794c0 135 case ( 03 ): nLine = 8; break;
WillemBraat 11:a5b0d98794c0 136 case ( 53 ): nLine = 8; break;
WillemBraat 11:a5b0d98794c0 137 case ( 04 ): nLine = 10; break;
WillemBraat 11:a5b0d98794c0 138 case ( 54 ): nLine = 10; break;
WillemBraat 11:a5b0d98794c0 139 case ( 05 ): nLine = 12; break;
WillemBraat 11:a5b0d98794c0 140 case ( 55 ): nLine = 12; break;
WillemBraat 11:a5b0d98794c0 141 }
WillemBraat 7:779c5b8d3b14 142 //display.graphic_string(char *s, int x, int y, char font, int color, char width multiplier, char height multiplier)
WillemBraat 7:779c5b8d3b14 143 display.graphic_string( SELKEY_SUBTEXT[Key_Subtext_Update].text , //Text to display
WillemBraat 7:779c5b8d3b14 144 LeftOrRight( Key_Subtext_Update, SELKEY_SUBTEXT[Key_Subtext_Update].text,12,48 )*nFontWidth( SELKEY_SUBTEXT[Key_Subtext_Update].font_size ) , //Horizontal position
WillemBraat 11:a5b0d98794c0 145 nLine2Pixel( nLine ), //Vertical position
WillemBraat 7:779c5b8d3b14 146 nFontSize( SELKEY_SUBTEXT[Key_Subtext_Update].font_size ), //Font
WillemBraat 7:779c5b8d3b14 147 cRGB( SELKEY_SUBTEXT[Key_Subtext_Update].text_RED ,SELKEY_SUBTEXT[Key_Subtext_Update].text_GREEN ,SELKEY_SUBTEXT[Key_Subtext_Update].text_BLUE ),
WillemBraat 7:779c5b8d3b14 148 1, 1 ); //multiplier always on 1
WillemBraat 7:779c5b8d3b14 149 Key_Subtext_Update = -1;
WillemBraat 6:904d00252480 150 }
WillemBraat 11:a5b0d98794c0 151
WillemBraat 7:779c5b8d3b14 152 if ( Text_Line_Update > 0)
WillemBraat 6:904d00252480 153 {
WillemBraat 7:779c5b8d3b14 154 //Text_Line_Update contains the the line number to write
WillemBraat 7:779c5b8d3b14 155 display.graphic_string( TEXTLINE[Text_Line_Update].text , //Text to display
WillemBraat 7:779c5b8d3b14 156 0, //Horizontal position always 0
WillemBraat 7:779c5b8d3b14 157 nLine2Pixel( Text_Line_Update ), //Vertical position
WillemBraat 7:779c5b8d3b14 158 nFontSize( TEXTLINE[Text_Line_Update].font_size ), //Font
WillemBraat 7:779c5b8d3b14 159 cRGB( TEXTLINE[Text_Line_Update].text_RED ,TEXTLINE[Text_Line_Update].text_GREEN ,TEXTLINE[Text_Line_Update].text_BLUE ),
WillemBraat 7:779c5b8d3b14 160 1, 1 ); //multiplier always on 1
WillemBraat 7:779c5b8d3b14 161 Text_Line_Update = 0;
WillemBraat 6:904d00252480 162 }
WillemBraat 11:a5b0d98794c0 163
WillemBraat 7:779c5b8d3b14 164 if ( CDU_Status_Update == 1 )
WillemBraat 6:904d00252480 165 {
WillemBraat 7:779c5b8d3b14 166 /*
WillemBraat 7:779c5b8d3b14 167 CDU_STATUS.stby_mode; // : 0 = operational mode, 1 = standby mode
WillemBraat 7:779c5b8d3b14 168 */ if ( CDU_STATUS.backlight ) // Backlight control
WillemBraat 7:779c5b8d3b14 169 {
WillemBraat 7:779c5b8d3b14 170 CDU_SET_BGL_INTENSITY( 255 );
WillemBraat 7:779c5b8d3b14 171 }
WillemBraat 7:779c5b8d3b14 172 else
WillemBraat 7:779c5b8d3b14 173 {
WillemBraat 7:779c5b8d3b14 174 CDU_SET_BGL_INTENSITY( 0 );
WillemBraat 7:779c5b8d3b14 175 }
WillemBraat 7:779c5b8d3b14 176 // Set CDU indicators
WillemBraat 7:779c5b8d3b14 177 MSG = CDU_STATUS.msg_indicator;
WillemBraat 7:779c5b8d3b14 178 EXEC = CDU_STATUS.exec_indicator;
WillemBraat 7:779c5b8d3b14 179 FAIL = CDU_STATUS.fail_indicator;
WillemBraat 7:779c5b8d3b14 180 DSPY = CDU_STATUS.dspy_indicator;
WillemBraat 7:779c5b8d3b14 181 OFST = CDU_STATUS.ofst_indicator;
WillemBraat 7:779c5b8d3b14 182
WillemBraat 7:779c5b8d3b14 183 CDU_Status_Update =0;
WillemBraat 6:904d00252480 184 }
WillemBraat 6:904d00252480 185 if ( DO_CLR_SCREEN )
WillemBraat 6:904d00252480 186 {
WillemBraat 6:904d00252480 187 display.cls();
WillemBraat 7:779c5b8d3b14 188 DO_CLR_SCREEN =0;
WillemBraat 6:904d00252480 189 }
WillemBraat 6:904d00252480 190 }
WillemBraat 7:779c5b8d3b14 191 //Reset global flag and release lock on dynamic storage
WillemBraat 6:904d00252480 192 FSdata_received_flag = false ;
WillemBraat 6:904d00252480 193 }
WillemBraat 6:904d00252480 194
WillemBraat 6:904d00252480 195 /*
WillemBraat 6:904d00252480 196 void GET_NEW_DATA_TASK(void) // : read new screendata from FS datastructures
WillemBraat 6:904d00252480 197 {
WillemBraat 6:904d00252480 198 while(1) { // : loop forever because it is a mbos taskfunction
WillemBraat 6:904d00252480 199 CDU_OS.WaitEvent(FS_DATA_EVENT);
WillemBraat 6:904d00252480 200 CDU_OS.LockResource(FS_DATA_RESOURCE); //lock resource to prevent intermediate updates
WillemBraat 6:904d00252480 201 CDU_CSS()
WillemBraat 6:904d00252480 202 CDU_OS.FreeResource(FS_DATA_RESOURCE); //free resource
WillemBraat 6:904d00252480 203 }
WillemBraat 6:904d00252480 204 }
WillemBraat 6:904d00252480 205 */