Skip to content

Commit 7bb1218

Browse files
committed
Added Arduino TFT/Processing compatibility
1 parent 9e9a288 commit 7bb1218

File tree

2 files changed

+169
-1
lines changed

2 files changed

+169
-1
lines changed

src/LcdScreen.cpp

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,127 @@ LcdScreen::LcdScreen(uint8_t CS, uint8_t RS, uint8_t RST)
4040
{ }
4141

4242
void LcdScreen::begin() {
43-
//initR(INITR_REDTAB);
4443
initG();
4544
setRotation(1);
4645
}
46+
47+
// Arduino TFT library compatibility.
48+
49+
void LcdScreen::background(uint8_t red, uint8_t green, uint8_t blue) {
50+
background(Color565(red, green, blue));
51+
}
52+
53+
void LcdScreen::background(color c) {
54+
fillScreen(c);
55+
}
56+
57+
void LcdScreen::stroke(uint8_t red, uint8_t green, uint8_t blue) {
58+
stroke(Color565(red, green, blue));
59+
}
60+
61+
void LcdScreen::stroke(color c) {
62+
useStroke = true;
63+
strokeColor = c;
64+
setTextColor(c);
65+
}
66+
67+
void LcdScreen::noStroke() {
68+
useStroke = false;
69+
}
70+
71+
void LcdScreen::noFill() {
72+
useFill = false;
73+
}
74+
75+
void LcdScreen::fill(uint8_t red, uint8_t green, uint8_t blue) {
76+
fill(Color565(red, green, blue));
77+
}
78+
79+
void LcdScreen::fill(color c) {
80+
useFill = true;
81+
fillColor = c;
82+
}
83+
84+
void LcdScreen::point(int16_t x, int16_t y) {
85+
if (!useStroke)
86+
return;
87+
88+
drawPixel(x, y, strokeColor);
89+
}
90+
91+
void LcdScreen::text(const char * text, int16_t x, int16_t y) {
92+
if (!useStroke)
93+
return;
94+
95+
setTextWrap(false);
96+
setTextColor(strokeColor);
97+
setCursor(x, y);
98+
print(text);
99+
}
100+
101+
void LcdScreen::textSize(uint8_t size) {
102+
setTextSize(size);
103+
}
104+
105+
void LcdScreen::line(int16_t x1, int16_t y1, int16_t x2, int16_t y2) {
106+
if (!useStroke)
107+
return;
108+
109+
if (x1 == x2) {
110+
if (y1 < y2)
111+
drawFastVLine(x1, y1, y2 - y1, strokeColor);
112+
else
113+
drawFastVLine(x1, y2, y1 - y2, strokeColor);
114+
}
115+
else if (y1 == y2) {
116+
if (x1 < x2)
117+
drawFastHLine(x1, y1, x2 - x1, strokeColor);
118+
else
119+
drawFastHLine(x2, y1, x1 - x2, strokeColor);
120+
}
121+
else {
122+
drawLine(x1, y1, x2, y2, strokeColor);
123+
}
124+
}
125+
126+
void LcdScreen::rect(int16_t x, int16_t y, int16_t width, int16_t height) {
127+
if (useFill) {
128+
fillRect(x, y, width, height, fillColor);
129+
}
130+
if (useStroke) {
131+
drawRect(x, y, width, height, strokeColor);
132+
}
133+
}
134+
135+
void LcdScreen::rect(int16_t x, int16_t y, int16_t width, int16_t height, int16_t radius) {
136+
if (radius == 0) {
137+
rect(x, y, width, height);
138+
}
139+
if (useFill) {
140+
fillRoundRect(x, y, width, height, radius, fillColor);
141+
}
142+
if (useStroke) {
143+
drawRoundRect(x, y, width, height, radius, strokeColor);
144+
}
145+
}
146+
147+
void LcdScreen::circle(int16_t x, int16_t y, int16_t r) {
148+
if (r == 0)
149+
return;
150+
151+
if (useFill) {
152+
fillCircle(x, y, r, fillColor);
153+
}
154+
if (useStroke) {
155+
drawCircle(x, y, r, strokeColor);
156+
}
157+
}
158+
159+
void LcdScreen::triangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3) {
160+
if (useFill) {
161+
fillTriangle(x1, y1, x2, y2, x3, y3, fillColor);
162+
}
163+
if (useStroke) {
164+
drawTriangle(x1, y1, x2, y2, x3, y3, strokeColor);
165+
}
166+
}

src/LcdScreen.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7272
#warning "The SD library was not found. loadImage() and image() won't be supported."
7373
#endif
7474

75+
typedef uint16_t color;
76+
7577
/// The Arduino LCD is a ILI9163-based device.
7678
/// By default, it is mounted horizontally.
7779
/// LcdScreen class follows the convention of other
@@ -89,6 +91,52 @@ class LcdScreen : public Arduino_ILI9163 {
8991

9092
void image(PImage & img, uint16_t x, uint16_t y);
9193
#endif
94+
95+
// Arduino TFT library compatibility.
96+
void
97+
// http://processing.org/reference/background_.html
98+
background(uint8_t red, uint8_t green, uint8_t blue),
99+
background(color c),
100+
101+
// http://processing.org/reference/fill_.html
102+
fill(uint8_t red, uint8_t green, uint8_t blue),
103+
fill(color c),
104+
105+
// http://processing.org/reference/noFill_.html
106+
noFill(),
107+
108+
// http://processing.org/reference/stroke_.html
109+
stroke(uint8_t red, uint8_t green, uint8_t blue),
110+
stroke(color c),
111+
112+
// http://processing.org/reference/noStroke_.html
113+
noStroke(),
114+
115+
// https://processing.org/reference/text_.html
116+
text(const char * text, int16_t x, int16_t y),
117+
118+
// https://processing.org/reference/textSize_.html
119+
textSize(uint8_t size),
120+
121+
// similar to ellipse() in Processing, but with
122+
// a single radius.
123+
// http://processing.org/reference/ellipse_.html
124+
circle(int16_t x, int16_t y, int16_t r),
125+
point(int16_t x, int16_t y),
126+
line(int16_t x1, int16_t y1, int16_t x2, int16_t y2),
127+
quad(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4),
128+
rect(int16_t x, int16_t y, int16_t width, int16_t height),
129+
rect(int16_t x, int16_t y, int16_t width, int16_t height, int16_t radius),
130+
triangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3);
131+
;
132+
protected:
133+
/*
134+
* Processing-style graphics state
135+
*/
136+
color strokeColor = 0x0000;
137+
bool useStroke = false;
138+
color fillColor = 0x0000;
139+
bool useFill = false;
92140
};
93141

94142
/// Esplora boards have hard-wired connections with

0 commit comments

Comments
 (0)