@@ -50,13 +50,59 @@ void LcdScreen::begin() {
5050#endif
5151}
5252
53+ // Arduino Robot library compatibility.
54+ void LcdScreen::debugPrint (long value, uint8_t x, uint8_t y) {
55+ static long oldVal = 0 ;
56+ stroke (backgroundColor);
57+ text (oldVal, x, y);
58+ stroke (strokeColor);
59+ text (value, x, y);
60+ oldVal = value;
61+ }
62+
63+ void LcdScreen::clearScreen () {
64+ background (backgroundColor);
65+ }
66+
67+ void drawCompassBase (LcdScreen* lcd, color strokeColor) {
68+ lcd->drawCircle (64 , 80 , 50 , strokeColor);
69+ lcd->drawLine (64 , 30 , 64 , 20 , strokeColor);
70+ }
71+
72+ void drawCompassDire (LcdScreen* lcd, int16_t dire, color backgroundColor) {
73+ static uint8_t x_old;
74+ static uint8_t y_old;
75+ static uint8_t x_t_old;
76+ static uint8_t y_t_old;
77+
78+ uint8_t x = 60 * sin (dire / 360.0 *6.28 ) + 64 ;
79+ uint8_t x_t = 40 * sin (dire / 360.0 *6.28 ) + 64 ;
80+ uint8_t y = 60 * cos (dire / 360.0 *6.28 ) + 80 ;
81+ uint8_t y_t = 40 * cos (dire / 360.0 *6.28 ) + 80 ;
82+
83+ lcd->drawLine (x_t_old, y_t_old, x_old, y_old, backgroundColor);
84+ lcd->drawLine (x_t , y_t , x, y, ILI9163_RED);
85+
86+ x_old = x;
87+ y_old = y;
88+ x_t_old = x_t ;
89+ y_t_old = y_t ;
90+ }
91+
92+ void LcdScreen::drawCompass (uint16_t value) {
93+ drawCompassBase (this , strokeColor);
94+ drawCompassDire (this , value, backgroundColor);
95+ debugPrint (value, 57 , 76 );
96+ }
97+
5398// Arduino TFT library compatibility.
5499
55100void LcdScreen::background (uint8_t red, uint8_t green, uint8_t blue) {
56101 background (Color565 (red, green, blue));
57102}
58103
59104void LcdScreen::background (color c) {
105+ backgroundColor = c;
60106 fillScreen (c);
61107}
62108
@@ -88,85 +134,114 @@ void LcdScreen::fill(color c) {
88134}
89135
90136void LcdScreen::point (int16_t x, int16_t y) {
91- if (!useStroke)
92- return ;
137+ if (!useStroke)
138+ return ;
139+
140+ drawPixel (x, y, strokeColor);
141+ }
142+
143+ void LcdScreen::text (char value, uint8_t x, uint8_t y) {
144+ if (!useStroke)
145+ return ;
146+
147+ setTextWrap (false );
148+ setTextColor (strokeColor);
149+ setCursor (x, y);
150+ print (value);
151+ }
152+
153+ void LcdScreen::text (int value, uint8_t x, uint8_t y) {
154+ if (!useStroke)
155+ return ;
156+
157+ setTextWrap (false );
158+ setTextColor (strokeColor);
159+ setCursor (x, y);
160+ print (value);
161+ }
162+ void LcdScreen::text (long value, uint8_t x, uint8_t y) {
163+ if (!useStroke)
164+ return ;
93165
94- drawPixel (x, y, strokeColor);
166+ setTextWrap (false );
167+ setTextColor (strokeColor);
168+ setCursor (x, y);
169+ print (value);
95170}
96171
97172void LcdScreen::text (const char * text, int16_t x, int16_t y) {
98- if (!useStroke)
99- return ;
173+ if (!useStroke)
174+ return ;
100175
101- setTextWrap (false );
102- setTextColor (strokeColor);
103- setCursor (x, y);
104- print (text);
176+ setTextWrap (false );
177+ setTextColor (strokeColor);
178+ setCursor (x, y);
179+ print (text);
105180}
106181
107182void LcdScreen::textSize (uint8_t size) {
108- setTextSize (size);
183+ setTextSize (size);
109184}
110185
111186void LcdScreen::line (int16_t x1, int16_t y1, int16_t x2, int16_t y2) {
112- if (!useStroke)
113- return ;
114-
115- if (x1 == x2) {
116- if (y1 < y2)
117- drawFastVLine (x1, y1, y2 - y1, strokeColor);
118- else
119- drawFastVLine (x1, y2, y1 - y2, strokeColor);
120- }
121- else if (y1 == y2) {
122- if (x1 < x2)
123- drawFastHLine (x1, y1, x2 - x1, strokeColor);
124- else
125- drawFastHLine (x2, y1, x1 - x2, strokeColor);
126- }
127- else {
128- drawLine (x1, y1, x2, y2, strokeColor);
129- }
187+ if (!useStroke)
188+ return ;
189+
190+ if (x1 == x2) {
191+ if (y1 < y2)
192+ drawFastVLine (x1, y1, y2 - y1, strokeColor);
193+ else
194+ drawFastVLine (x1, y2, y1 - y2, strokeColor);
195+ }
196+ else if (y1 == y2) {
197+ if (x1 < x2)
198+ drawFastHLine (x1, y1, x2 - x1, strokeColor);
199+ else
200+ drawFastHLine (x2, y1, x1 - x2, strokeColor);
201+ }
202+ else {
203+ drawLine (x1, y1, x2, y2, strokeColor);
204+ }
130205}
131206
132207void LcdScreen::rect (int16_t x, int16_t y, int16_t width, int16_t height) {
133- if (useFill) {
134- fillRect (x, y, width, height, fillColor);
135- }
136- if (useStroke) {
137- drawRect (x, y, width, height, strokeColor);
138- }
208+ if (useFill) {
209+ fillRect (x, y, width, height, fillColor);
210+ }
211+ if (useStroke) {
212+ drawRect (x, y, width, height, strokeColor);
213+ }
139214}
140215
141216void LcdScreen::rect (int16_t x, int16_t y, int16_t width, int16_t height, int16_t radius) {
142- if (radius == 0 ) {
143- rect (x, y, width, height);
144- }
145- if (useFill) {
146- fillRoundRect (x, y, width, height, radius, fillColor);
147- }
148- if (useStroke) {
149- drawRoundRect (x, y, width, height, radius, strokeColor);
150- }
217+ if (radius == 0 ) {
218+ rect (x, y, width, height);
219+ }
220+ if (useFill) {
221+ fillRoundRect (x, y, width, height, radius, fillColor);
222+ }
223+ if (useStroke) {
224+ drawRoundRect (x, y, width, height, radius, strokeColor);
225+ }
151226}
152227
153228void LcdScreen::circle (int16_t x, int16_t y, int16_t r) {
154- if (r == 0 )
155- return ;
229+ if (r == 0 )
230+ return ;
156231
157- if (useFill) {
158- fillCircle (x, y, r, fillColor);
159- }
160- if (useStroke) {
161- drawCircle (x, y, r, strokeColor);
162- }
232+ if (useFill) {
233+ fillCircle (x, y, r, fillColor);
234+ }
235+ if (useStroke) {
236+ drawCircle (x, y, r, strokeColor);
237+ }
163238}
164239
165240void LcdScreen::triangle (int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3) {
166- if (useFill) {
167- fillTriangle (x1, y1, x2, y2, x3, y3, fillColor);
168- }
169- if (useStroke) {
170- drawTriangle (x1, y1, x2, y2, x3, y3, strokeColor);
171- }
241+ if (useFill) {
242+ fillTriangle (x1, y1, x2, y2, x3, y3, fillColor);
243+ }
244+ if (useStroke) {
245+ drawTriangle (x1, y1, x2, y2, x3, y3, strokeColor);
246+ }
172247}
0 commit comments