C++ file for display control
Dependencies: 4DGL mbed ConfigFile
Fork of 4DGLtest by
fs_datastructures.cpp@7:779c5b8d3b14, 2014-07-05 (annotated)
- Committer:
- WillemBraat
- Date:
- Sat Jul 05 16:32:03 2014 +0000
- Revision:
- 7:779c5b8d3b14
- Parent:
- structures.cpp@6:904d00252480
- Child:
- 11:a5b0d98794c0
Display functions completed
Who changed what in which revision?
User | Revision | Line number | New 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 | 7:779c5b8d3b14 | 38 | extern int cRGB( int cRED, int cGREEN, int 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 | 6:904d00252480 | 64 | |
WillemBraat | 6:904d00252480 | 65 | { |
WillemBraat | 6:904d00252480 | 66 | //check common flag |
WillemBraat | 6:904d00252480 | 67 | if ( FSdata_received_flag ) |
WillemBraat | 7:779c5b8d3b14 | 68 | //if set, check all structures and lock dynamic storage |
WillemBraat | 6:904d00252480 | 69 | { |
WillemBraat | 7:779c5b8d3b14 | 70 | if ( Background_Col_Update == 1) |
WillemBraat | 6:904d00252480 | 71 | { |
WillemBraat | 6:904d00252480 | 72 | display.background_color( cRGB( BACKGROUND_COL.BG_RED, BACKGROUND_COL.BG_GREEN, BACKGROUND_COL.BG_BLUE ) ); |
WillemBraat | 7:779c5b8d3b14 | 73 | Background_Col_Update = 0; |
WillemBraat | 6:904d00252480 | 74 | } |
WillemBraat | 7:779c5b8d3b14 | 75 | if ( Key_Maintext_Update > -1 ) |
WillemBraat | 7:779c5b8d3b14 | 76 | //Key_Maintext_Update contains the line number 00-49 is LSK text, 50-99 is RSK text |
WillemBraat | 7:779c5b8d3b14 | 77 | //Currently used: |
WillemBraat | 7:779c5b8d3b14 | 78 | //00-14 left side of screen --> left adjust, horizontal position = 0 |
WillemBraat | 7:779c5b8d3b14 | 79 | //50-64 right side of screen --> right adjust, horizontal position calculated with righttext() (declared in display.cpp) |
WillemBraat | 6:904d00252480 | 80 | { |
WillemBraat | 7:779c5b8d3b14 | 81 | //display.graphic_string(char *s, int x, int y, char font, int color, char width multiplier, char height multiplier) |
WillemBraat | 7:779c5b8d3b14 | 82 | display.graphic_string( SELKEY_MAINTEXT[Key_Maintext_Update].text , //Text to display |
WillemBraat | 7:779c5b8d3b14 | 83 | LeftOrRight( Key_Maintext_Update, SELKEY_MAINTEXT[Key_Maintext_Update].text,24,24 )*nFontWidth( SELKEY_MAINTEXT[Key_Maintext_Update].font_size ) , //Horizontal position |
WillemBraat | 7:779c5b8d3b14 | 84 | nLine2Pixel( Key_Maintext_Update ), //Vertical position |
WillemBraat | 7:779c5b8d3b14 | 85 | nFontSize( SELKEY_MAINTEXT[Key_Maintext_Update].font_size ), //Font |
WillemBraat | 7:779c5b8d3b14 | 86 | 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 | 87 | 1, 1 ); |
WillemBraat | 7:779c5b8d3b14 | 88 | Key_Maintext_Update = -1; |
WillemBraat | 6:904d00252480 | 89 | } |
WillemBraat | 7:779c5b8d3b14 | 90 | if ( Key_Subtext_Update > -1 ) |
WillemBraat | 7:779c5b8d3b14 | 91 | //Key Subtext_Update contains the line number 00-49 is LSK subtext, 50-99 is RSK subtext |
WillemBraat | 7:779c5b8d3b14 | 92 | //Currently used: |
WillemBraat | 7:779c5b8d3b14 | 93 | //00-14 left side of screen --> left adjust, horizontal position = 0 |
WillemBraat | 7:779c5b8d3b14 | 94 | //50-64 right side of screen --> right adjust, horizontal position calculated with righttext() (declared in display.cpp) |
WillemBraat | 6:904d00252480 | 95 | { |
WillemBraat | 7:779c5b8d3b14 | 96 | //display.graphic_string(char *s, int x, int y, char font, int color, char width multiplier, char height multiplier) |
WillemBraat | 7:779c5b8d3b14 | 97 | display.graphic_string( SELKEY_SUBTEXT[Key_Subtext_Update].text , //Text to display |
WillemBraat | 7:779c5b8d3b14 | 98 | LeftOrRight( Key_Subtext_Update, SELKEY_SUBTEXT[Key_Subtext_Update].text,12,48 )*nFontWidth( SELKEY_SUBTEXT[Key_Subtext_Update].font_size ) , //Horizontal position |
WillemBraat | 7:779c5b8d3b14 | 99 | nLine2Pixel( Key_Subtext_Update ), //Vertical position |
WillemBraat | 7:779c5b8d3b14 | 100 | nFontSize( SELKEY_SUBTEXT[Key_Subtext_Update].font_size ), //Font |
WillemBraat | 7:779c5b8d3b14 | 101 | 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 | 102 | 1, 1 ); //multiplier always on 1 |
WillemBraat | 7:779c5b8d3b14 | 103 | Key_Subtext_Update = -1; |
WillemBraat | 6:904d00252480 | 104 | } |
WillemBraat | 7:779c5b8d3b14 | 105 | if ( Text_Line_Update > 0) |
WillemBraat | 6:904d00252480 | 106 | { |
WillemBraat | 7:779c5b8d3b14 | 107 | //Text_Line_Update contains the the line number to write |
WillemBraat | 7:779c5b8d3b14 | 108 | display.graphic_string( TEXTLINE[Text_Line_Update].text , //Text to display |
WillemBraat | 7:779c5b8d3b14 | 109 | 0, //Horizontal position always 0 |
WillemBraat | 7:779c5b8d3b14 | 110 | nLine2Pixel( Text_Line_Update ), //Vertical position |
WillemBraat | 7:779c5b8d3b14 | 111 | nFontSize( TEXTLINE[Text_Line_Update].font_size ), //Font |
WillemBraat | 7:779c5b8d3b14 | 112 | cRGB( TEXTLINE[Text_Line_Update].text_RED ,TEXTLINE[Text_Line_Update].text_GREEN ,TEXTLINE[Text_Line_Update].text_BLUE ), |
WillemBraat | 7:779c5b8d3b14 | 113 | 1, 1 ); //multiplier always on 1 |
WillemBraat | 7:779c5b8d3b14 | 114 | Text_Line_Update = 0; |
WillemBraat | 6:904d00252480 | 115 | } |
WillemBraat | 7:779c5b8d3b14 | 116 | if ( CDU_Status_Update == 1 ) |
WillemBraat | 6:904d00252480 | 117 | { |
WillemBraat | 7:779c5b8d3b14 | 118 | /* |
WillemBraat | 7:779c5b8d3b14 | 119 | CDU_STATUS.stby_mode; // : 0 = operational mode, 1 = standby mode |
WillemBraat | 7:779c5b8d3b14 | 120 | */ if ( CDU_STATUS.backlight ) // Backlight control |
WillemBraat | 7:779c5b8d3b14 | 121 | { |
WillemBraat | 7:779c5b8d3b14 | 122 | CDU_SET_BGL_INTENSITY( 255 ); |
WillemBraat | 7:779c5b8d3b14 | 123 | } |
WillemBraat | 7:779c5b8d3b14 | 124 | else |
WillemBraat | 7:779c5b8d3b14 | 125 | { |
WillemBraat | 7:779c5b8d3b14 | 126 | CDU_SET_BGL_INTENSITY( 0 ); |
WillemBraat | 7:779c5b8d3b14 | 127 | } |
WillemBraat | 7:779c5b8d3b14 | 128 | // Set CDU indicators |
WillemBraat | 7:779c5b8d3b14 | 129 | MSG = CDU_STATUS.msg_indicator; |
WillemBraat | 7:779c5b8d3b14 | 130 | EXEC = CDU_STATUS.exec_indicator; |
WillemBraat | 7:779c5b8d3b14 | 131 | FAIL = CDU_STATUS.fail_indicator; |
WillemBraat | 7:779c5b8d3b14 | 132 | DSPY = CDU_STATUS.dspy_indicator; |
WillemBraat | 7:779c5b8d3b14 | 133 | OFST = CDU_STATUS.ofst_indicator; |
WillemBraat | 7:779c5b8d3b14 | 134 | |
WillemBraat | 7:779c5b8d3b14 | 135 | CDU_Status_Update =0; |
WillemBraat | 6:904d00252480 | 136 | } |
WillemBraat | 6:904d00252480 | 137 | if ( DO_CLR_SCREEN ) |
WillemBraat | 6:904d00252480 | 138 | { |
WillemBraat | 6:904d00252480 | 139 | display.cls(); |
WillemBraat | 7:779c5b8d3b14 | 140 | DO_CLR_SCREEN =0; |
WillemBraat | 6:904d00252480 | 141 | } |
WillemBraat | 6:904d00252480 | 142 | } |
WillemBraat | 7:779c5b8d3b14 | 143 | //Reset global flag and release lock on dynamic storage |
WillemBraat | 6:904d00252480 | 144 | FSdata_received_flag = false ; |
WillemBraat | 6:904d00252480 | 145 | } |
WillemBraat | 6:904d00252480 | 146 | |
WillemBraat | 6:904d00252480 | 147 | /* |
WillemBraat | 6:904d00252480 | 148 | void GET_NEW_DATA_TASK(void) // : read new screendata from FS datastructures |
WillemBraat | 6:904d00252480 | 149 | { |
WillemBraat | 6:904d00252480 | 150 | while(1) { // : loop forever because it is a mbos taskfunction |
WillemBraat | 6:904d00252480 | 151 | CDU_OS.WaitEvent(FS_DATA_EVENT); |
WillemBraat | 6:904d00252480 | 152 | CDU_OS.LockResource(FS_DATA_RESOURCE); //lock resource to prevent intermediate updates |
WillemBraat | 6:904d00252480 | 153 | CDU_CSS() |
WillemBraat | 6:904d00252480 | 154 | CDU_OS.FreeResource(FS_DATA_RESOURCE); //free resource |
WillemBraat | 6:904d00252480 | 155 | } |
WillemBraat | 6:904d00252480 | 156 | } |
WillemBraat | 6:904d00252480 | 157 | */ |