Skip to content

Commit 1f1d39d

Browse files
authored
Merge pull request #193 from fdlamotte/t114-display
T114 display
2 parents fbfa8bb + f9bc3a1 commit 1f1d39d

File tree

15 files changed

+228
-33
lines changed

15 files changed

+228
-33
lines changed

examples/companion_radio/UITask.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ void UITask::begin(DisplayDriver* display, const char* node_name, const char* bu
4343
*dash = 0;
4444
}
4545

46+
#ifdef PIN_USER_BTN
47+
pinMode(PIN_USER_BTN, INPUT);
48+
#endif
49+
4650
// v1.2.3 (1 Jan 2025)
4751
sprintf(_version_info, "%s (%s)", version, build_date);
4852
}
@@ -57,6 +61,7 @@ void UITask::msgRead(int msgcount) {
5761
void UITask::clearMsgPreview() {
5862
_origin[0] = 0;
5963
_msg[0] = 0;
64+
_need_refresh = true;
6065
}
6166

6267
void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) {
@@ -72,6 +77,7 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, i
7277
if (_display != NULL) {
7378
if (!_display->isOn()) _display->turnOn();
7479
_auto_off = millis() + AUTO_OFF_MILLIS; // extend the auto-off timer
80+
_need_refresh = true;
7581
}
7682
}
7783

@@ -83,22 +89,29 @@ void UITask::renderCurrScreen() {
8389
// render message preview
8490
_display->setCursor(0, 0);
8591
_display->setTextSize(1);
92+
_display->setColor(DisplayDriver::GREEN);
8693
_display->print(_node_name);
8794

8895
_display->setCursor(0, 12);
96+
_display->setColor(DisplayDriver::YELLOW);
8997
_display->print(_origin);
9098
_display->setCursor(0, 24);
99+
_display->setColor(DisplayDriver::LIGHT);
91100
_display->print(_msg);
92101

93102
_display->setCursor(100, 9);
94103
_display->setTextSize(2);
104+
_display->setColor(DisplayDriver::ORANGE);
95105
sprintf(tmp, "%d", _msgcount);
96106
_display->print(tmp);
97107
} else {
98108
// render 'home' screen
109+
_display->setColor(DisplayDriver::BLUE);
99110
_display->drawXbm(0, 0, meshcore_logo, 128, 13);
100111
_display->setCursor(0, 20);
101112
_display->setTextSize(1);
113+
114+
_display->setColor(DisplayDriver::LIGHT);
102115
_display->print(_node_name);
103116

104117
_display->setCursor(0, 32);
@@ -108,12 +121,14 @@ void UITask::renderCurrScreen() {
108121
//_display->printf("freq : %03.2f sf %d\n", _prefs.freq, _prefs.sf);
109122
//_display->printf("bw : %03.2f cr %d\n", _prefs.bw, _prefs.cr);
110123
} else if (_pin_code != 0) {
124+
_display->setColor(DisplayDriver::RED);
111125
_display->setTextSize(2);
112126
_display->setCursor(0, 43);
113127
sprintf(tmp, "Pin:%d", _pin_code);
114128
_display->print(tmp);
115129
}
116130
}
131+
_need_refresh = false;
117132
}
118133

119134
void UITask::userLedHandler() {
@@ -157,6 +172,7 @@ void UITask::buttonHandler() {
157172
clearMsgPreview();
158173
} else {
159174
_display->turnOn();
175+
_need_refresh = true;
160176
}
161177
_auto_off = cur_time + AUTO_OFF_MILLIS; // extend auto-off timer
162178
}
@@ -182,7 +198,7 @@ void UITask::loop() {
182198
userLedHandler();
183199

184200
if (_display != NULL && _display->isOn()) {
185-
if (millis() >= _next_refresh) {
201+
if (millis() >= _next_refresh && _need_refresh) {
186202
_display->startFrame();
187203
renderCurrScreen();
188204
_display->endFrame();

examples/companion_radio/UITask.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class UITask {
1515
char _origin[62];
1616
char _msg[80];
1717
int _msgcount;
18+
bool _need_refresh = true;
1819

1920
void renderCurrScreen();
2021
void buttonHandler();

examples/companion_radio/main.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@
5959

6060
#ifdef DISPLAY_CLASS
6161
#include "UITask.h"
62-
#include <helpers/ui/SSD1306Display.h>
63-
64-
static DISPLAY_CLASS display;
62+
#ifdef ST7789
63+
#include <helpers/ui/ST7789Display.h>
64+
#else
65+
#include <helpers/ui/SSD1306Display.h>
66+
#endif
67+
static DISPLAY_CLASS display;
6568
#define HAS_UI
6669
#endif
6770

src/helpers/ui/DisplayDriver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class DisplayDriver {
77
protected:
88
DisplayDriver(int w, int h) { _w = w; _h = h; }
99
public:
10-
enum Color { DARK, LIGHT };
10+
enum Color { DARK=0, LIGHT, RED, GREEN, BLUE, YELLOW, ORANGE }; // on b/w screen, colors will be !=0 synonym of light
1111

1212
int width() const { return _w; }
1313
int height() const { return _h; }

src/helpers/ui/SSD1306Display.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void SSD1306Display::setTextSize(int sz) {
3838
}
3939

4040
void SSD1306Display::setColor(Color c) {
41-
_color = (c == LIGHT) ? SSD1306_WHITE : SSD1306_BLACK;
41+
_color = (c != 0) ? SSD1306_WHITE : SSD1306_BLACK;
4242
display.setTextColor(_color);
4343
}
4444

src/helpers/ui/ST7789Display.cpp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#ifdef ST7789
2+
3+
#include "ST7789Display.h"
4+
5+
bool ST7789Display::i2c_probe(TwoWire& wire, uint8_t addr) {
6+
return true;
7+
/*
8+
wire.beginTransmission(addr);
9+
uint8_t error = wire.endTransmission();
10+
return (error == 0);
11+
*/
12+
}
13+
14+
bool ST7789Display::begin() {
15+
if(!_isOn) {
16+
pinMode(PIN_TFT_VDD_CTL, OUTPUT);
17+
pinMode(PIN_TFT_LEDA_CTL, OUTPUT);
18+
digitalWrite(PIN_TFT_VDD_CTL, LOW);
19+
digitalWrite(PIN_TFT_LEDA_CTL, LOW);
20+
digitalWrite(PIN_TFT_RST, HIGH);
21+
22+
display.init(135, 240);
23+
display.setRotation(2);
24+
display.setSPISpeed(40000000);
25+
display.fillScreen(ST77XX_BLACK);
26+
display.setTextColor(ST77XX_WHITE);
27+
display.setTextSize(2);
28+
display.cp437(true); // Use full 256 char 'Code Page 437' font
29+
30+
_isOn = true;
31+
}
32+
return true;
33+
}
34+
35+
void ST7789Display::turnOn() {
36+
ST7789Display::begin();
37+
}
38+
39+
void ST7789Display::turnOff() {
40+
digitalWrite(PIN_TFT_VDD_CTL, HIGH);
41+
digitalWrite(PIN_TFT_LEDA_CTL, HIGH);
42+
digitalWrite(PIN_TFT_RST, LOW);
43+
// digitalWrite(PIN_TFT_VDD_CTL, LOW);
44+
// digitalWrite(PIN_TFT_LEDA_CTL, LOW);
45+
_isOn = false;
46+
}
47+
48+
void ST7789Display::clear() {
49+
display.fillScreen(ST77XX_BLACK);
50+
}
51+
52+
void ST7789Display::startFrame(Color bkg) {
53+
display.fillScreen(0x00);
54+
display.setTextColor(ST77XX_WHITE);
55+
display.setTextSize(2);
56+
display.cp437(true); // Use full 256 char 'Code Page 437' font
57+
}
58+
59+
void ST7789Display::setTextSize(int sz) {
60+
display.setTextSize(sz);
61+
}
62+
63+
void ST7789Display::setColor(Color c) {
64+
switch (c) {
65+
case DisplayDriver::DARK :
66+
_color = ST77XX_BLACK;
67+
break;
68+
case DisplayDriver::LIGHT :
69+
_color = ST77XX_WHITE;
70+
break;
71+
case DisplayDriver::RED :
72+
_color = ST77XX_RED;
73+
break;
74+
case DisplayDriver::GREEN :
75+
_color = ST77XX_GREEN;
76+
break;
77+
case DisplayDriver::BLUE :
78+
_color = ST77XX_BLUE;
79+
break;
80+
case DisplayDriver::YELLOW :
81+
_color = ST77XX_YELLOW;
82+
break;
83+
case DisplayDriver::ORANGE :
84+
_color = ST77XX_ORANGE;
85+
break;
86+
default:
87+
_color = ST77XX_WHITE;
88+
break;
89+
}
90+
display.setTextColor(_color);
91+
}
92+
93+
void ST7789Display::setCursor(int x, int y) {
94+
display.setCursor(x, y);
95+
}
96+
97+
void ST7789Display::print(const char* str) {
98+
display.print(str);
99+
}
100+
101+
void ST7789Display::fillRect(int x, int y, int w, int h) {
102+
display.fillRect(x, y, w, h, _color);
103+
}
104+
105+
void ST7789Display::drawRect(int x, int y, int w, int h) {
106+
display.drawRect(x, y, w, h, _color);
107+
}
108+
109+
void ST7789Display::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
110+
display.drawBitmap(x, y, bits, w, h, _color);
111+
}
112+
113+
void ST7789Display::endFrame() {
114+
// display.display();
115+
}
116+
117+
#endif

src/helpers/ui/ST7789Display.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#pragma once
2+
3+
#include "DisplayDriver.h"
4+
#include <Wire.h>
5+
#include <SPI.h>
6+
#include <Adafruit_GFX.h>
7+
#include <Adafruit_ST7789.h>
8+
9+
class ST7789Display : public DisplayDriver {
10+
Adafruit_ST7789 display;
11+
bool _isOn;
12+
uint16_t _color;
13+
14+
bool i2c_probe(TwoWire& wire, uint8_t addr);
15+
public:
16+
ST7789Display() : DisplayDriver(135, 240), display(&SPI1, PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RST) { _isOn = false; }
17+
// ST7789Display() : DisplayDriver(135, 240), display(PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_SDA, PIN_TFT_SCL, PIN_TFT_RST) { _isOn = false; }
18+
bool begin();
19+
20+
bool isOn() override { return _isOn; }
21+
void turnOn() override;
22+
void turnOff() override;
23+
void clear() override;
24+
void startFrame(Color bkg = DARK) override;
25+
void setTextSize(int sz) override;
26+
void setColor(Color c) override;
27+
void setCursor(int x, int y) override;
28+
void print(const char* str) override;
29+
void fillRect(int x, int y, int w, int h) override;
30+
void drawRect(int x, int y, int w, int h) override;
31+
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override;
32+
void endFrame() override;
33+
};

variants/heltec_v2/platformio.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ build_flags =
3232
; -D MESH_DEBUG=1
3333
build_src_filter = ${Heltec_lora32_v2.build_src_filter}
3434
+<../examples/simple_repeater>
35-
+<helpers/ui/*.cpp>
35+
+<helpers/ui/SSD1306Display.cpp>
3636
lib_deps =
3737
${Heltec_lora32_v2.lib_deps}
3838
${esp32_ota.lib_deps}
@@ -50,7 +50,7 @@ build_flags =
5050
; -D MESH_PACKET_LOGGING=1
5151
; -D MESH_DEBUG=1
5252
build_src_filter = ${Heltec_lora32_v2.build_src_filter}
53-
+<helpers/ui/*.cpp>
53+
+<helpers/ui/SSD1306Display.cpp>
5454
+<../examples/simple_room_server>
5555
lib_deps =
5656
${Heltec_lora32_v2.lib_deps}
@@ -81,7 +81,7 @@ build_flags =
8181
; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1
8282
build_src_filter = ${Heltec_lora32_v2.build_src_filter}
8383
+<helpers/esp32/*.cpp>
84-
+<helpers/ui/*.cpp>
84+
+<helpers/ui/SSD1306Display.cpp>
8585
+<../examples/companion_radio>
8686
lib_deps =
8787
${Heltec_lora32_v2.lib_deps}
@@ -102,7 +102,7 @@ build_flags =
102102
; -D MESH_DEBUG=1
103103
build_src_filter = ${Heltec_lora32_v2.build_src_filter}
104104
+<helpers/esp32/*.cpp>
105-
+<helpers/ui/*.cpp>
105+
+<helpers/ui/SSD1306Display.cpp>
106106
+<../examples/companion_radio>
107107
lib_deps =
108108
${Heltec_lora32_v2.lib_deps}

variants/heltec_v3/platformio.ini

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ build_flags =
3434
-D MESH_PACKET_LOGGING=1
3535
; -D MESH_DEBUG=1
3636
build_src_filter = ${Heltec_lora32_v3.build_src_filter}
37-
+<helpers/ui/*.cpp>
37+
+<helpers/ui/SSD1306Display.cpp>
3838
+<../examples/simple_repeater>
3939
lib_deps =
4040
${Heltec_lora32_v3.lib_deps}
@@ -53,7 +53,7 @@ build_flags =
5353
; -D MESH_PACKET_LOGGING=1
5454
; -D MESH_DEBUG=1
5555
build_src_filter = ${Heltec_lora32_v3.build_src_filter}
56-
+<helpers/ui/*.cpp>
56+
+<helpers/ui/SSD1306Display.cpp>
5757
+<../examples/simple_room_server>
5858
lib_deps =
5959
${Heltec_lora32_v3.lib_deps}
@@ -85,7 +85,7 @@ build_flags =
8585
; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1
8686
; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1
8787
build_src_filter = ${Heltec_lora32_v3.build_src_filter}
88-
+<helpers/ui/*.cpp>
88+
+<helpers/ui/SSD1306Display.cpp>
8989
+<../examples/companion_radio>
9090
lib_deps =
9191
${Heltec_lora32_v3.lib_deps}
@@ -105,7 +105,7 @@ build_flags =
105105
; -D MESH_PACKET_LOGGING=1
106106
; -D MESH_DEBUG=1
107107
build_src_filter = ${Heltec_lora32_v3.build_src_filter}
108-
+<helpers/ui/*.cpp>
108+
+<helpers/ui/SSD1306Display.cpp>
109109
+<helpers/esp32/*.cpp>
110110
+<../examples/companion_radio>
111111
lib_deps =
@@ -127,7 +127,7 @@ build_flags =
127127
; -D MESH_PACKET_LOGGING=1
128128
; -D MESH_DEBUG=1
129129
build_src_filter = ${Heltec_lora32_v3.build_src_filter}
130-
+<helpers/ui/*.cpp>
130+
+<helpers/ui/SSD1306Display.cpp>
131131
+<helpers/esp32/*.cpp>
132132
+<../examples/companion_radio>
133133
lib_deps =

0 commit comments

Comments
 (0)