Finished Lab 4 Pt 1
Dependencies: mbed Sounds PinDetect
LCDGraphics/uLCD_4DGL_Text.cpp@0:daf9e2f8e1a1, 2019-04-05 (annotated)
- Committer:
- trmontgomery
- Date:
- Fri Apr 05 19:46:26 2019 +0000
- Revision:
- 0:daf9e2f8e1a1
Finished Lab 4 pt 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
trmontgomery | 0:daf9e2f8e1a1 | 1 | // |
trmontgomery | 0:daf9e2f8e1a1 | 2 | // uLCD_4DGL is a class to drive 4D Systems TFT touch screens |
trmontgomery | 0:daf9e2f8e1a1 | 3 | // |
trmontgomery | 0:daf9e2f8e1a1 | 4 | // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> |
trmontgomery | 0:daf9e2f8e1a1 | 5 | // Modifed for Goldelox processor <2013> Jim Hamblen |
trmontgomery | 0:daf9e2f8e1a1 | 6 | // |
trmontgomery | 0:daf9e2f8e1a1 | 7 | // uLCD_4DGL is free software: you can redistribute it and/or modify |
trmontgomery | 0:daf9e2f8e1a1 | 8 | // it under the terms of the GNU General Public License as published by |
trmontgomery | 0:daf9e2f8e1a1 | 9 | // the Free Software Foundation, either version 3 of the License, or |
trmontgomery | 0:daf9e2f8e1a1 | 10 | // (at your option) any later version. |
trmontgomery | 0:daf9e2f8e1a1 | 11 | // |
trmontgomery | 0:daf9e2f8e1a1 | 12 | // uLCD_4DGL is distributed in the hope that it will be useful, |
trmontgomery | 0:daf9e2f8e1a1 | 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
trmontgomery | 0:daf9e2f8e1a1 | 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
trmontgomery | 0:daf9e2f8e1a1 | 15 | // GNU General Public License for more details. |
trmontgomery | 0:daf9e2f8e1a1 | 16 | // |
trmontgomery | 0:daf9e2f8e1a1 | 17 | // You should have received a copy of the GNU General Public License |
trmontgomery | 0:daf9e2f8e1a1 | 18 | // along with uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>. |
trmontgomery | 0:daf9e2f8e1a1 | 19 | |
trmontgomery | 0:daf9e2f8e1a1 | 20 | #include "mbed.h" |
trmontgomery | 0:daf9e2f8e1a1 | 21 | #include "uLCD_4DGL.h" |
trmontgomery | 0:daf9e2f8e1a1 | 22 | |
trmontgomery | 0:daf9e2f8e1a1 | 23 | //**************************************************************************************************** |
trmontgomery | 0:daf9e2f8e1a1 | 24 | void uLCD_4DGL :: set_font_size(char width, char height) // set font size |
trmontgomery | 0:daf9e2f8e1a1 | 25 | { |
trmontgomery | 0:daf9e2f8e1a1 | 26 | if (current_orientation == IS_PORTRAIT) { |
trmontgomery | 0:daf9e2f8e1a1 | 27 | current_fx = width; |
trmontgomery | 0:daf9e2f8e1a1 | 28 | current_fy = height; |
trmontgomery | 0:daf9e2f8e1a1 | 29 | } else { |
trmontgomery | 0:daf9e2f8e1a1 | 30 | current_fy = height; |
trmontgomery | 0:daf9e2f8e1a1 | 31 | current_fx = width; |
trmontgomery | 0:daf9e2f8e1a1 | 32 | } |
trmontgomery | 0:daf9e2f8e1a1 | 33 | max_col = current_w / (current_fx*current_wf); |
trmontgomery | 0:daf9e2f8e1a1 | 34 | max_row = current_h / (current_fy*current_hf); |
trmontgomery | 0:daf9e2f8e1a1 | 35 | } |
trmontgomery | 0:daf9e2f8e1a1 | 36 | |
trmontgomery | 0:daf9e2f8e1a1 | 37 | //**************************************************************************************************** |
trmontgomery | 0:daf9e2f8e1a1 | 38 | void uLCD_4DGL :: set_font(char mode) // set font - system or SD media |
trmontgomery | 0:daf9e2f8e1a1 | 39 | { |
trmontgomery | 0:daf9e2f8e1a1 | 40 | char command[3]= ""; |
trmontgomery | 0:daf9e2f8e1a1 | 41 | |
trmontgomery | 0:daf9e2f8e1a1 | 42 | command[0] = SETFONT; |
trmontgomery | 0:daf9e2f8e1a1 | 43 | command[1] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 44 | command[2] = mode; |
trmontgomery | 0:daf9e2f8e1a1 | 45 | |
trmontgomery | 0:daf9e2f8e1a1 | 46 | current_font = mode; |
trmontgomery | 0:daf9e2f8e1a1 | 47 | |
trmontgomery | 0:daf9e2f8e1a1 | 48 | if (current_orientation == IS_PORTRAIT) { |
trmontgomery | 0:daf9e2f8e1a1 | 49 | current_w = SIZE_X; |
trmontgomery | 0:daf9e2f8e1a1 | 50 | current_h = SIZE_Y; |
trmontgomery | 0:daf9e2f8e1a1 | 51 | } else { |
trmontgomery | 0:daf9e2f8e1a1 | 52 | current_w = SIZE_Y; |
trmontgomery | 0:daf9e2f8e1a1 | 53 | current_h = SIZE_X; |
trmontgomery | 0:daf9e2f8e1a1 | 54 | } |
trmontgomery | 0:daf9e2f8e1a1 | 55 | |
trmontgomery | 0:daf9e2f8e1a1 | 56 | switch (mode) { |
trmontgomery | 0:daf9e2f8e1a1 | 57 | case FONT_5X7 : |
trmontgomery | 0:daf9e2f8e1a1 | 58 | |
trmontgomery | 0:daf9e2f8e1a1 | 59 | current_fx = 6; |
trmontgomery | 0:daf9e2f8e1a1 | 60 | current_fy = 8; |
trmontgomery | 0:daf9e2f8e1a1 | 61 | break; |
trmontgomery | 0:daf9e2f8e1a1 | 62 | case FONT_7X8 : |
trmontgomery | 0:daf9e2f8e1a1 | 63 | current_fx = 7; |
trmontgomery | 0:daf9e2f8e1a1 | 64 | current_fy = 8; |
trmontgomery | 0:daf9e2f8e1a1 | 65 | break; |
trmontgomery | 0:daf9e2f8e1a1 | 66 | case FONT_8X8 : |
trmontgomery | 0:daf9e2f8e1a1 | 67 | current_fx = 8; |
trmontgomery | 0:daf9e2f8e1a1 | 68 | current_fy = 8; |
trmontgomery | 0:daf9e2f8e1a1 | 69 | break; |
trmontgomery | 0:daf9e2f8e1a1 | 70 | case FONT_8X12 : |
trmontgomery | 0:daf9e2f8e1a1 | 71 | current_fx = 8; |
trmontgomery | 0:daf9e2f8e1a1 | 72 | current_fy = 12; |
trmontgomery | 0:daf9e2f8e1a1 | 73 | break; |
trmontgomery | 0:daf9e2f8e1a1 | 74 | case FONT_12X16 : |
trmontgomery | 0:daf9e2f8e1a1 | 75 | current_fx = 12; |
trmontgomery | 0:daf9e2f8e1a1 | 76 | current_fy = 16; |
trmontgomery | 0:daf9e2f8e1a1 | 77 | break; |
trmontgomery | 0:daf9e2f8e1a1 | 78 | default: |
trmontgomery | 0:daf9e2f8e1a1 | 79 | current_fx = 8; |
trmontgomery | 0:daf9e2f8e1a1 | 80 | current_fy = 8; |
trmontgomery | 0:daf9e2f8e1a1 | 81 | } |
trmontgomery | 0:daf9e2f8e1a1 | 82 | |
trmontgomery | 0:daf9e2f8e1a1 | 83 | max_col = current_w / (current_fx*current_wf); |
trmontgomery | 0:daf9e2f8e1a1 | 84 | max_row = current_h / (current_fy*current_hf); |
trmontgomery | 0:daf9e2f8e1a1 | 85 | |
trmontgomery | 0:daf9e2f8e1a1 | 86 | writeCOMMAND(command, 3); |
trmontgomery | 0:daf9e2f8e1a1 | 87 | } |
trmontgomery | 0:daf9e2f8e1a1 | 88 | |
trmontgomery | 0:daf9e2f8e1a1 | 89 | |
trmontgomery | 0:daf9e2f8e1a1 | 90 | |
trmontgomery | 0:daf9e2f8e1a1 | 91 | //**************************************************************************************************** |
trmontgomery | 0:daf9e2f8e1a1 | 92 | void uLCD_4DGL :: text_mode(char mode) // set text mode |
trmontgomery | 0:daf9e2f8e1a1 | 93 | { |
trmontgomery | 0:daf9e2f8e1a1 | 94 | char command[3]= ""; |
trmontgomery | 0:daf9e2f8e1a1 | 95 | |
trmontgomery | 0:daf9e2f8e1a1 | 96 | command[0] = TEXTMODE; |
trmontgomery | 0:daf9e2f8e1a1 | 97 | command[1] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 98 | command[2] = mode; |
trmontgomery | 0:daf9e2f8e1a1 | 99 | |
trmontgomery | 0:daf9e2f8e1a1 | 100 | writeCOMMAND(command, 3); |
trmontgomery | 0:daf9e2f8e1a1 | 101 | } |
trmontgomery | 0:daf9e2f8e1a1 | 102 | |
trmontgomery | 0:daf9e2f8e1a1 | 103 | //**************************************************************************************************** |
trmontgomery | 0:daf9e2f8e1a1 | 104 | void uLCD_4DGL :: text_bold(char mode) // set text mode |
trmontgomery | 0:daf9e2f8e1a1 | 105 | { |
trmontgomery | 0:daf9e2f8e1a1 | 106 | char command[3]= ""; |
trmontgomery | 0:daf9e2f8e1a1 | 107 | |
trmontgomery | 0:daf9e2f8e1a1 | 108 | command[0] = TEXTBOLD; |
trmontgomery | 0:daf9e2f8e1a1 | 109 | command[1] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 110 | command[2] = mode; |
trmontgomery | 0:daf9e2f8e1a1 | 111 | |
trmontgomery | 0:daf9e2f8e1a1 | 112 | writeCOMMAND(command, 3); |
trmontgomery | 0:daf9e2f8e1a1 | 113 | } |
trmontgomery | 0:daf9e2f8e1a1 | 114 | |
trmontgomery | 0:daf9e2f8e1a1 | 115 | //**************************************************************************************************** |
trmontgomery | 0:daf9e2f8e1a1 | 116 | void uLCD_4DGL :: text_italic(char mode) // set text mode |
trmontgomery | 0:daf9e2f8e1a1 | 117 | { |
trmontgomery | 0:daf9e2f8e1a1 | 118 | char command[3]= ""; |
trmontgomery | 0:daf9e2f8e1a1 | 119 | |
trmontgomery | 0:daf9e2f8e1a1 | 120 | command[0] = TEXTITALIC; |
trmontgomery | 0:daf9e2f8e1a1 | 121 | command[1] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 122 | command[2] = mode; |
trmontgomery | 0:daf9e2f8e1a1 | 123 | |
trmontgomery | 0:daf9e2f8e1a1 | 124 | writeCOMMAND(command, 3); |
trmontgomery | 0:daf9e2f8e1a1 | 125 | } |
trmontgomery | 0:daf9e2f8e1a1 | 126 | |
trmontgomery | 0:daf9e2f8e1a1 | 127 | //**************************************************************************************************** |
trmontgomery | 0:daf9e2f8e1a1 | 128 | void uLCD_4DGL :: text_inverse(char mode) // set text mode |
trmontgomery | 0:daf9e2f8e1a1 | 129 | { |
trmontgomery | 0:daf9e2f8e1a1 | 130 | char command[3]= ""; |
trmontgomery | 0:daf9e2f8e1a1 | 131 | |
trmontgomery | 0:daf9e2f8e1a1 | 132 | command[0] = TEXTINVERSE; |
trmontgomery | 0:daf9e2f8e1a1 | 133 | command[1] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 134 | command[2] = mode; |
trmontgomery | 0:daf9e2f8e1a1 | 135 | |
trmontgomery | 0:daf9e2f8e1a1 | 136 | writeCOMMAND(command, 3); |
trmontgomery | 0:daf9e2f8e1a1 | 137 | } |
trmontgomery | 0:daf9e2f8e1a1 | 138 | |
trmontgomery | 0:daf9e2f8e1a1 | 139 | //**************************************************************************************************** |
trmontgomery | 0:daf9e2f8e1a1 | 140 | void uLCD_4DGL :: text_underline(char mode) // set text mode |
trmontgomery | 0:daf9e2f8e1a1 | 141 | { |
trmontgomery | 0:daf9e2f8e1a1 | 142 | char command[3]= ""; |
trmontgomery | 0:daf9e2f8e1a1 | 143 | |
trmontgomery | 0:daf9e2f8e1a1 | 144 | command[0] = TEXTUNDERLINE; |
trmontgomery | 0:daf9e2f8e1a1 | 145 | command[1] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 146 | command[2] = mode; |
trmontgomery | 0:daf9e2f8e1a1 | 147 | |
trmontgomery | 0:daf9e2f8e1a1 | 148 | writeCOMMAND(command, 3); |
trmontgomery | 0:daf9e2f8e1a1 | 149 | } |
trmontgomery | 0:daf9e2f8e1a1 | 150 | |
trmontgomery | 0:daf9e2f8e1a1 | 151 | //**************************************************************************************************** |
trmontgomery | 0:daf9e2f8e1a1 | 152 | void uLCD_4DGL :: text_width(char width) // set text width |
trmontgomery | 0:daf9e2f8e1a1 | 153 | { |
trmontgomery | 0:daf9e2f8e1a1 | 154 | char command[3]= ""; |
trmontgomery | 0:daf9e2f8e1a1 | 155 | |
trmontgomery | 0:daf9e2f8e1a1 | 156 | command[0] = TEXTWIDTH; |
trmontgomery | 0:daf9e2f8e1a1 | 157 | command[1] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 158 | command[2] = width; |
trmontgomery | 0:daf9e2f8e1a1 | 159 | current_wf = width; |
trmontgomery | 0:daf9e2f8e1a1 | 160 | max_col = current_w / (current_fx*current_wf); |
trmontgomery | 0:daf9e2f8e1a1 | 161 | writeCOMMAND(command, 3); |
trmontgomery | 0:daf9e2f8e1a1 | 162 | } |
trmontgomery | 0:daf9e2f8e1a1 | 163 | |
trmontgomery | 0:daf9e2f8e1a1 | 164 | //**************************************************************************************************** |
trmontgomery | 0:daf9e2f8e1a1 | 165 | void uLCD_4DGL :: text_height(char height) // set text height |
trmontgomery | 0:daf9e2f8e1a1 | 166 | { |
trmontgomery | 0:daf9e2f8e1a1 | 167 | char command[3]= ""; |
trmontgomery | 0:daf9e2f8e1a1 | 168 | |
trmontgomery | 0:daf9e2f8e1a1 | 169 | command[0] = TEXTHEIGHT; |
trmontgomery | 0:daf9e2f8e1a1 | 170 | command[1] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 171 | command[2] = height; |
trmontgomery | 0:daf9e2f8e1a1 | 172 | current_hf = height; |
trmontgomery | 0:daf9e2f8e1a1 | 173 | max_row = current_h / (current_fy*current_hf); |
trmontgomery | 0:daf9e2f8e1a1 | 174 | writeCOMMAND(command, 3); |
trmontgomery | 0:daf9e2f8e1a1 | 175 | } |
trmontgomery | 0:daf9e2f8e1a1 | 176 | |
trmontgomery | 0:daf9e2f8e1a1 | 177 | |
trmontgomery | 0:daf9e2f8e1a1 | 178 | //**************************************************************************************************** |
trmontgomery | 0:daf9e2f8e1a1 | 179 | void uLCD_4DGL :: text_char(char c, char col, char row, int color) // draw a text char |
trmontgomery | 0:daf9e2f8e1a1 | 180 | { |
trmontgomery | 0:daf9e2f8e1a1 | 181 | char command[6]= ""; |
trmontgomery | 0:daf9e2f8e1a1 | 182 | command[0] = 0xE4; //move cursor |
trmontgomery | 0:daf9e2f8e1a1 | 183 | command[1] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 184 | command[2] = row; |
trmontgomery | 0:daf9e2f8e1a1 | 185 | command[3] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 186 | command[4] = col; |
trmontgomery | 0:daf9e2f8e1a1 | 187 | writeCOMMAND(command, 5); |
trmontgomery | 0:daf9e2f8e1a1 | 188 | |
trmontgomery | 0:daf9e2f8e1a1 | 189 | command[0] = 0x7F; //set color |
trmontgomery | 0:daf9e2f8e1a1 | 190 | |
trmontgomery | 0:daf9e2f8e1a1 | 191 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
trmontgomery | 0:daf9e2f8e1a1 | 192 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
trmontgomery | 0:daf9e2f8e1a1 | 193 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
trmontgomery | 0:daf9e2f8e1a1 | 194 | |
trmontgomery | 0:daf9e2f8e1a1 | 195 | command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
trmontgomery | 0:daf9e2f8e1a1 | 196 | command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
trmontgomery | 0:daf9e2f8e1a1 | 197 | writeCOMMAND(command, 3); |
trmontgomery | 0:daf9e2f8e1a1 | 198 | |
trmontgomery | 0:daf9e2f8e1a1 | 199 | command[0] = TEXTCHAR; //print char |
trmontgomery | 0:daf9e2f8e1a1 | 200 | command[1] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 201 | command[2] = c; |
trmontgomery | 0:daf9e2f8e1a1 | 202 | writeCOMMAND(command, 3); |
trmontgomery | 0:daf9e2f8e1a1 | 203 | |
trmontgomery | 0:daf9e2f8e1a1 | 204 | } |
trmontgomery | 0:daf9e2f8e1a1 | 205 | |
trmontgomery | 0:daf9e2f8e1a1 | 206 | |
trmontgomery | 0:daf9e2f8e1a1 | 207 | //**************************************************************************************************** |
trmontgomery | 0:daf9e2f8e1a1 | 208 | void uLCD_4DGL :: text_string(char *s, char col, char row, char font, int color) // draw a text string |
trmontgomery | 0:daf9e2f8e1a1 | 209 | { |
trmontgomery | 0:daf9e2f8e1a1 | 210 | |
trmontgomery | 0:daf9e2f8e1a1 | 211 | char command[1000]= ""; |
trmontgomery | 0:daf9e2f8e1a1 | 212 | int size = strlen(s); |
trmontgomery | 0:daf9e2f8e1a1 | 213 | int i = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 214 | |
trmontgomery | 0:daf9e2f8e1a1 | 215 | set_font(font); |
trmontgomery | 0:daf9e2f8e1a1 | 216 | |
trmontgomery | 0:daf9e2f8e1a1 | 217 | command[0] = 0xE4; //move cursor |
trmontgomery | 0:daf9e2f8e1a1 | 218 | command[1] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 219 | command[2] = row; |
trmontgomery | 0:daf9e2f8e1a1 | 220 | command[3] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 221 | command[4] = col; |
trmontgomery | 0:daf9e2f8e1a1 | 222 | writeCOMMAND(command, 5); |
trmontgomery | 0:daf9e2f8e1a1 | 223 | |
trmontgomery | 0:daf9e2f8e1a1 | 224 | command[0] = 0x7F; //set color |
trmontgomery | 0:daf9e2f8e1a1 | 225 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
trmontgomery | 0:daf9e2f8e1a1 | 226 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
trmontgomery | 0:daf9e2f8e1a1 | 227 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
trmontgomery | 0:daf9e2f8e1a1 | 228 | |
trmontgomery | 0:daf9e2f8e1a1 | 229 | command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
trmontgomery | 0:daf9e2f8e1a1 | 230 | command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
trmontgomery | 0:daf9e2f8e1a1 | 231 | writeCOMMAND(command, 3); |
trmontgomery | 0:daf9e2f8e1a1 | 232 | |
trmontgomery | 0:daf9e2f8e1a1 | 233 | command[0] = TEXTSTRING; |
trmontgomery | 0:daf9e2f8e1a1 | 234 | for (i=0; i<size; i++) command[1+i] = s[i]; |
trmontgomery | 0:daf9e2f8e1a1 | 235 | command[1+size] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 236 | writeCOMMANDnull(command, 2 + size); |
trmontgomery | 0:daf9e2f8e1a1 | 237 | } |
trmontgomery | 0:daf9e2f8e1a1 | 238 | |
trmontgomery | 0:daf9e2f8e1a1 | 239 | |
trmontgomery | 0:daf9e2f8e1a1 | 240 | |
trmontgomery | 0:daf9e2f8e1a1 | 241 | //**************************************************************************************************** |
trmontgomery | 0:daf9e2f8e1a1 | 242 | void uLCD_4DGL :: locate(char col, char row) // place text curssor at col, row |
trmontgomery | 0:daf9e2f8e1a1 | 243 | { |
trmontgomery | 0:daf9e2f8e1a1 | 244 | char command[5] = ""; |
trmontgomery | 0:daf9e2f8e1a1 | 245 | current_col = col; |
trmontgomery | 0:daf9e2f8e1a1 | 246 | current_row = row; |
trmontgomery | 0:daf9e2f8e1a1 | 247 | command[0] = MOVECURSOR; //move cursor |
trmontgomery | 0:daf9e2f8e1a1 | 248 | command[1] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 249 | command[2] = current_row; |
trmontgomery | 0:daf9e2f8e1a1 | 250 | command[3] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 251 | command[4] = current_col; |
trmontgomery | 0:daf9e2f8e1a1 | 252 | writeCOMMAND(command, 5); |
trmontgomery | 0:daf9e2f8e1a1 | 253 | } |
trmontgomery | 0:daf9e2f8e1a1 | 254 | |
trmontgomery | 0:daf9e2f8e1a1 | 255 | //**************************************************************************************************** |
trmontgomery | 0:daf9e2f8e1a1 | 256 | void uLCD_4DGL :: color(int color) // set text color |
trmontgomery | 0:daf9e2f8e1a1 | 257 | { |
trmontgomery | 0:daf9e2f8e1a1 | 258 | char command[5] = ""; |
trmontgomery | 0:daf9e2f8e1a1 | 259 | current_color = color; |
trmontgomery | 0:daf9e2f8e1a1 | 260 | command[0] = 0x7F; //set color |
trmontgomery | 0:daf9e2f8e1a1 | 261 | |
trmontgomery | 0:daf9e2f8e1a1 | 262 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
trmontgomery | 0:daf9e2f8e1a1 | 263 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
trmontgomery | 0:daf9e2f8e1a1 | 264 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
trmontgomery | 0:daf9e2f8e1a1 | 265 | |
trmontgomery | 0:daf9e2f8e1a1 | 266 | command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
trmontgomery | 0:daf9e2f8e1a1 | 267 | command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
trmontgomery | 0:daf9e2f8e1a1 | 268 | writeCOMMAND(command, 3); |
trmontgomery | 0:daf9e2f8e1a1 | 269 | } |
trmontgomery | 0:daf9e2f8e1a1 | 270 | |
trmontgomery | 0:daf9e2f8e1a1 | 271 | //**************************************************************************************************** |
trmontgomery | 0:daf9e2f8e1a1 | 272 | void uLCD_4DGL :: putc(char c) // place char at current cursor position |
trmontgomery | 0:daf9e2f8e1a1 | 273 | //used by virtual printf function _putc |
trmontgomery | 0:daf9e2f8e1a1 | 274 | { |
trmontgomery | 0:daf9e2f8e1a1 | 275 | char command[6] =""; |
trmontgomery | 0:daf9e2f8e1a1 | 276 | if(c<0x20) { |
trmontgomery | 0:daf9e2f8e1a1 | 277 | if(c=='\n') { |
trmontgomery | 0:daf9e2f8e1a1 | 278 | current_col = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 279 | current_row++; |
trmontgomery | 0:daf9e2f8e1a1 | 280 | command[0] = MOVECURSOR; //move cursor to start of next line |
trmontgomery | 0:daf9e2f8e1a1 | 281 | command[1] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 282 | command[2] = current_row; |
trmontgomery | 0:daf9e2f8e1a1 | 283 | command[3] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 284 | command[4] = current_col; |
trmontgomery | 0:daf9e2f8e1a1 | 285 | writeCOMMAND(command, 5); |
trmontgomery | 0:daf9e2f8e1a1 | 286 | } |
trmontgomery | 0:daf9e2f8e1a1 | 287 | if(c=='\r') { |
trmontgomery | 0:daf9e2f8e1a1 | 288 | current_col = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 289 | command[0] = MOVECURSOR; //move cursor to start of line |
trmontgomery | 0:daf9e2f8e1a1 | 290 | command[1] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 291 | command[2] = current_row; |
trmontgomery | 0:daf9e2f8e1a1 | 292 | command[3] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 293 | command[4] = current_col; |
trmontgomery | 0:daf9e2f8e1a1 | 294 | writeCOMMAND(command, 5); |
trmontgomery | 0:daf9e2f8e1a1 | 295 | } |
trmontgomery | 0:daf9e2f8e1a1 | 296 | if(c=='\f') { |
trmontgomery | 0:daf9e2f8e1a1 | 297 | uLCD_4DGL::cls(); //clear screen on form feed |
trmontgomery | 0:daf9e2f8e1a1 | 298 | } |
trmontgomery | 0:daf9e2f8e1a1 | 299 | } else { |
trmontgomery | 0:daf9e2f8e1a1 | 300 | command[0] = PUTCHAR; |
trmontgomery | 0:daf9e2f8e1a1 | 301 | command[1] = 0x00; |
trmontgomery | 0:daf9e2f8e1a1 | 302 | command[2] = c; |
trmontgomery | 0:daf9e2f8e1a1 | 303 | writeCOMMAND(command,3); |
trmontgomery | 0:daf9e2f8e1a1 | 304 | current_col++; |
trmontgomery | 0:daf9e2f8e1a1 | 305 | } |
trmontgomery | 0:daf9e2f8e1a1 | 306 | if (current_col == max_col) { |
trmontgomery | 0:daf9e2f8e1a1 | 307 | current_col = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 308 | current_row++; |
trmontgomery | 0:daf9e2f8e1a1 | 309 | command[0] = MOVECURSOR; //move cursor to next line |
trmontgomery | 0:daf9e2f8e1a1 | 310 | command[1] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 311 | command[2] = current_row; |
trmontgomery | 0:daf9e2f8e1a1 | 312 | command[3] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 313 | command[4] = current_col; |
trmontgomery | 0:daf9e2f8e1a1 | 314 | writeCOMMAND(command, 5); |
trmontgomery | 0:daf9e2f8e1a1 | 315 | } |
trmontgomery | 0:daf9e2f8e1a1 | 316 | if (current_row == max_row) { |
trmontgomery | 0:daf9e2f8e1a1 | 317 | current_row = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 318 | command[0] = MOVECURSOR; //move cursor back to start |
trmontgomery | 0:daf9e2f8e1a1 | 319 | command[1] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 320 | command[2] = current_row; |
trmontgomery | 0:daf9e2f8e1a1 | 321 | command[3] = 0; |
trmontgomery | 0:daf9e2f8e1a1 | 322 | command[4] = current_col; |
trmontgomery | 0:daf9e2f8e1a1 | 323 | writeCOMMAND(command, 5); |
trmontgomery | 0:daf9e2f8e1a1 | 324 | } |
trmontgomery | 0:daf9e2f8e1a1 | 325 | } |
trmontgomery | 0:daf9e2f8e1a1 | 326 | |
trmontgomery | 0:daf9e2f8e1a1 | 327 | |
trmontgomery | 0:daf9e2f8e1a1 | 328 | //**************************************************************************************************** |
trmontgomery | 0:daf9e2f8e1a1 | 329 | void uLCD_4DGL :: puts(char *s) // place string at current cursor position |
trmontgomery | 0:daf9e2f8e1a1 | 330 | { |
trmontgomery | 0:daf9e2f8e1a1 | 331 | |
trmontgomery | 0:daf9e2f8e1a1 | 332 | text_string(s, current_col, current_row, current_font, current_color); |
trmontgomery | 0:daf9e2f8e1a1 | 333 | |
trmontgomery | 0:daf9e2f8e1a1 | 334 | current_col += strlen(s); |
trmontgomery | 0:daf9e2f8e1a1 | 335 | |
trmontgomery | 0:daf9e2f8e1a1 | 336 | if (current_col >= max_col) { |
trmontgomery | 0:daf9e2f8e1a1 | 337 | current_row += current_col / max_col; |
trmontgomery | 0:daf9e2f8e1a1 | 338 | current_col %= max_col; |
trmontgomery | 0:daf9e2f8e1a1 | 339 | } |
trmontgomery | 0:daf9e2f8e1a1 | 340 | if (current_row >= max_row) { |
trmontgomery | 0:daf9e2f8e1a1 | 341 | current_row %= max_row; |
trmontgomery | 0:daf9e2f8e1a1 | 342 | } |
trmontgomery | 0:daf9e2f8e1a1 | 343 | } |
trmontgomery | 0:daf9e2f8e1a1 | 344 |