Fork of 4DGL lib for uLCD-144-G2. Different command values needed. See https://mbed.org/users/4180_1/notebook/ulcd-144-g2-128-by-128-color-lcd/ for instructions and demo code.

Dependents:   mythermostat MorseCode SuperMbedBall frogger_G ... more

Fork of 4DGL by Adam Green

Revision:
7:e39a44de229a
Parent:
5:8936798c19a3
--- a/uLCD_4DGL_Text.cpp	Mon Nov 25 04:24:22 2013 +0000
+++ b/uLCD_4DGL_Text.cpp	Sat Nov 30 02:05:15 2013 +0000
@@ -2,6 +2,7 @@
 // uLCD_4DGL is a class to drive 4D Systems TFT touch screens
 //
 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
+// Modifed for Goldelox processor <2013> Jim Hamblen
 //
 // uLCD_4DGL is free software: you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -20,7 +21,21 @@
 #include "uLCD_4DGL.h"
 
 //****************************************************************************************************
-void uLCD_4DGL :: set_font(char mode)     // set font size
+void uLCD_4DGL :: set_font_size(char width, char height)     // set font size
+{
+    if (current_orientation == IS_PORTRAIT) {
+        current_fx = width;
+        current_fy = height;
+    } else {
+        current_fy = height;
+        current_fx = width;
+    }
+    max_col = current_w / (current_fx*current_wf);
+    max_row = current_h / (current_fy*current_hf);
+}
+
+//****************************************************************************************************
+void uLCD_4DGL :: set_font(char mode)     // set font - system or SD media
 {
     char command[3]= "";
 
@@ -40,6 +55,7 @@
 
     switch (mode) {
         case FONT_5X7 :
+
             current_fx = 6;
             current_fy = 8;
             break;
@@ -59,6 +75,9 @@
             current_fx = 12;
             current_fy = 16;
             break;
+        default:
+            current_fx = 8;
+            current_fy = 8;
     }
 
     max_col = current_w / (current_fx*current_wf);
@@ -118,6 +137,18 @@
 }
 
 //****************************************************************************************************
+void uLCD_4DGL :: text_underline(char mode)     // set text mode
+{
+    char command[3]= "";
+
+    command[0] = TEXTUNDERLINE;
+    command[1] = 0;
+    command[2] = mode;
+
+    writeCOMMAND(command, 3);
+}
+
+//****************************************************************************************************
 void uLCD_4DGL :: text_width(char width)     // set text width
 {
     char command[3]= "";
@@ -172,34 +203,6 @@
 
 }
 
-//****************************************************************************************************
-void uLCD_4DGL :: graphic_char(char c, int x, int y, int color, char width, char height)     // draw a graphic char
-{
-    char command[10]= "";
-
-    command[0] = GRAPHCHAR;
-
-    command[1] = c;
-
-    command[2] = (x >> 8) & 0xFF;
-    command[3] = x & 0xFF;
-
-    command[4] = (y >> 8) & 0xFF;
-    command[5] = y & 0xFF;
-
-    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[6] = ((red5 << 3)   + (green6 >> 3)) & 0xFF;  // first part of 16 bits color
-    command[7] = ((green6 << 5) + (blue5 >>  0)) & 0xFF;  // second part of 16 bits color
-
-    command[8] = width;
-
-    command[9] = height;
-
-    writeCOMMAND(command, 10);
-}
 
 //****************************************************************************************************
 void uLCD_4DGL :: text_string(char *s, char col, char row, char font, int color)     // draw a text string
@@ -233,86 +236,7 @@
     writeCOMMANDnull(command, 2 + size);
 }
 
-//****************************************************************************************************
-void uLCD_4DGL :: graphic_string(char *s, int x, int y, char font, int color, char width, char height)     // draw a text string
-{
 
-    char command[1000]= "";
-    int size = strlen(s);
-    int i = 0;
-
-    command[0] = GRAPHSTRING;
-
-    command[1] = (x >> 8) & 0xFF;
-    command[2] = x & 0xFF;
-
-    command[3] = (y >> 8) & 0xFF;
-    command[4] = y & 0xFF;
-
-    command[5] = font;
-
-    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[6] = ((red5 << 3)   + (green6 >> 3)) & 0xFF;  // first part of 16 bits color
-    command[7] = ((green6 << 5) + (blue5 >>  0)) & 0xFF;  // second part of 16 bits color
-
-    command[8] = width;
-
-    command[9] = height;
-
-    for (i=0; i<size; i++) command[10+i] = s[i];
-
-    command[10+size] = 0;
-
-    writeCOMMAND(command, 11 + size);
-}
-
-//****************************************************************************************************
-void uLCD_4DGL :: text_button(char *s, char mode, int x, int y, int button_color, char font, int text_color, char width, char height)     // draw a text string
-{
-
-    char command[1000]= "";
-    int size = strlen(s);
-    int i = 0, red5, green6, blue5;
-
-    command[0] = TEXTBUTTON;
-
-    command[1] = mode;
-
-    command[2] = (x >> 8) & 0xFF;
-    command[3] = x & 0xFF;
-
-    command[4] = (y >> 8) & 0xFF;
-    command[5] = y & 0xFF;
-
-    red5   = (button_color >> (16 + 3)) & 0x1F;              // get red on 5 bits
-    green6 = (button_color >> (8 + 2))  & 0x3F;              // get green on 6 bits
-    blue5  = (button_color >> (0 + 3))  & 0x1F;              // get blue on 5 bits
-
-    command[6] = ((red5 << 3)   + (green6 >> 3)) & 0xFF;  // first part of 16 bits color
-    command[7] = ((green6 << 5) + (blue5 >>  0)) & 0xFF;  // second part of 16 bits color
-
-    command[8] = font;
-
-    red5   = (text_color >> (16 + 3)) & 0x1F;              // get red on 5 bits
-    green6 = (text_color >> (8 + 2))  & 0x3F;              // get green on 6 bits
-    blue5  = (text_color >> (0 + 3))  & 0x1F;              // get blue on 5 bits
-
-    command[9] = ((red5 << 3)   + (green6 >> 3)) & 0xFF;  // first part of 16 bits color
-    command[10] = ((green6 << 5) + (blue5 >>  0)) & 0xFF;  // second part of 16 bits color
-
-    command[11] = width;
-
-    command[12] = height;
-
-    for (i=0; i<size; i++) command[13+i] = s[i];
-
-    command[13+size] = 0;
-
-    writeCOMMAND(command, 14 + size);
-}
 
 //****************************************************************************************************
 void uLCD_4DGL :: locate(char col, char row)     // place text curssor at col, row
@@ -320,7 +244,7 @@
     char command[5] = "";
     current_col = col;
     current_row = row;
-    command[0] = 0xE4; //move cursor
+    command[0] = MOVECURSOR; //move cursor
     command[1] = 0;
     command[2] = current_row;
     command[3] = 0;
@@ -349,26 +273,40 @@
 //used by virtual printf function _putc
 {
     char command[6] ="";
-
-    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);
+    if(c<0x20) {
+        if(c=='\n') {
+            current_col = 0;
+            current_row++;
+            command[0] = MOVECURSOR; //move cursor to start of next line
+            command[1] = 0;
+            command[2] = current_row;
+            command[3] = 0;
+            command[4] = current_col;
+            writeCOMMAND(command, 5);
+        }
+        if(c=='\r') {
+            current_col = 0;
+            command[0] = MOVECURSOR; //move cursor to start of line
+            command[1] = 0;
+            command[2] = current_row;
+            command[3] = 0;
+            command[4] = current_col;
+            writeCOMMAND(command, 5);
+        }
+        if(c=='\f') {
+            uLCD_4DGL::cls(); //clear screen on form feed
+        }
     } else {
         command[0] = PUTCHAR;
         command[1] = 0x00;
         command[2] = c;
         writeCOMMAND(command,3);
+        current_col++;
     }
     if (current_col == max_col) {
         current_col = 0;
         current_row++;
-        command[0] = 0xE4; //move cursor to next line
+        command[0] = MOVECURSOR; //move cursor to next line
         command[1] = 0;
         command[2] = current_row;
         command[3] = 0;
@@ -377,7 +315,7 @@
     }
     if (current_row == max_row) {
         current_row = 0;
-        command[0] = 0xE4; //move cursor back to start
+        command[0] = MOVECURSOR; //move cursor back to start
         command[1] = 0;
         command[2] = current_row;
         command[3] = 0;