display and btn handling starts working ...
This commit is contained in:
@@ -43,6 +43,10 @@ void UITask::begin(DisplayDriver* display, const char* node_name, const char* bu
|
|||||||
*dash = 0;
|
*dash = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PIN_USER_BTN
|
||||||
|
pinMode(PIN_USER_BTN, INPUT);
|
||||||
|
#endif
|
||||||
|
|
||||||
// v1.2.3 (1 Jan 2025)
|
// v1.2.3 (1 Jan 2025)
|
||||||
sprintf(_version_info, "%s (%s)", version, build_date);
|
sprintf(_version_info, "%s (%s)", version, build_date);
|
||||||
}
|
}
|
||||||
@@ -57,6 +61,7 @@ void UITask::msgRead(int msgcount) {
|
|||||||
void UITask::clearMsgPreview() {
|
void UITask::clearMsgPreview() {
|
||||||
_origin[0] = 0;
|
_origin[0] = 0;
|
||||||
_msg[0] = 0;
|
_msg[0] = 0;
|
||||||
|
_need_refresh = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) {
|
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
|
|||||||
if (_display != NULL) {
|
if (_display != NULL) {
|
||||||
if (!_display->isOn()) _display->turnOn();
|
if (!_display->isOn()) _display->turnOn();
|
||||||
_auto_off = millis() + AUTO_OFF_MILLIS; // extend the auto-off timer
|
_auto_off = millis() + AUTO_OFF_MILLIS; // extend the auto-off timer
|
||||||
|
_need_refresh = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,6 +120,7 @@ void UITask::renderCurrScreen() {
|
|||||||
_display->print(tmp);
|
_display->print(tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_need_refresh = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UITask::userLedHandler() {
|
void UITask::userLedHandler() {
|
||||||
@@ -157,6 +164,7 @@ void UITask::buttonHandler() {
|
|||||||
clearMsgPreview();
|
clearMsgPreview();
|
||||||
} else {
|
} else {
|
||||||
_display->turnOn();
|
_display->turnOn();
|
||||||
|
_need_refresh = true;
|
||||||
}
|
}
|
||||||
_auto_off = cur_time + AUTO_OFF_MILLIS; // extend auto-off timer
|
_auto_off = cur_time + AUTO_OFF_MILLIS; // extend auto-off timer
|
||||||
}
|
}
|
||||||
@@ -182,7 +190,7 @@ void UITask::loop() {
|
|||||||
userLedHandler();
|
userLedHandler();
|
||||||
|
|
||||||
if (_display != NULL && _display->isOn()) {
|
if (_display != NULL && _display->isOn()) {
|
||||||
if (millis() >= _next_refresh) {
|
if (millis() >= _next_refresh && _need_refresh) {
|
||||||
_display->startFrame();
|
_display->startFrame();
|
||||||
renderCurrScreen();
|
renderCurrScreen();
|
||||||
_display->endFrame();
|
_display->endFrame();
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class UITask {
|
|||||||
char _origin[62];
|
char _origin[62];
|
||||||
char _msg[80];
|
char _msg[80];
|
||||||
int _msgcount;
|
int _msgcount;
|
||||||
|
bool _need_refresh = true;
|
||||||
|
|
||||||
void renderCurrScreen();
|
void renderCurrScreen();
|
||||||
void buttonHandler();
|
void buttonHandler();
|
||||||
|
|||||||
@@ -59,9 +59,12 @@
|
|||||||
|
|
||||||
#ifdef DISPLAY_CLASS
|
#ifdef DISPLAY_CLASS
|
||||||
#include "UITask.h"
|
#include "UITask.h"
|
||||||
#include <helpers/ui/SSD1306Display.h>
|
#ifdef ST7789
|
||||||
|
#include <helpers/ui/ST7789Display.h>
|
||||||
static DISPLAY_CLASS display;
|
#else
|
||||||
|
#include <helpers/ui/SSD1306Display.h>
|
||||||
|
#endif
|
||||||
|
static DISPLAY_CLASS display;
|
||||||
#define HAS_UI
|
#define HAS_UI
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
88
src/helpers/ui/ST7789Display.cpp
Normal file
88
src/helpers/ui/ST7789Display.cpp
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
#include "ST7789Display.h"
|
||||||
|
|
||||||
|
bool ST7789Display::i2c_probe(TwoWire& wire, uint8_t addr) {
|
||||||
|
return true;
|
||||||
|
/*
|
||||||
|
wire.beginTransmission(addr);
|
||||||
|
uint8_t error = wire.endTransmission();
|
||||||
|
return (error == 0);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ST7789Display::begin() {
|
||||||
|
if(!_isOn) {
|
||||||
|
pinMode(PIN_TFT_VDD_CTL, OUTPUT);
|
||||||
|
pinMode(PIN_TFT_LEDA_CTL, OUTPUT);
|
||||||
|
digitalWrite(PIN_TFT_VDD_CTL, LOW);
|
||||||
|
digitalWrite(PIN_TFT_LEDA_CTL, LOW);
|
||||||
|
digitalWrite(PIN_TFT_RST, HIGH);
|
||||||
|
|
||||||
|
display.init(135, 240);
|
||||||
|
display.setRotation(2);
|
||||||
|
display.setSPISpeed(40000000);
|
||||||
|
display.fillScreen(ST77XX_BLACK);
|
||||||
|
display.setTextColor(ST77XX_WHITE);
|
||||||
|
display.setTextSize(2);
|
||||||
|
display.cp437(true); // Use full 256 char 'Code Page 437' font
|
||||||
|
|
||||||
|
_isOn = true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ST7789Display::turnOn() {
|
||||||
|
ST7789Display::begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ST7789Display::turnOff() {
|
||||||
|
digitalWrite(PIN_TFT_VDD_CTL, HIGH);
|
||||||
|
digitalWrite(PIN_TFT_LEDA_CTL, HIGH);
|
||||||
|
digitalWrite(PIN_TFT_RST, LOW);
|
||||||
|
// digitalWrite(PIN_TFT_VDD_CTL, LOW);
|
||||||
|
// digitalWrite(PIN_TFT_LEDA_CTL, LOW);
|
||||||
|
_isOn = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ST7789Display::clear() {
|
||||||
|
display.fillScreen(ST77XX_BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ST7789Display::startFrame(Color bkg) {
|
||||||
|
display.fillScreen(0x00);
|
||||||
|
display.setTextColor(ST77XX_WHITE);
|
||||||
|
display.setTextSize(2);
|
||||||
|
display.cp437(true); // Use full 256 char 'Code Page 437' font
|
||||||
|
}
|
||||||
|
|
||||||
|
void ST7789Display::setTextSize(int sz) {
|
||||||
|
display.setTextSize(sz);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ST7789Display::setColor(Color c) {
|
||||||
|
_color = (c == LIGHT) ? ST77XX_WHITE : ST77XX_BLACK;
|
||||||
|
display.setTextColor(_color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ST7789Display::setCursor(int x, int y) {
|
||||||
|
display.setCursor(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ST7789Display::print(const char* str) {
|
||||||
|
display.print(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ST7789Display::fillRect(int x, int y, int w, int h) {
|
||||||
|
display.fillRect(x, y, w, h, _color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ST7789Display::drawRect(int x, int y, int w, int h) {
|
||||||
|
display.drawRect(x, y, w, h, _color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ST7789Display::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
|
||||||
|
display.drawBitmap(x, y, bits, w, h, ST77XX_BLUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ST7789Display::endFrame() {
|
||||||
|
// display.display();
|
||||||
|
}
|
||||||
33
src/helpers/ui/ST7789Display.h
Normal file
33
src/helpers/ui/ST7789Display.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "DisplayDriver.h"
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_ST7789.h>
|
||||||
|
|
||||||
|
class ST7789Display : public DisplayDriver {
|
||||||
|
Adafruit_ST7789 display;
|
||||||
|
bool _isOn;
|
||||||
|
uint8_t _color;
|
||||||
|
|
||||||
|
bool i2c_probe(TwoWire& wire, uint8_t addr);
|
||||||
|
public:
|
||||||
|
ST7789Display() : DisplayDriver(135, 240), display(&SPI1, PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RST) { _isOn = false; }
|
||||||
|
// ST7789Display() : DisplayDriver(135, 240), display(PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_SDA, PIN_TFT_SCL, PIN_TFT_RST) { _isOn = false; }
|
||||||
|
bool begin();
|
||||||
|
|
||||||
|
bool isOn() override { return _isOn; }
|
||||||
|
void turnOn() override;
|
||||||
|
void turnOff() override;
|
||||||
|
void clear() override;
|
||||||
|
void startFrame(Color bkg = DARK) override;
|
||||||
|
void setTextSize(int sz) override;
|
||||||
|
void setColor(Color c) override;
|
||||||
|
void setCursor(int x, int y) override;
|
||||||
|
void print(const char* str) override;
|
||||||
|
void fillRect(int x, int y, int w, int h) override;
|
||||||
|
void drawRect(int x, int y, int w, int h) override;
|
||||||
|
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override;
|
||||||
|
void endFrame() override;
|
||||||
|
};
|
||||||
@@ -60,6 +60,9 @@ build_flags =
|
|||||||
extends = Heltec_t114
|
extends = Heltec_t114
|
||||||
build_flags =
|
build_flags =
|
||||||
${Heltec_t114.build_flags}
|
${Heltec_t114.build_flags}
|
||||||
|
-I src/helpers/ui
|
||||||
|
-D ST7789
|
||||||
|
-D DISPLAY_CLASS=ST7789Display
|
||||||
-D MAX_CONTACTS=100
|
-D MAX_CONTACTS=100
|
||||||
-D MAX_GROUP_CHANNELS=8
|
-D MAX_GROUP_CHANNELS=8
|
||||||
-D BLE_PIN_CODE=123456
|
-D BLE_PIN_CODE=123456
|
||||||
@@ -71,9 +74,12 @@ build_flags =
|
|||||||
build_src_filter = ${Heltec_t114.build_src_filter}
|
build_src_filter = ${Heltec_t114.build_src_filter}
|
||||||
+<helpers/nrf52/*.cpp>
|
+<helpers/nrf52/*.cpp>
|
||||||
+<../examples/companion_radio/main.cpp>
|
+<../examples/companion_radio/main.cpp>
|
||||||
|
+<../examples/companion_radio/UITask.cpp>
|
||||||
|
+<helpers/ui/ST7789Display.cpp>
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${Heltec_t114.lib_deps}
|
${Heltec_t114.lib_deps}
|
||||||
densaugeo/base64 @ ~1.4.0
|
densaugeo/base64 @ ~1.4.0
|
||||||
|
adafruit/Adafruit ST7735 and ST7789 Library @ ^1.11.0
|
||||||
|
|
||||||
[env:Heltec_t114_companion_radio_usb]
|
[env:Heltec_t114_companion_radio_usb]
|
||||||
extends = Heltec_t114
|
extends = Heltec_t114
|
||||||
|
|||||||
@@ -80,11 +80,13 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Builtin buttons
|
// Builtin buttons
|
||||||
|
|
||||||
#define PIN_BUTTON1 (5)
|
#define PIN_BUTTON1 (42)
|
||||||
#define BUTTON_PIN PIN_BUTTON1
|
#define BUTTON_PIN PIN_BUTTON1
|
||||||
|
|
||||||
#define PIN_BUTTON2 (11)
|
// #define PIN_BUTTON2 (11)
|
||||||
#define BUTTON_PIN2 PIN_BUTTON2
|
// #define BUTTON_PIN2 PIN_BUTTON2
|
||||||
|
|
||||||
|
#define PIN_USER_BTN BUTTON_PIN
|
||||||
|
|
||||||
#define EXTERNAL_FLASH_DEVICES MX25R1635F
|
#define EXTERNAL_FLASH_DEVICES MX25R1635F
|
||||||
#define EXTERNAL_FLASH_USE_QSPI
|
#define EXTERNAL_FLASH_USE_QSPI
|
||||||
@@ -108,3 +110,14 @@
|
|||||||
// Buzzer
|
// Buzzer
|
||||||
|
|
||||||
#define PIN_BUZZER (46)
|
#define PIN_BUZZER (46)
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// TFT
|
||||||
|
#define PIN_TFT_SCL (40)
|
||||||
|
#define PIN_TFT_SDA (41)
|
||||||
|
#define PIN_TFT_RST (2)
|
||||||
|
#define PIN_TFT_VDD_CTL (3)
|
||||||
|
#define PIN_TFT_LEDA_CTL (15)
|
||||||
|
#define PIN_TFT_CS (11)
|
||||||
|
#define PIN_TFT_DC (12)
|
||||||
|
|||||||
Reference in New Issue
Block a user