added string drawing and test. doesn't inherit the printing library (yet)

This commit is contained in:
Ladyada
2011-02-11 16:52:16 -05:00
parent 6e8edf0202
commit 2eb12095df
3 changed files with 38 additions and 0 deletions
+27
View File
@@ -2,6 +2,7 @@
// MIT license
#include "TFTLCD.h"
#include "glcdfont.c"
#include <avr/pgmspace.h>
void TFTLCD::goHome(void) {
@@ -10,6 +11,32 @@ void TFTLCD::goHome(void) {
writeCommand(0x0022); // Write Data to GRAM (R22h)
}
void TFTLCD::drawString(uint16_t x, uint16_t y, char *c,
uint16_t color, uint8_t size) {
while (c[0] != 0) {
drawChar(x, y, c[0], color, size);
x += size*6;
c++;
}
}
// draw a character
void TFTLCD::drawChar(uint16_t x, uint16_t y, char c,
uint16_t color, uint8_t size) {
for (uint8_t i =0; i<5; i++ ) {
uint8_t line = pgm_read_byte(font+(c*5)+i);
for (uint8_t j = 0; j<8; j++) {
if (line & 0x1) {
if (size == 1) // default size
drawPixel(x+i, y+j, color);
else { // big size
fillRect(x+i*size, y+j*size, size, size, color);
}
}
line >>= 1;
}
}
}
// draw a rectangle
void TFTLCD::drawRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
uint16_t color) {