From e674fd1b42b740b0816acb816e436e70ff0e3295 Mon Sep 17 00:00:00 2001 From: KTOWN Date: Mon, 14 Oct 2013 21:27:17 +0200 Subject: [PATCH] Set cursor position for text --- Adafruit_RA8875.cpp | 21 +++++++++++++++++++++ Adafruit_RA8875.h | 1 + examples/textmode/textmode.ino | 18 +++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Adafruit_RA8875.cpp b/Adafruit_RA8875.cpp index 8126912..140419b 100644 --- a/Adafruit_RA8875.cpp +++ b/Adafruit_RA8875.cpp @@ -234,6 +234,27 @@ void Adafruit_RA8875::textMode(void) writeData(temp); } +/**************************************************************************/ +/*! + Sets the display in text mode (as opposed to graphics mode) + + @args x[in] The x position of the cursor (in pixels, 0..1023) + @args y[in] The y position of the cursor (in pixels, 0..511) +*/ +/**************************************************************************/ +void Adafruit_RA8875::textSetCursor(uint16_t x, uint16_t y) +{ + /* Set cursor location */ + writeCommand(0x2A); + writeData(x & 0xFF); + writeCommand(0x2B); + writeData(x >> 8); + writeCommand(0x2C); + writeData(y & 0xFF); + writeCommand(0x2D); + writeData(y >> 8); +} + /**************************************************************************/ /*! Sets the fore and background color when rendering text diff --git a/Adafruit_RA8875.h b/Adafruit_RA8875.h index acf4d27..45d87f7 100644 --- a/Adafruit_RA8875.h +++ b/Adafruit_RA8875.h @@ -62,6 +62,7 @@ class Adafruit_RA8875 : public Adafruit_GFX { /* Text functions */ void textMode(void); + void textSetCursor(uint16_t x, uint16_t y); void textColor(uint16_t foreColor, uint16_t bgColor); void textTransparent(uint16_t foreColor); void textEnlarge(uint8_t scale); diff --git a/examples/textmode/textmode.ino b/examples/textmode/textmode.ino index acf1cc0..3fcc572 100644 --- a/examples/textmode/textmode.ino +++ b/examples/textmode/textmode.ino @@ -25,11 +25,22 @@ void setup() tft.PWM1config(true, RA8875_PWM_CLK_DIV1024); // PWM output for backlight tft.PWM1out(255); tft.fillScreen(RA8875_BLACK); - + + /* Switch to text mode */ tft.textMode(); + + /* If necessary, enlarge the font */ // tft.textEnlarge(0); + + /* Set a solid for + bg color ... */ // tft.textColor(RA8875_WHITE, RA8875_RED); + /* ... or a fore color plus a transparent background */ tft.textTransparent(RA8875_WHITE); + + /* Set the cursor location (in pixels) */ + tft.textSetCursor(10, 10); + + /* Render some text! */ uint8_t string[15] = "Hello, World! "; tft.textWrite(string, 15); tft.textWrite(string, 15); @@ -37,6 +48,11 @@ void setup() tft.textWrite(string, 15); tft.textWrite(string, 15); tft.textWrite(string, 15); + + /* Change the cursor location and color ... */ + tft.textSetCursor(100, 100); + tft.textTransparent(RA8875_RED); + /* ... and render some more text! */ tft.textWrite(string, 15); tft.textWrite(string, 15); }