Permalink
Browse files

Tweaks for Adafruit_GFX

  • Loading branch information...
1 parent 737712e commit d74280654e81810a0471f156297d03dfee5bff63 @PaintYourDragon PaintYourDragon committed Apr 10, 2012
View
@@ -255,12 +255,7 @@ void Adafruit_ST7735::commandList(prog_uchar *addr) {
// Initialization code common to both 'B' and 'R' type displays
void Adafruit_ST7735::commonInit(prog_uchar *cmdList) {
- _width = ST7735_TFTWIDTH;
- _height = ST7735_TFTHEIGHT;
- rotation = 0;
- cursor_y = cursor_x = 0;
- textsize = 1;
- textcolor = 0xFFFF;
+ constructor(ST7735_TFTWIDTH, ST7735_TFTHEIGHT);
colstart = rowstart = 0; // May be overridden in init func
pinMode(_rs, OUTPUT);
@@ -373,9 +368,9 @@ void Adafruit_ST7735::pushColor(uint16_t color) {
}
-void Adafruit_ST7735::drawPixel(uint16_t x, uint16_t y, uint16_t color) {
+void Adafruit_ST7735::drawPixel(int16_t x, int16_t y, uint16_t color) {
- if ((x >= _width) || (y >= _height)) return;
+ if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return;
setAddrWindow(x,y,x+1,y+1);
@@ -389,7 +384,7 @@ void Adafruit_ST7735::drawPixel(uint16_t x, uint16_t y, uint16_t color) {
}
-void Adafruit_ST7735::drawFastVLine(uint16_t x, uint16_t y, uint16_t h,
+void Adafruit_ST7735::drawFastVLine(int16_t x, int16_t y, int16_t h,
uint16_t color) {
// Rudimentary clipping
@@ -408,7 +403,7 @@ void Adafruit_ST7735::drawFastVLine(uint16_t x, uint16_t y, uint16_t h,
}
-void Adafruit_ST7735::drawFastHLine(uint16_t x, uint16_t y, uint16_t w,
+void Adafruit_ST7735::drawFastHLine(int16_t x, int16_t y, int16_t w,
uint16_t color) {
// Rudimentary clipping
@@ -428,7 +423,7 @@ void Adafruit_ST7735::drawFastHLine(uint16_t x, uint16_t y, uint16_t w,
// fill a rectangle
-void Adafruit_ST7735::fillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
+void Adafruit_ST7735::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
uint16_t color) {
// rudimentary clipping (drawChar w/big text requires this)
View
@@ -105,10 +105,10 @@ class Adafruit_ST7735 : public Adafruit_GFX {
setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1),
pushColor(uint16_t color),
fillScreen(uint16_t color),
- drawPixel(uint16_t x, uint16_t y, uint16_t color),
- drawFastVLine(uint16_t x, uint16_t y, uint16_t h, uint16_t color),
- drawFastHLine(uint16_t x, uint16_t y, uint16_t w, uint16_t color),
- fillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
+ drawPixel(int16_t x, int16_t y, uint16_t color),
+ drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
+ drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
+ fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
uint16_t color),
setRotation(uint8_t r),
invertDisplay(boolean i);
@@ -92,6 +92,7 @@ void setup(void) {
tft.fillScreen(ST7735_BLACK);
testfillcircles(10, ST7735_BLUE);
testdrawcircles(10, ST7735_WHITE);
+ delay(500);
testroundrects();
delay(500);
@@ -115,80 +116,81 @@ void loop() {
void testlines(uint16_t color) {
tft.fillScreen(ST7735_BLACK);
- for (uint16_t x=0; x < tft.width(); x+=6) {
+ for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(0, 0, x, tft.height()-1, color);
}
- for (uint16_t y=0; y < tft.height(); y+=6) {
+ for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(0, 0, tft.width()-1, y, color);
}
tft.fillScreen(ST7735_BLACK);
- for (uint16_t x=0; x < tft.width(); x+=6) {
+ for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
}
- for (uint16_t y=0; y < tft.height(); y+=6) {
+ for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(tft.width()-1, 0, 0, y, color);
}
tft.fillScreen(ST7735_BLACK);
- for (uint16_t x=0; x < tft.width(); x+=6) {
+ for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(0, tft.height()-1, x, 0, color);
}
- for (uint16_t y=0; y < tft.height(); y+=6) {
+ for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
}
tft.fillScreen(ST7735_BLACK);
- for (uint16_t x=0; x < tft.width(); x+=6) {
+ for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
}
- for (uint16_t y=0; y < tft.height(); y+=6) {
+ for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
}
}
void testdrawtext(char *text, uint16_t color) {
tft.setCursor(0, 0);
tft.setTextColor(color);
+ tft.setTextWrap(true);
tft.print(text);
}
void testfastlines(uint16_t color1, uint16_t color2) {
tft.fillScreen(ST7735_BLACK);
- for (uint16_t y=0; y < tft.height(); y+=5) {
+ for (int16_t y=0; y < tft.height(); y+=5) {
tft.drawFastHLine(0, y, tft.width(), color1);
}
- for (uint16_t x=0; x < tft.width(); x+=5) {
+ for (int16_t x=0; x < tft.width(); x+=5) {
tft.drawFastVLine(x, 0, tft.height(), color2);
}
}
void testdrawrects(uint16_t color) {
tft.fillScreen(ST7735_BLACK);
- for (uint16_t x=0; x < tft.width(); x+=6) {
+ for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
}
}
void testfillrects(uint16_t color1, uint16_t color2) {
tft.fillScreen(ST7735_BLACK);
- for (uint16_t x=tft.width()-1; x > 6; x-=6) {
+ for (int16_t x=tft.width()-1; x > 6; x-=6) {
tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1);
tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2);
}
}
void testfillcircles(uint8_t radius, uint16_t color) {
- for (uint8_t x=radius; x < tft.width(); x+=radius*2) {
- for (uint8_t y=radius; y < tft.height(); y+=radius*2) {
+ for (int16_t x=radius; x < tft.width(); x+=radius*2) {
+ for (int16_t y=radius; y < tft.height(); y+=radius*2) {
tft.fillCircle(x, y, radius, color);
}
}
}
void testdrawcircles(uint8_t radius, uint16_t color) {
- for (uint8_t x=0; x < tft.width()+radius; x+=radius*2) {
- for (uint8_t y=0; y < tft.height()+radius; y+=radius*2) {
+ for (int16_t x=0; x < tft.width()+radius; x+=radius*2) {
+ for (int16_t y=0; y < tft.height()+radius; y+=radius*2) {
tft.drawCircle(x, y, radius, color);
}
}
@@ -234,6 +236,7 @@ void testroundrects() {
}
void tftPrintTest() {
+ tft.setTextWrap(false);
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 30);
tft.setTextColor(ST7735_RED);
@@ -91,6 +91,7 @@ void setup(void) {
tft.fillScreen(ST7735_BLACK);
testfillcircles(10, ST7735_BLUE);
testdrawcircles(10, ST7735_WHITE);
+ delay(500);
testroundrects();
delay(500);
@@ -114,80 +115,81 @@ void loop() {
void testlines(uint16_t color) {
tft.fillScreen(ST7735_BLACK);
- for (uint16_t x=0; x < tft.width(); x+=6) {
+ for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(0, 0, x, tft.height()-1, color);
}
- for (uint16_t y=0; y < tft.height(); y+=6) {
+ for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(0, 0, tft.width()-1, y, color);
}
tft.fillScreen(ST7735_BLACK);
- for (uint16_t x=0; x < tft.width(); x+=6) {
+ for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
}
- for (uint16_t y=0; y < tft.height(); y+=6) {
+ for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(tft.width()-1, 0, 0, y, color);
}
tft.fillScreen(ST7735_BLACK);
- for (uint16_t x=0; x < tft.width(); x+=6) {
+ for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(0, tft.height()-1, x, 0, color);
}
- for (uint16_t y=0; y < tft.height(); y+=6) {
+ for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
}
tft.fillScreen(ST7735_BLACK);
- for (uint16_t x=0; x < tft.width(); x+=6) {
+ for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
}
- for (uint16_t y=0; y < tft.height(); y+=6) {
+ for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
}
}
void testdrawtext(char *text, uint16_t color) {
tft.setCursor(0, 0);
tft.setTextColor(color);
+ tft.setTextWrap(true);
tft.print(text);
}
void testfastlines(uint16_t color1, uint16_t color2) {
tft.fillScreen(ST7735_BLACK);
- for (uint16_t y=0; y < tft.height(); y+=5) {
+ for (int16_t y=0; y < tft.height(); y+=5) {
tft.drawFastHLine(0, y, tft.width(), color1);
}
- for (uint16_t x=0; x < tft.width(); x+=5) {
+ for (int16_t x=0; x < tft.width(); x+=5) {
tft.drawFastVLine(x, 0, tft.height(), color2);
}
}
void testdrawrects(uint16_t color) {
tft.fillScreen(ST7735_BLACK);
- for (uint16_t x=0; x < tft.width(); x+=6) {
+ for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
}
}
void testfillrects(uint16_t color1, uint16_t color2) {
tft.fillScreen(ST7735_BLACK);
- for (uint16_t x=tft.width()-1; x > 6; x-=6) {
+ for (int16_t x=tft.width()-1; x > 6; x-=6) {
tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1);
tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2);
}
}
void testfillcircles(uint8_t radius, uint16_t color) {
- for (uint8_t x=radius; x < tft.width(); x+=radius*2) {
- for (uint8_t y=radius; y < tft.height(); y+=radius*2) {
+ for (int16_t x=radius; x < tft.width(); x+=radius*2) {
+ for (int16_t y=radius; y < tft.height(); y+=radius*2) {
tft.fillCircle(x, y, radius, color);
}
}
}
void testdrawcircles(uint8_t radius, uint16_t color) {
- for (uint8_t x=0; x < tft.width()+radius; x+=radius*2) {
- for (uint8_t y=0; y < tft.height()+radius; y+=radius*2) {
+ for (int16_t x=0; x < tft.width()+radius; x+=radius*2) {
+ for (int16_t y=0; y < tft.height()+radius; y+=radius*2) {
tft.drawCircle(x, y, radius, color);
}
}
@@ -233,6 +235,7 @@ void testroundrects() {
}
void tftPrintTest() {
+ tft.setTextWrap(false);
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 30);
tft.setTextColor(ST7735_RED);
@@ -54,6 +54,7 @@ void setup(void) {
Serial.println("init");
+ tft.setTextWrap(false); // Allow text to run off right edge
tft.fillScreen(ST7735_BLACK);
Serial.println("This is a test of the rotation capabilities of the TFT library!");
@@ -53,6 +53,7 @@ void setup(void) {
Serial.println("init");
+ tft.setTextWrap(false); // Allow text to run off right edge
tft.fillScreen(ST7735_BLACK);
Serial.println("This is a test of the rotation capabilities of the TFT library!");

0 comments on commit d742806

Please sign in to comment.