Skip to content

Commit 5b4544b

Browse files
authored
Merge pull request #889 from fdlamotte/sensecap_indicator
Sensecap indicator
2 parents 920ac51 + ce70792 commit 5b4544b

File tree

6 files changed

+427
-0
lines changed

6 files changed

+427
-0
lines changed

src/helpers/ui/LGFXDisplay.cpp

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#include "LGFXDisplay.h"
2+
3+
bool LGFXDisplay::begin() {
4+
turnOn();
5+
display->init();
6+
display->setRotation(1);
7+
display->setBrightness(64);
8+
display->setColorDepth(8);
9+
display->setTextColor(TFT_WHITE);
10+
11+
buffer.setColorDepth(8);
12+
buffer.setPsram(true);
13+
buffer.createSprite(width(), height());
14+
15+
return true;
16+
}
17+
18+
void LGFXDisplay::turnOn() {
19+
// display->wakeup();
20+
if (!_isOn) {
21+
display->wakeup();
22+
}
23+
_isOn = true;
24+
}
25+
26+
void LGFXDisplay::turnOff() {
27+
if (_isOn) {
28+
display->sleep();
29+
}
30+
_isOn = false;
31+
}
32+
33+
void LGFXDisplay::clear() {
34+
// display->clearDisplay();
35+
buffer.clearDisplay();
36+
}
37+
38+
void LGFXDisplay::startFrame(Color bkg) {
39+
// display->startWrite();
40+
// display->getScanLine();
41+
buffer.clearDisplay();
42+
buffer.setTextColor(TFT_WHITE);
43+
}
44+
45+
void LGFXDisplay::setTextSize(int sz) {
46+
buffer.setTextSize(sz);
47+
}
48+
49+
void LGFXDisplay::setColor(Color c) {
50+
// _color = (c != 0) ? ILI9342_WHITE : ILI9342_BLACK;
51+
switch (c) {
52+
case DARK:
53+
_color = TFT_BLACK;
54+
break;
55+
case LIGHT:
56+
_color = TFT_WHITE;
57+
break;
58+
case RED:
59+
_color = TFT_RED;
60+
break;
61+
case GREEN:
62+
_color = TFT_GREEN;
63+
break;
64+
case BLUE:
65+
_color = TFT_BLUE;
66+
break;
67+
case YELLOW:
68+
_color = TFT_YELLOW;
69+
break;
70+
case ORANGE:
71+
_color = TFT_ORANGE;
72+
break;
73+
default:
74+
_color = TFT_WHITE;
75+
}
76+
buffer.setTextColor(_color);
77+
}
78+
79+
void LGFXDisplay::setCursor(int x, int y) {
80+
buffer.setCursor(x, y);
81+
}
82+
83+
void LGFXDisplay::print(const char* str) {
84+
buffer.println(str);
85+
// Serial.println(str);
86+
}
87+
88+
void LGFXDisplay::fillRect(int x, int y, int w, int h) {
89+
buffer.fillRect(x, y, w, h, _color);
90+
}
91+
92+
void LGFXDisplay::drawRect(int x, int y, int w, int h) {
93+
buffer.drawRect(x, y, w, h, _color);
94+
}
95+
96+
void LGFXDisplay::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
97+
buffer.drawBitmap(x, y, bits, w, h, _color);
98+
}
99+
100+
uint16_t LGFXDisplay::getTextWidth(const char* str) {
101+
return buffer.textWidth(str);
102+
}
103+
104+
void LGFXDisplay::endFrame() {
105+
display->startWrite();
106+
if (UI_ZOOM != 1) {
107+
buffer.pushRotateZoom(display, display->width()/2, display->height()/2 , 0, UI_ZOOM, UI_ZOOM);
108+
} else {
109+
buffer.pushSprite(display, 0, 0);
110+
}
111+
display->endWrite();
112+
}
113+
114+
bool LGFXDisplay::getTouch(int *x, int *y) {
115+
lgfx::v1::touch_point_t point;
116+
display->getTouch(&point);
117+
if (UI_ZOOM != 1) {
118+
*x = point.x / UI_ZOOM;
119+
*y = point.y / UI_ZOOM;
120+
} else {
121+
*x = point.x;
122+
*y = point.y;
123+
}
124+
return (*x >= 0) && (*y >= 0);
125+
}

src/helpers/ui/LGFXDisplay.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include <helpers/ui/DisplayDriver.h>
4+
5+
#define LGFX_USE_V1
6+
#include <LovyanGFX.hpp>
7+
8+
#ifndef UI_ZOOM
9+
#define UI_ZOOM 1
10+
#endif
11+
12+
class LGFXDisplay : public DisplayDriver {
13+
protected:
14+
LGFX_Device* display;
15+
LGFX_Sprite buffer;
16+
17+
bool _isOn = false;
18+
int _color = TFT_WHITE;
19+
20+
public:
21+
LGFXDisplay(int w, int h, LGFX_Device &disp)
22+
: DisplayDriver(w/UI_ZOOM, h/UI_ZOOM), display(&disp) {}
23+
bool begin();
24+
bool isOn() override { return _isOn; }
25+
void turnOn() override;
26+
void turnOff() override;
27+
void clear() override;
28+
void startFrame(Color bkg = DARK) override;
29+
void setTextSize(int sz) override;
30+
void setColor(Color c) override;
31+
void setCursor(int x, int y) override;
32+
void print(const char* str) override;
33+
void fillRect(int x, int y, int w, int h) override;
34+
void drawRect(int x, int y, int w, int h) override;
35+
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override;
36+
uint16_t getTextWidth(const char* str) override;
37+
void endFrame() override;
38+
virtual bool getTouch(int *x, int *y);
39+
};
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#pragma once
2+
3+
#include <helpers/ui/LGFXDisplay.h>
4+
5+
#define LGFX_USE_V1
6+
#include <LovyanGFX.hpp>
7+
8+
#include <lgfx/v1/platforms/esp32s3/Panel_RGB.hpp>
9+
#include <lgfx/v1/platforms/esp32s3/Bus_RGB.hpp>
10+
11+
class LGFX : public lgfx::LGFX_Device
12+
{
13+
lgfx::Panel_ST7701 _panel_instance;
14+
lgfx::Bus_RGB _bus_instance;
15+
lgfx::Light_PWM _light_instance;
16+
lgfx::Touch_FT5x06 _touch_instance;
17+
18+
public:
19+
const uint16_t screenWidth = 480;
20+
const uint16_t screenHeight = 480;
21+
22+
bool hasButton(void) { return true; }
23+
24+
LGFX(void)
25+
{
26+
{
27+
auto cfg = _panel_instance.config();
28+
cfg.memory_width = 480;
29+
cfg.memory_height = 480;
30+
cfg.panel_width = screenWidth;
31+
cfg.panel_height = screenHeight;
32+
cfg.offset_x = 0;
33+
cfg.offset_y = 0;
34+
cfg.offset_rotation = 1;
35+
_panel_instance.config(cfg);
36+
}
37+
38+
{
39+
auto cfg = _panel_instance.config_detail();
40+
cfg.pin_cs = 4 | IO_EXPANDER;
41+
cfg.pin_sclk = 41;
42+
cfg.pin_mosi = 48;
43+
cfg.use_psram = 1;
44+
_panel_instance.config_detail(cfg);
45+
}
46+
47+
{
48+
auto cfg = _bus_instance.config();
49+
cfg.panel = &_panel_instance;
50+
51+
cfg.freq_write = 8000000;
52+
cfg.pin_henable = 18;
53+
54+
cfg.pin_pclk = 21;
55+
cfg.pclk_active_neg = 0;
56+
cfg.pclk_idle_high = 0;
57+
cfg.de_idle_high = 1;
58+
59+
cfg.pin_hsync = 16;
60+
cfg.hsync_polarity = 0;
61+
cfg.hsync_front_porch = 10;
62+
cfg.hsync_pulse_width = 8;
63+
cfg.hsync_back_porch = 50;
64+
65+
cfg.pin_vsync = 17;
66+
cfg.vsync_polarity = 0;
67+
cfg.vsync_front_porch = 10;
68+
cfg.vsync_pulse_width = 8;
69+
cfg.vsync_back_porch = 20;
70+
71+
cfg.pin_d0 = 15;
72+
cfg.pin_d1 = 14;
73+
cfg.pin_d2 = 13;
74+
cfg.pin_d3 = 12;
75+
cfg.pin_d4 = 11;
76+
cfg.pin_d5 = 10;
77+
cfg.pin_d6 = 9;
78+
cfg.pin_d7 = 8;
79+
cfg.pin_d8 = 7;
80+
cfg.pin_d9 = 6;
81+
cfg.pin_d10 = 5;
82+
cfg.pin_d11 = 4;
83+
cfg.pin_d12 = 3;
84+
cfg.pin_d13 = 2;
85+
cfg.pin_d14 = 1;
86+
cfg.pin_d15 = 0;
87+
88+
_bus_instance.config(cfg);
89+
}
90+
_panel_instance.setBus(&_bus_instance);
91+
92+
{
93+
auto cfg = _light_instance.config();
94+
cfg.pin_bl = 45;
95+
_light_instance.config(cfg);
96+
}
97+
_panel_instance.light(&_light_instance);
98+
99+
{
100+
auto cfg = _touch_instance.config();
101+
cfg.pin_cs = GPIO_NUM_NC;
102+
cfg.x_min = 0;
103+
cfg.x_max = 479;
104+
cfg.y_min = 0;
105+
cfg.y_max = 479;
106+
cfg.pin_int = GPIO_NUM_NC;
107+
cfg.pin_rst = GPIO_NUM_NC;
108+
cfg.bus_shared = true;
109+
cfg.offset_rotation = 0;
110+
111+
cfg.i2c_port = 0;
112+
cfg.i2c_addr = 0x48;
113+
cfg.pin_sda = 39;
114+
cfg.pin_scl = 40;
115+
cfg.freq = 400000;
116+
_touch_instance.config(cfg);
117+
_panel_instance.setTouch(&_touch_instance);
118+
}
119+
120+
setPanel(&_panel_instance);
121+
}
122+
};
123+
124+
class SCIndicatorDisplay : public LGFXDisplay {
125+
LGFX disp;
126+
public:
127+
SCIndicatorDisplay() : LGFXDisplay(480, 480, disp) {}
128+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[SenseCapIndicator-ESPNow]
2+
extends = esp32_base
3+
board = esp32-s3-devkitc-1
4+
board_build.arduino.memory_type = qio_opi
5+
board_build.flash_mode = qio
6+
board_build.psram_type = opi
7+
board_upload.flash_size = 8MB
8+
board_upload.maximum_size = 8388608
9+
board_build.partitions = default.csv
10+
build_flags =
11+
${esp32_base.build_flags}
12+
-D PIN_BOARD_SDA=39
13+
-D PIN_BOARD_SCL=40
14+
-D DISPLAY_CLASS=SCIndicatorDisplay
15+
-D DISPLAY_LINES=21
16+
-D LINE_LENGTH=53
17+
-D DISABLE_WIFI_OTA=1
18+
-D IO_EXPANDER=0x40
19+
-D IO_EXPANDER_IRQ=42
20+
-D UI_ZOOM=3.5
21+
-D UI_RECENT_LIST_SIZE=9
22+
-D UI_SENSORS_PAGE=1
23+
-D PIN_USER_BTN=38
24+
-D HAS_TOUCH
25+
-I variants/sensecap_indicator-espnow
26+
build_src_filter = ${esp32_base.build_src_filter}
27+
+<../variants/sensecap_indicator-espnow/*.cpp>
28+
+<helpers/esp32/ESPNOWRadio.cpp>
29+
+<helpers/ui/LGFXDisplay.cpp>
30+
+<helpers/sensors/*>
31+
lib_deps=${esp32_base.lib_deps}
32+
adafruit/Adafruit BusIO @ ^1.17.2
33+
lovyan03/LovyanGFX @ ^1.2.7
34+
35+
[env:SenseCapIndicator-ESPNow_comp_radio_usb]
36+
extends =SenseCapIndicator-ESPNow
37+
build_flags =
38+
${SenseCapIndicator-ESPNow.build_flags}
39+
-I examples/companion_radio/ui-new
40+
-D MAX_CONTACTS=300
41+
-D MAX_GROUP_CHANNELS=8
42+
; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1
43+
; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1
44+
; NOTE: DO NOT ENABLE --> -D ESPNOW_DEBUG_LOGGING=1
45+
build_src_filter = ${SenseCapIndicator-ESPNow.build_src_filter}
46+
+<../examples/companion_radio/ui-new/*.cpp>
47+
+<../examples/companion_radio/*.cpp>
48+
lib_deps =
49+
${SenseCapIndicator-ESPNow.lib_deps}
50+
densaugeo/base64 @ ~1.4.0

0 commit comments

Comments
 (0)