Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of 4DGL-uLCD-SE by
Diff: uLCD_4DGL_Text.cpp
- Revision:
- 2:edae99e4abe7
- Parent:
- 1:8b656995301f
- Child:
- 5:8936798c19a3
diff -r 8b656995301f -r edae99e4abe7 uLCD_4DGL_Text.cpp
--- a/uLCD_4DGL_Text.cpp Mon Nov 11 01:22:41 2013 +0000
+++ b/uLCD_4DGL_Text.cpp Sun Nov 17 04:36:12 2013 +0000
@@ -24,8 +24,6 @@
{
char command[3]= "";
- int w, h, fx = 8, fy = 8;
-
command[0] = SETFONT;
command[1] = 0;
command[2] = mode;
@@ -33,34 +31,38 @@
current_font = mode;
if (current_orientation == IS_PORTRAIT) {
- w = SIZE_X;
- h = SIZE_Y;
+ current_w = SIZE_X;
+ current_h = SIZE_Y;
} else {
- w = SIZE_Y;
- h = SIZE_X;
+ current_w = SIZE_Y;
+ current_h = SIZE_X;
}
switch (mode) {
case FONT_5X7 :
- fx = 6;
- fy = 8;
+ current_fx = 6;
+ current_fy = 8;
+ break;
+ case FONT_7X8 :
+ current_fx = 7;
+ current_fy = 8;
break;
case FONT_8X8 :
- fx = 8;
- fy = 8;
+ current_fx = 8;
+ current_fy = 8;
break;
case FONT_8X12 :
- fx = 8;
- fy = 12;
+ current_fx = 8;
+ current_fy = 12;
break;
case FONT_12X16 :
- fx = 12;
- fy = 16;
+ current_fx = 12;
+ current_fy = 16;
break;
}
- max_col = w / fx;
- max_row = h / fy;
+ max_col = current_w / (current_fx*current_wf);
+ max_row = current_h / (current_fy*current_hf);
writeCOMMAND(command, 3);
}
@@ -78,6 +80,33 @@
}
//****************************************************************************************************
+void uLCD_4DGL :: text_width(char width) // set text width
+{
+ char command[3]= "";
+
+ command[0] = TEXTWIDTH;
+ command[1] = 0;
+ command[2] = width;
+ current_wf = width;
+ max_col = current_w / (current_fx*current_wf);
+ writeCOMMAND(command, 3);
+}
+
+//****************************************************************************************************
+void uLCD_4DGL :: text_height(char height) // set text height
+{
+ char command[3]= "";
+
+ command[0] = TEXTHEIGHT;
+ command[1] = 0;
+ command[2] = height;
+ current_hf = height;
+ max_row = current_h / (current_fy*current_hf);
+ writeCOMMAND(command, 3);
+}
+
+
+//****************************************************************************************************
void uLCD_4DGL :: text_char(char c, char col, char row, int color) // draw a text char
{
char command[6]= "";
@@ -250,31 +279,76 @@
//****************************************************************************************************
void uLCD_4DGL :: locate(char col, char row) // place text curssor at col, row
{
+ char command[5] = "";
current_col = col;
current_row = row;
+ command[0] = 0xE4; //move cursor
+ command[1] = 0;
+ command[2] = current_row;
+ command[3] = 0;
+ command[4] = current_col;
+ writeCOMMAND(command, 5);
}
//****************************************************************************************************
void uLCD_4DGL :: color(int color) // set text color
{
+ char command[5] = "";
current_color = color;
+ command[0] = 0x7F; //set color
+
+ int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
+ int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
+ int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
+
+ command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
+ command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
+ writeCOMMAND(command, 3);
}
//****************************************************************************************************
-void uLCD_4DGL :: putc(char c) // place char at current cursor position
+void uLCD_4DGL :: putc(char c) // place char at current cursor position
+//used by virtual printf function _putc
{
+ char command[6] ="";
- text_char(c, current_col++, current_row, current_color);
-
+ if(c=='\n') {
+ current_col = 0;
+ current_row++;
+ command[0] = 0xE4; //move cursor to start of next line
+ command[1] = 0;
+ command[2] = current_row;
+ command[3] = 0;
+ command[4] = current_col;
+ writeCOMMAND(command, 5);
+ } else {
+ command[0] = PUTCHAR;
+ command[1] = 0x00;
+ command[2] = c;
+ writeCOMMAND(command,3);
+ }
if (current_col == max_col) {
current_col = 0;
current_row++;
+ command[0] = 0xE4; //move cursor to next line
+ command[1] = 0;
+ command[2] = current_row;
+ command[3] = 0;
+ command[4] = current_col;
+ writeCOMMAND(command, 5);
}
if (current_row == max_row) {
current_row = 0;
+ command[0] = 0xE4; //move cursor back to start
+ command[1] = 0;
+ command[2] = current_row;
+ command[3] = 0;
+ command[4] = current_col;
+ writeCOMMAND(command, 5);
}
}
+
//****************************************************************************************************
void uLCD_4DGL :: puts(char *s) // place string at current cursor position
{
