Merge pull request #20 from meshcore-dev/dev

merge Dev
This commit is contained in:
Quency-D authored and GitHub committed 2026-11-12 14:03:11 +08:00
commit 6ff32a57da
435 files changed
+18738 -2929

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
#include "AutoDetectDisplay.h"
#include <MeshCore.h>
int AutoDetectDisplay::getDisplayStatus(TwoWire& wire, uint8_t addr) {
int status = -1;
for(int i = 0; i < 4; i++){
// request display status
wire.beginTransmission(addr);
wire.write((uint8_t)0x00);
// ensure response received
if (wire.endTransmission() != 0) return -1; // expect success
if (wire.requestFrom((int)addr, 1) == 0) return -1; // expect at least 1 byte
// ensure two consecutive reads are the same
int previous = status;
status = wire.read() & 0x0F;
if(status == previous){
break;
}
}
return status;
}
bool AutoDetectDisplay::begin() {
// request status from display address
int status = getDisplayStatus(Wire, DISPLAY_ADDRESS);
MESH_DEBUG_PRINTLN("AutoDetectDisplay: status=0x%02X", status);
// detect SH1106
if(status == 0x00 || status == 0x08){
MESH_DEBUG_PRINTLN("AutoDetectDisplay: SH1106 detected");
_impl = &_sh1106;
return _sh1106.begin();
}
// fallback to SSD1306
MESH_DEBUG_PRINTLN("AutoDetectDisplay: falling back to SSD1306");
_impl = &_ssd1306;
return _ssd1306.begin();
}
+32
View File
@@ -0,0 +1,32 @@
#pragma once
#include "DisplayDriver.h"
#include "SSD1306Display.h"
#include "SH1106Display.h"
// Auto detects SH1106 display at runtime, otherwise falls back to using SSD1306
class AutoDetectDisplay : public DisplayDriver {
DisplayDriver* _impl;
SSD1306Display _ssd1306;
SH1106Display _sh1106;
int getDisplayStatus(TwoWire& wire, uint8_t addr);
public:
AutoDetectDisplay() : DisplayDriver(128, 64), _impl(&_ssd1306) { }
bool begin();
bool isOn() override { return _impl->isOn(); }
void turnOn() override { _impl->turnOn(); }
void turnOff() override { _impl->turnOff(); }
void clear() override { _impl->clear(); }
void startFrame(ColorVal bkg = UIColor::window_bkg) override { _impl->startFrame(bkg); }
void setTextSize(int sz) override { _impl->setTextSize(sz); }
void setColor(ColorVal c) override { _impl->setColor(c); }
void setCursor(int x, int y) override { _impl->setCursor(x, y); }
void print(const char* str) override { _impl->print(str); }
void fillRect(int x, int y, int w, int h) override { _impl->fillRect(x, y, w, h); }
void drawRect(int x, int y, int w, int h) override { _impl->drawRect(x, y, w, h); }
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override { _impl->drawXbm(x, y, bits, w, h); }
uint16_t getTextWidth(const char* str) override { return _impl->getTextWidth(str); }
void endFrame() override { _impl->endFrame(); }
};
+47
View File
@@ -0,0 +1,47 @@
#ifdef HAS_DRV2605
#include "DRV2605Vibration.h"
#include <Wire.h>
void DRV2605Vibration::begin() {
#ifdef PIN_DRV_EN
pinMode(PIN_DRV_EN, OUTPUT);
digitalWrite(PIN_DRV_EN, HIGH); // power up the haptic driver
delay(10);
#endif
if (!drv.begin(&Wire)) {
return; // no haptic driver found, stay silent
}
#ifdef DRV2605_USE_LRA
// LRA mode: 4x brake factor, medium loop gain, back-EMF gain 2
drv.writeRegister8(DRV2605_REG_FEEDBACK, 0xB6);
#endif
drv.selectLibrary(1);
drv.setMode(DRV2605_MODE_INTTRIG);
_ready = true;
}
void DRV2605Vibration::trigger(bool force) {
if (!_ready || _quiet) return;
unsigned long now = millis();
if (!force && _last_trigger != 0 && now - _last_trigger < VIBRATION_TIMEOUT) return;
_last_trigger = now;
drv.setWaveform(0, DRV2605_EFFECT);
drv.setWaveform(1, 0); // pause
drv.setWaveform(2, DRV2605_EFFECT);
drv.setWaveform(3, 0); // end of sequence
drv.go();
}
void DRV2605Vibration::loop() {
}
bool DRV2605Vibration::isVibrating() {
return false; // effects are short, treat as instantaneous
}
void DRV2605Vibration::stop() {
if (_ready) drv.stop();
}
#endif // ifdef HAS_DRV2605
+39
View File
@@ -0,0 +1,39 @@
#pragma once
#ifdef HAS_DRV2605
#include <Arduino.h>
#include <Adafruit_DRV2605.h>
/*
* Vibration control class for boards where the motor is behind a
* DRV2605 haptic driver on I2C (e.g. Seeed SenseCAP MeshTracker X1).
* Same interface as GenericVibration.
*/
#ifndef VIBRATION_TIMEOUT
#define VIBRATION_TIMEOUT 5000 // cooldown between vibrations
#endif
#ifndef DRV2605_EFFECT
#define DRV2605_EFFECT 16 // "1000 ms alert" from the DRV2605 effect library
#endif
class DRV2605Vibration {
public:
void begin(); // power up and init the DRV2605
void trigger(bool force = false); // trigger vibration; force skips the cooldown
void loop(); // no-op, the DRV2605 plays effects autonomously
bool isVibrating();
void stop(); // stop vibration immediately
void quiet(bool q) { _quiet = q; }
bool isQuiet() const { return _quiet; }
private:
Adafruit_DRV2605 drv;
bool _ready = false;
bool _quiet = false;
unsigned long _last_trigger = 0;
};
#endif // ifdef HAS_DRV2605
+15 -3
View File
@@ -3,24 +3,36 @@
#include <stdint.h>
#include <string.h>
using ColorVal = uint16_t;
class UIColor {
public:
// color definitions (by element _type_)
static ColorVal window_bkg, title_bkg, title_txt, primary_txt, secondary_txt, warning_txt, popup_bkg, popup_txt, corp_blue;
};
class DisplayDriver {
int _w, _h;
protected:
DisplayDriver(int w, int h) { _w = w; _h = h; }
public:
enum Color { DARK=0, LIGHT, RED, GREEN, BLUE, YELLOW, ORANGE }; // on b/w screen, colors will be !=0 synonym of light
//enum Color { DARK=0, LIGHT, RED, GREEN, BLUE, YELLOW, ORANGE }; // on b/w screen, colors will be !=0 synonym of light
int width() const { return _w; }
int height() const { return _h; }
virtual bool isOn() = 0;
virtual bool isEink() { return false; } // default to non-eink, override in eink drivers
virtual void forceFullRefresh() {} // next refresh will be full for eink
virtual void setBusyHook(void (*hook)()) {} // eink: hook is called repeatedly while waiting for panel refresh
virtual void turnOn() = 0;
virtual void turnOn(int max_partial) { turnOn(); }
virtual void turnOff() = 0;
virtual void turnOff(bool blank) { turnOff(); }
virtual void clear() = 0;
virtual void startFrame(Color bkg = DARK) = 0;
virtual void startFrame(ColorVal bkg = UIColor::window_bkg) = 0;
virtual void setTextSize(int sz) = 0;
virtual void setColor(Color c) = 0;
virtual void setColor(ColorVal c) = 0;
virtual void setCursor(int x, int y) = 0;
virtual void print(const char* str) = 0;
virtual void printWordWrap(const char* str, int max_width) { print(str); } // fallback to basic print() if no override
+22 -8
View File
@@ -2,6 +2,17 @@
#include "../../MeshCore.h"
// Color scheme
ColorVal UIColor::window_bkg = WHITE;
ColorVal UIColor::title_bkg = WHITE;
ColorVal UIColor::title_txt = BLACK;
ColorVal UIColor::primary_txt = BLACK;
ColorVal UIColor::secondary_txt = BLACK;
ColorVal UIColor::warning_txt = BLACK;
ColorVal UIColor::popup_bkg = WHITE;
ColorVal UIColor::popup_txt = BLACK;
ColorVal UIColor::corp_blue = BLACK;
BaseDisplay* E213Display::detectEInk()
{
// Test 1: Logic of BUSY pin
@@ -108,16 +119,18 @@ void E213Display::clear() {
display->clear();
}
void E213Display::startFrame(Color bkg) {
void E213Display::startFrame(ColorVal bkg) {
display_crc.reset();
// Fill screen with white first to ensure clean background
display->fillRect(0, 0, width(), height(), WHITE);
if (bkg == LIGHT) {
if (bkg == 0) {
// Fill with black if light background requested (inverted for e-ink)
display->fillRect(0, 0, width(), height(), BLACK);
}
_color = UIColor::primary_txt;
display->setTextColor(_color);
}
void E213Display::setTextSize(int sz) {
@@ -126,9 +139,10 @@ void E213Display::setTextSize(int sz) {
display->setTextSize(sz);
}
void E213Display::setColor(Color c) {
display_crc.update<Color>(c);
// implemented in individual display methods
void E213Display::setColor(ColorVal c) {
_color = c;
display_crc.update<ColorVal>(c);
display->setTextColor(_color);
}
void E213Display::setCursor(int x, int y) {
@@ -147,7 +161,7 @@ void E213Display::fillRect(int x, int y, int w, int h) {
display_crc.update<int>(y);
display_crc.update<int>(w);
display_crc.update<int>(h);
display->fillRect(x, y, w, h, BLACK);
display->fillRect(x, y, w, h, _color);
}
void E213Display::drawRect(int x, int y, int w, int h) {
@@ -155,7 +169,7 @@ void E213Display::drawRect(int x, int y, int w, int h) {
display_crc.update<int>(y);
display_crc.update<int>(w);
display_crc.update<int>(h);
display->drawRect(x, y, w, h, BLACK);
display->drawRect(x, y, w, h, _color);
}
void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
@@ -179,7 +193,7 @@ void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
// If the bit is set, draw the pixel
if (bitSet) {
display->drawPixel(x + bx, y + by, BLACK);
display->drawPixel(x + bx, y + by, _color);
}
}
}
+3 -2
View File
@@ -16,6 +16,7 @@ class E213Display : public DisplayDriver {
RefCountedDigitalPin* _periph_power;
CRC32 display_crc;
uint32_t last_display_crc_value = 0;
uint16_t _color;
public:
E213Display(RefCountedDigitalPin* periph_power = NULL) : DisplayDriver(250, 122), _periph_power(periph_power) {}
@@ -30,9 +31,9 @@ public:
void turnOn() override;
void turnOff() override;
void clear() override;
void startFrame(Color bkg = DARK) override;
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override;
void setColor(Color c) override;
void setColor(ColorVal 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;
+22 -8
View File
@@ -2,6 +2,17 @@
#include "../../MeshCore.h"
// Color scheme
ColorVal UIColor::window_bkg = WHITE;
ColorVal UIColor::title_bkg = WHITE;
ColorVal UIColor::title_txt = BLACK;
ColorVal UIColor::primary_txt = BLACK;
ColorVal UIColor::secondary_txt = BLACK;
ColorVal UIColor::warning_txt = BLACK;
ColorVal UIColor::popup_bkg = WHITE;
ColorVal UIColor::popup_txt = BLACK;
ColorVal UIColor::corp_blue = BLACK;
bool E290Display::begin() {
if (_init) return true;
@@ -62,15 +73,17 @@ void E290Display::clear() {
display.clear();
}
void E290Display::startFrame(Color bkg) {
void E290Display::startFrame(ColorVal bkg) {
display_crc.reset();
// Fill screen with white first to ensure clean background
display.fillRect(0, 0, width(), height(), WHITE);
if (bkg == LIGHT) {
if (bkg == 0) {
// Fill with black if light background requested (inverted for e-ink)
display.fillRect(0, 0, width(), height(), BLACK);
}
_color = UIColor::primary_txt;
display.setTextColor(_color);
}
void E290Display::setTextSize(int sz) {
@@ -79,9 +92,10 @@ void E290Display::setTextSize(int sz) {
display.setTextSize(sz);
}
void E290Display::setColor(Color c) {
display_crc.update<Color>(c);
// implemented in individual display methods
void E290Display::setColor(ColorVal c) {
_color = c;
display_crc.update<ColorVal>(c);
display.setTextColor(_color);
}
void E290Display::setCursor(int x, int y) {
@@ -100,7 +114,7 @@ void E290Display::fillRect(int x, int y, int w, int h) {
display_crc.update<int>(y);
display_crc.update<int>(w);
display_crc.update<int>(h);
display.fillRect(x, y, w, h, BLACK);
display.fillRect(x, y, w, h, _color);
}
void E290Display::drawRect(int x, int y, int w, int h) {
@@ -108,7 +122,7 @@ void E290Display::drawRect(int x, int y, int w, int h) {
display_crc.update<int>(y);
display_crc.update<int>(w);
display_crc.update<int>(h);
display.drawRect(x, y, w, h, BLACK);
display.drawRect(x, y, w, h, _color);
}
void E290Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
@@ -132,7 +146,7 @@ void E290Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
// If the bit is set, draw the pixel
if (bitSet) {
display.drawPixel(x + bx, y + by, BLACK);
display.drawPixel(x + bx, y + by, _color);
}
}
}
+3 -2
View File
@@ -16,6 +16,7 @@ class E290Display : public DisplayDriver {
RefCountedDigitalPin* _periph_power;
CRC32 display_crc;
uint32_t last_display_crc_value = 0;
uint16_t _color;
public:
E290Display(RefCountedDigitalPin* periph_power = NULL) : DisplayDriver(296, 128), _periph_power(periph_power) {}
@@ -26,9 +27,9 @@ public:
void turnOn() override;
void turnOff() override;
void clear() override;
void startFrame(Color bkg = DARK) override;
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override;
void setColor(Color c) override;
void setColor(ColorVal 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;
+107 -32
View File
@@ -1,11 +1,6 @@
#include "GxEPDDisplay.h"
#ifdef EXP_PIN_BACKLIGHT
#include <PCA9557.h>
extern PCA9557 expander;
#endif
#ifndef DISPLAY_ROTATION
#define DISPLAY_ROTATION 3
#endif
@@ -14,6 +9,21 @@
SPIClass SPI1 = SPIClass(FSPI);
#endif
#ifndef EPD_WASHING_MACHINE_CYCLES
#define EPD_WASHING_MACHINE_CYCLES 0
#endif
// Color scheme
ColorVal UIColor::window_bkg = GxEPD_WHITE;
ColorVal UIColor::title_bkg = GxEPD_WHITE;
ColorVal UIColor::title_txt = GxEPD_BLACK;
ColorVal UIColor::primary_txt = GxEPD_BLACK;
ColorVal UIColor::secondary_txt = GxEPD_BLACK;
ColorVal UIColor::warning_txt = GxEPD_BLACK;
ColorVal UIColor::popup_bkg = GxEPD_WHITE;
ColorVal UIColor::popup_txt = GxEPD_BLACK;
ColorVal UIColor::corp_blue = GxEPD_BLACK;
bool GxEPDDisplay::begin() {
display.epd2.selectSPI(SPI1, SPISettings(4000000, MSBFIRST, SPI_MODE0));
#ifdef ESP32
@@ -24,35 +34,85 @@ bool GxEPDDisplay::begin() {
display.init(115200, true, 2, false);
display.setRotation(DISPLAY_ROTATION);
setTextSize(1); // Default to size 1
display.setPartialWindow(0, 0, display.width(), display.height());
display.fillScreen(GxEPD_WHITE);
display.display(true);
display.setFullWindow();
for (int i = 0; i < EPD_WASHING_MACHINE_CYCLES; i++) {
display.fillScreen(GxEPD_BLACK);
display.display(false);
delay(2000);
display.fillScreen(GxEPD_WHITE);
display.display(false);
delay(2000);
}
display.setPartialWindow(0, 0, display.width(), display.height());
_partial_refresh_count = 0;
#if DISP_BACKLIGHT
digitalWrite(DISP_BACKLIGHT, LOW);
pinMode(DISP_BACKLIGHT, OUTPUT);
#endif
_init = true;
_isOn = true;
return true;
}
void GxEPDDisplay::turnOn() {
if (!_init) begin();
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN)
digitalWrite(DISP_BACKLIGHT, HIGH);
#elif defined(EXP_PIN_BACKLIGHT) && !defined(BACKLIGHT_BTN)
expander.digitalWrite(EXP_PIN_BACKLIGHT, HIGH);
#endif
_isOn = true;
if (!_isOn) {
_isOn = true;
}
}
void GxEPDDisplay::turnOff() {
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN)
digitalWrite(DISP_BACKLIGHT, LOW);
#elif defined(EXP_PIN_BACKLIGHT) && !defined(BACKLIGHT_BTN)
expander.digitalWrite(EXP_PIN_BACKLIGHT, LOW);
#endif
void GxEPDDisplay::turnOn(int max_partial) {
setMaxPartialRefresh(max_partial);
turnOn();
}
// 24x24 sleep icon, MSB-first (matches GxEPDDisplay::drawXbm)
static const uint8_t sleep_icon_24x24[] = {
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0xe0, 0x0e, 0x03, 0xc0, 0x18,
0x0f, 0x80, 0x70, 0x1f, 0x80, 0xff, 0x3f, 0x80, 0xff, 0x3f, 0x00, 0x00,
0x7f, 0x3f, 0x00, 0x7f, 0x3f, 0x00, 0xff, 0x0e, 0x00, 0xff, 0x1c, 0x7c,
0xff, 0xbf, 0x7c, 0xff, 0xbf, 0x38, 0xff, 0xc0, 0x7c, 0xff, 0xe0, 0x7c,
0xff, 0xf0, 0x00, 0x7f, 0xfc, 0x00, 0x7f, 0xff, 0xf8, 0x3f, 0xff, 0xf0,
0x1f, 0xff, 0xf0, 0x0f, 0xff, 0xe0, 0x07, 0xff, 0x80, 0x01, 0xff, 0x00
};
void GxEPDDisplay::drawSleepIcon() {
const int W = 24, H = 24;
int x = (int)(display.width() / scale_x) - W; // top-right, logical coordinates
int y = 0;
display.fillRect((x - 5) * scale_x - 1, y * scale_y, (W+5) * scale_x + 2, (H-2) * scale_y + 1, GxEPD_WHITE);
_curr_color = GxEPD_BLACK;
drawXbm(x, y, sleep_icon_24x24, W, H);
if (_busy_hook) display.epd2.setBusyCallback(busyCallback, this);
display.display(true);
display.epd2.setBusyCallback(NULL);
}
void GxEPDDisplay::turnOff(bool blank) {
if (blank) {
blankScreen();
} else {
drawSleepIcon();
}
_isOn = false;
last_display_crc_value=0;
display.hibernate();
}
void GxEPDDisplay::blankScreen() {
// do full refresh before powering off to clear screen
// no full refresh needed at wakeup
if (_busy_hook) display.epd2.setBusyCallback(busyCallback, this);
display.clearScreen(0xFF); // Clears microcontroller side RAM
display.writeScreenBuffer(0xFF); // Forces 0xFF (White) into the display controller's history registers
display.epd2.setBusyCallback(NULL);
_partial_refresh_count = 0;
last_display_crc_value = 0;
}
void GxEPDDisplay::clear() {
@@ -61,10 +121,25 @@ void GxEPDDisplay::clear() {
display_crc.reset();
}
void GxEPDDisplay::startFrame(Color bkg) {
display.fillScreen(GxEPD_WHITE);
display.setTextColor(_curr_color = GxEPD_BLACK);
void GxEPDDisplay::startFrame(ColorVal bkg) {
display.fillScreen(bkg);
display.setTextColor(_curr_color = UIColor::primary_txt);
display_crc.reset();
if (_force_full_refresh
|| (_max_partial_refresh > 0
&& _partial_refresh_count >= _max_partial_refresh)) {
// forces a full wipe of the screen ...
if (_busy_hook) display.epd2.setBusyCallback(busyCallback, this);
display.clearScreen(0xFF); // Clears microcontroller side RAM
display.writeScreenBuffer(0xFF); // Forces 0xFF (White) into the display controller's history registers
display.epd2.setBusyCallback(NULL);
// we'll need a partial refresh after that (whatever crc value is)
last_display_crc_value = 0;
_partial_refresh_count = 0;
_force_full_refresh = false;
} else {
display.setPartialWindow(0, 0, display.width(), display.height());
}
}
void GxEPDDisplay::setTextSize(int sz) {
@@ -85,14 +160,9 @@ void GxEPDDisplay::setTextSize(int sz) {
}
}
void GxEPDDisplay::setColor(Color c) {
display_crc.update<Color> (c);
// colours need to be inverted for epaper displays
if (c == DARK) {
display.setTextColor(_curr_color = GxEPD_WHITE);
} else {
display.setTextColor(_curr_color = GxEPD_BLACK);
}
void GxEPDDisplay::setColor(ColorVal c) {
display_crc.update<ColorVal> (c);
display.setTextColor(_curr_color = c);
}
void GxEPDDisplay::setCursor(int x, int y) {
@@ -171,9 +241,14 @@ uint16_t GxEPDDisplay::getTextWidth(const char* str) {
}
void GxEPDDisplay::endFrame() {
if (_isOn == false) return;
uint32_t crc = display_crc.finalize();
if (crc != last_display_crc_value) {
// keep the rest of the firmware running while the panel refreshes (~0.5s partial)
if (_busy_hook) display.epd2.setBusyCallback(busyCallback, this);
display.display(true);
last_display_crc_value = crc;
display.epd2.setBusyCallback(NULL);
_partial_refresh_count++;
}
last_display_crc_value = crc;
}
+19 -3
View File
@@ -36,6 +36,15 @@ class GxEPDDisplay : public DisplayDriver {
uint16_t _curr_color;
CRC32 display_crc;
int last_display_crc_value = 0;
bool _force_full_refresh = false;
int _partial_refresh_count = 0;
int _max_partial_refresh = 0;
void (*_busy_hook)() = NULL;
static void busyCallback(const void* self) {
((const GxEPDDisplay*)self)->_busy_hook();
delay(1); // same as GxEPD2 does without a callback
}
public:
#if defined(EINK_DISPLAY_MODEL)
@@ -48,17 +57,24 @@ public:
bool isOn() override { return _isOn; }
bool isEink() override { return true; }
void forceFullRefresh() override { _force_full_refresh = true; }
void turnOn(int max_partial) override;
void setBusyHook(void (*hook)()) override { _busy_hook = hook; }
void turnOn() override;
void turnOff() override;
void turnOff(bool blank) override;
void turnOff() override { turnOff(false); }
virtual void blankScreen();
virtual void setMaxPartialRefresh(int count) {_max_partial_refresh = count; }
void clear() override;
void startFrame(Color bkg = DARK) override;
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override;
void setColor(Color c) override;
void setColor(ColorVal 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 drawSleepIcon();
uint16_t getTextWidth(const char* str) override;
void endFrame() override;
};
+17 -31
View File
@@ -1,5 +1,16 @@
#include "LGFXDisplay.h"
// Color scheme
ColorVal UIColor::window_bkg = 0xFFFF;
ColorVal UIColor::title_bkg = 0x001F;
ColorVal UIColor::title_txt = 0xFFFF;
ColorVal UIColor::primary_txt = 0x0000;
ColorVal UIColor::secondary_txt = (18 << 11) | (36 << 5) | 18; // mid-gray
ColorVal UIColor::warning_txt = 0xFD20;
ColorVal UIColor::popup_bkg = 0x07FF; // CYAN
ColorVal UIColor::popup_txt = 0x0000;
ColorVal UIColor::corp_blue = 0x001A;
bool LGFXDisplay::begin() {
turnOn();
display->init();
@@ -35,45 +46,20 @@ void LGFXDisplay::clear() {
buffer.clearDisplay();
}
void LGFXDisplay::startFrame(Color bkg) {
void LGFXDisplay::startFrame(ColorVal bkg) {
// display->startWrite();
// display->getScanLine();
buffer.clearDisplay();
buffer.setTextColor(TFT_WHITE);
_color = bkg;
buffer.fillScreen(_color);
buffer.setTextColor(_color = UIColor::primary_txt);
}
void LGFXDisplay::setTextSize(int sz) {
buffer.setTextSize(sz);
}
void LGFXDisplay::setColor(Color c) {
// _color = (c != 0) ? ILI9342_WHITE : ILI9342_BLACK;
switch (c) {
case DARK:
_color = TFT_BLACK;
break;
case LIGHT:
_color = TFT_WHITE;
break;
case RED:
_color = TFT_RED;
break;
case GREEN:
_color = TFT_GREEN;
break;
case BLUE:
_color = TFT_BLUE;
break;
case YELLOW:
_color = TFT_YELLOW;
break;
case ORANGE:
_color = TFT_ORANGE;
break;
default:
_color = TFT_WHITE;
}
buffer.setTextColor(_color);
void LGFXDisplay::setColor(ColorVal c) {
buffer.setTextColor(_color = c);
}
void LGFXDisplay::setCursor(int x, int y) {
+2 -2
View File
@@ -25,9 +25,9 @@ public:
void turnOn() override;
void turnOff() override;
void clear() override;
void startFrame(Color bkg = DARK) override;
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override;
void setColor(Color c) override;
void setColor(ColorVal 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;
+2 -2
View File
@@ -25,8 +25,8 @@ class MomentaryButton {
public:
MomentaryButton(int8_t pin, int long_press_mills=0, bool reverse=false, bool pulldownup=false, bool multiclick=true);
MomentaryButton(int8_t pin, int long_press_mills, int analog_threshold);
void begin();
int check(bool repeat_click=false); // returns one of BUTTON_EVENT_*
virtual void begin();
virtual int check(bool repeat_click=false); // returns one of BUTTON_EVENT_*
void cancelClick(); // suppress next BUTTON_EVENT_CLICK (if already in DOWN state)
uint8_t getPin() { return _pin; }
bool isPressed() const;
+16 -18
View File
@@ -96,18 +96,16 @@
#define NV3001B_TEXT_SIZE2_SCALE_Y 3
#endif
static uint16_t mapColor(DisplayDriver::Color c) {
switch (c) {
case DisplayDriver::DARK: return 0x0000;
case DisplayDriver::LIGHT: return 0xffff;
case DisplayDriver::RED: return 0xf800;
case DisplayDriver::GREEN: return 0x07e0;
case DisplayDriver::BLUE: return 0x001f;
case DisplayDriver::YELLOW: return 0xffe0;
case DisplayDriver::ORANGE: return 0xfd20;
default: return 0xffff;
}
}
// Color scheme
ColorVal UIColor::window_bkg = 0xFFFF;
ColorVal UIColor::title_bkg = 0x001F;
ColorVal UIColor::title_txt = 0xFFFF;
ColorVal UIColor::primary_txt = 0x0000;
ColorVal UIColor::secondary_txt = (18 << 11) | (36 << 5) | 18; // mid-gray
ColorVal UIColor::warning_txt = 0xFD20;
ColorVal UIColor::popup_bkg = 0x07FF; // CYAN
ColorVal UIColor::popup_txt = 0x0000;
ColorVal UIColor::corp_blue = 0x001A;
static int scaleX(int x) {
return (int)(x * DISPLAY_SCALE_X);
@@ -471,15 +469,15 @@ void NV3001BDisplay::turnOff() {
void NV3001BDisplay::clear() {
uint16_t saved = color;
color = 0x0000;
color = UIColor::window_bkg;
fillPhysicalRect(0, 0, NV3001B_SCREEN_WIDTH, NV3001B_SCREEN_HEIGHT);
color = saved;
}
void NV3001BDisplay::startFrame(Color bkg) {
color = mapColor(bkg);
void NV3001BDisplay::startFrame(ColorVal bkg) {
color = bkg;
fillPhysicalRect(0, 0, NV3001B_SCREEN_WIDTH, NV3001B_SCREEN_HEIGHT);
color = 0xffff;
color = UIColor::primary_txt;
text_size = 1;
cursor_x = 0;
cursor_y = 0;
@@ -489,8 +487,8 @@ void NV3001BDisplay::setTextSize(int sz) {
text_size = sz < 1 ? 1 : sz;
}
void NV3001BDisplay::setColor(Color c) {
color = mapColor(c);
void NV3001BDisplay::setColor(ColorVal c) {
color = c;
}
void NV3001BDisplay::setCursor(int x, int y) {
+2 -2
View File
@@ -67,9 +67,9 @@ public:
void turnOn() override;
void turnOff() override;
void clear() override;
void startFrame(Color bkg = DARK) override;
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override;
void setColor(Color c) override;
void setColor(ColorVal 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;
+11
View File
@@ -0,0 +1,11 @@
#include "NullDisplayDriver.h"
ColorVal UIColor::window_bkg = 0;
ColorVal UIColor::title_bkg = 0;
ColorVal UIColor::title_txt = 0;
ColorVal UIColor::primary_txt = 0;
ColorVal UIColor::secondary_txt = 0;
ColorVal UIColor::warning_txt = 0;
ColorVal UIColor::popup_bkg = 0;
ColorVal UIColor::popup_txt = 0;
ColorVal UIColor::corp_blue = 0;
+2 -2
View File
@@ -11,9 +11,9 @@ public:
void turnOn() override { }
void turnOff() override { }
void clear() override { }
void startFrame(Color bkg = DARK) override { }
void startFrame(ColorVal bkg = UIColor::window_bkg) override { }
void setTextSize(int sz) override { }
void setColor(Color c) override { }
void setColor(ColorVal 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 { }
+34
View File
@@ -0,0 +1,34 @@
#include "RotaryInputGPIO.h"
bool RotaryInputGPIO::begin() {
if (_pin_a >= 0) {
pinMode(_pin_a, _pull_a ? INPUT_PULLUP : INPUT);
}
if (_pin_b >= 0) {
pinMode(_pin_b, _pull_b ? INPUT_PULLUP : INPUT);
}
b_prec = digitalRead(_pin_b);
return true;
}
RotaryInputEvent RotaryInputGPIO::poll() {
RotaryInputEvent ev = RotaryInputEvent::None;
bool a = digitalRead(_pin_a);
bool b = digitalRead(_pin_b);
// this is the simplest scheme and it works well
// for thinknode M8, just read A when B rises ;)
if (!b_prec && b) { // rising edge of A
if (a) {
ev = RotaryInputEvent::Next;
} else {
ev = RotaryInputEvent::Prev;
}
}
b_prec = b;
return ev;
}
+21
View File
@@ -0,0 +1,21 @@
#pragma once
#include <Arduino.h>
#include "RotaryInput.h"
#define BUTTON_EVENT_UP 5
#define BUTTON_EVENT_DOWN 6
class RotaryInputGPIO: public RotaryInput {
int8_t _pin_a;
bool _pull_a;
int8_t _pin_b;
bool _pull_b;
bool b_prec;
public:
RotaryInputGPIO(int8_t pin_a, int8_t pin_b, bool pull_a=false, bool pull_b=false): _pin_a(pin_a), _pin_b(pin_b), _pull_a(pull_a), _pull_b(pull_b) {}
bool begin() override;
RotaryInputEvent poll() override;
bool isReady() const override { return true;}
};
+32 -5
View File
@@ -9,9 +9,36 @@ bool SH1106Display::i2c_probe(TwoWire &wire, uint8_t addr)
return (error == 0);
}
// Color scheme
__attribute__((weak)) ColorVal UIColor::window_bkg = SH110X_BLACK;
__attribute__((weak)) ColorVal UIColor::title_bkg = SH110X_BLACK;
__attribute__((weak)) ColorVal UIColor::title_txt = SH110X_WHITE;
__attribute__((weak)) ColorVal UIColor::primary_txt = SH110X_WHITE;
__attribute__((weak)) ColorVal UIColor::secondary_txt = SH110X_WHITE;
__attribute__((weak)) ColorVal UIColor::warning_txt = SH110X_WHITE;
__attribute__((weak)) ColorVal UIColor::popup_bkg = SH110X_BLACK;
__attribute__((weak)) ColorVal UIColor::popup_txt = SH110X_WHITE;
__attribute__((weak)) ColorVal UIColor::corp_blue = SH110X_WHITE;
bool SH1106Display::begin()
{
return display.begin(DISPLAY_ADDRESS, true) && i2c_probe(Wire, DISPLAY_ADDRESS);
// Wire must already be initialised by board.begin() before this is called.
// Boards with non-standard SH1106 addresses should define DISPLAY_ADDRESS
// in their variant/platformio configuration. The SA0 strap selects 0x3C or
// 0x3D and differs between revisions of the same board (e.g. T-Beam
// Supreme), so fall back to the other address of the pair.
uint8_t addr = 0;
if (i2c_probe(Wire, DISPLAY_ADDRESS)) {
addr = DISPLAY_ADDRESS;
} else if (i2c_probe(Wire, DISPLAY_ADDRESS ^ 1)) {
addr = DISPLAY_ADDRESS ^ 1;
}
// Run the Adafruit init even when no panel answered: it is what allocates
// the frame buffer and the I2C device. Skipping it leaves i2c_dev and
// spi_dev NULL, and UITask::begin() calls turnOn() regardless of our
// return value, which then dereferences the null spi_dev.
bool ok = display.begin(addr ? addr : DISPLAY_ADDRESS, true);
return addr != 0 && ok;
}
void SH1106Display::turnOn()
@@ -32,7 +59,7 @@ void SH1106Display::clear()
display.display();
}
void SH1106Display::startFrame(Color bkg)
void SH1106Display::startFrame(ColorVal bkg)
{
display.clearDisplay(); // TODO: apply 'bkg'
_color = SH110X_WHITE;
@@ -46,9 +73,9 @@ void SH1106Display::setTextSize(int sz)
display.setTextSize(sz);
}
void SH1106Display::setColor(Color c)
void SH1106Display::setColor(ColorVal c)
{
_color = (c != 0) ? SH110X_WHITE : SH110X_BLACK;
_color = c;
display.setTextColor(_color);
}
@@ -74,7 +101,7 @@ void SH1106Display::drawRect(int x, int y, int w, int h)
void SH1106Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h)
{
display.drawBitmap(x, y, bits, w, h, SH110X_WHITE);
display.drawBitmap(x, y, bits, w, h, _color);
}
uint16_t SH1106Display::getTextWidth(const char *str)
+2 -2
View File
@@ -30,9 +30,9 @@ public:
void turnOn() override;
void turnOff() override;
void clear() override;
void startFrame(Color bkg = DARK) override;
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override;
void setColor(Color c) override;
void setColor(ColorVal 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;
+113
View File
@@ -0,0 +1,113 @@
#include "SH1107Display.h"
#include <Adafruit_GrayOLED.h>
#include "Adafruit_SH110X.h"
#ifndef DISPLAY_ROTATION
#define DISPLAY_ROTATION 0
#endif
ColorVal UIColor::window_bkg = SH110X_BLACK;
ColorVal UIColor::title_bkg = SH110X_BLACK;
ColorVal UIColor::title_txt = SH110X_WHITE;
ColorVal UIColor::primary_txt = SH110X_WHITE;
ColorVal UIColor::secondary_txt = SH110X_WHITE;
ColorVal UIColor::warning_txt = SH110X_WHITE;
ColorVal UIColor::popup_bkg = SH110X_BLACK;
ColorVal UIColor::popup_txt = SH110X_WHITE;
ColorVal UIColor::corp_blue = SH110X_WHITE;
bool SH1107Display::i2c_probe(TwoWire &wire, uint8_t addr)
{
wire.beginTransmission(addr);
uint8_t error = wire.endTransmission();
return (error == 0);
}
bool SH1107Display::begin()
{
bool result = display.begin(DISPLAY_ADDRESS, true) && i2c_probe(Wire, DISPLAY_ADDRESS);
if (result) {
display.setRotation(DISPLAY_ROTATION);
}
return result;
}
void SH1107Display::turnOn()
{
display.oled_command(SH110X_DISPLAYON);
uint8_t cmd[] = {0xD5, 0xF0};
display.oled_commandList(cmd, 2);
_isOn = true;
}
void SH1107Display::turnOff()
{
display.oled_command(SH110X_DISPLAYOFF);
_isOn = false;
}
void SH1107Display::clear()
{
display.clearDisplay();
display.display();
}
void SH1107Display::startFrame(ColorVal bkg)
{
display.clearDisplay(); // TODO: apply 'bkg'
display.setContrast(120); // 0-127. default setting was causing some flickering.
// display.SH110X_SETPRECHARGE(255);
_color = SH110X_WHITE;
display.setTextColor(_color);
display.setTextSize(1);
display.cp437(true); // Use full 256 char 'Code Page 437' font
}
void SH1107Display::setTextSize(int sz)
{
display.setTextSize(sz);
}
void SH1107Display::setColor(ColorVal c)
{
_color = (c != 0) ? SH110X_WHITE : SH110X_BLACK;
display.setTextColor(_color);
}
void SH1107Display::setCursor(int x, int y)
{
display.setCursor(x, y);
}
void SH1107Display::print(const char *str)
{
display.print(str);
}
void SH1107Display::fillRect(int x, int y, int w, int h)
{
display.fillRect(x, y, w, h, _color);
}
void SH1107Display::drawRect(int x, int y, int w, int h)
{
display.drawRect(x, y, w, h, _color);
}
void SH1107Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h)
{
display.drawBitmap(x, y, bits, w, h, SH110X_WHITE);
}
uint16_t SH1107Display::getTextWidth(const char *str)
{
int16_t x1, y1;
uint16_t w, h;
display.getTextBounds(str, 0, 0, &x1, &y1, &w, &h);
return w;
}
void SH1107Display::endFrame()
{
display.display();
}
+43
View File
@@ -0,0 +1,43 @@
#pragma once
#include "DisplayDriver.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#define SH110X_NO_SPLASH
#include <Adafruit_SH110X.h>
#ifndef PIN_OLED_RESET
#define PIN_OLED_RESET -1
#endif
#ifndef DISPLAY_ADDRESS
#define DISPLAY_ADDRESS 0x3c
#endif
class SH1107Display : public DisplayDriver
{
Adafruit_SH1107 display;
bool _isOn;
uint8_t _color;
bool i2c_probe(TwoWire &wire, uint8_t addr);
public:
SH1107Display() : DisplayDriver(128, 128), display(128, 128, &Wire, PIN_OLED_RESET) { _isOn = false; }
bool begin();
bool isOn() override { return _isOn; }
void turnOn() override;
void turnOff() override;
void clear() override;
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override;
void setColor(ColorVal 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;
uint16_t getTextWidth(const char *str) override;
void endFrame() override;
};
+21 -5
View File
@@ -6,6 +6,17 @@ bool SSD1306Display::i2c_probe(TwoWire& wire, uint8_t addr) {
return (error == 0);
}
// Color scheme
ColorVal UIColor::window_bkg = SSD1306_BLACK;
ColorVal UIColor::title_bkg = SSD1306_BLACK;
ColorVal UIColor::title_txt = SSD1306_WHITE;
ColorVal UIColor::primary_txt = SSD1306_WHITE;
ColorVal UIColor::secondary_txt = SSD1306_WHITE;
ColorVal UIColor::warning_txt = SSD1306_WHITE;
ColorVal UIColor::popup_bkg = SSD1306_BLACK;
ColorVal UIColor::popup_txt = SSD1306_WHITE;
ColorVal UIColor::corp_blue = SSD1306_WHITE;
bool SSD1306Display::begin() {
if (!_isOn) {
if (_peripher_power) _peripher_power->claim();
@@ -14,7 +25,12 @@ bool SSD1306Display::begin() {
#ifdef DISPLAY_ROTATION
display.setRotation(DISPLAY_ROTATION);
#endif
return display.begin(SSD1306_SWITCHCAPVCC, DISPLAY_ADDRESS, true, false) && i2c_probe(Wire, DISPLAY_ADDRESS);
bool success = display.begin(SSD1306_SWITCHCAPVCC, DISPLAY_ADDRESS, true, false);
#if defined(PIN_OLED_CS) && defined(PIN_OLED_DC)
return success;
#else
return success && i2c_probe(Wire, DISPLAY_ADDRESS);
#endif
}
void SSD1306Display::turnOn() {
@@ -44,7 +60,7 @@ void SSD1306Display::clear() {
display.display();
}
void SSD1306Display::startFrame(Color bkg) {
void SSD1306Display::startFrame(ColorVal bkg) {
display.clearDisplay(); // TODO: apply 'bkg'
_color = SSD1306_WHITE;
display.setTextColor(_color);
@@ -56,8 +72,8 @@ void SSD1306Display::setTextSize(int sz) {
display.setTextSize(sz);
}
void SSD1306Display::setColor(Color c) {
_color = (c != 0) ? SSD1306_WHITE : SSD1306_BLACK;
void SSD1306Display::setColor(ColorVal c) {
_color = c;
display.setTextColor(_color);
}
@@ -78,7 +94,7 @@ void SSD1306Display::drawRect(int x, int y, int w, int h) {
}
void SSD1306Display::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
display.drawBitmap(x, y, bits, w, h, SSD1306_WHITE);
display.drawBitmap(x, y, bits, w, h, _color);
}
uint16_t SSD1306Display::getTextWidth(const char* str) {
+10 -2
View File
@@ -15,6 +15,10 @@
#define DISPLAY_ADDRESS 0x3C
#endif
#if defined(PIN_OLED_CS) != defined(PIN_OLED_DC)
#error "SPI OLED requires both PIN_OLED_CS and PIN_OLED_DC"
#endif
class SSD1306Display : public DisplayDriver {
Adafruit_SSD1306 display;
bool _isOn;
@@ -24,7 +28,11 @@ class SSD1306Display : public DisplayDriver {
bool i2c_probe(TwoWire& wire, uint8_t addr);
public:
SSD1306Display(RefCountedDigitalPin* peripher_power=NULL) : DisplayDriver(128, 64),
#if defined(PIN_OLED_CS) && defined(PIN_OLED_DC)
display(128, 64, &SPI, PIN_OLED_DC, PIN_OLED_RESET, PIN_OLED_CS),
#else
display(128, 64, &Wire, PIN_OLED_RESET),
#endif
_peripher_power(peripher_power)
{
_isOn = false;
@@ -35,9 +43,9 @@ public:
void turnOn() override;
void turnOff() override;
void clear() override;
void startFrame(Color bkg = DARK) override;
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override;
void setColor(Color c) override;
void setColor(ColorVal 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;
+19 -32
View File
@@ -102,7 +102,8 @@
static TFT_eSPI lcd = TFT_eSPI(160, 80);
static uint32_t curr_color;
#if defined(HELTEC_LORA_V3) || defined(HELTEC_TRACKER_V2)
#if defined(HELTEC_LORA_V3) || defined(HELTEC_TRACKER_V2) || defined(DFROBOT_LORAWAN_ESP32S3)
// ESP32-S3: HSPI is SPI3. The SX1262 uses FSPI (SPI2) so the two buses do not share a controller.
static SPIClass tft_spi(HSPI);
#define _spi (&tft_spi)
#else
@@ -417,6 +418,17 @@ bool ST7735Display::i2c_probe(TwoWire& wire, uint8_t addr) {
#define PIN_TFT_LEDA_CTL_ACTIVE HIGH
#endif
// Color scheme
ColorVal UIColor::window_bkg = ST77XX_WHITE;
ColorVal UIColor::title_bkg = ST77XX_BLUE;
ColorVal UIColor::title_txt = ST77XX_WHITE;
ColorVal UIColor::primary_txt = ST77XX_BLACK;
ColorVal UIColor::secondary_txt = (18 << 11) | (36 << 5) | 18; // mid-gray
ColorVal UIColor::warning_txt = ST77XX_ORANGE;
ColorVal UIColor::popup_bkg = ST77XX_CYAN;
ColorVal UIColor::popup_txt = ST77XX_BLACK;
ColorVal UIColor::corp_blue = 0x001A;
bool ST7735Display::begin() {
if (!sprite) {
// alloc offscreen canvas
@@ -479,7 +491,7 @@ void ST7735Display::_resetAndInit() {
// run init commands
displayInit(Rcmd1);
#if defined(HELTEC_TRACKER_V2) || defined(HELTEC_T096)
#if defined(HELTEC_TRACKER_V2) || defined(HELTEC_T096) || defined(DFROBOT_LORAWAN_ESP32S3)
displayInit(Rcmd2green160x80);
//uint8_t madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_MV |ST7735_MADCTL_BGR;//Adjust color to BGR
//display.sendCommand(ST77XX_MADCTL, &madctl, 1);
@@ -527,9 +539,9 @@ void ST7735Display::clear() {
sprite->fillScreen(ST77XX_BLACK);
}
void ST7735Display::startFrame(Color bkg) {
sprite->fillScreen(ST77XX_BLACK);
sprite->setTextColor(curr_color = ST77XX_WHITE);
void ST7735Display::startFrame(ColorVal bkg) {
sprite->fillScreen(bkg);
sprite->setTextColor(curr_color = UIColor::primary_txt);
sprite->setFreeFont();
sprite->setTextSize(1); // This one affects size of Please wait... message
//sprite->cp437(true); // Use full 256 char 'Code Page 437' font
@@ -539,33 +551,8 @@ void ST7735Display::setTextSize(int sz) {
sprite->setTextSize(sz);
}
void ST7735Display::setColor(Color c) {
switch (c) {
case DisplayDriver::DARK :
curr_color = ST77XX_BLACK;
break;
case DisplayDriver::LIGHT :
curr_color = ST77XX_WHITE;
break;
case DisplayDriver::RED :
curr_color = ST77XX_RED;
break;
case DisplayDriver::GREEN :
curr_color = ST77XX_GREEN;
break;
case DisplayDriver::BLUE :
curr_color = ST77XX_BLUE;
break;
case DisplayDriver::YELLOW :
curr_color = ST77XX_YELLOW;
break;
case DisplayDriver::ORANGE :
curr_color = ST77XX_ORANGE;
break;
default:
curr_color = ST77XX_WHITE;
break;
}
void ST7735Display::setColor(ColorVal c) {
curr_color = c;
sprite->setTextColor(curr_color);
}
+2 -2
View File
@@ -33,9 +33,9 @@ public:
void turnOn() override;
void turnOff() override;
void clear() override;
void startFrame(Color bkg = DARK) override;
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override;
void setColor(Color c) override;
void setColor(ColorVal 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;
+18 -36
View File
@@ -26,6 +26,17 @@
#define SCALE_Y DISPLAY_SCALE_Y
#endif
// Color scheme
ColorVal UIColor::window_bkg = OLEDDISPLAY_COLOR::BLACK;
ColorVal UIColor::title_bkg = OLEDDISPLAY_COLOR::BLACK;
ColorVal UIColor::title_txt = OLEDDISPLAY_COLOR::WHITE;
ColorVal UIColor::primary_txt = OLEDDISPLAY_COLOR::WHITE;
ColorVal UIColor::secondary_txt = OLEDDISPLAY_COLOR::WHITE;
ColorVal UIColor::warning_txt = OLEDDISPLAY_COLOR::WHITE;
ColorVal UIColor::popup_bkg = OLEDDISPLAY_COLOR::BLACK;
ColorVal UIColor::popup_txt = OLEDDISPLAY_COLOR::WHITE;
ColorVal UIColor::corp_blue = OLEDDISPLAY_COLOR::WHITE;
bool ST7789Display::begin() {
if(!_isOn) {
pinMode(PIN_TFT_VDD_CTL, OUTPUT);
@@ -90,10 +101,9 @@ void ST7789Display::clear() {
display.clear();
}
void ST7789Display::startFrame(Color bkg) {
display.clear();
_color = ST77XX_WHITE;
display.setRGB(_color);
void ST7789Display::startFrame(ColorVal bkg) {
display.clear(); // TODO: use bkg
setColor(UIColor::primary_txt);
display.setFont(ArialMT_Plain_16);
}
@@ -110,38 +120,10 @@ void ST7789Display::setTextSize(int sz) {
}
}
void ST7789Display::setColor(Color c) {
switch (c) {
case DisplayDriver::DARK :
_color = ST77XX_BLACK;
display.setColor(OLEDDISPLAY_COLOR::BLACK);
break;
#if 0
case DisplayDriver::LIGHT :
_color = ST77XX_WHITE;
break;
case DisplayDriver::RED :
_color = ST77XX_RED;
break;
case DisplayDriver::GREEN :
_color = ST77XX_GREEN;
break;
case DisplayDriver::BLUE :
_color = ST77XX_BLUE;
break;
case DisplayDriver::YELLOW :
_color = ST77XX_YELLOW;
break;
case DisplayDriver::ORANGE :
_color = ST77XX_ORANGE;
break;
#endif
default:
_color = ST77XX_WHITE;
display.setColor(OLEDDISPLAY_COLOR::WHITE);
break;
}
display.setRGB(_color);
void ST7789Display::setColor(ColorVal c) {
_color = c;
display.setColor((OLEDDISPLAY_COLOR)_color);
display.setRGB(_color == OLEDDISPLAY_COLOR::WHITE ? ST77XX_WHITE : ST77XX_BLACK);
}
void ST7789Display::setCursor(int x, int y) {
+2 -2
View File
@@ -27,9 +27,9 @@ public:
void turnOn() override;
void turnOff() override;
void clear() override;
void startFrame(Color bkg = DARK) override;
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override;
void setColor(Color c) override;
void setColor(ColorVal c) override;
void setCursor(int x, int y) override;
void print(const char* str) override;
void printWordWrap(const char* str, int max_width) override;
+16 -31
View File
@@ -23,6 +23,17 @@ bool ST7789LCDDisplay::i2c_probe(TwoWire& wire, uint8_t addr) {
return true;
}
// Color scheme
ColorVal UIColor::window_bkg = ST77XX_WHITE;
ColorVal UIColor::title_bkg = ST77XX_BLUE;
ColorVal UIColor::title_txt = ST77XX_WHITE;
ColorVal UIColor::primary_txt = ST77XX_BLACK;
ColorVal UIColor::secondary_txt = (18 << 11) | (36 << 5) | 18; // mid-gray
ColorVal UIColor::warning_txt = ST77XX_ORANGE;
ColorVal UIColor::popup_bkg = ST77XX_CYAN;
ColorVal UIColor::popup_txt = ST77XX_BLACK;
ColorVal UIColor::corp_blue = 0x001A;
bool ST7789LCDDisplay::begin() {
if (!_isOn) {
if (_peripher_power) _peripher_power->claim();
@@ -78,9 +89,9 @@ void ST7789LCDDisplay::clear() {
display.fillScreen(ST77XX_BLACK);
}
void ST7789LCDDisplay::startFrame(Color bkg) {
display.fillScreen(ST77XX_BLACK);
display.setTextColor(ST77XX_WHITE);
void ST7789LCDDisplay::startFrame(ColorVal bkg) {
display.fillScreen(bkg);
display.setTextColor(_color = UIColor::primary_txt);
display.setTextSize(1 * DISPLAY_SCALE_X); // This one affects size of Please wait... message
display.cp437(true); // Use full 256 char 'Code Page 437' font
}
@@ -89,34 +100,8 @@ void ST7789LCDDisplay::setTextSize(int sz) {
display.setTextSize(sz * DISPLAY_SCALE_X);
}
void ST7789LCDDisplay::setColor(Color c) {
switch (c) {
case DisplayDriver::DARK :
_color = ST77XX_BLACK;
break;
case DisplayDriver::LIGHT :
_color = ST77XX_WHITE;
break;
case DisplayDriver::RED :
_color = ST77XX_RED;
break;
case DisplayDriver::GREEN :
_color = ST77XX_GREEN;
break;
case DisplayDriver::BLUE :
_color = ST77XX_BLUE;
break;
case DisplayDriver::YELLOW :
_color = ST77XX_YELLOW;
break;
case DisplayDriver::ORANGE :
_color = ST77XX_ORANGE;
break;
default:
_color = ST77XX_WHITE;
break;
}
display.setTextColor(_color);
void ST7789LCDDisplay::setColor(ColorVal c) {
display.setTextColor(_color = c);
}
void ST7789LCDDisplay::setCursor(int x, int y) {
+2 -2
View File
@@ -47,9 +47,9 @@ public:
void turnOn() override;
void turnOff() override;
void clear() override;
void startFrame(Color bkg = DARK) override;
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override;
void setColor(Color c) override;
void setColor(ColorVal 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;
+12
View File
@@ -0,0 +1,12 @@
#include "U8g2Display.h"
// Color scheme
ColorVal UIColor::window_bkg = 0;
ColorVal UIColor::title_bkg = 0;
ColorVal UIColor::title_txt = 1;
ColorVal UIColor::primary_txt = 1;
ColorVal UIColor::secondary_txt = 1;
ColorVal UIColor::warning_txt = 1;
ColorVal UIColor::popup_bkg = 0;
ColorVal UIColor::popup_txt = 1;
ColorVal UIColor::corp_blue = 1;
+6 -10
View File
@@ -72,10 +72,10 @@ public:
_u8g2.sendBuffer();
}
void startFrame(Color bkg = DARK) override {
_u8g2.clearBuffer();
_drawColor = 1;
_u8g2.setDrawColor(1);
void startFrame(ColorVal bkg = UIColor::window_bkg) override {
_u8g2.clearBuffer(); // TODO: apply 'bkg' color
_drawColor = UIColor::primary_txt;
_u8g2.setDrawColor(_drawColor);
applyFont(1);
}
@@ -83,8 +83,8 @@ public:
applyFont(sz);
}
void setColor(Color c) override {
_drawColor = (c != DARK) ? 1 : 0;
void setColor(ColorVal c) override {
_drawColor = c;
_u8g2.setDrawColor(_drawColor);
}
@@ -94,22 +94,18 @@ public:
}
void print(const char* str) override {
_u8g2.setDrawColor(_drawColor);
_u8g2.drawStr(_cursorX, _cursorY, str);
}
void fillRect(int x, int y, int w, int h) override {
_u8g2.setDrawColor(_drawColor);
_u8g2.drawBox(x, y, w, h);
}
void drawRect(int x, int y, int w, int h) override {
_u8g2.setDrawColor(_drawColor);
_u8g2.drawFrame(x, y, w, h);
}
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override {
_u8g2.setDrawColor(1);
_u8g2.drawXBM(x, y, w, h, bits);
}