Skip to content

Commit 47b22b8

Browse files
committed
Use TFT_eSPI
1 parent dcaa5c6 commit 47b22b8

File tree

218 files changed

+49329
-20
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

218 files changed

+49329
-20
lines changed

src/Braccio++.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
#include "drivers/Ticker.h"
1010
#include "lib/PCINT/src/pcint.h"
1111
#include "lib/ArduinoMenu/src/menu.h"
12-
#include "lib/ArduinoMenu/src/menuIO/adafruitGfxOut.h"
12+
#include "lib/ArduinoMenu/src/menuIO/TFT_eSPIOut.h"
1313
#include "lib/ArduinoMenu/src/menuIO/interruptPins.h"
1414
#include "lib/ArduinoMenu/src/menuIO/keyIn.h"
1515
#include "lib/ArduinoMenu/src/menuIO/chainStream.h"
1616
#include "lib/ArduinoMenu/src/menuIO/serialOut.h"
1717
#include "lib/ArduinoMenu/src/menuIO/serialIn.h"
18-
#include <Adafruit_GFX.h> // Core graphics library
19-
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
20-
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
18+
#include "lib/TFT_eSPI/TFT_eSPI.h" // Hardware-specific library
2119

2220
class MotorsWrapper {
2321
public:

src/Braccio.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,10 @@ bool BraccioClass::begin(positionMode _positionMode) {
4949

5050
braccio::encoder.begin();
5151

52-
braccio::gfx.init(240, 240);
53-
braccio::gfx.setRotation(2);
54-
braccio::gfx.setTextSize(textScale);//test scalling
55-
braccio::gfx.setTextWrap(false);
56-
braccio::gfx.fillScreen(ST7735_BLACK);
57-
//gfx.setFont(&FreeMono12pt7b);
58-
braccio::gfx.setTextColor(ST7735_RED, ST7735_BLACK);
52+
braccio::gfx.init();
53+
braccio::gfx.setRotation(4);
54+
braccio::gfx.fillScreen(TFT_BLACK);
55+
braccio::gfx.setFreeFont(&FreeMono18pt7b);
5956
braccio::gfx.println("Arduino\nBraccio++");
6057

6158
#ifdef __MBED__
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/***************************************************************************************
2+
** Code for the GFX button UI element
3+
** Grabbed from Adafruit_GFX library and enhanced to handle any label font
4+
***************************************************************************************/
5+
TFT_eSPI_Button::TFT_eSPI_Button(void) {
6+
_gfx = nullptr;
7+
_xd = 0;
8+
_yd = 0;
9+
_textdatum = MC_DATUM;
10+
_label[9] = '\0';
11+
}
12+
13+
// Classic initButton() function: pass center & size
14+
void TFT_eSPI_Button::initButton(
15+
TFT_eSPI *gfx, int16_t x, int16_t y, uint16_t w, uint16_t h,
16+
uint16_t outline, uint16_t fill, uint16_t textcolor,
17+
char *label, uint8_t textsize)
18+
{
19+
// Tweak arguments and pass to the newer initButtonUL() function...
20+
initButtonUL(gfx, x - (w / 2), y - (h / 2), w, h, outline, fill,
21+
textcolor, label, textsize);
22+
}
23+
24+
// Newer function instead accepts upper-left corner & size
25+
void TFT_eSPI_Button::initButtonUL(
26+
TFT_eSPI *gfx, int16_t x1, int16_t y1, uint16_t w, uint16_t h,
27+
uint16_t outline, uint16_t fill, uint16_t textcolor,
28+
char *label, uint8_t textsize)
29+
{
30+
_x1 = x1;
31+
_y1 = y1;
32+
_w = w;
33+
_h = h;
34+
_outlinecolor = outline;
35+
_fillcolor = fill;
36+
_textcolor = textcolor;
37+
_textsize = textsize;
38+
_gfx = gfx;
39+
strncpy(_label, label, 9);
40+
}
41+
42+
// Adjust text datum and x, y deltas
43+
void TFT_eSPI_Button::setLabelDatum(int16_t x_delta, int16_t y_delta, uint8_t datum)
44+
{
45+
_xd = x_delta;
46+
_yd = y_delta;
47+
_textdatum = datum;
48+
}
49+
50+
void TFT_eSPI_Button::drawButton(bool inverted, String long_name) {
51+
uint16_t fill, outline, text;
52+
53+
if(!inverted) {
54+
fill = _fillcolor;
55+
outline = _outlinecolor;
56+
text = _textcolor;
57+
} else {
58+
fill = _textcolor;
59+
outline = _outlinecolor;
60+
text = _fillcolor;
61+
}
62+
63+
uint8_t r = min(_w, _h) / 4; // Corner radius
64+
_gfx->fillRoundRect(_x1, _y1, _w, _h, r, fill);
65+
_gfx->drawRoundRect(_x1, _y1, _w, _h, r, outline);
66+
67+
_gfx->setTextColor(text, fill);
68+
_gfx->setTextSize(_textsize);
69+
70+
uint8_t tempdatum = _gfx->getTextDatum();
71+
_gfx->setTextDatum(_textdatum);
72+
uint16_t tempPadding = _gfx->getTextPadding();
73+
_gfx->setTextPadding(0);
74+
75+
if (long_name == "")
76+
_gfx->drawString(_label, _x1 + (_w/2) + _xd, _y1 + (_h/2) - 4 + _yd);
77+
else
78+
_gfx->drawString(long_name, _x1 + (_w/2) + _xd, _y1 + (_h/2) - 4 + _yd);
79+
80+
_gfx->setTextDatum(tempdatum);
81+
_gfx->setTextPadding(tempPadding);
82+
}
83+
84+
bool TFT_eSPI_Button::contains(int16_t x, int16_t y) {
85+
return ((x >= _x1) && (x < (_x1 + _w)) &&
86+
(y >= _y1) && (y < (_y1 + _h)));
87+
}
88+
89+
void TFT_eSPI_Button::press(bool p) {
90+
laststate = currstate;
91+
currstate = p;
92+
}
93+
94+
bool TFT_eSPI_Button::isPressed() { return currstate; }
95+
bool TFT_eSPI_Button::justPressed() { return (currstate && !laststate); }
96+
bool TFT_eSPI_Button::justReleased() { return (!currstate && laststate); }

src/lib/TFT_eSPI/Extensions/Button.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/***************************************************************************************
2+
// The following button class has been ported over from the Adafruit_GFX library so
3+
// should be compatible.
4+
// A slightly different implementation in this TFT_eSPI library allows the button
5+
// legends to be in any font, allow longer labels and to adjust text positioning
6+
// within button
7+
***************************************************************************************/
8+
9+
class TFT_eSPI_Button {
10+
11+
public:
12+
TFT_eSPI_Button(void);
13+
// "Classic" initButton() uses centre & size
14+
void initButton(TFT_eSPI *gfx, int16_t x, int16_t y,
15+
uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
16+
uint16_t textcolor, char *label, uint8_t textsize);
17+
18+
// New/alt initButton() uses upper-left corner & size
19+
void initButtonUL(TFT_eSPI *gfx, int16_t x1, int16_t y1,
20+
uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
21+
uint16_t textcolor, char *label, uint8_t textsize);
22+
23+
// Adjust text datum and x, y deltas
24+
void setLabelDatum(int16_t x_delta, int16_t y_delta, uint8_t datum = MC_DATUM);
25+
26+
void drawButton(bool inverted = false, String long_name = "");
27+
bool contains(int16_t x, int16_t y);
28+
29+
void press(bool p);
30+
bool isPressed();
31+
bool justPressed();
32+
bool justReleased();
33+
34+
private:
35+
TFT_eSPI *_gfx;
36+
int16_t _x1, _y1; // Coordinates of top-left corner of button
37+
int16_t _xd, _yd; // Button text datum offsets (wrt centre of button)
38+
uint16_t _w, _h; // Width and height of button
39+
uint8_t _textsize, _textdatum; // Text size multiplier and text datum for button
40+
uint16_t _outlinecolor, _fillcolor, _textcolor;
41+
char _label[10]; // Button text is 9 chars maximum unless long_name used
42+
43+
bool currstate, laststate; // Button states
44+
};

0 commit comments

Comments
 (0)