mirror of
https://github.com/alexhopeoconnor/firmware.git
synced 2026-10-13 15:11:20 +10:00
Compare commits
19
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f341a289e | ||
|
|
f04746a928 | ||
|
|
1be2529fb9 | ||
|
|
959756abf1 | ||
|
|
c88b802e32 | ||
|
|
9f74fc11de | ||
|
|
2ef09d17b9 | ||
|
|
19d070c284 | ||
|
|
e24db2994b | ||
|
|
ac7a58cd45 | ||
|
|
53c21eb30d | ||
|
|
e51e6cad84 | ||
|
|
4890f7084f | ||
|
|
3fcbfe4370 | ||
|
|
da808cb43b | ||
|
|
82580c6798 | ||
|
|
016e68ec53 | ||
|
|
79f469ce71 | ||
|
|
0501e177e9 |
@@ -0,0 +1,60 @@
|
|||||||
|
{
|
||||||
|
"build": {
|
||||||
|
"arduino": {
|
||||||
|
"ldscript": "nrf52840_s140_v7.ld"
|
||||||
|
},
|
||||||
|
"core": "nRF5",
|
||||||
|
"cpu": "cortex-m4",
|
||||||
|
"extra_flags": "-DARDUINO_TRACKER_T2000_C -DNRF52840_XXAA",
|
||||||
|
"f_cpu": "64000000L",
|
||||||
|
"hwids": [
|
||||||
|
["0x239A", "0x8029"],
|
||||||
|
["0x239A", "0x0029"],
|
||||||
|
["0x239A", "0x002A"],
|
||||||
|
["0x239A", "0x802A"],
|
||||||
|
["0x2886", "0x0057"]
|
||||||
|
],
|
||||||
|
"usb_product": "T2000-BOOT",
|
||||||
|
"mcu": "nrf52840",
|
||||||
|
"variant": "Seeed_T2000-C",
|
||||||
|
"bsp": {
|
||||||
|
"name": "adafruit"
|
||||||
|
},
|
||||||
|
"softdevice": {
|
||||||
|
"sd_flags": "-DS140",
|
||||||
|
"sd_name": "s140",
|
||||||
|
"sd_version": "7.3.0",
|
||||||
|
"sd_fwid": "0x0123"
|
||||||
|
},
|
||||||
|
"bootloader": {
|
||||||
|
"settings_addr": "0xFF000"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"connectivity": ["bluetooth"],
|
||||||
|
"debug": {
|
||||||
|
"jlink_device": "nRF52840_xxAA",
|
||||||
|
"svd_path": "nrf52840.svd",
|
||||||
|
"openocd_target": "nrf52840-mdk-rs"
|
||||||
|
},
|
||||||
|
"frameworks": ["arduino"],
|
||||||
|
"name": "Seeed T2000-C",
|
||||||
|
"upload": {
|
||||||
|
"maximum_ram_size": 248832,
|
||||||
|
"maximum_size": 815104,
|
||||||
|
"speed": 115200,
|
||||||
|
"protocol": "nrfutil",
|
||||||
|
"protocols": [
|
||||||
|
"jlink",
|
||||||
|
"nrfjprog",
|
||||||
|
"nrfutil",
|
||||||
|
"stlink",
|
||||||
|
"cmsis-dap",
|
||||||
|
"blackmagic"
|
||||||
|
],
|
||||||
|
"use_1200bps_touch": true,
|
||||||
|
"require_upload_port": true,
|
||||||
|
"wait_for_upload_port": true
|
||||||
|
},
|
||||||
|
"url": "https://www.seeedstudio.com/",
|
||||||
|
"vendor": "Seeed Studio"
|
||||||
|
}
|
||||||
@@ -345,7 +345,7 @@ void RedirectablePrint::log(const char *logLevel, const char *format, ...)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RedirectablePrint::hexDump(const char *logLevel, unsigned char *buf, uint16_t len)
|
void RedirectablePrint::hexDump(const char *logLevel, const unsigned char *buf, uint16_t len)
|
||||||
{
|
{
|
||||||
const char alphabet[17] = "0123456789abcdef";
|
const char alphabet[17] = "0123456789abcdef";
|
||||||
log(logLevel, " +------------------------------------------------+ +----------------+");
|
log(logLevel, " +------------------------------------------------+ +----------------+");
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class RedirectablePrint : public Print
|
|||||||
/** like printf but va_list based */
|
/** like printf but va_list based */
|
||||||
size_t vprintf(const char *logLevel, const char *format, va_list arg);
|
size_t vprintf(const char *logLevel, const char *format, va_list arg);
|
||||||
|
|
||||||
void hexDump(const char *logLevel, unsigned char *buf, uint16_t len);
|
void hexDump(const char *logLevel, const unsigned char *buf, uint16_t len);
|
||||||
|
|
||||||
std::string mt_sprintf(const std::string fmt_str, ...);
|
std::string mt_sprintf(const std::string fmt_str, ...);
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
// Configuration
|
// Configuration
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Pre-hop drop handling (compile-time flag).
|
||||||
|
#ifndef MESHTASTIC_PREHOP_DROP
|
||||||
|
#define MESHTASTIC_PREHOP_DROP 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/// Convert a preprocessor name into a quoted string
|
/// Convert a preprocessor name into a quoted string
|
||||||
#define xstr(s) ystr(s)
|
#define xstr(s) ystr(s)
|
||||||
#define ystr(s) #s
|
#define ystr(s) #s
|
||||||
@@ -499,6 +504,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#define MESHTASTIC_EXCLUDE_REMOTEHARDWARE 1
|
#define MESHTASTIC_EXCLUDE_REMOTEHARDWARE 1
|
||||||
#define MESHTASTIC_EXCLUDE_STOREFORWARD 1
|
#define MESHTASTIC_EXCLUDE_STOREFORWARD 1
|
||||||
#define MESHTASTIC_EXCLUDE_TEXTMESSAGE 1
|
#define MESHTASTIC_EXCLUDE_TEXTMESSAGE 1
|
||||||
|
#define MESHTASTIC_EXCLUDE_TRAFFIC_MANAGEMENT 1
|
||||||
#define MESHTASTIC_EXCLUDE_ATAK 1
|
#define MESHTASTIC_EXCLUDE_ATAK 1
|
||||||
#define MESHTASTIC_EXCLUDE_CANNEDMESSAGES 1
|
#define MESHTASTIC_EXCLUDE_CANNEDMESSAGES 1
|
||||||
#define MESHTASTIC_EXCLUDE_NEIGHBORINFO 1
|
#define MESHTASTIC_EXCLUDE_NEIGHBORINFO 1
|
||||||
|
|||||||
@@ -37,8 +37,9 @@ ScanI2C::FoundDevice ScanI2C::firstKeyboard() const
|
|||||||
|
|
||||||
ScanI2C::FoundDevice ScanI2C::firstAccelerometer() const
|
ScanI2C::FoundDevice ScanI2C::firstAccelerometer() const
|
||||||
{
|
{
|
||||||
ScanI2C::DeviceType types[] = {MPU6050, LIS3DH, BMA423, LSM6DS3, BMX160, STK8BAXX, ICM20948, QMA6100P, BMM150, BMI270};
|
ScanI2C::DeviceType types[] = {MPU6050, LIS3DH, BMA423, LSM6DS3, LSM6DSOX, BMX160,
|
||||||
return firstOfOrNONE(10, types);
|
STK8BAXX, ICM20948, QMA6100P, BMM150, BMI270};
|
||||||
|
return firstOfOrNONE(11, types);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScanI2C::FoundDevice ScanI2C::firstAQI() const
|
ScanI2C::FoundDevice ScanI2C::firstAQI() const
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ class ScanI2C
|
|||||||
BMA423,
|
BMA423,
|
||||||
BQ24295,
|
BQ24295,
|
||||||
LSM6DS3,
|
LSM6DS3,
|
||||||
|
LSM6DSOX,
|
||||||
TCA9535,
|
TCA9535,
|
||||||
TCA9555,
|
TCA9555,
|
||||||
VEML7700,
|
VEML7700,
|
||||||
|
|||||||
@@ -341,7 +341,9 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
|
|||||||
type = DPS310;
|
type = DPS310;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
if (type == DPS310) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x00), 1); // GET_ID
|
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x00), 1); // GET_ID
|
||||||
switch (registerValue) {
|
switch (registerValue) {
|
||||||
@@ -509,6 +511,9 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
|
|||||||
if (registerValue == 0x6A) {
|
if (registerValue == 0x6A) {
|
||||||
type = LSM6DS3;
|
type = LSM6DS3;
|
||||||
logFoundDevice("LSM6DS3", (uint8_t)addr.address);
|
logFoundDevice("LSM6DS3", (uint8_t)addr.address);
|
||||||
|
} else if (registerValue == 0x6C) {
|
||||||
|
type = LSM6DSOX;
|
||||||
|
logFoundDevice("LSM6DSOX", (uint8_t)addr.address);
|
||||||
} else {
|
} else {
|
||||||
type = QMI8658;
|
type = QMI8658;
|
||||||
logFoundDevice("QMI8658", (uint8_t)addr.address);
|
logFoundDevice("QMI8658", (uint8_t)addr.address);
|
||||||
@@ -546,7 +551,19 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
SCAN_SIMPLE_CASE(LSM6DS3_ADDR, LSM6DS3, "LSM6DS3", (uint8_t)addr.address);
|
case LSM6DS3_ADDR:
|
||||||
|
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x0F), 1);
|
||||||
|
if (registerValue == 0x6A) {
|
||||||
|
type = LSM6DS3;
|
||||||
|
logFoundDevice("LSM6DS3", (uint8_t)addr.address);
|
||||||
|
} else if (registerValue == 0x6C) {
|
||||||
|
type = LSM6DSOX;
|
||||||
|
logFoundDevice("LSM6DSOX", (uint8_t)addr.address);
|
||||||
|
} else {
|
||||||
|
type = QMI8658;
|
||||||
|
logFoundDevice("QMI8658", (uint8_t)addr.address);
|
||||||
|
}
|
||||||
|
break;
|
||||||
SCAN_SIMPLE_CASE(VEML7700_ADDR, VEML7700, "VEML7700", (uint8_t)addr.address);
|
SCAN_SIMPLE_CASE(VEML7700_ADDR, VEML7700, "VEML7700", (uint8_t)addr.address);
|
||||||
case TCA9555_ADDR:
|
case TCA9555_ADDR:
|
||||||
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x01), 1);
|
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x01), 1);
|
||||||
|
|||||||
@@ -143,6 +143,10 @@ bool EInkDisplay::connect()
|
|||||||
#ifdef ELECROW_ThinkNode_M1
|
#ifdef ELECROW_ThinkNode_M1
|
||||||
// ThinkNode M1 has a hardware dimmable backlight. Start enabled
|
// ThinkNode M1 has a hardware dimmable backlight. Start enabled
|
||||||
digitalWrite(PIN_EINK_EN, HIGH);
|
digitalWrite(PIN_EINK_EN, HIGH);
|
||||||
|
#elif defined(MINI_EPAPER_S3)
|
||||||
|
// T-Mini Epaper S3 requires panel power rail enabled before SPI transfer.
|
||||||
|
digitalWrite(PIN_EINK_EN, HIGH);
|
||||||
|
delay(10);
|
||||||
#else
|
#else
|
||||||
digitalWrite(PIN_EINK_EN, LOW);
|
digitalWrite(PIN_EINK_EN, LOW);
|
||||||
#endif
|
#endif
|
||||||
@@ -202,7 +206,8 @@ bool EInkDisplay::connect()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(HELTEC_WIRELESS_PAPER_V1_0) || defined(HELTEC_VISION_MASTER_E290) || defined(TLORA_T3S3_EPAPER) || \
|
#elif defined(HELTEC_WIRELESS_PAPER_V1_0) || defined(HELTEC_VISION_MASTER_E290) || defined(TLORA_T3S3_EPAPER) || \
|
||||||
defined(CROWPANEL_ESP32S3_5_EPAPER) || defined(CROWPANEL_ESP32S3_4_EPAPER) || defined(CROWPANEL_ESP32S3_2_EPAPER)
|
defined(CROWPANEL_ESP32S3_5_EPAPER) || defined(CROWPANEL_ESP32S3_4_EPAPER) || defined(CROWPANEL_ESP32S3_2_EPAPER) || \
|
||||||
|
defined(MINI_EPAPER_S3)
|
||||||
{
|
{
|
||||||
// Start HSPI
|
// Start HSPI
|
||||||
hspi = new SPIClass(HSPI);
|
hspi = new SPIClass(HSPI);
|
||||||
@@ -216,9 +221,13 @@ bool EInkDisplay::connect()
|
|||||||
|
|
||||||
// Init GxEPD2
|
// Init GxEPD2
|
||||||
adafruitDisplay->init();
|
adafruitDisplay->init();
|
||||||
|
#if defined(MINI_EPAPER_S3)
|
||||||
|
adafruitDisplay->setRotation(3);
|
||||||
|
#else
|
||||||
adafruitDisplay->setRotation(3);
|
adafruitDisplay->setRotation(3);
|
||||||
#if defined(CROWPANEL_ESP32S3_5_EPAPER) || defined(CROWPANEL_ESP32S3_4_EPAPER)
|
#if defined(CROWPANEL_ESP32S3_5_EPAPER) || defined(CROWPANEL_ESP32S3_4_EPAPER)
|
||||||
adafruitDisplay->setRotation(0);
|
adafruitDisplay->setRotation(0);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#elif defined(PCA10059) || defined(ME25LS01)
|
#elif defined(PCA10059) || defined(ME25LS01)
|
||||||
@@ -259,17 +268,6 @@ bool EInkDisplay::connect()
|
|||||||
adafruitDisplay->setRotation(3);
|
adafruitDisplay->setRotation(3);
|
||||||
adafruitDisplay->setPartialWindow(0, 0, EINK_WIDTH, EINK_HEIGHT);
|
adafruitDisplay->setPartialWindow(0, 0, EINK_WIDTH, EINK_HEIGHT);
|
||||||
}
|
}
|
||||||
#elif defined(MINI_EPAPER_S3)
|
|
||||||
spi1 = new SPIClass(HSPI);
|
|
||||||
spi1->begin(PIN_SPI1_SCK, PIN_SPI1_MISO, PIN_SPI1_MOSI, PIN_EINK_CS);
|
|
||||||
|
|
||||||
// Create GxEPD2 objects
|
|
||||||
auto lowLevel = new EINK_DISPLAY_MODEL(PIN_EINK_CS, PIN_EINK_DC, PIN_EINK_RES, PIN_EINK_BUSY, *spi1);
|
|
||||||
adafruitDisplay = new GxEPD2_BW<EINK_DISPLAY_MODEL, EINK_DISPLAY_MODEL::HEIGHT>(*lowLevel);
|
|
||||||
|
|
||||||
// Init GxEPD2
|
|
||||||
adafruitDisplay->init();
|
|
||||||
adafruitDisplay->setRotation(1);
|
|
||||||
#elif defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_VISION_MASTER_E213)
|
#elif defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_VISION_MASTER_E213)
|
||||||
|
|
||||||
// Detect display model, before starting SPI
|
// Detect display model, before starting SPI
|
||||||
|
|||||||
@@ -89,12 +89,12 @@ class EInkDisplay : public OLEDDisplay
|
|||||||
// If display uses HSPI
|
// If display uses HSPI
|
||||||
#if defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_WIRELESS_PAPER_V1_0) || defined(HELTEC_VISION_MASTER_E213) || \
|
#if defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_WIRELESS_PAPER_V1_0) || defined(HELTEC_VISION_MASTER_E213) || \
|
||||||
defined(HELTEC_VISION_MASTER_E290) || defined(TLORA_T3S3_EPAPER) || defined(CROWPANEL_ESP32S3_5_EPAPER) || \
|
defined(HELTEC_VISION_MASTER_E290) || defined(TLORA_T3S3_EPAPER) || defined(CROWPANEL_ESP32S3_5_EPAPER) || \
|
||||||
defined(CROWPANEL_ESP32S3_4_EPAPER) || defined(CROWPANEL_ESP32S3_2_EPAPER) || defined(ELECROW_ThinkNode_M5)
|
defined(CROWPANEL_ESP32S3_4_EPAPER) || defined(CROWPANEL_ESP32S3_2_EPAPER) || defined(ELECROW_ThinkNode_M5) || \
|
||||||
|
defined(MINI_EPAPER_S3)
|
||||||
SPIClass *hspi = NULL;
|
SPIClass *hspi = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HELTEC_MESH_POCKET) || defined(SEEED_WIO_TRACKER_L1_EINK) || defined(HELTEC_MESH_SOLAR_EINK) || \
|
#if defined(HELTEC_MESH_POCKET) || defined(SEEED_WIO_TRACKER_L1_EINK) || defined(HELTEC_MESH_SOLAR_EINK)
|
||||||
defined(MINI_EPAPER_S3)
|
|
||||||
SPIClass *spi1 = NULL;
|
SPIClass *spi1 = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,434 @@
|
|||||||
|
#include "configuration.h"
|
||||||
|
#if HAS_SCREEN
|
||||||
|
|
||||||
|
#include "graphics/EmoteRenderer.h"
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
namespace graphics
|
||||||
|
{
|
||||||
|
namespace EmoteRenderer
|
||||||
|
{
|
||||||
|
|
||||||
|
static inline int getStringWidth(OLEDDisplay *display, const char *text, size_t len)
|
||||||
|
{
|
||||||
|
#if defined(OLED_UA) || defined(OLED_RU)
|
||||||
|
return display->getStringWidth(text, len, true);
|
||||||
|
#else
|
||||||
|
(void)len;
|
||||||
|
return display->getStringWidth(text);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t utf8CharLen(uint8_t c)
|
||||||
|
{
|
||||||
|
if ((c & 0xE0) == 0xC0)
|
||||||
|
return 2;
|
||||||
|
if ((c & 0xF0) == 0xE0)
|
||||||
|
return 3;
|
||||||
|
if ((c & 0xF8) == 0xF0)
|
||||||
|
return 4;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool isPossibleEmoteLead(uint8_t c)
|
||||||
|
{
|
||||||
|
// All supported emoji labels in emotes.cpp are currently in these UTF-8 lead ranges.
|
||||||
|
return c == 0xE2 || c == 0xF0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int getUtf8ChunkWidth(OLEDDisplay *display, const char *text, size_t len)
|
||||||
|
{
|
||||||
|
char chunk[5] = {0, 0, 0, 0, 0};
|
||||||
|
if (len > 4)
|
||||||
|
len = 4;
|
||||||
|
memcpy(chunk, text, len);
|
||||||
|
return getStringWidth(display, chunk, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool isFE0FAt(const char *s, size_t pos, size_t len)
|
||||||
|
{
|
||||||
|
return pos + 2 < len && static_cast<uint8_t>(s[pos]) == 0xEF && static_cast<uint8_t>(s[pos + 1]) == 0xB8 &&
|
||||||
|
static_cast<uint8_t>(s[pos + 2]) == 0x8F;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool isSkinToneAt(const char *s, size_t pos, size_t len)
|
||||||
|
{
|
||||||
|
return pos + 3 < len && static_cast<uint8_t>(s[pos]) == 0xF0 && static_cast<uint8_t>(s[pos + 1]) == 0x9F &&
|
||||||
|
static_cast<uint8_t>(s[pos + 2]) == 0x8F &&
|
||||||
|
(static_cast<uint8_t>(s[pos + 3]) >= 0xBB && static_cast<uint8_t>(s[pos + 3]) <= 0xBF);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline size_t ignorableModifierLenAt(const char *s, size_t pos, size_t len)
|
||||||
|
{
|
||||||
|
// Skip modifiers that do not change which bitmap we render.
|
||||||
|
if (isFE0FAt(s, pos, len))
|
||||||
|
return 3;
|
||||||
|
if (isSkinToneAt(s, pos, len))
|
||||||
|
return 4;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Emote *findEmoteByLabel(const char *label, const Emote *emoteSet, int emoteCount)
|
||||||
|
{
|
||||||
|
if (!label || !*label)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
for (int i = 0; i < emoteCount; ++i) {
|
||||||
|
if (emoteSet[i].label && strcmp(label, emoteSet[i].label) == 0)
|
||||||
|
return &emoteSet[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool matchAtIgnoringModifiers(const char *text, size_t textLen, size_t pos, const char *label, size_t &textConsumed,
|
||||||
|
size_t &matchScore)
|
||||||
|
{
|
||||||
|
// Treat FE0F and skin-tone modifiers as optional while matching.
|
||||||
|
textConsumed = 0;
|
||||||
|
matchScore = 0;
|
||||||
|
if (!label || !*label || pos >= textLen)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const size_t labelLen = strlen(label);
|
||||||
|
size_t ti = pos;
|
||||||
|
size_t li = 0;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
while (ti < textLen) {
|
||||||
|
const size_t skipLen = ignorableModifierLenAt(text, ti, textLen);
|
||||||
|
if (!skipLen)
|
||||||
|
break;
|
||||||
|
ti += skipLen;
|
||||||
|
}
|
||||||
|
while (li < labelLen) {
|
||||||
|
const size_t skipLen = ignorableModifierLenAt(label, li, labelLen);
|
||||||
|
if (!skipLen)
|
||||||
|
break;
|
||||||
|
li += skipLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (li >= labelLen) {
|
||||||
|
while (ti < textLen) {
|
||||||
|
const size_t skipLen = ignorableModifierLenAt(text, ti, textLen);
|
||||||
|
if (!skipLen)
|
||||||
|
break;
|
||||||
|
ti += skipLen;
|
||||||
|
}
|
||||||
|
textConsumed = ti - pos;
|
||||||
|
return textConsumed > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ti >= textLen)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const uint8_t tc = static_cast<uint8_t>(text[ti]);
|
||||||
|
const uint8_t lc = static_cast<uint8_t>(label[li]);
|
||||||
|
const size_t tlen = utf8CharLen(tc);
|
||||||
|
const size_t llen = utf8CharLen(lc);
|
||||||
|
|
||||||
|
if (tlen != llen || ti + tlen > textLen || li + llen > labelLen)
|
||||||
|
return false;
|
||||||
|
if (memcmp(text + ti, label + li, tlen) != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ti += tlen;
|
||||||
|
li += llen;
|
||||||
|
matchScore += llen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const Emote *findEmoteAt(const char *text, size_t textLen, size_t pos, size_t &matchLen, const Emote *emoteSet, int emoteCount)
|
||||||
|
{
|
||||||
|
// Prefer the longest matching label at this byte offset.
|
||||||
|
const Emote *matched = nullptr;
|
||||||
|
matchLen = 0;
|
||||||
|
size_t bestScore = 0;
|
||||||
|
if (!text || pos >= textLen)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
if (!isPossibleEmoteLead(static_cast<uint8_t>(text[pos])))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
for (int i = 0; i < emoteCount; ++i) {
|
||||||
|
const char *label = emoteSet[i].label;
|
||||||
|
if (!label || !*label)
|
||||||
|
continue;
|
||||||
|
if (static_cast<uint8_t>(label[0]) != static_cast<uint8_t>(text[pos]))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const size_t labelLen = strlen(label);
|
||||||
|
if (labelLen == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
size_t candidateLen = 0;
|
||||||
|
size_t candidateScore = 0;
|
||||||
|
if (pos + labelLen <= textLen && memcmp(text + pos, label, labelLen) == 0) {
|
||||||
|
candidateLen = labelLen;
|
||||||
|
candidateScore = labelLen;
|
||||||
|
} else if (matchAtIgnoringModifiers(text, textLen, pos, label, candidateLen, candidateScore)) {
|
||||||
|
// Matched with FE0F/skin tone modifiers treated as optional.
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (candidateScore > bestScore) {
|
||||||
|
matched = &emoteSet[i];
|
||||||
|
matchLen = candidateLen;
|
||||||
|
bestScore = candidateScore;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return matched;
|
||||||
|
}
|
||||||
|
|
||||||
|
static LineMetrics analyzeLineInternal(OLEDDisplay *display, const char *line, size_t lineLen, int fallbackHeight,
|
||||||
|
const Emote *emoteSet, int emoteCount, int emoteSpacing)
|
||||||
|
{
|
||||||
|
// Scan once to collect width and tallest emote for this line.
|
||||||
|
LineMetrics metrics{0, fallbackHeight, false};
|
||||||
|
if (!line)
|
||||||
|
return metrics;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < lineLen;) {
|
||||||
|
size_t matchLen = 0;
|
||||||
|
const Emote *matched = findEmoteAt(line, lineLen, i, matchLen, emoteSet, emoteCount);
|
||||||
|
if (matched) {
|
||||||
|
metrics.hasEmote = true;
|
||||||
|
metrics.tallestHeight = std::max(metrics.tallestHeight, matched->height);
|
||||||
|
if (display)
|
||||||
|
metrics.width += matched->width + emoteSpacing;
|
||||||
|
i += matchLen;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t skipLen = ignorableModifierLenAt(line, i, lineLen);
|
||||||
|
if (skipLen) {
|
||||||
|
i += skipLen;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t charLen = utf8CharLen(static_cast<uint8_t>(line[i]));
|
||||||
|
if (display)
|
||||||
|
metrics.width += getUtf8ChunkWidth(display, line + i, charLen);
|
||||||
|
i += charLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
return metrics;
|
||||||
|
}
|
||||||
|
|
||||||
|
LineMetrics analyzeLine(OLEDDisplay *display, const char *line, int fallbackHeight, const Emote *emoteSet, int emoteCount,
|
||||||
|
int emoteSpacing)
|
||||||
|
{
|
||||||
|
return analyzeLineInternal(display, line, line ? strlen(line) : 0, fallbackHeight, emoteSet, emoteCount, emoteSpacing);
|
||||||
|
}
|
||||||
|
|
||||||
|
int maxEmoteHeight(const Emote *emoteSet, int emoteCount)
|
||||||
|
{
|
||||||
|
int tallest = 0;
|
||||||
|
for (int i = 0; i < emoteCount; ++i) {
|
||||||
|
if (emoteSet[i].label && *emoteSet[i].label)
|
||||||
|
tallest = std::max(tallest, emoteSet[i].height);
|
||||||
|
}
|
||||||
|
return tallest;
|
||||||
|
}
|
||||||
|
|
||||||
|
int measureStringWithEmotes(OLEDDisplay *display, const char *line, const Emote *emoteSet, int emoteCount, int emoteSpacing)
|
||||||
|
{
|
||||||
|
if (!display)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!line || !*line)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return analyzeLine(display, line, 0, emoteSet, emoteCount, emoteSpacing).width;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int appendTextSpanAndMeasure(OLEDDisplay *display, int cursorX, int fontY, const char *text, size_t len, bool draw,
|
||||||
|
bool fauxBold)
|
||||||
|
{
|
||||||
|
// Draw plain-text runs in chunks so UTF-8 stays intact.
|
||||||
|
if (!text || len == 0)
|
||||||
|
return cursorX;
|
||||||
|
|
||||||
|
char chunk[33];
|
||||||
|
size_t pos = 0;
|
||||||
|
while (pos < len) {
|
||||||
|
size_t chunkLen = 0;
|
||||||
|
while (pos + chunkLen < len) {
|
||||||
|
const size_t charLen = utf8CharLen(static_cast<uint8_t>(text[pos + chunkLen]));
|
||||||
|
if (chunkLen + charLen >= sizeof(chunk))
|
||||||
|
break;
|
||||||
|
chunkLen += charLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chunkLen == 0) {
|
||||||
|
chunkLen = std::min(len - pos, sizeof(chunk) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(chunk, text + pos, chunkLen);
|
||||||
|
chunk[chunkLen] = '\0';
|
||||||
|
if (draw) {
|
||||||
|
if (fauxBold)
|
||||||
|
display->drawString(cursorX + 1, fontY, chunk);
|
||||||
|
display->drawString(cursorX, fontY, chunk);
|
||||||
|
}
|
||||||
|
cursorX += getStringWidth(display, chunk, chunkLen);
|
||||||
|
pos += chunkLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cursorX;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t truncateToWidth(OLEDDisplay *display, const char *line, char *out, size_t outSize, int maxWidth, const char *ellipsis,
|
||||||
|
const Emote *emoteSet, int emoteCount, int emoteSpacing)
|
||||||
|
{
|
||||||
|
if (!out || outSize == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
out[0] = '\0';
|
||||||
|
if (!display || !line || maxWidth <= 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
const size_t lineLen = strlen(line);
|
||||||
|
const int suffixWidth =
|
||||||
|
(ellipsis && *ellipsis) ? measureStringWithEmotes(display, ellipsis, emoteSet, emoteCount, emoteSpacing) : 0;
|
||||||
|
const char *suffix = (ellipsis && suffixWidth <= maxWidth) ? ellipsis : "";
|
||||||
|
const size_t suffixLen = strlen(suffix);
|
||||||
|
const int availableWidth = maxWidth - (*suffix ? suffixWidth : 0);
|
||||||
|
|
||||||
|
if (measureStringWithEmotes(display, line, emoteSet, emoteCount, emoteSpacing) <= maxWidth) {
|
||||||
|
strncpy(out, line, outSize - 1);
|
||||||
|
out[outSize - 1] = '\0';
|
||||||
|
return strlen(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
int used = 0;
|
||||||
|
size_t cut = 0;
|
||||||
|
for (size_t i = 0; i < lineLen;) {
|
||||||
|
// Keep whole emotes together when deciding where to cut.
|
||||||
|
int tokenWidth = 0;
|
||||||
|
size_t advance = 0;
|
||||||
|
|
||||||
|
if (isPossibleEmoteLead(static_cast<uint8_t>(line[i]))) {
|
||||||
|
size_t matchLen = 0;
|
||||||
|
const Emote *matched = findEmoteAt(line, lineLen, i, matchLen, emoteSet, emoteCount);
|
||||||
|
if (matched) {
|
||||||
|
tokenWidth = matched->width + emoteSpacing;
|
||||||
|
advance = matchLen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (advance == 0) {
|
||||||
|
const size_t skipLen = ignorableModifierLenAt(line, i, lineLen);
|
||||||
|
if (skipLen) {
|
||||||
|
i += skipLen;
|
||||||
|
cut = i;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t charLen = utf8CharLen(static_cast<uint8_t>(line[i]));
|
||||||
|
tokenWidth = getUtf8ChunkWidth(display, line + i, charLen);
|
||||||
|
advance = charLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (used + tokenWidth > availableWidth)
|
||||||
|
break;
|
||||||
|
|
||||||
|
used += tokenWidth;
|
||||||
|
i += advance;
|
||||||
|
cut = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cut == 0) {
|
||||||
|
strncpy(out, suffix, outSize - 1);
|
||||||
|
out[outSize - 1] = '\0';
|
||||||
|
return strlen(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t copyLen = cut;
|
||||||
|
if (copyLen > outSize - 1)
|
||||||
|
copyLen = outSize - 1;
|
||||||
|
if (suffixLen > 0 && copyLen + suffixLen > outSize - 1) {
|
||||||
|
copyLen = (outSize - 1 > suffixLen) ? (outSize - 1 - suffixLen) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(out, line, copyLen);
|
||||||
|
size_t totalLen = copyLen;
|
||||||
|
if (suffixLen > 0 && totalLen < outSize - 1) {
|
||||||
|
memcpy(out + totalLen, suffix, std::min(suffixLen, outSize - 1 - totalLen));
|
||||||
|
totalLen += std::min(suffixLen, outSize - 1 - totalLen);
|
||||||
|
}
|
||||||
|
out[totalLen] = '\0';
|
||||||
|
return totalLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawStringWithEmotes(OLEDDisplay *display, int x, int y, const char *line, int fontHeight, const Emote *emoteSet,
|
||||||
|
int emoteCount, int emoteSpacing, bool fauxBold)
|
||||||
|
{
|
||||||
|
if (!line)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const size_t lineLen = strlen(line);
|
||||||
|
// Center text vertically when any emote is taller than the font.
|
||||||
|
const int maxIconHeight =
|
||||||
|
analyzeLineInternal(nullptr, line, lineLen, fontHeight, emoteSet, emoteCount, emoteSpacing).tallestHeight;
|
||||||
|
const int lineHeight = std::max(fontHeight, maxIconHeight);
|
||||||
|
const int fontY = y + (lineHeight - fontHeight) / 2;
|
||||||
|
|
||||||
|
int cursorX = x;
|
||||||
|
bool inBold = false;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < lineLen;) {
|
||||||
|
// Toggle faux bold.
|
||||||
|
if (fauxBold && i + 1 < lineLen && line[i] == '*' && line[i + 1] == '*') {
|
||||||
|
inBold = !inBold;
|
||||||
|
i += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t skipLen = ignorableModifierLenAt(line, i, lineLen);
|
||||||
|
if (skipLen) {
|
||||||
|
i += skipLen;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t matchLen = 0;
|
||||||
|
const Emote *matched = findEmoteAt(line, lineLen, i, matchLen, emoteSet, emoteCount);
|
||||||
|
if (matched) {
|
||||||
|
const int iconY = y + (lineHeight - matched->height) / 2;
|
||||||
|
display->drawXbm(cursorX, iconY, matched->width, matched->height, matched->bitmap);
|
||||||
|
cursorX += matched->width + emoteSpacing;
|
||||||
|
i += matchLen;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t next = i;
|
||||||
|
while (next < lineLen) {
|
||||||
|
// Stop the text run before the next emote or bold marker.
|
||||||
|
if (fauxBold && next + 1 < lineLen && line[next] == '*' && line[next + 1] == '*')
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (ignorableModifierLenAt(line, next, lineLen))
|
||||||
|
break;
|
||||||
|
|
||||||
|
size_t nextMatchLen = 0;
|
||||||
|
if (findEmoteAt(line, lineLen, next, nextMatchLen, emoteSet, emoteCount) != nullptr)
|
||||||
|
break;
|
||||||
|
|
||||||
|
next += utf8CharLen(static_cast<uint8_t>(line[next]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (next == i)
|
||||||
|
next += utf8CharLen(static_cast<uint8_t>(line[i]));
|
||||||
|
|
||||||
|
cursorX = appendTextSpanAndMeasure(display, cursorX, fontY, line + i, next - i, true, fauxBold && inBold);
|
||||||
|
i = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace EmoteRenderer
|
||||||
|
} // namespace graphics
|
||||||
|
|
||||||
|
#endif // HAS_SCREEN
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "configuration.h"
|
||||||
|
|
||||||
|
#if HAS_SCREEN
|
||||||
|
#include "graphics/emotes.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <OLEDDisplay.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace graphics
|
||||||
|
{
|
||||||
|
namespace EmoteRenderer
|
||||||
|
{
|
||||||
|
|
||||||
|
struct LineMetrics {
|
||||||
|
int width;
|
||||||
|
int tallestHeight;
|
||||||
|
bool hasEmote;
|
||||||
|
};
|
||||||
|
|
||||||
|
size_t utf8CharLen(uint8_t c);
|
||||||
|
|
||||||
|
const Emote *findEmoteByLabel(const char *label, const Emote *emoteSet = emotes, int emoteCount = numEmotes);
|
||||||
|
const Emote *findEmoteAt(const char *text, size_t textLen, size_t pos, size_t &matchLen, const Emote *emoteSet = emotes,
|
||||||
|
int emoteCount = numEmotes);
|
||||||
|
inline const Emote *findEmoteAt(const std::string &text, size_t pos, size_t &matchLen, const Emote *emoteSet = emotes,
|
||||||
|
int emoteCount = numEmotes)
|
||||||
|
{
|
||||||
|
return findEmoteAt(text.c_str(), text.length(), pos, matchLen, emoteSet, emoteCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
LineMetrics analyzeLine(OLEDDisplay *display, const char *line, int fallbackHeight = 0, const Emote *emoteSet = emotes,
|
||||||
|
int emoteCount = numEmotes, int emoteSpacing = 1);
|
||||||
|
inline LineMetrics analyzeLine(OLEDDisplay *display, const std::string &line, int fallbackHeight = 0,
|
||||||
|
const Emote *emoteSet = emotes, int emoteCount = numEmotes, int emoteSpacing = 1)
|
||||||
|
{
|
||||||
|
return analyzeLine(display, line.c_str(), fallbackHeight, emoteSet, emoteCount, emoteSpacing);
|
||||||
|
}
|
||||||
|
int maxEmoteHeight(const Emote *emoteSet = emotes, int emoteCount = numEmotes);
|
||||||
|
|
||||||
|
int measureStringWithEmotes(OLEDDisplay *display, const char *line, const Emote *emoteSet = emotes, int emoteCount = numEmotes,
|
||||||
|
int emoteSpacing = 1);
|
||||||
|
inline int measureStringWithEmotes(OLEDDisplay *display, const std::string &line, const Emote *emoteSet = emotes,
|
||||||
|
int emoteCount = numEmotes, int emoteSpacing = 1)
|
||||||
|
{
|
||||||
|
return measureStringWithEmotes(display, line.c_str(), emoteSet, emoteCount, emoteSpacing);
|
||||||
|
}
|
||||||
|
size_t truncateToWidth(OLEDDisplay *display, const char *line, char *out, size_t outSize, int maxWidth,
|
||||||
|
const char *ellipsis = "...", const Emote *emoteSet = emotes, int emoteCount = numEmotes,
|
||||||
|
int emoteSpacing = 1);
|
||||||
|
inline std::string truncateToWidth(OLEDDisplay *display, const std::string &line, int maxWidth,
|
||||||
|
const std::string &ellipsis = "...", const Emote *emoteSet = emotes,
|
||||||
|
int emoteCount = numEmotes, int emoteSpacing = 1)
|
||||||
|
{
|
||||||
|
if (!display || maxWidth <= 0)
|
||||||
|
return "";
|
||||||
|
if (measureStringWithEmotes(display, line.c_str(), emoteSet, emoteCount, emoteSpacing) <= maxWidth)
|
||||||
|
return line;
|
||||||
|
|
||||||
|
std::vector<char> out(line.length() + ellipsis.length() + 1, '\0');
|
||||||
|
truncateToWidth(display, line.c_str(), out.data(), out.size(), maxWidth, ellipsis.c_str(), emoteSet, emoteCount,
|
||||||
|
emoteSpacing);
|
||||||
|
return std::string(out.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawStringWithEmotes(OLEDDisplay *display, int x, int y, const char *line, int fontHeight, const Emote *emoteSet = emotes,
|
||||||
|
int emoteCount = numEmotes, int emoteSpacing = 1, bool fauxBold = true);
|
||||||
|
inline void drawStringWithEmotes(OLEDDisplay *display, int x, int y, const std::string &line, int fontHeight,
|
||||||
|
const Emote *emoteSet = emotes, int emoteCount = numEmotes, int emoteSpacing = 1,
|
||||||
|
bool fauxBold = true)
|
||||||
|
{
|
||||||
|
drawStringWithEmotes(display, x, y, line.c_str(), fontHeight, emoteSet, emoteCount, emoteSpacing, fauxBold);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace EmoteRenderer
|
||||||
|
} // namespace graphics
|
||||||
|
|
||||||
|
#endif // HAS_SCREEN
|
||||||
@@ -121,11 +121,10 @@ void drawCommonHeader(OLEDDisplay *display, int16_t x, int16_t y, const char *ti
|
|||||||
}
|
}
|
||||||
|
|
||||||
// === Screen Title ===
|
// === Screen Title ===
|
||||||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
const char *headerTitle = titleStr ? titleStr : "";
|
||||||
display->drawString(SCREEN_WIDTH / 2, y, titleStr);
|
const int titleWidth = UIRenderer::measureStringWithEmotes(display, headerTitle);
|
||||||
if (config.display.heading_bold) {
|
const int titleX = (SCREEN_WIDTH - titleWidth) / 2;
|
||||||
display->drawString((SCREEN_WIDTH / 2) + 1, y, titleStr);
|
UIRenderer::drawStringWithEmotes(display, titleX, y, headerTitle, FONT_HEIGHT_SMALL, 1, config.display.heading_bold);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
|
|
||||||
@@ -515,4 +514,4 @@ std::string sanitizeString(const std::string &input)
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace graphics
|
} // namespace graphics
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "NodeDB.h"
|
#include "NodeDB.h"
|
||||||
#include "UIRenderer.h"
|
#include "UIRenderer.h"
|
||||||
#include "gps/RTC.h"
|
#include "gps/RTC.h"
|
||||||
|
#include "graphics/EmoteRenderer.h"
|
||||||
#include "graphics/Screen.h"
|
#include "graphics/Screen.h"
|
||||||
#include "graphics/ScreenFonts.h"
|
#include "graphics/ScreenFonts.h"
|
||||||
#include "graphics/SharedUIDisplay.h"
|
#include "graphics/SharedUIDisplay.h"
|
||||||
@@ -34,44 +35,6 @@ static std::vector<std::string> cachedLines;
|
|||||||
static std::vector<int> cachedHeights;
|
static std::vector<int> cachedHeights;
|
||||||
static bool manualScrolling = false;
|
static bool manualScrolling = false;
|
||||||
|
|
||||||
// UTF-8 skip helper
|
|
||||||
static inline size_t utf8CharLen(uint8_t c)
|
|
||||||
{
|
|
||||||
if ((c & 0xE0) == 0xC0)
|
|
||||||
return 2;
|
|
||||||
if ((c & 0xF0) == 0xE0)
|
|
||||||
return 3;
|
|
||||||
if ((c & 0xF8) == 0xF0)
|
|
||||||
return 4;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove variation selectors (FE0F) and skin tone modifiers from emoji so they match your labels
|
|
||||||
static std::string normalizeEmoji(const std::string &s)
|
|
||||||
{
|
|
||||||
std::string out;
|
|
||||||
for (size_t i = 0; i < s.size();) {
|
|
||||||
uint8_t c = static_cast<uint8_t>(s[i]);
|
|
||||||
size_t len = utf8CharLen(c);
|
|
||||||
|
|
||||||
if (c == 0xEF && i + 2 < s.size() && (uint8_t)s[i + 1] == 0xB8 && (uint8_t)s[i + 2] == 0x8F) {
|
|
||||||
i += 3;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip skin tone modifiers
|
|
||||||
if (c == 0xF0 && i + 3 < s.size() && (uint8_t)s[i + 1] == 0x9F && (uint8_t)s[i + 2] == 0x8F &&
|
|
||||||
((uint8_t)s[i + 3] >= 0xBB && (uint8_t)s[i + 3] <= 0xBF)) {
|
|
||||||
i += 4;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
out.append(s, i, len);
|
|
||||||
i += len;
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scroll state (file scope so we can reset on new message)
|
// Scroll state (file scope so we can reset on new message)
|
||||||
float scrollY = 0.0f;
|
float scrollY = 0.0f;
|
||||||
uint32_t lastTime = 0;
|
uint32_t lastTime = 0;
|
||||||
@@ -110,102 +73,7 @@ void scrollDown()
|
|||||||
|
|
||||||
void drawStringWithEmotes(OLEDDisplay *display, int x, int y, const std::string &line, const Emote *emotes, int emoteCount)
|
void drawStringWithEmotes(OLEDDisplay *display, int x, int y, const std::string &line, const Emote *emotes, int emoteCount)
|
||||||
{
|
{
|
||||||
int cursorX = x;
|
graphics::EmoteRenderer::drawStringWithEmotes(display, x, y, line, FONT_HEIGHT_SMALL, emotes, emoteCount);
|
||||||
const int fontHeight = FONT_HEIGHT_SMALL;
|
|
||||||
|
|
||||||
// Step 1: Find tallest emote in the line
|
|
||||||
int maxIconHeight = fontHeight;
|
|
||||||
for (size_t i = 0; i < line.length();) {
|
|
||||||
bool matched = false;
|
|
||||||
for (int e = 0; e < emoteCount; ++e) {
|
|
||||||
size_t emojiLen = strlen(emotes[e].label);
|
|
||||||
if (line.compare(i, emojiLen, emotes[e].label) == 0) {
|
|
||||||
if (emotes[e].height > maxIconHeight)
|
|
||||||
maxIconHeight = emotes[e].height;
|
|
||||||
i += emojiLen;
|
|
||||||
matched = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!matched) {
|
|
||||||
i += utf8CharLen(static_cast<uint8_t>(line[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 2: Baseline alignment
|
|
||||||
int lineHeight = std::max(fontHeight, maxIconHeight);
|
|
||||||
int baselineOffset = (lineHeight - fontHeight) / 2;
|
|
||||||
int fontY = y + baselineOffset;
|
|
||||||
|
|
||||||
// Step 3: Render line in segments
|
|
||||||
size_t i = 0;
|
|
||||||
bool inBold = false;
|
|
||||||
|
|
||||||
while (i < line.length()) {
|
|
||||||
// Check for ** start/end for faux bold
|
|
||||||
if (line.compare(i, 2, "**") == 0) {
|
|
||||||
inBold = !inBold;
|
|
||||||
i += 2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Look ahead for the next emote match
|
|
||||||
size_t nextEmotePos = std::string::npos;
|
|
||||||
const Emote *matchedEmote = nullptr;
|
|
||||||
size_t emojiLen = 0;
|
|
||||||
|
|
||||||
for (int e = 0; e < emoteCount; ++e) {
|
|
||||||
size_t pos = line.find(emotes[e].label, i);
|
|
||||||
if (pos != std::string::npos && (nextEmotePos == std::string::npos || pos < nextEmotePos)) {
|
|
||||||
nextEmotePos = pos;
|
|
||||||
matchedEmote = &emotes[e];
|
|
||||||
emojiLen = strlen(emotes[e].label);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render normal text segment up to the emote or bold toggle
|
|
||||||
size_t nextControl = std::min(nextEmotePos, line.find("**", i));
|
|
||||||
if (nextControl == std::string::npos)
|
|
||||||
nextControl = line.length();
|
|
||||||
|
|
||||||
if (nextControl > i) {
|
|
||||||
std::string textChunk = line.substr(i, nextControl - i);
|
|
||||||
if (inBold) {
|
|
||||||
// Faux bold: draw twice, offset by 1px
|
|
||||||
display->drawString(cursorX + 1, fontY, textChunk.c_str());
|
|
||||||
}
|
|
||||||
display->drawString(cursorX, fontY, textChunk.c_str());
|
|
||||||
#if defined(OLED_UA) || defined(OLED_RU)
|
|
||||||
cursorX += display->getStringWidth(textChunk.c_str(), textChunk.length(), true);
|
|
||||||
#else
|
|
||||||
cursorX += display->getStringWidth(textChunk.c_str());
|
|
||||||
#endif
|
|
||||||
i = nextControl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render the emote (if found)
|
|
||||||
if (matchedEmote && i == nextEmotePos) {
|
|
||||||
int iconY = y + (lineHeight - matchedEmote->height) / 2;
|
|
||||||
display->drawXbm(cursorX, iconY, matchedEmote->width, matchedEmote->height, matchedEmote->bitmap);
|
|
||||||
cursorX += matchedEmote->width + 1;
|
|
||||||
i += emojiLen;
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
// No more emotes — render the rest of the line
|
|
||||||
std::string remaining = line.substr(i);
|
|
||||||
if (inBold) {
|
|
||||||
display->drawString(cursorX + 1, fontY, remaining.c_str());
|
|
||||||
}
|
|
||||||
display->drawString(cursorX, fontY, remaining.c_str());
|
|
||||||
#if defined(OLED_UA) || defined(OLED_RU)
|
|
||||||
cursorX += display->getStringWidth(remaining.c_str(), remaining.length(), true);
|
|
||||||
#else
|
|
||||||
cursorX += display->getStringWidth(remaining.c_str());
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset scroll state when new messages arrive
|
// Reset scroll state when new messages arrive
|
||||||
@@ -377,32 +245,7 @@ static void drawRelayMark(OLEDDisplay *display, int x, int y, int size = 8)
|
|||||||
|
|
||||||
static inline int getRenderedLineWidth(OLEDDisplay *display, const std::string &line, const Emote *emotes, int emoteCount)
|
static inline int getRenderedLineWidth(OLEDDisplay *display, const std::string &line, const Emote *emotes, int emoteCount)
|
||||||
{
|
{
|
||||||
std::string normalized = normalizeEmoji(line);
|
return graphics::EmoteRenderer::analyzeLine(display, line, 0, emotes, emoteCount).width;
|
||||||
int totalWidth = 0;
|
|
||||||
|
|
||||||
size_t i = 0;
|
|
||||||
while (i < normalized.length()) {
|
|
||||||
bool matched = false;
|
|
||||||
for (int e = 0; e < emoteCount; ++e) {
|
|
||||||
size_t emojiLen = strlen(emotes[e].label);
|
|
||||||
if (normalized.compare(i, emojiLen, emotes[e].label) == 0) {
|
|
||||||
totalWidth += emotes[e].width + 1; // +1 spacing
|
|
||||||
i += emojiLen;
|
|
||||||
matched = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!matched) {
|
|
||||||
size_t charLen = utf8CharLen(static_cast<uint8_t>(normalized[i]));
|
|
||||||
#if defined(OLED_UA) || defined(OLED_RU)
|
|
||||||
totalWidth += display->getStringWidth(normalized.substr(i, charLen).c_str(), charLen, true);
|
|
||||||
#else
|
|
||||||
totalWidth += display->getStringWidth(normalized.substr(i, charLen).c_str());
|
|
||||||
#endif
|
|
||||||
i += charLen;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return totalWidth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MessageBlock {
|
struct MessageBlock {
|
||||||
@@ -417,13 +260,7 @@ static int getDrawnLinePixelBottom(int lineTopY, const std::string &line, bool i
|
|||||||
return lineTopY + (FONT_HEIGHT_SMALL - 1);
|
return lineTopY + (FONT_HEIGHT_SMALL - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int tallest = FONT_HEIGHT_SMALL;
|
const int tallest = graphics::EmoteRenderer::analyzeLine(nullptr, line, FONT_HEIGHT_SMALL, emotes, numEmotes).tallestHeight;
|
||||||
for (int e = 0; e < numEmotes; ++e) {
|
|
||||||
if (line.find(emotes[e].label) != std::string::npos) {
|
|
||||||
if (emotes[e].height > tallest)
|
|
||||||
tallest = emotes[e].height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const int lineHeight = std::max(FONT_HEIGHT_SMALL, tallest);
|
const int lineHeight = std::max(FONT_HEIGHT_SMALL, tallest);
|
||||||
const int iconTop = lineTopY + (lineHeight - tallest) / 2;
|
const int iconTop = lineTopY + (lineHeight - tallest) / 2;
|
||||||
@@ -536,30 +373,28 @@ void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
|
|||||||
const int rightTextWidth = SCREEN_WIDTH - LEFT_MARGIN - RIGHT_MARGIN - SCROLLBAR_WIDTH;
|
const int rightTextWidth = SCREEN_WIDTH - LEFT_MARGIN - RIGHT_MARGIN - SCROLLBAR_WIDTH;
|
||||||
|
|
||||||
// Title string depending on mode
|
// Title string depending on mode
|
||||||
static char titleBuf[32];
|
char titleStr[48];
|
||||||
const char *titleStr = "Messages";
|
snprintf(titleStr, sizeof(titleStr), "Messages");
|
||||||
switch (currentMode) {
|
switch (currentMode) {
|
||||||
case ThreadMode::ALL:
|
case ThreadMode::ALL:
|
||||||
titleStr = "Messages";
|
snprintf(titleStr, sizeof(titleStr), "Messages");
|
||||||
break;
|
break;
|
||||||
case ThreadMode::CHANNEL: {
|
case ThreadMode::CHANNEL: {
|
||||||
const char *cname = channels.getName(currentChannel);
|
const char *cname = channels.getName(currentChannel);
|
||||||
if (cname && cname[0]) {
|
if (cname && cname[0]) {
|
||||||
snprintf(titleBuf, sizeof(titleBuf), "#%s", cname);
|
snprintf(titleStr, sizeof(titleStr), "#%s", cname);
|
||||||
} else {
|
} else {
|
||||||
snprintf(titleBuf, sizeof(titleBuf), "Ch%d", currentChannel);
|
snprintf(titleStr, sizeof(titleStr), "Ch%d", currentChannel);
|
||||||
}
|
}
|
||||||
titleStr = titleBuf;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ThreadMode::DIRECT: {
|
case ThreadMode::DIRECT: {
|
||||||
meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(currentPeer);
|
meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(currentPeer);
|
||||||
if (node && node->has_user) {
|
if (node && node->has_user && node->user.short_name[0]) {
|
||||||
snprintf(titleBuf, sizeof(titleBuf), "@%s", node->user.short_name);
|
snprintf(titleStr, sizeof(titleStr), "@%s", node->user.short_name);
|
||||||
} else {
|
} else {
|
||||||
snprintf(titleBuf, sizeof(titleBuf), "@%08x", currentPeer);
|
snprintf(titleStr, sizeof(titleStr), "@%08x", currentPeer);
|
||||||
}
|
}
|
||||||
titleStr = titleBuf;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -666,44 +501,50 @@ void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
|
|||||||
meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(m.sender);
|
meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(m.sender);
|
||||||
meshtastic_NodeInfoLite *node_recipient = nodeDB->getMeshNode(m.dest);
|
meshtastic_NodeInfoLite *node_recipient = nodeDB->getMeshNode(m.dest);
|
||||||
|
|
||||||
char senderBuf[48] = "";
|
char senderName[64] = "";
|
||||||
if (node && node->has_user) {
|
if (node && node->has_user) {
|
||||||
// Use long name if present
|
if (node->user.long_name[0]) {
|
||||||
strncpy(senderBuf, node->user.long_name, sizeof(senderBuf) - 1);
|
strncpy(senderName, node->user.long_name, sizeof(senderName) - 1);
|
||||||
senderBuf[sizeof(senderBuf) - 1] = '\0';
|
} else if (node->user.short_name[0]) {
|
||||||
} else {
|
strncpy(senderName, node->user.short_name, sizeof(senderName) - 1);
|
||||||
// No long/short name → show NodeID in parentheses
|
}
|
||||||
snprintf(senderBuf, sizeof(senderBuf), "(%08x)", m.sender);
|
senderName[sizeof(senderName) - 1] = '\0';
|
||||||
|
}
|
||||||
|
if (!senderName[0]) {
|
||||||
|
snprintf(senderName, sizeof(senderName), "(%08x)", m.sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is *our own* message, override senderBuf to who the recipient was
|
// If this is *our own* message, override senderName to who the recipient was
|
||||||
bool mine = (m.sender == nodeDB->getNodeNum());
|
bool mine = (m.sender == nodeDB->getNodeNum());
|
||||||
if (mine && node_recipient && node_recipient->has_user) {
|
if (mine && node_recipient && node_recipient->has_user) {
|
||||||
strcpy(senderBuf, node_recipient->user.long_name);
|
if (node_recipient->user.long_name[0]) {
|
||||||
|
strncpy(senderName, node_recipient->user.long_name, sizeof(senderName) - 1);
|
||||||
|
senderName[sizeof(senderName) - 1] = '\0';
|
||||||
|
} else if (node_recipient->user.short_name[0]) {
|
||||||
|
strncpy(senderName, node_recipient->user.short_name, sizeof(senderName) - 1);
|
||||||
|
senderName[sizeof(senderName) - 1] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If recipient info is missing/empty, prefer a recipient identifier for outbound messages.
|
||||||
|
if (mine && (!node_recipient || !node_recipient->has_user ||
|
||||||
|
(!node_recipient->user.long_name[0] && !node_recipient->user.short_name[0]))) {
|
||||||
|
snprintf(senderName, sizeof(senderName), "(%08x)", m.dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shrink Sender name if needed
|
// Shrink Sender name if needed
|
||||||
int availWidth = (mine ? rightTextWidth : leftTextWidth) - display->getStringWidth(timeBuf) -
|
int availWidth = (mine ? rightTextWidth : leftTextWidth) - display->getStringWidth(timeBuf) -
|
||||||
display->getStringWidth(chanType) - display->getStringWidth(" @...");
|
display->getStringWidth(chanType) - graphics::UIRenderer::measureStringWithEmotes(display, " @...");
|
||||||
if (availWidth < 0)
|
if (availWidth < 0)
|
||||||
availWidth = 0;
|
availWidth = 0;
|
||||||
|
char truncatedSender[64];
|
||||||
size_t origLen = strlen(senderBuf);
|
graphics::UIRenderer::truncateStringWithEmotes(display, senderName, truncatedSender, sizeof(truncatedSender), availWidth);
|
||||||
while (senderBuf[0] && display->getStringWidth(senderBuf) > availWidth) {
|
|
||||||
senderBuf[strlen(senderBuf) - 1] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we actually truncated, append "..."
|
|
||||||
if (strlen(senderBuf) < origLen) {
|
|
||||||
strcat(senderBuf, "...");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Final header line
|
// Final header line
|
||||||
char headerStr[96];
|
char headerStr[128];
|
||||||
if (mine) {
|
if (mine) {
|
||||||
if (currentMode == ThreadMode::ALL) {
|
if (currentMode == ThreadMode::ALL) {
|
||||||
if (strcmp(chanType, "(DM)") == 0) {
|
if (strcmp(chanType, "(DM)") == 0) {
|
||||||
snprintf(headerStr, sizeof(headerStr), "%s to %s", timeBuf, senderBuf);
|
snprintf(headerStr, sizeof(headerStr), "%s to %s", timeBuf, truncatedSender);
|
||||||
} else {
|
} else {
|
||||||
snprintf(headerStr, sizeof(headerStr), "%s to %s", timeBuf, chanType);
|
snprintf(headerStr, sizeof(headerStr), "%s to %s", timeBuf, chanType);
|
||||||
}
|
}
|
||||||
@@ -711,11 +552,11 @@ void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
|
|||||||
snprintf(headerStr, sizeof(headerStr), "%s", timeBuf);
|
snprintf(headerStr, sizeof(headerStr), "%s", timeBuf);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
snprintf(headerStr, sizeof(headerStr), "%s @%s %s", timeBuf, senderBuf, chanType);
|
snprintf(headerStr, sizeof(headerStr), chanType[0] ? "%s @%s %s" : "%s @%s", timeBuf, truncatedSender, chanType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push header line
|
// Push header line
|
||||||
allLines.push_back(std::string(headerStr));
|
allLines.push_back(headerStr);
|
||||||
isMine.push_back(mine);
|
isMine.push_back(mine);
|
||||||
isHeader.push_back(true);
|
isHeader.push_back(true);
|
||||||
ackForLine.push_back(m.ackStatus);
|
ackForLine.push_back(m.ackStatus);
|
||||||
@@ -816,13 +657,8 @@ void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
|
|||||||
topY = visualTop - BUBBLE_PAD_TOP_HEADER;
|
topY = visualTop - BUBBLE_PAD_TOP_HEADER;
|
||||||
} else {
|
} else {
|
||||||
// Body start
|
// Body start
|
||||||
bool thisLineHasEmote = false;
|
const bool thisLineHasEmote =
|
||||||
for (int e = 0; e < numEmotes; ++e) {
|
graphics::EmoteRenderer::analyzeLine(nullptr, cachedLines[b.start].c_str(), 0, emotes, numEmotes).hasEmote;
|
||||||
if (cachedLines[b.start].find(emotes[e].label) != std::string::npos) {
|
|
||||||
thisLineHasEmote = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (thisLineHasEmote) {
|
if (thisLineHasEmote) {
|
||||||
constexpr int EMOTE_PADDING_ABOVE = 4;
|
constexpr int EMOTE_PADDING_ABOVE = 4;
|
||||||
visualTop -= EMOTE_PADDING_ABOVE;
|
visualTop -= EMOTE_PADDING_ABOVE;
|
||||||
@@ -851,7 +687,7 @@ void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
|
|||||||
for (size_t i = b.start; i <= b.end; ++i) {
|
for (size_t i = b.start; i <= b.end; ++i) {
|
||||||
int w = 0;
|
int w = 0;
|
||||||
if (isHeader[i]) {
|
if (isHeader[i]) {
|
||||||
w = display->getStringWidth(cachedLines[i].c_str());
|
w = graphics::UIRenderer::measureStringWithEmotes(display, cachedLines[i].c_str());
|
||||||
if (b.mine)
|
if (b.mine)
|
||||||
w += 12; // room for ACK/NACK/relay mark
|
w += 12; // room for ACK/NACK/relay mark
|
||||||
} else {
|
} else {
|
||||||
@@ -907,7 +743,7 @@ void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
|
|||||||
if (lineY > -cachedHeights[i] && lineY < scrollBottom) {
|
if (lineY > -cachedHeights[i] && lineY < scrollBottom) {
|
||||||
if (isHeader[i]) {
|
if (isHeader[i]) {
|
||||||
|
|
||||||
int w = display->getStringWidth(cachedLines[i].c_str());
|
int w = graphics::UIRenderer::measureStringWithEmotes(display, cachedLines[i].c_str());
|
||||||
int headerX;
|
int headerX;
|
||||||
if (isMine[i]) {
|
if (isMine[i]) {
|
||||||
// push header left to avoid overlap with scrollbar
|
// push header left to avoid overlap with scrollbar
|
||||||
@@ -917,7 +753,8 @@ void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
|
|||||||
} else {
|
} else {
|
||||||
headerX = x + textIndent;
|
headerX = x + textIndent;
|
||||||
}
|
}
|
||||||
display->drawString(headerX, lineY, cachedLines[i].c_str());
|
graphics::UIRenderer::drawStringWithEmotes(display, headerX, lineY, cachedLines[i].c_str(), FONT_HEIGHT_SMALL, 1,
|
||||||
|
false);
|
||||||
|
|
||||||
// Draw underline just under header text
|
// Draw underline just under header text
|
||||||
int underlineY = lineY + FONT_HEIGHT_SMALL;
|
int underlineY = lineY + FONT_HEIGHT_SMALL;
|
||||||
@@ -1005,11 +842,7 @@ std::vector<std::string> generateLines(OLEDDisplay *display, const char *headerS
|
|||||||
} else {
|
} else {
|
||||||
word += ch;
|
word += ch;
|
||||||
std::string test = line + word;
|
std::string test = line + word;
|
||||||
#if defined(OLED_UA) || defined(OLED_RU)
|
uint16_t strWidth = graphics::UIRenderer::measureStringWithEmotes(display, test.c_str());
|
||||||
uint16_t strWidth = display->getStringWidth(test.c_str(), test.length(), true);
|
|
||||||
#else
|
|
||||||
uint16_t strWidth = display->getStringWidth(test.c_str());
|
|
||||||
#endif
|
|
||||||
if (strWidth > textWidth) {
|
if (strWidth > textWidth) {
|
||||||
if (!line.empty())
|
if (!line.empty())
|
||||||
lines.push_back(line);
|
lines.push_back(line);
|
||||||
@@ -1038,31 +871,20 @@ std::vector<int> calculateLineHeights(const std::vector<std::string> &lines, con
|
|||||||
|
|
||||||
std::vector<int> rowHeights;
|
std::vector<int> rowHeights;
|
||||||
rowHeights.reserve(lines.size());
|
rowHeights.reserve(lines.size());
|
||||||
|
std::vector<graphics::EmoteRenderer::LineMetrics> lineMetrics;
|
||||||
|
lineMetrics.reserve(lines.size());
|
||||||
|
|
||||||
|
for (const auto &line : lines) {
|
||||||
|
lineMetrics.push_back(graphics::EmoteRenderer::analyzeLine(nullptr, line, FONT_HEIGHT_SMALL, emotes, numEmotes));
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t idx = 0; idx < lines.size(); ++idx) {
|
for (size_t idx = 0; idx < lines.size(); ++idx) {
|
||||||
const auto &line = lines[idx];
|
|
||||||
const int baseHeight = FONT_HEIGHT_SMALL;
|
const int baseHeight = FONT_HEIGHT_SMALL;
|
||||||
int lineHeight = baseHeight;
|
int lineHeight = baseHeight;
|
||||||
|
|
||||||
// Detect if THIS line or NEXT line contains an emote
|
const int tallestEmote = lineMetrics[idx].tallestHeight;
|
||||||
bool hasEmote = false;
|
const bool hasEmote = lineMetrics[idx].hasEmote;
|
||||||
int tallestEmote = baseHeight;
|
const bool nextHasEmote = (idx + 1 < lines.size()) && lineMetrics[idx + 1].hasEmote;
|
||||||
for (int i = 0; i < numEmotes; ++i) {
|
|
||||||
if (line.find(emotes[i].label) != std::string::npos) {
|
|
||||||
hasEmote = true;
|
|
||||||
tallestEmote = std::max(tallestEmote, emotes[i].height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool nextHasEmote = false;
|
|
||||||
if (idx + 1 < lines.size()) {
|
|
||||||
for (int i = 0; i < numEmotes; ++i) {
|
|
||||||
if (lines[idx + 1].find(emotes[i].label) != std::string::npos) {
|
|
||||||
nextHasEmote = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isHeaderVec[idx]) {
|
if (isHeaderVec[idx]) {
|
||||||
// Header line spacing
|
// Header line spacing
|
||||||
@@ -1112,22 +934,22 @@ void handleNewMessage(OLEDDisplay *display, const StoredMessage &sm, const mesht
|
|||||||
|
|
||||||
// Banner logic
|
// Banner logic
|
||||||
const meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(packet.from);
|
const meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(packet.from);
|
||||||
char longName[48] = "?";
|
char longName[64] = "?";
|
||||||
if (node && node->user.long_name) {
|
if (node && node->has_user) {
|
||||||
strncpy(longName, node->user.long_name, sizeof(longName) - 1);
|
if (node->user.long_name[0]) {
|
||||||
longName[sizeof(longName) - 1] = '\0';
|
strncpy(longName, node->user.long_name, sizeof(longName) - 1);
|
||||||
|
longName[sizeof(longName) - 1] = '\0';
|
||||||
|
} else if (node->user.short_name[0]) {
|
||||||
|
strncpy(longName, node->user.short_name, sizeof(longName) - 1);
|
||||||
|
longName[sizeof(longName) - 1] = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
int availWidth = display->getWidth() - ((currentResolution == ScreenResolution::High) ? 40 : 20);
|
int availWidth = display->getWidth() - ((currentResolution == ScreenResolution::High) ? 40 : 20);
|
||||||
if (availWidth < 0)
|
if (availWidth < 0)
|
||||||
availWidth = 0;
|
availWidth = 0;
|
||||||
|
char truncatedLongName[64];
|
||||||
size_t origLen = strlen(longName);
|
graphics::UIRenderer::truncateStringWithEmotes(display, longName, truncatedLongName, sizeof(truncatedLongName),
|
||||||
while (longName[0] && display->getStringWidth(longName) > availWidth) {
|
availWidth);
|
||||||
longName[strlen(longName) - 1] = '\0';
|
|
||||||
}
|
|
||||||
if (strlen(longName) < origLen) {
|
|
||||||
strcat(longName, "...");
|
|
||||||
}
|
|
||||||
const char *msgRaw = reinterpret_cast<const char *>(packet.decoded.payload.bytes);
|
const char *msgRaw = reinterpret_cast<const char *>(packet.decoded.payload.bytes);
|
||||||
|
|
||||||
char banner[256];
|
char banner[256];
|
||||||
@@ -1145,8 +967,8 @@ void handleNewMessage(OLEDDisplay *display, const StoredMessage &sm, const mesht
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isAlert) {
|
if (isAlert) {
|
||||||
if (longName && longName[0])
|
if (truncatedLongName[0])
|
||||||
snprintf(banner, sizeof(banner), "Alert Received from\n%s", longName);
|
snprintf(banner, sizeof(banner), "Alert Received from\n%s", truncatedLongName);
|
||||||
else
|
else
|
||||||
strcpy(banner, "Alert Received");
|
strcpy(banner, "Alert Received");
|
||||||
} else {
|
} else {
|
||||||
@@ -1154,11 +976,11 @@ void handleNewMessage(OLEDDisplay *display, const StoredMessage &sm, const mesht
|
|||||||
if (isChannelMuted)
|
if (isChannelMuted)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (longName && longName[0]) {
|
if (truncatedLongName[0]) {
|
||||||
if (currentResolution == ScreenResolution::UltraLow) {
|
if (currentResolution == ScreenResolution::UltraLow) {
|
||||||
strcpy(banner, "New Message");
|
strcpy(banner, "New Message");
|
||||||
} else {
|
} else {
|
||||||
snprintf(banner, sizeof(banner), "New Message from\n%s", longName);
|
snprintf(banner, sizeof(banner), "New Message from\n%s", truncatedLongName);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
strcpy(banner, "New Message");
|
strcpy(banner, "New Message");
|
||||||
@@ -1221,4 +1043,4 @@ void setThreadFor(const StoredMessage &sm, const meshtastic_MeshPacket &packet)
|
|||||||
|
|
||||||
} // namespace MessageRenderer
|
} // namespace MessageRenderer
|
||||||
} // namespace graphics
|
} // namespace graphics
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -79,13 +79,15 @@ void scrollDown()
|
|||||||
// Utility Functions
|
// Utility Functions
|
||||||
// =============================
|
// =============================
|
||||||
|
|
||||||
const char *getSafeNodeName(OLEDDisplay *display, meshtastic_NodeInfoLite *node, int columnWidth)
|
std::string getSafeNodeName(OLEDDisplay *display, meshtastic_NodeInfoLite *node, int columnWidth)
|
||||||
{
|
{
|
||||||
static char nodeName[25]; // single static buffer we return
|
(void)display;
|
||||||
nodeName[0] = '\0';
|
(void)columnWidth;
|
||||||
|
|
||||||
auto writeFallbackId = [&] {
|
auto fallbackId = [&] {
|
||||||
std::snprintf(nodeName, sizeof(nodeName), "(%04X)", static_cast<uint16_t>(node ? (node->num & 0xFFFF) : 0));
|
char id[12];
|
||||||
|
std::snprintf(id, sizeof(id), "(%04X)", static_cast<uint16_t>(node ? (node->num & 0xFFFF) : 0));
|
||||||
|
return std::string(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 1) Choose target candidate (long vs short) only if present
|
// 1) Choose target candidate (long vs short) only if present
|
||||||
@@ -94,42 +96,10 @@ const char *getSafeNodeName(OLEDDisplay *display, meshtastic_NodeInfoLite *node,
|
|||||||
raw = config.display.use_long_node_name ? node->user.long_name : node->user.short_name;
|
raw = config.display.use_long_node_name ? node->user.long_name : node->user.short_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2) Sanitize (empty if raw is null/empty)
|
// 2) Preserve UTF-8 names so emotes can be detected and rendered.
|
||||||
std::string s = (raw && *raw) ? sanitizeString(raw) : std::string{};
|
std::string nodeName = (raw && *raw) ? std::string(raw) : std::string{};
|
||||||
|
if (nodeName.empty()) {
|
||||||
// 3) Fallback if sanitize yields empty; otherwise copy safely (truncate if needed)
|
nodeName = fallbackId();
|
||||||
if (s.empty() || s == "¿" || s.find_first_not_of("¿") == std::string::npos) {
|
|
||||||
writeFallbackId();
|
|
||||||
} else {
|
|
||||||
// %.*s ensures null-termination and safe truncation to buffer size - 1
|
|
||||||
std::snprintf(nodeName, sizeof(nodeName), "%.*s", static_cast<int>(sizeof(nodeName) - 1), s.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4) Width-based truncation + ellipsis (long-name mode only)
|
|
||||||
if (config.display.use_long_node_name && display) {
|
|
||||||
int availWidth = columnWidth - ((currentResolution == ScreenResolution::High) ? 65 : 38);
|
|
||||||
if (availWidth < 0)
|
|
||||||
availWidth = 0;
|
|
||||||
|
|
||||||
const size_t beforeLen = std::strlen(nodeName);
|
|
||||||
|
|
||||||
// Trim from the end until it fits or is empty
|
|
||||||
size_t len = beforeLen;
|
|
||||||
while (len && display->getStringWidth(nodeName) > availWidth) {
|
|
||||||
nodeName[--len] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
// If truncated, append "..." (respect buffer size)
|
|
||||||
if (len < beforeLen) {
|
|
||||||
// Make sure there's room for "..." and '\0'
|
|
||||||
const size_t capForText = sizeof(nodeName) - 1; // leaving space for '\0'
|
|
||||||
const size_t needed = 3; // "..."
|
|
||||||
if (len > capForText - needed) {
|
|
||||||
len = capForText - needed;
|
|
||||||
nodeName[len] = '\0';
|
|
||||||
}
|
|
||||||
std::strcat(nodeName, "...");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodeName;
|
return nodeName;
|
||||||
@@ -163,6 +133,15 @@ const char *getCurrentModeTitle_Location(int screenWidth)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int getNodeNameMaxWidth(int columnWidth, int baseWidth)
|
||||||
|
{
|
||||||
|
if (!config.display.use_long_node_name)
|
||||||
|
return baseWidth;
|
||||||
|
|
||||||
|
const int legacyLongNameWidth = columnWidth - ((currentResolution == ScreenResolution::High) ? 65 : 38);
|
||||||
|
return std::max(0, std::min(baseWidth, legacyLongNameWidth));
|
||||||
|
}
|
||||||
|
|
||||||
// Use dynamic timing based on mode
|
// Use dynamic timing based on mode
|
||||||
unsigned long getModeCycleIntervalMs()
|
unsigned long getModeCycleIntervalMs()
|
||||||
{
|
{
|
||||||
@@ -205,10 +184,13 @@ void drawScrollbar(OLEDDisplay *display, int visibleNodeRows, int totalEntries,
|
|||||||
void drawEntryLastHeard(OLEDDisplay *display, meshtastic_NodeInfoLite *node, int16_t x, int16_t y, int columnWidth)
|
void drawEntryLastHeard(OLEDDisplay *display, meshtastic_NodeInfoLite *node, int16_t x, int16_t y, int columnWidth)
|
||||||
{
|
{
|
||||||
bool isLeftCol = (x < SCREEN_WIDTH / 2);
|
bool isLeftCol = (x < SCREEN_WIDTH / 2);
|
||||||
int nameMaxWidth = columnWidth - 25;
|
int nameMaxWidth = getNodeNameMaxWidth(columnWidth, columnWidth - 25);
|
||||||
int timeOffset = (currentResolution == ScreenResolution::High) ? (isLeftCol ? 7 : 10) : (isLeftCol ? 3 : 7);
|
int timeOffset = (currentResolution == ScreenResolution::High) ? (isLeftCol ? 7 : 10) : (isLeftCol ? 3 : 7);
|
||||||
|
|
||||||
const char *nodeName = getSafeNodeName(display, node, columnWidth);
|
const int nameX = x + ((currentResolution == ScreenResolution::High) ? 6 : 3);
|
||||||
|
char nodeName[96];
|
||||||
|
UIRenderer::truncateStringWithEmotes(display, getSafeNodeName(display, node, columnWidth).c_str(), nodeName, sizeof(nodeName),
|
||||||
|
nameMaxWidth);
|
||||||
bool isMuted = (node->bitfield & NODEINFO_BITFIELD_IS_MUTED_MASK) != 0;
|
bool isMuted = (node->bitfield & NODEINFO_BITFIELD_IS_MUTED_MASK) != 0;
|
||||||
|
|
||||||
char timeStr[10];
|
char timeStr[10];
|
||||||
@@ -228,7 +210,7 @@ void drawEntryLastHeard(OLEDDisplay *display, meshtastic_NodeInfoLite *node, int
|
|||||||
|
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
display->setFont(FONT_SMALL);
|
display->setFont(FONT_SMALL);
|
||||||
display->drawString(x + ((currentResolution == ScreenResolution::High) ? 6 : 3), y, nodeName);
|
UIRenderer::drawStringWithEmotes(display, nameX, y, nodeName, FONT_HEIGHT_SMALL, 1, false);
|
||||||
if (node->is_favorite) {
|
if (node->is_favorite) {
|
||||||
if (currentResolution == ScreenResolution::High) {
|
if (currentResolution == ScreenResolution::High) {
|
||||||
drawScaledXBitmap16x16(x, y + 6, smallbulletpoint_width, smallbulletpoint_height, smallbulletpoint, display);
|
drawScaledXBitmap16x16(x, y + 6, smallbulletpoint_width, smallbulletpoint_height, smallbulletpoint, display);
|
||||||
@@ -255,19 +237,22 @@ void drawEntryHopSignal(OLEDDisplay *display, meshtastic_NodeInfoLite *node, int
|
|||||||
{
|
{
|
||||||
bool isLeftCol = (x < SCREEN_WIDTH / 2);
|
bool isLeftCol = (x < SCREEN_WIDTH / 2);
|
||||||
|
|
||||||
int nameMaxWidth = columnWidth - 25;
|
int nameMaxWidth = getNodeNameMaxWidth(columnWidth, columnWidth - 25);
|
||||||
int barsOffset = (currentResolution == ScreenResolution::High) ? (isLeftCol ? 20 : 24) : (isLeftCol ? 15 : 19);
|
int barsOffset = (currentResolution == ScreenResolution::High) ? (isLeftCol ? 20 : 24) : (isLeftCol ? 15 : 19);
|
||||||
int hopOffset = (currentResolution == ScreenResolution::High) ? (isLeftCol ? 21 : 29) : (isLeftCol ? 13 : 17);
|
int hopOffset = (currentResolution == ScreenResolution::High) ? (isLeftCol ? 21 : 29) : (isLeftCol ? 13 : 17);
|
||||||
|
|
||||||
int barsXOffset = columnWidth - barsOffset;
|
int barsXOffset = columnWidth - barsOffset;
|
||||||
|
|
||||||
const char *nodeName = getSafeNodeName(display, node, columnWidth);
|
const int nameX = x + ((currentResolution == ScreenResolution::High) ? 6 : 3);
|
||||||
|
char nodeName[96];
|
||||||
|
UIRenderer::truncateStringWithEmotes(display, getSafeNodeName(display, node, columnWidth).c_str(), nodeName, sizeof(nodeName),
|
||||||
|
nameMaxWidth);
|
||||||
bool isMuted = (node->bitfield & NODEINFO_BITFIELD_IS_MUTED_MASK) != 0;
|
bool isMuted = (node->bitfield & NODEINFO_BITFIELD_IS_MUTED_MASK) != 0;
|
||||||
|
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
display->setFont(FONT_SMALL);
|
display->setFont(FONT_SMALL);
|
||||||
|
|
||||||
display->drawStringMaxWidth(x + ((currentResolution == ScreenResolution::High) ? 6 : 3), y, nameMaxWidth, nodeName);
|
UIRenderer::drawStringWithEmotes(display, nameX, y, nodeName, FONT_HEIGHT_SMALL, 1, false);
|
||||||
if (node->is_favorite) {
|
if (node->is_favorite) {
|
||||||
if (currentResolution == ScreenResolution::High) {
|
if (currentResolution == ScreenResolution::High) {
|
||||||
drawScaledXBitmap16x16(x, y + 6, smallbulletpoint_width, smallbulletpoint_height, smallbulletpoint, display);
|
drawScaledXBitmap16x16(x, y + 6, smallbulletpoint_width, smallbulletpoint_height, smallbulletpoint, display);
|
||||||
@@ -312,9 +297,13 @@ void drawNodeDistance(OLEDDisplay *display, meshtastic_NodeInfoLite *node, int16
|
|||||||
{
|
{
|
||||||
bool isLeftCol = (x < SCREEN_WIDTH / 2);
|
bool isLeftCol = (x < SCREEN_WIDTH / 2);
|
||||||
int nameMaxWidth =
|
int nameMaxWidth =
|
||||||
columnWidth - ((currentResolution == ScreenResolution::High) ? (isLeftCol ? 25 : 28) : (isLeftCol ? 20 : 22));
|
getNodeNameMaxWidth(columnWidth, columnWidth - ((currentResolution == ScreenResolution::High) ? (isLeftCol ? 25 : 28)
|
||||||
|
: (isLeftCol ? 20 : 22)));
|
||||||
|
|
||||||
const char *nodeName = getSafeNodeName(display, node, columnWidth);
|
const int nameX = x + ((currentResolution == ScreenResolution::High) ? 6 : 3);
|
||||||
|
char nodeName[96];
|
||||||
|
UIRenderer::truncateStringWithEmotes(display, getSafeNodeName(display, node, columnWidth).c_str(), nodeName, sizeof(nodeName),
|
||||||
|
nameMaxWidth);
|
||||||
bool isMuted = (node->bitfield & NODEINFO_BITFIELD_IS_MUTED_MASK) != 0;
|
bool isMuted = (node->bitfield & NODEINFO_BITFIELD_IS_MUTED_MASK) != 0;
|
||||||
char distStr[10] = "";
|
char distStr[10] = "";
|
||||||
|
|
||||||
@@ -368,7 +357,7 @@ void drawNodeDistance(OLEDDisplay *display, meshtastic_NodeInfoLite *node, int16
|
|||||||
|
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
display->setFont(FONT_SMALL);
|
display->setFont(FONT_SMALL);
|
||||||
display->drawStringMaxWidth(x + ((currentResolution == ScreenResolution::High) ? 6 : 3), y, nameMaxWidth, nodeName);
|
UIRenderer::drawStringWithEmotes(display, nameX, y, nodeName, FONT_HEIGHT_SMALL, 1, false);
|
||||||
if (node->is_favorite) {
|
if (node->is_favorite) {
|
||||||
if (currentResolution == ScreenResolution::High) {
|
if (currentResolution == ScreenResolution::High) {
|
||||||
drawScaledXBitmap16x16(x, y + 6, smallbulletpoint_width, smallbulletpoint_height, smallbulletpoint, display);
|
drawScaledXBitmap16x16(x, y + 6, smallbulletpoint_width, smallbulletpoint_height, smallbulletpoint, display);
|
||||||
@@ -414,14 +403,18 @@ void drawEntryCompass(OLEDDisplay *display, meshtastic_NodeInfoLite *node, int16
|
|||||||
|
|
||||||
// Adjust max text width depending on column and screen width
|
// Adjust max text width depending on column and screen width
|
||||||
int nameMaxWidth =
|
int nameMaxWidth =
|
||||||
columnWidth - ((currentResolution == ScreenResolution::High) ? (isLeftCol ? 25 : 28) : (isLeftCol ? 20 : 22));
|
getNodeNameMaxWidth(columnWidth, columnWidth - ((currentResolution == ScreenResolution::High) ? (isLeftCol ? 25 : 28)
|
||||||
|
: (isLeftCol ? 20 : 22)));
|
||||||
|
|
||||||
const char *nodeName = getSafeNodeName(display, node, columnWidth);
|
const int nameX = x + ((currentResolution == ScreenResolution::High) ? 6 : 3);
|
||||||
|
char nodeName[96];
|
||||||
|
UIRenderer::truncateStringWithEmotes(display, getSafeNodeName(display, node, columnWidth).c_str(), nodeName, sizeof(nodeName),
|
||||||
|
nameMaxWidth);
|
||||||
bool isMuted = (node->bitfield & NODEINFO_BITFIELD_IS_MUTED_MASK) != 0;
|
bool isMuted = (node->bitfield & NODEINFO_BITFIELD_IS_MUTED_MASK) != 0;
|
||||||
|
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
display->setFont(FONT_SMALL);
|
display->setFont(FONT_SMALL);
|
||||||
display->drawStringMaxWidth(x + ((currentResolution == ScreenResolution::High) ? 6 : 3), y, nameMaxWidth, nodeName);
|
UIRenderer::drawStringWithEmotes(display, nameX, y, nodeName, FONT_HEIGHT_SMALL, 1, false);
|
||||||
if (node->is_favorite) {
|
if (node->is_favorite) {
|
||||||
if (currentResolution == ScreenResolution::High) {
|
if (currentResolution == ScreenResolution::High) {
|
||||||
drawScaledXBitmap16x16(x, y + 6, smallbulletpoint_width, smallbulletpoint_height, smallbulletpoint, display);
|
drawScaledXBitmap16x16(x, y + 6, smallbulletpoint_width, smallbulletpoint_height, smallbulletpoint, display);
|
||||||
@@ -828,4 +821,4 @@ void drawColumns(OLEDDisplay *display, int16_t x, int16_t y, const char **fields
|
|||||||
|
|
||||||
} // namespace NodeListRenderer
|
} // namespace NodeListRenderer
|
||||||
} // namespace graphics
|
} // namespace graphics
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "mesh/generated/meshtastic/mesh.pb.h"
|
#include "mesh/generated/meshtastic/mesh.pb.h"
|
||||||
#include <OLEDDisplay.h>
|
#include <OLEDDisplay.h>
|
||||||
#include <OLEDDisplayUi.h>
|
#include <OLEDDisplayUi.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace graphics
|
namespace graphics
|
||||||
{
|
{
|
||||||
@@ -56,7 +57,7 @@ void drawNodeListWithCompasses(OLEDDisplay *display, OLEDDisplayUiState *state,
|
|||||||
// Utility functions
|
// Utility functions
|
||||||
const char *getCurrentModeTitle_Nodes(int screenWidth);
|
const char *getCurrentModeTitle_Nodes(int screenWidth);
|
||||||
const char *getCurrentModeTitle_Location(int screenWidth);
|
const char *getCurrentModeTitle_Location(int screenWidth);
|
||||||
const char *getSafeNodeName(meshtastic_NodeInfoLite *node, int columnWidth);
|
std::string getSafeNodeName(OLEDDisplay *display, meshtastic_NodeInfoLite *node, int columnWidth);
|
||||||
void drawColumns(OLEDDisplay *display, int16_t x, int16_t y, const char **fields);
|
void drawColumns(OLEDDisplay *display, int16_t x, int16_t y, const char **fields);
|
||||||
|
|
||||||
// Scrolling controls
|
// Scrolling controls
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "DisplayFormatters.h"
|
#include "DisplayFormatters.h"
|
||||||
#include "NodeDB.h"
|
#include "NodeDB.h"
|
||||||
#include "NotificationRenderer.h"
|
#include "NotificationRenderer.h"
|
||||||
|
#include "UIRenderer.h"
|
||||||
#include "graphics/ScreenFonts.h"
|
#include "graphics/ScreenFonts.h"
|
||||||
#include "graphics/SharedUIDisplay.h"
|
#include "graphics/SharedUIDisplay.h"
|
||||||
#include "graphics/images.h"
|
#include "graphics/images.h"
|
||||||
@@ -299,7 +300,7 @@ void NotificationRenderer::drawNodePicker(OLEDDisplay *display, OLEDDisplayUiSta
|
|||||||
for (int i = 0; i < lineCount; i++) {
|
for (int i = 0; i < lineCount; i++) {
|
||||||
linePointers[i] = lineStarts[i];
|
linePointers[i] = lineStarts[i];
|
||||||
}
|
}
|
||||||
char scratchLineBuffer[visibleTotalLines - lineCount][40];
|
char scratchLineBuffer[visibleTotalLines - lineCount][64];
|
||||||
|
|
||||||
uint8_t firstOptionToShow = 0;
|
uint8_t firstOptionToShow = 0;
|
||||||
if (curSelected > 1 && alertBannerOptions > visibleTotalLines - lineCount) {
|
if (curSelected > 1 && alertBannerOptions > visibleTotalLines - lineCount) {
|
||||||
@@ -312,28 +313,47 @@ void NotificationRenderer::drawNodePicker(OLEDDisplay *display, OLEDDisplayUiSta
|
|||||||
}
|
}
|
||||||
int scratchLineNum = 0;
|
int scratchLineNum = 0;
|
||||||
for (int i = firstOptionToShow; i < alertBannerOptions && linesShown < visibleTotalLines; i++, linesShown++) {
|
for (int i = firstOptionToShow; i < alertBannerOptions && linesShown < visibleTotalLines; i++, linesShown++) {
|
||||||
char temp_name[16] = {0};
|
char tempName[48] = {0};
|
||||||
if (nodeDB->getMeshNodeByIndex(i + 1)->has_user) {
|
meshtastic_NodeInfoLite *node = nodeDB->getMeshNodeByIndex(i + 1);
|
||||||
std::string sanitized = sanitizeString(nodeDB->getMeshNodeByIndex(i + 1)->user.long_name);
|
if (node && node->has_user) {
|
||||||
strncpy(temp_name, sanitized.c_str(), sizeof(temp_name) - 1);
|
const char *rawName = nullptr;
|
||||||
|
if (node->user.long_name[0]) {
|
||||||
|
rawName = node->user.long_name;
|
||||||
|
} else if (node->user.short_name[0]) {
|
||||||
|
rawName = node->user.short_name;
|
||||||
|
}
|
||||||
|
if (rawName) {
|
||||||
|
const int arrowWidth = (currentResolution == ScreenResolution::High)
|
||||||
|
? UIRenderer::measureStringWithEmotes(display, "> <")
|
||||||
|
: UIRenderer::measureStringWithEmotes(display, "><");
|
||||||
|
const int maxTextWidth = std::max(0, display->getWidth() - 28 - arrowWidth);
|
||||||
|
UIRenderer::truncateStringWithEmotes(display, rawName, tempName, sizeof(tempName), maxTextWidth);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
snprintf(temp_name, sizeof(temp_name), "(%04X)", (uint16_t)(nodeDB->getMeshNodeByIndex(i + 1)->num & 0xFFFF));
|
snprintf(tempName, sizeof(tempName), "(%04X)", (uint16_t)(node ? (node->num & 0xFFFF) : 0));
|
||||||
|
}
|
||||||
|
if (!tempName[0]) {
|
||||||
|
snprintf(tempName, sizeof(tempName), "(%04X)", (uint16_t)(node ? (node->num & 0xFFFF) : 0));
|
||||||
}
|
}
|
||||||
if (i == curSelected) {
|
if (i == curSelected) {
|
||||||
selectedNodenum = nodeDB->getMeshNodeByIndex(i + 1)->num;
|
selectedNodenum = node ? node->num : 0;
|
||||||
if (currentResolution == ScreenResolution::High) {
|
if (currentResolution == ScreenResolution::High) {
|
||||||
strncpy(scratchLineBuffer[scratchLineNum], "> ", 3);
|
strncpy(scratchLineBuffer[scratchLineNum], "> ", 3);
|
||||||
strncpy(scratchLineBuffer[scratchLineNum] + 2, temp_name, 36);
|
strncpy(scratchLineBuffer[scratchLineNum] + 2, tempName, sizeof(scratchLineBuffer[scratchLineNum]) - 3);
|
||||||
strncpy(scratchLineBuffer[scratchLineNum] + strlen(temp_name) + 2, " <", 3);
|
scratchLineBuffer[scratchLineNum][sizeof(scratchLineBuffer[scratchLineNum]) - 1] = '\0';
|
||||||
|
const size_t used = strnlen(scratchLineBuffer[scratchLineNum], sizeof(scratchLineBuffer[scratchLineNum]) - 1);
|
||||||
|
strncpy(scratchLineBuffer[scratchLineNum] + used, " <", sizeof(scratchLineBuffer[scratchLineNum]) - used - 1);
|
||||||
} else {
|
} else {
|
||||||
strncpy(scratchLineBuffer[scratchLineNum], ">", 2);
|
strncpy(scratchLineBuffer[scratchLineNum], ">", 2);
|
||||||
strncpy(scratchLineBuffer[scratchLineNum] + 1, temp_name, 37);
|
strncpy(scratchLineBuffer[scratchLineNum] + 1, tempName, sizeof(scratchLineBuffer[scratchLineNum]) - 2);
|
||||||
strncpy(scratchLineBuffer[scratchLineNum] + strlen(temp_name) + 1, "<", 2);
|
scratchLineBuffer[scratchLineNum][sizeof(scratchLineBuffer[scratchLineNum]) - 1] = '\0';
|
||||||
|
const size_t used = strnlen(scratchLineBuffer[scratchLineNum], sizeof(scratchLineBuffer[scratchLineNum]) - 1);
|
||||||
|
strncpy(scratchLineBuffer[scratchLineNum] + used, "<", sizeof(scratchLineBuffer[scratchLineNum]) - used - 1);
|
||||||
}
|
}
|
||||||
scratchLineBuffer[scratchLineNum][39] = '\0';
|
scratchLineBuffer[scratchLineNum][sizeof(scratchLineBuffer[scratchLineNum]) - 1] = '\0';
|
||||||
} else {
|
} else {
|
||||||
strncpy(scratchLineBuffer[scratchLineNum], temp_name, 39);
|
strncpy(scratchLineBuffer[scratchLineNum], tempName, sizeof(scratchLineBuffer[scratchLineNum]) - 1);
|
||||||
scratchLineBuffer[scratchLineNum][39] = '\0';
|
scratchLineBuffer[scratchLineNum][sizeof(scratchLineBuffer[scratchLineNum]) - 1] = '\0';
|
||||||
}
|
}
|
||||||
linePointers[linesShown] = scratchLineBuffer[scratchLineNum++];
|
linePointers[linesShown] = scratchLineBuffer[scratchLineNum++];
|
||||||
}
|
}
|
||||||
@@ -501,7 +521,13 @@ void NotificationRenderer::drawNotificationBox(OLEDDisplay *display, OLEDDisplay
|
|||||||
else // if the newline wasn't found, then pull string length from strlen
|
else // if the newline wasn't found, then pull string length from strlen
|
||||||
lineLengths[lineCount] = strlen(lines[lineCount]);
|
lineLengths[lineCount] = strlen(lines[lineCount]);
|
||||||
|
|
||||||
lineWidths[lineCount] = display->getStringWidth(lines[lineCount], lineLengths[lineCount], true);
|
if (current_notification_type == notificationTypeEnum::node_picker) {
|
||||||
|
char measureBuffer[64] = {0};
|
||||||
|
strncpy(measureBuffer, lines[lineCount], std::min<size_t>(lineLengths[lineCount], sizeof(measureBuffer) - 1));
|
||||||
|
lineWidths[lineCount] = UIRenderer::measureStringWithEmotes(display, measureBuffer);
|
||||||
|
} else {
|
||||||
|
lineWidths[lineCount] = display->getStringWidth(lines[lineCount], lineLengths[lineCount], true);
|
||||||
|
}
|
||||||
|
|
||||||
// Consider extra width for signal bars on lines that contain "Signal:"
|
// Consider extra width for signal bars on lines that contain "Signal:"
|
||||||
uint16_t potentialWidth = lineWidths[lineCount];
|
uint16_t potentialWidth = lineWidths[lineCount];
|
||||||
@@ -607,7 +633,11 @@ void NotificationRenderer::drawNotificationBox(OLEDDisplay *display, OLEDDisplay
|
|||||||
display->fillRect(boxLeft, boxTop + 1, boxWidth, effectiveLineHeight - background_yOffset);
|
display->fillRect(boxLeft, boxTop + 1, boxWidth, effectiveLineHeight - background_yOffset);
|
||||||
display->setColor(BLACK);
|
display->setColor(BLACK);
|
||||||
int yOffset = 3;
|
int yOffset = 3;
|
||||||
display->drawString(textX, lineY - yOffset, lineBuffer);
|
if (current_notification_type == notificationTypeEnum::node_picker) {
|
||||||
|
UIRenderer::drawStringWithEmotes(display, textX, lineY - yOffset, lineBuffer, FONT_HEIGHT_SMALL, 1, false);
|
||||||
|
} else {
|
||||||
|
display->drawString(textX, lineY - yOffset, lineBuffer);
|
||||||
|
}
|
||||||
display->setColor(WHITE);
|
display->setColor(WHITE);
|
||||||
lineY += (effectiveLineHeight - 2 - background_yOffset);
|
lineY += (effectiveLineHeight - 2 - background_yOffset);
|
||||||
} else {
|
} else {
|
||||||
@@ -626,7 +656,11 @@ void NotificationRenderer::drawNotificationBox(OLEDDisplay *display, OLEDDisplay
|
|||||||
int totalWidth = textWidth + barsWidth;
|
int totalWidth = textWidth + barsWidth;
|
||||||
int groupStartX = boxLeft + (boxWidth - totalWidth) / 2;
|
int groupStartX = boxLeft + (boxWidth - totalWidth) / 2;
|
||||||
|
|
||||||
display->drawString(groupStartX, lineY, lineBuffer);
|
if (current_notification_type == notificationTypeEnum::node_picker) {
|
||||||
|
UIRenderer::drawStringWithEmotes(display, groupStartX, lineY, lineBuffer, FONT_HEIGHT_SMALL, 1, false);
|
||||||
|
} else {
|
||||||
|
display->drawString(groupStartX, lineY, lineBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
int baseX = groupStartX + textWidth + gap;
|
int baseX = groupStartX + textWidth + gap;
|
||||||
int baseY = lineY + effectiveLineHeight - 1;
|
int baseY = lineY + effectiveLineHeight - 1;
|
||||||
@@ -642,7 +676,11 @@ void NotificationRenderer::drawNotificationBox(OLEDDisplay *display, OLEDDisplay
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
display->drawString(textX, lineY, lineBuffer);
|
if (current_notification_type == notificationTypeEnum::node_picker) {
|
||||||
|
UIRenderer::drawStringWithEmotes(display, textX, lineY, lineBuffer, FONT_HEIGHT_SMALL, 1, false);
|
||||||
|
} else {
|
||||||
|
display->drawString(textX, lineY, lineBuffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lineY += (effectiveLineHeight);
|
lineY += (effectiveLineHeight);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "UIRenderer.h"
|
#include "UIRenderer.h"
|
||||||
#include "airtime.h"
|
#include "airtime.h"
|
||||||
#include "gps/GeoCoord.h"
|
#include "gps/GeoCoord.h"
|
||||||
|
#include "graphics/EmoteRenderer.h"
|
||||||
#include "graphics/SharedUIDisplay.h"
|
#include "graphics/SharedUIDisplay.h"
|
||||||
#include "graphics/TimeFormatters.h"
|
#include "graphics/TimeFormatters.h"
|
||||||
#include "graphics/images.h"
|
#include "graphics/images.h"
|
||||||
@@ -313,8 +314,8 @@ void UIRenderer::drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, i
|
|||||||
#endif
|
#endif
|
||||||
currentFavoriteNodeNum = node->num;
|
currentFavoriteNodeNum = node->num;
|
||||||
// === Create the shortName and title string ===
|
// === Create the shortName and title string ===
|
||||||
const char *shortName = (node->has_user && haveGlyphs(node->user.short_name)) ? node->user.short_name : "Node";
|
const char *shortName = (node->has_user && node->user.short_name[0]) ? node->user.short_name : "Node";
|
||||||
char titlestr[32] = {0};
|
char titlestr[40];
|
||||||
snprintf(titlestr, sizeof(titlestr), "*%s*", shortName);
|
snprintf(titlestr, sizeof(titlestr), "*%s*", shortName);
|
||||||
|
|
||||||
// === Draw battery/time/mail header (common across screens) ===
|
// === Draw battery/time/mail header (common across screens) ===
|
||||||
@@ -328,7 +329,6 @@ void UIRenderer::drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, i
|
|||||||
|
|
||||||
// List of available macro Y positions in order, from top to bottom.
|
// List of available macro Y positions in order, from top to bottom.
|
||||||
int line = 1; // which slot to use next
|
int line = 1; // which slot to use next
|
||||||
std::string usernameStr;
|
|
||||||
// === 1. Long Name (always try to show first) ===
|
// === 1. Long Name (always try to show first) ===
|
||||||
const char *username;
|
const char *username;
|
||||||
if (currentResolution == ScreenResolution::UltraLow) {
|
if (currentResolution == ScreenResolution::UltraLow) {
|
||||||
@@ -338,9 +338,8 @@ void UIRenderer::drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, i
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (username) {
|
if (username) {
|
||||||
usernameStr = sanitizeString(username); // Sanitize the incoming long_name just in case
|
|
||||||
// Print node's long name (e.g. "Backpack Node")
|
// Print node's long name (e.g. "Backpack Node")
|
||||||
display->drawString(x, getTextPositions(display)[line++], usernameStr.c_str());
|
UIRenderer::drawStringWithEmotes(display, x, getTextPositions(display)[line++], username, FONT_HEIGHT_SMALL, 1, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// === 2. Signal and Hops (combined on one line, if available) ===
|
// === 2. Signal and Hops (combined on one line, if available) ===
|
||||||
@@ -802,14 +801,12 @@ void UIRenderer::drawDeviceFocused(OLEDDisplay *display, OLEDDisplayUiState *sta
|
|||||||
// === Node Identity ===
|
// === Node Identity ===
|
||||||
int textWidth = 0;
|
int textWidth = 0;
|
||||||
int nameX = 0;
|
int nameX = 0;
|
||||||
char shortnameble[35];
|
const char *shortName = owner.short_name ? owner.short_name : "";
|
||||||
snprintf(shortnameble, sizeof(shortnameble), "%s",
|
|
||||||
graphics::UIRenderer::haveGlyphs(owner.short_name) ? owner.short_name : "");
|
|
||||||
|
|
||||||
// === ShortName Centered ===
|
// === ShortName Centered ===
|
||||||
textWidth = display->getStringWidth(shortnameble);
|
textWidth = UIRenderer::measureStringWithEmotes(display, shortName);
|
||||||
nameX = (SCREEN_WIDTH - textWidth) / 2;
|
nameX = (SCREEN_WIDTH - textWidth) / 2;
|
||||||
display->drawString(nameX, getTextPositions(display)[line++], shortnameble);
|
UIRenderer::drawStringWithEmotes(display, nameX, getTextPositions(display)[line++], shortName, FONT_HEIGHT_SMALL, 1, false);
|
||||||
#else
|
#else
|
||||||
if (powerStatus->getHasBattery()) {
|
if (powerStatus->getHasBattery()) {
|
||||||
char batStr[20];
|
char batStr[20];
|
||||||
@@ -904,36 +901,36 @@ void UIRenderer::drawDeviceFocused(OLEDDisplay *display, OLEDDisplayUiState *sta
|
|||||||
int textWidth = 0;
|
int textWidth = 0;
|
||||||
int nameX = 0;
|
int nameX = 0;
|
||||||
int yOffset = (currentResolution == ScreenResolution::High) ? 0 : 5;
|
int yOffset = (currentResolution == ScreenResolution::High) ? 0 : 5;
|
||||||
std::string longNameStr;
|
const char *longName = (ourNode && ourNode->has_user && ourNode->user.long_name[0]) ? ourNode->user.long_name : "";
|
||||||
|
const char *shortName = owner.short_name ? owner.short_name : "";
|
||||||
if (ourNode && ourNode->has_user && strlen(ourNode->user.long_name) > 0) {
|
char combinedName[96];
|
||||||
longNameStr = sanitizeString(ourNode->user.long_name);
|
if (longName[0] && shortName[0]) {
|
||||||
|
snprintf(combinedName, sizeof(combinedName), "%s (%s)", longName, shortName);
|
||||||
|
} else if (longName[0]) {
|
||||||
|
strncpy(combinedName, longName, sizeof(combinedName) - 1);
|
||||||
|
combinedName[sizeof(combinedName) - 1] = '\0';
|
||||||
|
} else {
|
||||||
|
strncpy(combinedName, shortName, sizeof(combinedName) - 1);
|
||||||
|
combinedName[sizeof(combinedName) - 1] = '\0';
|
||||||
}
|
}
|
||||||
char shortnameble[35];
|
if (SCREEN_WIDTH - UIRenderer::measureStringWithEmotes(display, combinedName) > 10) {
|
||||||
snprintf(shortnameble, sizeof(shortnameble), "%s",
|
textWidth = UIRenderer::measureStringWithEmotes(display, combinedName);
|
||||||
graphics::UIRenderer::haveGlyphs(owner.short_name) ? owner.short_name : "");
|
|
||||||
|
|
||||||
char combinedName[50];
|
|
||||||
snprintf(combinedName, sizeof(combinedName), "%s (%s)", longNameStr.empty() ? "" : longNameStr.c_str(), shortnameble);
|
|
||||||
if (SCREEN_WIDTH - (display->getStringWidth(combinedName)) > 10) {
|
|
||||||
size_t len = strlen(combinedName);
|
|
||||||
if (len >= 3 && strcmp(combinedName + len - 3, " ()") == 0) {
|
|
||||||
combinedName[len - 3] = '\0'; // Remove the last three characters
|
|
||||||
}
|
|
||||||
textWidth = display->getStringWidth(combinedName);
|
|
||||||
nameX = (SCREEN_WIDTH - textWidth) / 2;
|
nameX = (SCREEN_WIDTH - textWidth) / 2;
|
||||||
display->drawString(
|
UIRenderer::drawStringWithEmotes(
|
||||||
nameX, ((rows == 4) ? getTextPositions(display)[line++] : getTextPositions(display)[line++]) + yOffset, combinedName);
|
display, nameX, ((rows == 4) ? getTextPositions(display)[line++] : getTextPositions(display)[line++]) + yOffset,
|
||||||
|
combinedName, FONT_HEIGHT_SMALL, 1, false);
|
||||||
} else {
|
} else {
|
||||||
// === LongName Centered ===
|
// === LongName Centered ===
|
||||||
textWidth = display->getStringWidth(longNameStr.c_str());
|
textWidth = UIRenderer::measureStringWithEmotes(display, longName);
|
||||||
nameX = (SCREEN_WIDTH - textWidth) / 2;
|
nameX = (SCREEN_WIDTH - textWidth) / 2;
|
||||||
display->drawString(nameX, getTextPositions(display)[line++], longNameStr.c_str());
|
UIRenderer::drawStringWithEmotes(display, nameX, getTextPositions(display)[line++], longName, FONT_HEIGHT_SMALL, 1,
|
||||||
|
false);
|
||||||
|
|
||||||
// === ShortName Centered ===
|
// === ShortName Centered ===
|
||||||
textWidth = display->getStringWidth(shortnameble);
|
textWidth = UIRenderer::measureStringWithEmotes(display, shortName);
|
||||||
nameX = (SCREEN_WIDTH - textWidth) / 2;
|
nameX = (SCREEN_WIDTH - textWidth) / 2;
|
||||||
display->drawString(nameX, getTextPositions(display)[line++], shortnameble);
|
UIRenderer::drawStringWithEmotes(display, nameX, getTextPositions(display)[line++], shortName, FONT_HEIGHT_SMALL, 1,
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
graphics::drawCommonFooter(display, x, y);
|
graphics::drawCommonFooter(display, x, y);
|
||||||
@@ -1045,12 +1042,12 @@ void UIRenderer::drawScreensaverOverlay(OLEDDisplay *display, OLEDDisplayUiState
|
|||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
const char *pauseText = "Screen Paused";
|
const char *pauseText = "Screen Paused";
|
||||||
const char *idText = owner.short_name;
|
const char *idText = owner.short_name;
|
||||||
const bool useId = haveGlyphs(idText);
|
const bool useId = (idText && idText[0]);
|
||||||
constexpr uint8_t padding = 2;
|
constexpr uint8_t padding = 2;
|
||||||
constexpr uint8_t dividerGap = 1;
|
constexpr uint8_t dividerGap = 1;
|
||||||
|
|
||||||
// Text widths
|
// Text widths
|
||||||
const uint16_t idTextWidth = display->getStringWidth(idText, strlen(idText), true);
|
const uint16_t idTextWidth = useId ? UIRenderer::measureStringWithEmotes(display, idText) : 0;
|
||||||
const uint16_t pauseTextWidth = display->getStringWidth(pauseText, strlen(pauseText));
|
const uint16_t pauseTextWidth = display->getStringWidth(pauseText, strlen(pauseText));
|
||||||
const uint16_t boxWidth = padding + (useId ? idTextWidth + padding : 0) + pauseTextWidth + padding;
|
const uint16_t boxWidth = padding + (useId ? idTextWidth + padding : 0) + pauseTextWidth + padding;
|
||||||
const uint16_t boxHeight = FONT_HEIGHT_SMALL + (padding * 2);
|
const uint16_t boxHeight = FONT_HEIGHT_SMALL + (padding * 2);
|
||||||
@@ -1075,7 +1072,7 @@ void UIRenderer::drawScreensaverOverlay(OLEDDisplay *display, OLEDDisplayUiState
|
|||||||
|
|
||||||
// Draw: text
|
// Draw: text
|
||||||
if (useId)
|
if (useId)
|
||||||
display->drawString(idTextLeft, idTextTop, idText);
|
UIRenderer::drawStringWithEmotes(display, idTextLeft, idTextTop, idText, FONT_HEIGHT_SMALL, 1, false);
|
||||||
display->drawString(pauseTextLeft, pauseTextTop, pauseText);
|
display->drawString(pauseTextLeft, pauseTextTop, pauseText);
|
||||||
display->drawString(pauseTextLeft + 1, pauseTextTop, pauseText); // Faux bold
|
display->drawString(pauseTextLeft + 1, pauseTextTop, pauseText); // Faux bold
|
||||||
|
|
||||||
@@ -1108,11 +1105,16 @@ void UIRenderer::drawIconScreen(const char *upperMsg, OLEDDisplay *display, OLED
|
|||||||
display->drawString(msgX, msgY, upperMsg);
|
display->drawString(msgX, msgY, upperMsg);
|
||||||
}
|
}
|
||||||
// Draw version and short name in bottom middle
|
// Draw version and short name in bottom middle
|
||||||
char buf[25];
|
char footer[64];
|
||||||
snprintf(buf, sizeof(buf), "%s %s", xstr(APP_VERSION_SHORT),
|
if (owner.short_name && owner.short_name[0]) {
|
||||||
graphics::UIRenderer::haveGlyphs(owner.short_name) ? owner.short_name : "");
|
snprintf(footer, sizeof(footer), "%s %s", xstr(APP_VERSION_SHORT), owner.short_name);
|
||||||
|
} else {
|
||||||
display->drawString(x + getStringCenteredX(buf), y + SCREEN_HEIGHT - FONT_HEIGHT_MEDIUM, buf);
|
snprintf(footer, sizeof(footer), "%s", xstr(APP_VERSION_SHORT));
|
||||||
|
}
|
||||||
|
int footerW = UIRenderer::measureStringWithEmotes(display, footer);
|
||||||
|
int footerX = x + ((SCREEN_WIDTH - footerW) / 2);
|
||||||
|
UIRenderer::drawStringWithEmotes(display, footerX, y + SCREEN_HEIGHT - FONT_HEIGHT_MEDIUM, footer, FONT_HEIGHT_SMALL, 1,
|
||||||
|
false);
|
||||||
screen->forceDisplay();
|
screen->forceDisplay();
|
||||||
|
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT); // Restore left align, just to be kind to any other unsuspecting code
|
display->setTextAlignment(TEXT_ALIGN_LEFT); // Restore left align, just to be kind to any other unsuspecting code
|
||||||
@@ -1130,12 +1132,15 @@ void UIRenderer::drawIconScreen(const char *upperMsg, OLEDDisplay *display, OLED
|
|||||||
display->drawString(x + 0, y + 0, upperMsg);
|
display->drawString(x + 0, y + 0, upperMsg);
|
||||||
|
|
||||||
// Draw version and short name in upper right
|
// Draw version and short name in upper right
|
||||||
char buf[25];
|
const char *version = xstr(APP_VERSION_SHORT);
|
||||||
snprintf(buf, sizeof(buf), "%s\n%s", xstr(APP_VERSION_SHORT),
|
int versionX = x + SCREEN_WIDTH - display->getStringWidth(version);
|
||||||
graphics::UIRenderer::haveGlyphs(owner.short_name) ? owner.short_name : "");
|
display->drawString(versionX, y + 0, version);
|
||||||
|
if (owner.short_name && owner.short_name[0]) {
|
||||||
display->setTextAlignment(TEXT_ALIGN_RIGHT);
|
const char *shortName = owner.short_name;
|
||||||
display->drawString(x + SCREEN_WIDTH, y + 0, buf);
|
int shortNameW = UIRenderer::measureStringWithEmotes(display, shortName);
|
||||||
|
int shortNameX = x + SCREEN_WIDTH - shortNameW;
|
||||||
|
UIRenderer::drawStringWithEmotes(display, shortNameX, y + FONT_HEIGHT_SMALL, shortName, FONT_HEIGHT_SMALL, 1, false);
|
||||||
|
}
|
||||||
screen->forceDisplay();
|
screen->forceDisplay();
|
||||||
|
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT); // Restore left align, just to be kind to any other unsuspecting code
|
display->setTextAlignment(TEXT_ALIGN_LEFT); // Restore left align, just to be kind to any other unsuspecting code
|
||||||
@@ -1365,11 +1370,15 @@ void UIRenderer::drawOEMIconScreen(const char *upperMsg, OLEDDisplay *display, O
|
|||||||
display->drawString(x + 0, y + 0, upperMsg);
|
display->drawString(x + 0, y + 0, upperMsg);
|
||||||
|
|
||||||
// Draw version and shortname in upper right
|
// Draw version and shortname in upper right
|
||||||
char buf[25];
|
const char *version = xstr(APP_VERSION_SHORT);
|
||||||
snprintf(buf, sizeof(buf), "%s\n%s", xstr(APP_VERSION_SHORT), haveGlyphs(owner.short_name) ? owner.short_name : "");
|
int versionX = x + SCREEN_WIDTH - display->getStringWidth(version);
|
||||||
|
display->drawString(versionX, y + 0, version);
|
||||||
display->setTextAlignment(TEXT_ALIGN_RIGHT);
|
if (owner.short_name && owner.short_name[0]) {
|
||||||
display->drawString(x + SCREEN_WIDTH, y + 0, buf);
|
const char *shortName = owner.short_name;
|
||||||
|
int shortNameW = UIRenderer::measureStringWithEmotes(display, shortName);
|
||||||
|
int shortNameX = x + SCREEN_WIDTH - shortNameW;
|
||||||
|
UIRenderer::drawStringWithEmotes(display, shortNameX, y + FONT_HEIGHT_SMALL, shortName, FONT_HEIGHT_SMALL, 1, false);
|
||||||
|
}
|
||||||
screen->forceDisplay();
|
screen->forceDisplay();
|
||||||
|
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT); // Restore left align, just to be kind to any other unsuspecting code
|
display->setTextAlignment(TEXT_ALIGN_LEFT); // Restore left align, just to be kind to any other unsuspecting code
|
||||||
@@ -1558,6 +1567,25 @@ std::string UIRenderer::drawTimeDelta(uint32_t days, uint32_t hours, uint32_t mi
|
|||||||
return uptime;
|
return uptime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int UIRenderer::measureStringWithEmotes(OLEDDisplay *display, const char *line, int emoteSpacing)
|
||||||
|
{
|
||||||
|
return graphics::EmoteRenderer::measureStringWithEmotes(display, line, graphics::emotes, graphics::numEmotes, emoteSpacing);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t UIRenderer::truncateStringWithEmotes(OLEDDisplay *display, const char *line, char *out, size_t outSize, int maxWidth,
|
||||||
|
const char *ellipsis, int emoteSpacing)
|
||||||
|
{
|
||||||
|
return graphics::EmoteRenderer::truncateToWidth(display, line, out, outSize, maxWidth, ellipsis, graphics::emotes,
|
||||||
|
graphics::numEmotes, emoteSpacing);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIRenderer::drawStringWithEmotes(OLEDDisplay *display, int x, int y, const char *line, int fontHeight, int emoteSpacing,
|
||||||
|
bool fauxBold)
|
||||||
|
{
|
||||||
|
graphics::EmoteRenderer::drawStringWithEmotes(display, x, y, line, fontHeight, graphics::emotes, graphics::numEmotes,
|
||||||
|
emoteSpacing, fauxBold);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace graphics
|
} // namespace graphics
|
||||||
|
|
||||||
#endif // HAS_SCREEN
|
#endif // HAS_SCREEN
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "NodeDB.h"
|
#include "NodeDB.h"
|
||||||
|
#include "graphics/EmoteRenderer.h"
|
||||||
#include "graphics/Screen.h"
|
#include "graphics/Screen.h"
|
||||||
#include "graphics/emotes.h"
|
#include "graphics/emotes.h"
|
||||||
#include <OLEDDisplay.h>
|
#include <OLEDDisplay.h>
|
||||||
@@ -80,6 +81,28 @@ class UIRenderer
|
|||||||
static std::string drawTimeDelta(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds);
|
static std::string drawTimeDelta(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds);
|
||||||
static int formatDateTime(char *buffer, size_t bufferSize, uint32_t rtc_sec, OLEDDisplay *display, bool showTime);
|
static int formatDateTime(char *buffer, size_t bufferSize, uint32_t rtc_sec, OLEDDisplay *display, bool showTime);
|
||||||
|
|
||||||
|
// Shared BaseUI emote helpers.
|
||||||
|
static int measureStringWithEmotes(OLEDDisplay *display, const char *line, int emoteSpacing = 1);
|
||||||
|
static inline int measureStringWithEmotes(OLEDDisplay *display, const std::string &line, int emoteSpacing = 1)
|
||||||
|
{
|
||||||
|
return measureStringWithEmotes(display, line.c_str(), emoteSpacing);
|
||||||
|
}
|
||||||
|
static size_t truncateStringWithEmotes(OLEDDisplay *display, const char *line, char *out, size_t outSize, int maxWidth,
|
||||||
|
const char *ellipsis = "...", int emoteSpacing = 1);
|
||||||
|
static inline std::string truncateStringWithEmotes(OLEDDisplay *display, const std::string &line, int maxWidth,
|
||||||
|
const std::string &ellipsis = "...", int emoteSpacing = 1)
|
||||||
|
{
|
||||||
|
return graphics::EmoteRenderer::truncateToWidth(display, line, maxWidth, ellipsis, graphics::emotes, graphics::numEmotes,
|
||||||
|
emoteSpacing);
|
||||||
|
}
|
||||||
|
static void drawStringWithEmotes(OLEDDisplay *display, int x, int y, const char *line, int fontHeight, int emoteSpacing = 1,
|
||||||
|
bool fauxBold = true);
|
||||||
|
static inline void drawStringWithEmotes(OLEDDisplay *display, int x, int y, const std::string &line, int fontHeight,
|
||||||
|
int emoteSpacing = 1, bool fauxBold = true)
|
||||||
|
{
|
||||||
|
drawStringWithEmotes(display, x, y, line.c_str(), fontHeight, emoteSpacing, fauxBold);
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the display can render a string (detect special chars; emoji)
|
// Check if the display can render a string (detect special chars; emoji)
|
||||||
static bool haveGlyphs(const char *str);
|
static bool haveGlyphs(const char *str);
|
||||||
}; // namespace UIRenderer
|
}; // namespace UIRenderer
|
||||||
|
|||||||
@@ -0,0 +1,178 @@
|
|||||||
|
#ifdef MESHTASTIC_INCLUDE_NICHE_GRAPHICS
|
||||||
|
|
||||||
|
#include "./GDEW0102T4.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
using namespace NicheGraphics::Drivers;
|
||||||
|
|
||||||
|
// LUTs from GxEPD2_102.cpp (GDEW0102T4 / UC8175).
|
||||||
|
static const uint8_t LUT_W_FULL[] = {
|
||||||
|
0x60, 0x5A, 0x5A, 0x00, 0x00, 0x01, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t LUT_B_FULL[] = {
|
||||||
|
0x90, 0x5A, 0x5A, 0x00, 0x00, 0x01, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t LUT_W_FAST[] = {
|
||||||
|
0x60, 0x01, 0x01, 0x00, 0x00, 0x01, //
|
||||||
|
0x80, 0x12, 0x00, 0x00, 0x00, 0x01, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t LUT_B_FAST[] = {
|
||||||
|
0x90, 0x01, 0x01, 0x00, 0x00, 0x01, //
|
||||||
|
0x40, 0x14, 0x00, 0x00, 0x00, 0x01, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
};
|
||||||
|
|
||||||
|
GDEW0102T4::GDEW0102T4() : UC8175(width, height, supported) {}
|
||||||
|
|
||||||
|
void GDEW0102T4::setFastConfig(FastConfig cfg)
|
||||||
|
{
|
||||||
|
// Clamp out only clearly invalid PLL settings.
|
||||||
|
if (cfg.reg30 < 0x05)
|
||||||
|
cfg.reg30 = 0x05;
|
||||||
|
fastConfig = cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
GDEW0102T4::FastConfig GDEW0102T4::getFastConfig() const
|
||||||
|
{
|
||||||
|
return fastConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GDEW0102T4::configCommon()
|
||||||
|
{
|
||||||
|
// Init path aligned with GxEPD2_GDEW0102T4 (UC8175 family).
|
||||||
|
sendCommand(0xD2);
|
||||||
|
sendData(0x3F);
|
||||||
|
|
||||||
|
sendCommand(0x00);
|
||||||
|
sendData(0x6F);
|
||||||
|
|
||||||
|
sendCommand(0x01);
|
||||||
|
sendData(0x03);
|
||||||
|
sendData(0x00);
|
||||||
|
sendData(0x2B);
|
||||||
|
sendData(0x2B);
|
||||||
|
|
||||||
|
sendCommand(0x06);
|
||||||
|
sendData(0x3F);
|
||||||
|
|
||||||
|
sendCommand(0x2A);
|
||||||
|
sendData(0x00);
|
||||||
|
sendData(0x00);
|
||||||
|
|
||||||
|
sendCommand(0x30); // PLL / drive clock
|
||||||
|
sendData(0x13);
|
||||||
|
|
||||||
|
sendCommand(0x50); // Last border/data interval; subtle but can affect artifacts
|
||||||
|
sendData(0x57);
|
||||||
|
|
||||||
|
sendCommand(0x60);
|
||||||
|
sendData(0x22);
|
||||||
|
|
||||||
|
sendCommand(0x61);
|
||||||
|
sendData(width);
|
||||||
|
sendData(height);
|
||||||
|
|
||||||
|
sendCommand(0x82); // VCOM DC setting
|
||||||
|
sendData(0x12);
|
||||||
|
|
||||||
|
sendCommand(0xE3);
|
||||||
|
sendData(0x33);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GDEW0102T4::configFull()
|
||||||
|
{
|
||||||
|
sendCommand(0x23);
|
||||||
|
sendData(LUT_W_FULL, sizeof(LUT_W_FULL));
|
||||||
|
sendCommand(0x24);
|
||||||
|
sendData(LUT_B_FULL, sizeof(LUT_B_FULL));
|
||||||
|
|
||||||
|
powerOn();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GDEW0102T4::configFast()
|
||||||
|
{
|
||||||
|
uint8_t lutW[sizeof(LUT_W_FAST)];
|
||||||
|
uint8_t lutB[sizeof(LUT_B_FAST)];
|
||||||
|
memcpy(lutW, LUT_W_FAST, sizeof(LUT_W_FAST));
|
||||||
|
memcpy(lutB, LUT_B_FAST, sizeof(LUT_B_FAST));
|
||||||
|
|
||||||
|
// Second stage duration bytes are the main "darkness vs ghosting" control for this panel.
|
||||||
|
lutW[7] = fastConfig.lutW2;
|
||||||
|
lutB[7] = fastConfig.lutB2;
|
||||||
|
|
||||||
|
sendCommand(0x30);
|
||||||
|
sendData(fastConfig.reg30);
|
||||||
|
|
||||||
|
sendCommand(0x50);
|
||||||
|
sendData(fastConfig.reg50);
|
||||||
|
|
||||||
|
sendCommand(0x82);
|
||||||
|
sendData(fastConfig.reg82);
|
||||||
|
|
||||||
|
sendCommand(0x23);
|
||||||
|
sendData(lutW, sizeof(lutW));
|
||||||
|
sendCommand(0x24);
|
||||||
|
sendData(lutB, sizeof(lutB));
|
||||||
|
|
||||||
|
powerOn();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GDEW0102T4::writeOldImage()
|
||||||
|
{
|
||||||
|
// On this panel, FULL refresh is most reliable when "old image" is all white.
|
||||||
|
if (updateType == FULL) {
|
||||||
|
sendCommand(0x10);
|
||||||
|
// Use buffered writes of 0xFF to avoid per-byte SPI transactions.
|
||||||
|
const uint16_t chunkSize = 64;
|
||||||
|
uint8_t ffBuf[chunkSize];
|
||||||
|
memset(ffBuf, 0xFF, sizeof(ffBuf));
|
||||||
|
|
||||||
|
uint32_t remaining = bufferSize;
|
||||||
|
while (remaining > 0) {
|
||||||
|
uint16_t toSend = remaining > chunkSize ? chunkSize : static_cast<uint16_t>(remaining);
|
||||||
|
sendData(ffBuf, toSend);
|
||||||
|
remaining -= toSend;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FAST refresh uses differential data (previous frame as old image).
|
||||||
|
if (previousBuffer) {
|
||||||
|
writeImage(0x10, previousBuffer);
|
||||||
|
} else {
|
||||||
|
writeImage(0x10, buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GDEW0102T4::finalizeUpdate()
|
||||||
|
{
|
||||||
|
// Keep panel out of deep-sleep between updates for better reliability of repeated FAST refresh.
|
||||||
|
powerOff();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // MESHTASTIC_INCLUDE_NICHE_GRAPHICS
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
E-Ink display driver
|
||||||
|
- GDEW0102T4
|
||||||
|
- Controller: UC8175
|
||||||
|
- Size: 1.02 inch
|
||||||
|
- Resolution: 80px x 128px
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef MESHTASTIC_INCLUDE_NICHE_GRAPHICS
|
||||||
|
|
||||||
|
#include "configuration.h"
|
||||||
|
|
||||||
|
#include "./UC8175.h"
|
||||||
|
|
||||||
|
namespace NicheGraphics::Drivers
|
||||||
|
{
|
||||||
|
|
||||||
|
class GDEW0102T4 : public UC8175
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static constexpr uint16_t width = 80;
|
||||||
|
static constexpr uint16_t height = 128;
|
||||||
|
static constexpr UpdateTypes supported = (UpdateTypes)(FULL | FAST);
|
||||||
|
|
||||||
|
public:
|
||||||
|
struct FastConfig {
|
||||||
|
uint8_t reg30;
|
||||||
|
uint8_t reg50;
|
||||||
|
uint8_t reg82;
|
||||||
|
uint8_t lutW2;
|
||||||
|
uint8_t lutB2;
|
||||||
|
};
|
||||||
|
|
||||||
|
GDEW0102T4();
|
||||||
|
void setFastConfig(FastConfig cfg);
|
||||||
|
FastConfig getFastConfig() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void configCommon() override;
|
||||||
|
void configFull() override;
|
||||||
|
void configFast() override;
|
||||||
|
void writeOldImage() override;
|
||||||
|
void finalizeUpdate() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
FastConfig fastConfig = {0x13, 0xF2, 0x12, 0x0E, 0x14};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace NicheGraphics::Drivers
|
||||||
|
|
||||||
|
#endif // MESHTASTIC_INCLUDE_NICHE_GRAPHICS
|
||||||
@@ -0,0 +1,203 @@
|
|||||||
|
#ifdef MESHTASTIC_INCLUDE_NICHE_GRAPHICS
|
||||||
|
|
||||||
|
#include "./UC8175.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "SPILock.h"
|
||||||
|
|
||||||
|
using namespace NicheGraphics::Drivers;
|
||||||
|
|
||||||
|
UC8175::UC8175(uint16_t width, uint16_t height, UpdateTypes supported) : EInk(width, height, supported)
|
||||||
|
{
|
||||||
|
bufferRowSize = ((width - 1) / 8) + 1;
|
||||||
|
bufferSize = bufferRowSize * height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UC8175::begin(SPIClass *spi, uint8_t pin_dc, uint8_t pin_cs, uint8_t pin_busy, uint8_t pin_rst)
|
||||||
|
{
|
||||||
|
this->spi = spi;
|
||||||
|
this->pin_dc = pin_dc;
|
||||||
|
this->pin_cs = pin_cs;
|
||||||
|
this->pin_busy = pin_busy;
|
||||||
|
this->pin_rst = pin_rst;
|
||||||
|
|
||||||
|
pinMode(pin_dc, OUTPUT);
|
||||||
|
pinMode(pin_cs, OUTPUT);
|
||||||
|
pinMode(pin_busy, INPUT);
|
||||||
|
|
||||||
|
// Reset is active LOW, hold HIGH when idle.
|
||||||
|
if (pin_rst != (uint8_t)-1) {
|
||||||
|
pinMode(pin_rst, OUTPUT);
|
||||||
|
digitalWrite(pin_rst, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!previousBuffer) {
|
||||||
|
previousBuffer = new uint8_t[bufferSize];
|
||||||
|
if (previousBuffer)
|
||||||
|
memset(previousBuffer, 0xFF, bufferSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UC8175::update(uint8_t *imageData, UpdateTypes type)
|
||||||
|
{
|
||||||
|
buffer = imageData;
|
||||||
|
updateType = (type == UpdateTypes::UNSPECIFIED) ? UpdateTypes::FULL : type;
|
||||||
|
|
||||||
|
if (updateType == FAST && hasPreviousBuffer && previousBuffer && memcmp(previousBuffer, buffer, bufferSize) == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
reset();
|
||||||
|
configCommon();
|
||||||
|
|
||||||
|
if (updateType == FAST)
|
||||||
|
configFast();
|
||||||
|
else
|
||||||
|
configFull();
|
||||||
|
|
||||||
|
writeOldImage();
|
||||||
|
writeNewImage();
|
||||||
|
sendCommand(0x12); // Display refresh.
|
||||||
|
|
||||||
|
if (previousBuffer) {
|
||||||
|
memcpy(previousBuffer, buffer, bufferSize);
|
||||||
|
hasPreviousBuffer = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
detachFromUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UC8175::wait(uint32_t timeoutMs)
|
||||||
|
{
|
||||||
|
if (failed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uint32_t started = millis();
|
||||||
|
while (digitalRead(pin_busy) == BUSY_ACTIVE) {
|
||||||
|
if ((millis() - started) > timeoutMs) {
|
||||||
|
failed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UC8175::reset()
|
||||||
|
{
|
||||||
|
if (pin_rst != (uint8_t)-1) {
|
||||||
|
digitalWrite(pin_rst, LOW);
|
||||||
|
delay(20);
|
||||||
|
digitalWrite(pin_rst, HIGH);
|
||||||
|
delay(20);
|
||||||
|
} else {
|
||||||
|
sendCommand(0x12); // Software reset.
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
wait(3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UC8175::sendCommand(uint8_t command)
|
||||||
|
{
|
||||||
|
if (failed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
spiLock->lock();
|
||||||
|
spi->beginTransaction(spiSettings);
|
||||||
|
digitalWrite(pin_dc, LOW);
|
||||||
|
digitalWrite(pin_cs, LOW);
|
||||||
|
spi->transfer(command);
|
||||||
|
digitalWrite(pin_cs, HIGH);
|
||||||
|
digitalWrite(pin_dc, HIGH);
|
||||||
|
spi->endTransaction();
|
||||||
|
spiLock->unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UC8175::sendData(uint8_t data)
|
||||||
|
{
|
||||||
|
sendData(&data, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UC8175::sendData(const uint8_t *data, uint32_t size)
|
||||||
|
{
|
||||||
|
if (failed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
spiLock->lock();
|
||||||
|
spi->beginTransaction(spiSettings);
|
||||||
|
digitalWrite(pin_dc, HIGH);
|
||||||
|
digitalWrite(pin_cs, LOW);
|
||||||
|
|
||||||
|
#if defined(ARCH_ESP32)
|
||||||
|
spi->transferBytes(data, NULL, size);
|
||||||
|
#elif defined(ARCH_NRF52)
|
||||||
|
spi->transfer(data, NULL, size);
|
||||||
|
#else
|
||||||
|
for (uint32_t i = 0; i < size; ++i)
|
||||||
|
spi->transfer(data[i]);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
digitalWrite(pin_cs, HIGH);
|
||||||
|
digitalWrite(pin_dc, HIGH);
|
||||||
|
spi->endTransaction();
|
||||||
|
spiLock->unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UC8175::powerOn()
|
||||||
|
{
|
||||||
|
sendCommand(0x04);
|
||||||
|
wait(2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UC8175::powerOff()
|
||||||
|
{
|
||||||
|
sendCommand(0x02); // Power off.
|
||||||
|
wait(1500);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UC8175::writeImage(uint8_t command, const uint8_t *image)
|
||||||
|
{
|
||||||
|
sendCommand(command);
|
||||||
|
sendData(image, bufferSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UC8175::writeOldImage()
|
||||||
|
{
|
||||||
|
if (updateType == FAST && previousBuffer)
|
||||||
|
writeImage(0x10, previousBuffer);
|
||||||
|
else
|
||||||
|
writeImage(0x10, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UC8175::writeNewImage()
|
||||||
|
{
|
||||||
|
writeImage(0x13, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UC8175::detachFromUpdate()
|
||||||
|
{
|
||||||
|
switch (updateType) {
|
||||||
|
case FAST:
|
||||||
|
return beginPolling(50, 400);
|
||||||
|
case FULL:
|
||||||
|
default:
|
||||||
|
return beginPolling(100, 2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UC8175::isUpdateDone()
|
||||||
|
{
|
||||||
|
return digitalRead(pin_busy) != BUSY_ACTIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UC8175::finalizeUpdate()
|
||||||
|
{
|
||||||
|
powerOff();
|
||||||
|
|
||||||
|
if (pin_rst != (uint8_t)-1) {
|
||||||
|
sendCommand(0x07); // Deep sleep.
|
||||||
|
sendData(0xA5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // MESHTASTIC_INCLUDE_NICHE_GRAPHICS
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
// E-Ink base class for displays based on UC8175 / UC8176 style controller ICs.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef MESHTASTIC_INCLUDE_NICHE_GRAPHICS
|
||||||
|
|
||||||
|
#include "configuration.h"
|
||||||
|
|
||||||
|
#include "./EInk.h"
|
||||||
|
|
||||||
|
namespace NicheGraphics::Drivers
|
||||||
|
{
|
||||||
|
|
||||||
|
class UC8175 : public EInk
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UC8175(uint16_t width, uint16_t height, UpdateTypes supported);
|
||||||
|
void begin(SPIClass *spi, uint8_t pin_dc, uint8_t pin_cs, uint8_t pin_busy, uint8_t pin_rst = -1) override;
|
||||||
|
void update(uint8_t *imageData, UpdateTypes type) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void wait(uint32_t timeoutMs = 1000);
|
||||||
|
virtual void reset();
|
||||||
|
virtual void sendCommand(uint8_t command);
|
||||||
|
virtual void sendData(uint8_t data);
|
||||||
|
virtual void sendData(const uint8_t *data, uint32_t size);
|
||||||
|
|
||||||
|
virtual void configCommon() = 0; // Always run
|
||||||
|
virtual void configFull() = 0; // Run when updateType == FULL
|
||||||
|
virtual void configFast() = 0; // Run when updateType == FAST
|
||||||
|
|
||||||
|
virtual void powerOn();
|
||||||
|
virtual void powerOff();
|
||||||
|
virtual void writeOldImage();
|
||||||
|
virtual void writeNewImage();
|
||||||
|
virtual void writeImage(uint8_t command, const uint8_t *image);
|
||||||
|
|
||||||
|
virtual void detachFromUpdate();
|
||||||
|
virtual bool isUpdateDone() override;
|
||||||
|
virtual void finalizeUpdate() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static constexpr uint8_t BUSY_ACTIVE = LOW;
|
||||||
|
|
||||||
|
uint16_t bufferRowSize = 0;
|
||||||
|
uint32_t bufferSize = 0;
|
||||||
|
uint8_t *buffer = nullptr;
|
||||||
|
uint8_t *previousBuffer = nullptr;
|
||||||
|
bool hasPreviousBuffer = false;
|
||||||
|
UpdateTypes updateType = UpdateTypes::UNSPECIFIED;
|
||||||
|
|
||||||
|
uint8_t pin_dc = (uint8_t)-1;
|
||||||
|
uint8_t pin_cs = (uint8_t)-1;
|
||||||
|
uint8_t pin_busy = (uint8_t)-1;
|
||||||
|
uint8_t pin_rst = (uint8_t)-1;
|
||||||
|
SPIClass *spi = nullptr;
|
||||||
|
SPISettings spiSettings = SPISettings(8000000, MSBFIRST, SPI_MODE0);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace NicheGraphics::Drivers
|
||||||
|
|
||||||
|
#endif // MESHTASTIC_INCLUDE_NICHE_GRAPHICS
|
||||||
@@ -349,13 +349,13 @@ void InkHUD::MenuApplet::execute(MenuItem item)
|
|||||||
handleFreeText = true;
|
handleFreeText = true;
|
||||||
cm.freeTextItem.rawText.erase(); // clear the previous freetext message
|
cm.freeTextItem.rawText.erase(); // clear the previous freetext message
|
||||||
freeTextMode = true; // render input field instead of normal menu
|
freeTextMode = true; // render input field instead of normal menu
|
||||||
// Open the on-screen keyboard if the joystick is enabled
|
// Open the on-screen keyboard only for full joystick devices
|
||||||
if (settings->joystick.enabled)
|
if (settings->joystick.enabled && !inkhud->twoWayRocker)
|
||||||
inkhud->openKeyboard();
|
inkhud->openKeyboard();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STORE_CANNEDMESSAGE_SELECTION:
|
case STORE_CANNEDMESSAGE_SELECTION:
|
||||||
if (!settings->joystick.enabled)
|
if (!settings->joystick.enabled || inkhud->twoWayRocker)
|
||||||
cm.selectedMessageItem = &cm.messageItems.at(cursor - 1); // Minus one: offset for the initial "Send Ping" entry
|
cm.selectedMessageItem = &cm.messageItems.at(cursor - 1); // Minus one: offset for the initial "Send Ping" entry
|
||||||
else
|
else
|
||||||
cm.selectedMessageItem = &cm.messageItems.at(cursor - 2); // Minus two: offset for the "Send Ping" and free text entry
|
cm.selectedMessageItem = &cm.messageItems.at(cursor - 2); // Minus two: offset for the "Send Ping" and free text entry
|
||||||
@@ -922,7 +922,7 @@ void InkHUD::MenuApplet::showPage(MenuPage page)
|
|||||||
if (settings->userTiles.maxCount > 1)
|
if (settings->userTiles.maxCount > 1)
|
||||||
items.push_back(MenuItem("Layout", MenuAction::LAYOUT, MenuPage::OPTIONS));
|
items.push_back(MenuItem("Layout", MenuAction::LAYOUT, MenuPage::OPTIONS));
|
||||||
items.push_back(MenuItem("Rotate", MenuAction::ROTATE, MenuPage::OPTIONS));
|
items.push_back(MenuItem("Rotate", MenuAction::ROTATE, MenuPage::OPTIONS));
|
||||||
if (settings->joystick.enabled)
|
if (settings->joystick.enabled && !inkhud->twoWayRocker)
|
||||||
items.push_back(MenuItem("Align Joystick", MenuAction::ALIGN_JOYSTICK, MenuPage::EXIT));
|
items.push_back(MenuItem("Align Joystick", MenuAction::ALIGN_JOYSTICK, MenuPage::EXIT));
|
||||||
items.push_back(MenuItem("Notifications", MenuAction::TOGGLE_NOTIFICATIONS, MenuPage::OPTIONS,
|
items.push_back(MenuItem("Notifications", MenuAction::TOGGLE_NOTIFICATIONS, MenuPage::OPTIONS,
|
||||||
&settings->optionalFeatures.notifications));
|
&settings->optionalFeatures.notifications));
|
||||||
@@ -1751,7 +1751,7 @@ void InkHUD::MenuApplet::populateSendPage()
|
|||||||
items.push_back(MenuItem("Ping", MenuAction::SEND_PING, MenuPage::EXIT));
|
items.push_back(MenuItem("Ping", MenuAction::SEND_PING, MenuPage::EXIT));
|
||||||
|
|
||||||
// If joystick is available, include the Free Text option
|
// If joystick is available, include the Free Text option
|
||||||
if (settings->joystick.enabled)
|
if (settings->joystick.enabled && !inkhud->twoWayRocker)
|
||||||
items.push_back(MenuItem("Free Text", MenuAction::FREE_TEXT, MenuPage::SEND));
|
items.push_back(MenuItem("Free Text", MenuAction::FREE_TEXT, MenuPage::SEND));
|
||||||
|
|
||||||
// One menu item for each canned message
|
// One menu item for each canned message
|
||||||
|
|||||||
@@ -152,6 +152,11 @@ void InkHUD::TipsApplet::onRender(bool full)
|
|||||||
drawBullet("User Button");
|
drawBullet("User Button");
|
||||||
drawBullet("- short press: next");
|
drawBullet("- short press: next");
|
||||||
drawBullet("- long press: select or open menu");
|
drawBullet("- long press: select or open menu");
|
||||||
|
} else if (inkhud->twoWayRocker) {
|
||||||
|
drawBullet("Rocker + Button");
|
||||||
|
drawBullet("- center press: open menu or select");
|
||||||
|
drawBullet("- left/right: applet nav");
|
||||||
|
drawBullet("- in menu: up/down");
|
||||||
} else {
|
} else {
|
||||||
drawBullet("Joystick");
|
drawBullet("Joystick");
|
||||||
drawBullet("- press: open menu or select");
|
drawBullet("- press: open menu or select");
|
||||||
|
|||||||
@@ -88,6 +88,9 @@ class InkHUD
|
|||||||
// Used by TipsApplet to force menu to start on Region selection
|
// Used by TipsApplet to force menu to start on Region selection
|
||||||
bool forceRegionMenu = false;
|
bool forceRegionMenu = false;
|
||||||
|
|
||||||
|
// Input mode hint for devices that use a left/right rocker plus center button
|
||||||
|
bool twoWayRocker = false;
|
||||||
|
|
||||||
// Updating the display
|
// Updating the display
|
||||||
// - called by various InkHUD components
|
// - called by various InkHUD components
|
||||||
|
|
||||||
@@ -130,4 +133,4 @@ class InkHUD
|
|||||||
|
|
||||||
} // namespace NicheGraphics::InkHUD
|
} // namespace NicheGraphics::InkHUD
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ void InkHUD::WindowManager::openMenu()
|
|||||||
// Bring the AlignStick applet to the foreground
|
// Bring the AlignStick applet to the foreground
|
||||||
void InkHUD::WindowManager::openAlignStick()
|
void InkHUD::WindowManager::openAlignStick()
|
||||||
{
|
{
|
||||||
if (settings->joystick.enabled) {
|
if (settings->joystick.enabled && !inkhud->twoWayRocker) {
|
||||||
AlignStickApplet *alignStick = (AlignStickApplet *)inkhud->getSystemApplet("AlignStick");
|
AlignStickApplet *alignStick = (AlignStickApplet *)inkhud->getSystemApplet("AlignStick");
|
||||||
alignStick->bringToForeground();
|
alignStick->bringToForeground();
|
||||||
}
|
}
|
||||||
@@ -151,6 +151,9 @@ void InkHUD::WindowManager::openAlignStick()
|
|||||||
|
|
||||||
void InkHUD::WindowManager::openKeyboard()
|
void InkHUD::WindowManager::openKeyboard()
|
||||||
{
|
{
|
||||||
|
if (!settings->joystick.enabled || inkhud->twoWayRocker)
|
||||||
|
return;
|
||||||
|
|
||||||
KeyboardApplet *keyboard = (KeyboardApplet *)inkhud->getSystemApplet("Keyboard");
|
KeyboardApplet *keyboard = (KeyboardApplet *)inkhud->getSystemApplet("Keyboard");
|
||||||
|
|
||||||
if (keyboard) {
|
if (keyboard) {
|
||||||
@@ -162,6 +165,9 @@ void InkHUD::WindowManager::openKeyboard()
|
|||||||
|
|
||||||
void InkHUD::WindowManager::closeKeyboard()
|
void InkHUD::WindowManager::closeKeyboard()
|
||||||
{
|
{
|
||||||
|
if (!settings->joystick.enabled || inkhud->twoWayRocker)
|
||||||
|
return;
|
||||||
|
|
||||||
KeyboardApplet *keyboard = (KeyboardApplet *)inkhud->getSystemApplet("Keyboard");
|
KeyboardApplet *keyboard = (KeyboardApplet *)inkhud->getSystemApplet("Keyboard");
|
||||||
|
|
||||||
if (keyboard) {
|
if (keyboard) {
|
||||||
@@ -477,7 +483,7 @@ void InkHUD::WindowManager::createSystemApplets()
|
|||||||
addSystemApplet("Logo", new LogoApplet, new Tile);
|
addSystemApplet("Logo", new LogoApplet, new Tile);
|
||||||
addSystemApplet("Pairing", new PairingApplet, new Tile);
|
addSystemApplet("Pairing", new PairingApplet, new Tile);
|
||||||
addSystemApplet("Tips", new TipsApplet, new Tile);
|
addSystemApplet("Tips", new TipsApplet, new Tile);
|
||||||
if (settings->joystick.enabled) {
|
if (settings->joystick.enabled && !inkhud->twoWayRocker) {
|
||||||
addSystemApplet("AlignStick", new AlignStickApplet, new Tile);
|
addSystemApplet("AlignStick", new AlignStickApplet, new Tile);
|
||||||
addSystemApplet("Keyboard", new KeyboardApplet, new Tile);
|
addSystemApplet("Keyboard", new KeyboardApplet, new Tile);
|
||||||
}
|
}
|
||||||
@@ -503,7 +509,7 @@ void InkHUD::WindowManager::placeSystemTiles()
|
|||||||
inkhud->getSystemApplet("Logo")->getTile()->setRegion(0, 0, inkhud->width(), inkhud->height());
|
inkhud->getSystemApplet("Logo")->getTile()->setRegion(0, 0, inkhud->width(), inkhud->height());
|
||||||
inkhud->getSystemApplet("Pairing")->getTile()->setRegion(0, 0, inkhud->width(), inkhud->height());
|
inkhud->getSystemApplet("Pairing")->getTile()->setRegion(0, 0, inkhud->width(), inkhud->height());
|
||||||
inkhud->getSystemApplet("Tips")->getTile()->setRegion(0, 0, inkhud->width(), inkhud->height());
|
inkhud->getSystemApplet("Tips")->getTile()->setRegion(0, 0, inkhud->width(), inkhud->height());
|
||||||
if (settings->joystick.enabled) {
|
if (settings->joystick.enabled && !inkhud->twoWayRocker) {
|
||||||
inkhud->getSystemApplet("AlignStick")->getTile()->setRegion(0, 0, inkhud->width(), inkhud->height());
|
inkhud->getSystemApplet("AlignStick")->getTile()->setRegion(0, 0, inkhud->width(), inkhud->height());
|
||||||
const uint16_t keyboardHeight = KeyboardApplet::getKeyboardHeight();
|
const uint16_t keyboardHeight = KeyboardApplet::getKeyboardHeight();
|
||||||
inkhud->getSystemApplet("Keyboard")
|
inkhud->getSystemApplet("Keyboard")
|
||||||
|
|||||||
@@ -156,6 +156,24 @@ void TwoButtonExtended::setJoystickWiring(uint8_t uPin, uint8_t dPin, uint8_t lP
|
|||||||
pinMode(joystick[Direction::RIGHT].pin, internalPullup ? INPUT_PULLUP : INPUT);
|
pinMode(joystick[Direction::RIGHT].pin, internalPullup ? INPUT_PULLUP : INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Configures only left/right joystick directions for a two-way rocker
|
||||||
|
void TwoButtonExtended::setTwoWayRockerWiring(uint8_t leftPin, uint8_t rightPin, bool internalPullup)
|
||||||
|
{
|
||||||
|
if (leftPin == rightPin) {
|
||||||
|
LOG_WARN("Attempted reuse of TwoWayRocker GPIO. Ignoring assignment");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
joystick[Direction::UP].pin = 0xFF;
|
||||||
|
joystick[Direction::DOWN].pin = 0xFF;
|
||||||
|
joystick[Direction::LEFT].pin = leftPin;
|
||||||
|
joystick[Direction::RIGHT].pin = rightPin;
|
||||||
|
joystickActiveLogic = LOW;
|
||||||
|
|
||||||
|
pinMode(joystick[Direction::LEFT].pin, internalPullup ? INPUT_PULLUP : INPUT);
|
||||||
|
pinMode(joystick[Direction::RIGHT].pin, internalPullup ? INPUT_PULLUP : INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
void TwoButtonExtended::setTiming(uint8_t whichButton, uint32_t debounceMs, uint32_t longpressMs)
|
void TwoButtonExtended::setTiming(uint8_t whichButton, uint32_t debounceMs, uint32_t longpressMs)
|
||||||
{
|
{
|
||||||
assert(whichButton < 2);
|
assert(whichButton < 2);
|
||||||
@@ -229,6 +247,13 @@ void TwoButtonExtended::setJoystickPressHandlers(Callback uPress, Callback dPres
|
|||||||
joystick[Direction::RIGHT].onPress = rPress;
|
joystick[Direction::RIGHT].onPress = rPress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set press handlers for a two-way rocker mapped to left/right directions
|
||||||
|
void TwoButtonExtended::setTwoWayRockerPressHandlers(Callback lPress, Callback rPress)
|
||||||
|
{
|
||||||
|
joystick[Direction::LEFT].onPress = lPress;
|
||||||
|
joystick[Direction::RIGHT].onPress = rPress;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle the start of a press to the primary button
|
// Handle the start of a press to the primary button
|
||||||
// Wakes our button thread
|
// Wakes our button thread
|
||||||
void TwoButtonExtended::isrPrimary()
|
void TwoButtonExtended::isrPrimary()
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ class TwoButtonExtended : protected concurrency::OSThread
|
|||||||
void stop(); // Stop handling button input (disconnect ISRs for sleep)
|
void stop(); // Stop handling button input (disconnect ISRs for sleep)
|
||||||
void setWiring(uint8_t whichButton, uint8_t pin, bool internalPullup = false);
|
void setWiring(uint8_t whichButton, uint8_t pin, bool internalPullup = false);
|
||||||
void setJoystickWiring(uint8_t uPin, uint8_t dPin, uint8_t lPin, uint8_t rPin, bool internalPullup = false);
|
void setJoystickWiring(uint8_t uPin, uint8_t dPin, uint8_t lPin, uint8_t rPin, bool internalPullup = false);
|
||||||
|
void setTwoWayRockerWiring(uint8_t leftPin, uint8_t rightPin, bool internalPullup = false);
|
||||||
void setTiming(uint8_t whichButton, uint32_t debounceMs, uint32_t longpressMs);
|
void setTiming(uint8_t whichButton, uint32_t debounceMs, uint32_t longpressMs);
|
||||||
void setJoystickDebounce(uint32_t debounceMs);
|
void setJoystickDebounce(uint32_t debounceMs);
|
||||||
void setHandlerDown(uint8_t whichButton, Callback onDown);
|
void setHandlerDown(uint8_t whichButton, Callback onDown);
|
||||||
@@ -54,6 +55,7 @@ class TwoButtonExtended : protected concurrency::OSThread
|
|||||||
void setJoystickDownHandlers(Callback uDown, Callback dDown, Callback ldown, Callback rDown);
|
void setJoystickDownHandlers(Callback uDown, Callback dDown, Callback ldown, Callback rDown);
|
||||||
void setJoystickUpHandlers(Callback uUp, Callback dUp, Callback lUp, Callback rUp);
|
void setJoystickUpHandlers(Callback uUp, Callback dUp, Callback lUp, Callback rUp);
|
||||||
void setJoystickPressHandlers(Callback uPress, Callback dPress, Callback lPress, Callback rPress);
|
void setJoystickPressHandlers(Callback uPress, Callback dPress, Callback lPress, Callback rPress);
|
||||||
|
void setTwoWayRockerPressHandlers(Callback lPress, Callback rPress);
|
||||||
|
|
||||||
// Disconnect and reconnect interrupts for light sleep
|
// Disconnect and reconnect interrupts for light sleep
|
||||||
#ifdef ARCH_ESP32
|
#ifdef ARCH_ESP32
|
||||||
|
|||||||
@@ -8,6 +8,14 @@ UpDownInterruptImpl1::UpDownInterruptImpl1() : UpDownInterruptBase("upDown1") {}
|
|||||||
|
|
||||||
bool UpDownInterruptImpl1::init()
|
bool UpDownInterruptImpl1::init()
|
||||||
{
|
{
|
||||||
|
#if defined(INPUTDRIVER_TWO_WAY_ROCKER) && defined(INPUTDRIVER_TWO_WAY_ROCKER_LEFT) && defined(INPUTDRIVER_TWO_WAY_ROCKER_RIGHT)
|
||||||
|
moduleConfig.canned_message.updown1_enabled = true;
|
||||||
|
moduleConfig.canned_message.inputbroker_pin_a = INPUTDRIVER_TWO_WAY_ROCKER_LEFT;
|
||||||
|
moduleConfig.canned_message.inputbroker_pin_b = INPUTDRIVER_TWO_WAY_ROCKER_RIGHT;
|
||||||
|
#if defined(INPUTDRIVER_TWO_WAY_ROCKER_BTN)
|
||||||
|
moduleConfig.canned_message.inputbroker_pin_press = INPUTDRIVER_TWO_WAY_ROCKER_BTN;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!moduleConfig.canned_message.updown1_enabled) {
|
if (!moduleConfig.canned_message.updown1_enabled) {
|
||||||
// Input device is disabled.
|
// Input device is disabled.
|
||||||
@@ -46,4 +54,4 @@ void UpDownInterruptImpl1::handleIntUp()
|
|||||||
void UpDownInterruptImpl1::handleIntPressed()
|
void UpDownInterruptImpl1::handleIntPressed()
|
||||||
{
|
{
|
||||||
upDownInterruptImpl1->intPressHandler();
|
upDownInterruptImpl1->intPressHandler();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,11 @@
|
|||||||
#define min_node_info_broadcast_secs 60 * 60 // No regular broadcasts of more than once an hour
|
#define min_node_info_broadcast_secs 60 * 60 // No regular broadcasts of more than once an hour
|
||||||
#define min_neighbor_info_broadcast_secs 4 * 60 * 60
|
#define min_neighbor_info_broadcast_secs 4 * 60 * 60
|
||||||
#define default_map_publish_interval_secs 60 * 60
|
#define default_map_publish_interval_secs 60 * 60
|
||||||
|
|
||||||
|
// Traffic management defaults
|
||||||
|
#define default_traffic_mgmt_position_precision_bits 24 // ~10m grid cells
|
||||||
|
#define default_traffic_mgmt_position_min_interval_secs ONE_DAY // 1 day between identical positions
|
||||||
|
|
||||||
#ifdef USERPREFS_RINGTONE_NAG_SECS
|
#ifdef USERPREFS_RINGTONE_NAG_SECS
|
||||||
#define default_ringtone_nag_secs USERPREFS_RINGTONE_NAG_SECS
|
#define default_ringtone_nag_secs USERPREFS_RINGTONE_NAG_SECS
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ void LoRaFEMInterface::init(void)
|
|||||||
pinMode(LORA_KCT8103L_PA_CSD, OUTPUT);
|
pinMode(LORA_KCT8103L_PA_CSD, OUTPUT);
|
||||||
digitalWrite(LORA_KCT8103L_PA_CSD, HIGH);
|
digitalWrite(LORA_KCT8103L_PA_CSD, HIGH);
|
||||||
pinMode(LORA_KCT8103L_PA_CTX, OUTPUT);
|
pinMode(LORA_KCT8103L_PA_CTX, OUTPUT);
|
||||||
digitalWrite(LORA_KCT8103L_PA_CTX, HIGH);
|
digitalWrite(LORA_KCT8103L_PA_CTX, LOW); // LNA enabled by default
|
||||||
setLnaCanControl(true);
|
setLnaCanControl(true);
|
||||||
} else if (digitalRead(LORA_KCT8103L_PA_CSD) == LOW) {
|
} else if (digitalRead(LORA_KCT8103L_PA_CSD) == LOW) {
|
||||||
// FEM is GC1109
|
// FEM is GC1109
|
||||||
@@ -66,7 +66,7 @@ void LoRaFEMInterface::init(void)
|
|||||||
pinMode(LORA_KCT8103L_PA_CSD, OUTPUT);
|
pinMode(LORA_KCT8103L_PA_CSD, OUTPUT);
|
||||||
digitalWrite(LORA_KCT8103L_PA_CSD, HIGH);
|
digitalWrite(LORA_KCT8103L_PA_CSD, HIGH);
|
||||||
pinMode(LORA_KCT8103L_PA_CTX, OUTPUT);
|
pinMode(LORA_KCT8103L_PA_CTX, OUTPUT);
|
||||||
digitalWrite(LORA_KCT8103L_PA_CTX, HIGH);
|
digitalWrite(LORA_KCT8103L_PA_CTX, LOW); // LNA enabled by default
|
||||||
setLnaCanControl(true);
|
setLnaCanControl(true);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class LoRaFEMInterface
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
LoRaFEMType fem_type;
|
LoRaFEMType fem_type;
|
||||||
bool lna_enabled = false;
|
bool lna_enabled = true;
|
||||||
bool lna_can_control = false;
|
bool lna_can_control = false;
|
||||||
};
|
};
|
||||||
extern LoRaFEMInterface loraFEMInterface;
|
extern LoRaFEMInterface loraFEMInterface;
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
#if !MESHTASTIC_EXCLUDE_TRACEROUTE
|
#if !MESHTASTIC_EXCLUDE_TRACEROUTE
|
||||||
#include "modules/TraceRouteModule.h"
|
#include "modules/TraceRouteModule.h"
|
||||||
#endif
|
#endif
|
||||||
|
#if HAS_TRAFFIC_MANAGEMENT
|
||||||
|
#include "modules/TrafficManagementModule.h"
|
||||||
|
#endif
|
||||||
#include "NodeDB.h"
|
#include "NodeDB.h"
|
||||||
|
|
||||||
NextHopRouter::NextHopRouter() {}
|
NextHopRouter::NextHopRouter() {}
|
||||||
@@ -126,15 +129,28 @@ void NextHopRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtast
|
|||||||
/* Check if we should be rebroadcasting this packet if so, do so. */
|
/* Check if we should be rebroadcasting this packet if so, do so. */
|
||||||
bool NextHopRouter::perhapsRebroadcast(const meshtastic_MeshPacket *p)
|
bool NextHopRouter::perhapsRebroadcast(const meshtastic_MeshPacket *p)
|
||||||
{
|
{
|
||||||
if (!isToUs(p) && !isFromUs(p) && p->hop_limit > 0) {
|
// Check if traffic management wants to exhaust this packet's hops
|
||||||
|
bool exhaustHops = false;
|
||||||
|
#if HAS_TRAFFIC_MANAGEMENT
|
||||||
|
if (trafficManagementModule && trafficManagementModule->shouldExhaustHops(*p)) {
|
||||||
|
exhaustHops = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Allow rebroadcast if hop_limit > 0 OR if we're exhausting hops (which sets hop_limit = 0 but still needs one relay)
|
||||||
|
if (!isToUs(p) && !isFromUs(p) && (p->hop_limit > 0 || exhaustHops)) {
|
||||||
if (p->id != 0) {
|
if (p->id != 0) {
|
||||||
if (isRebroadcaster()) {
|
if (isRebroadcaster()) {
|
||||||
if (p->next_hop == NO_NEXT_HOP_PREFERENCE || p->next_hop == nodeDB->getLastByteOfNodeNum(getNodeNum())) {
|
if (p->next_hop == NO_NEXT_HOP_PREFERENCE || p->next_hop == nodeDB->getLastByteOfNodeNum(getNodeNum())) {
|
||||||
meshtastic_MeshPacket *tosend = packetPool.allocCopy(*p); // keep a copy because we will be sending it
|
meshtastic_MeshPacket *tosend = packetPool.allocCopy(*p); // keep a copy because we will be sending it
|
||||||
LOG_INFO("Rebroadcast received message coming from %x", p->relay_node);
|
LOG_INFO("Rebroadcast received message coming from %x", p->relay_node);
|
||||||
|
|
||||||
// Use shared logic to determine if hop_limit should be decremented
|
// If exhausting hops, force hop_limit = 0 regardless of other logic
|
||||||
if (shouldDecrementHopLimit(p)) {
|
if (exhaustHops) {
|
||||||
|
tosend->hop_limit = 0;
|
||||||
|
LOG_INFO("Traffic management: exhausting hops for 0x%08x, setting hop_limit=0", getFrom(p));
|
||||||
|
} else if (shouldDecrementHopLimit(p)) {
|
||||||
|
// Use shared logic to determine if hop_limit should be decremented
|
||||||
tosend->hop_limit--; // bump down the hop count
|
tosend->hop_limit--; // bump down the hop count
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("favorite-ROUTER/CLIENT_BASE-to-ROUTER/CLIENT_BASE rebroadcast: preserving hop_limit");
|
LOG_INFO("favorite-ROUTER/CLIENT_BASE-to-ROUTER/CLIENT_BASE rebroadcast: preserving hop_limit");
|
||||||
|
|||||||
+45
-1
@@ -569,7 +569,7 @@ void NodeDB::installDefaultConfig(bool preserveKey = false)
|
|||||||
config.lora.override_duty_cycle = false;
|
config.lora.override_duty_cycle = false;
|
||||||
config.lora.config_ok_to_mqtt = false;
|
config.lora.config_ok_to_mqtt = false;
|
||||||
#if HAS_LORA_FEM
|
#if HAS_LORA_FEM
|
||||||
config.lora.fem_lna_mode = meshtastic_Config_LoRaConfig_FEM_LNA_Mode_DISABLED;
|
config.lora.fem_lna_mode = meshtastic_Config_LoRaConfig_FEM_LNA_Mode_ENABLED;
|
||||||
#else
|
#else
|
||||||
config.lora.fem_lna_mode = meshtastic_Config_LoRaConfig_FEM_LNA_Mode_NOT_PRESENT;
|
config.lora.fem_lna_mode = meshtastic_Config_LoRaConfig_FEM_LNA_Mode_NOT_PRESENT;
|
||||||
#endif
|
#endif
|
||||||
@@ -910,8 +910,17 @@ void NodeDB::installDefaultModuleConfig()
|
|||||||
moduleConfig.neighbor_info.enabled = false;
|
moduleConfig.neighbor_info.enabled = false;
|
||||||
|
|
||||||
moduleConfig.has_detection_sensor = true;
|
moduleConfig.has_detection_sensor = true;
|
||||||
|
#ifdef DETECTION_SENSOR_DEFAULT_PIN
|
||||||
|
moduleConfig.detection_sensor.enabled = true;
|
||||||
|
moduleConfig.detection_sensor.monitor_pin = DETECTION_SENSOR_DEFAULT_PIN;
|
||||||
|
moduleConfig.detection_sensor.detection_trigger_type =
|
||||||
|
meshtastic_ModuleConfig_DetectionSensorConfig_TriggerType_EITHER_EDGE_ACTIVE_HIGH;
|
||||||
|
moduleConfig.detection_sensor.use_pullup = true;
|
||||||
|
strncpy(moduleConfig.detection_sensor.name, "Tamper", sizeof(moduleConfig.detection_sensor.name));
|
||||||
|
#else
|
||||||
moduleConfig.detection_sensor.enabled = false;
|
moduleConfig.detection_sensor.enabled = false;
|
||||||
moduleConfig.detection_sensor.detection_trigger_type = meshtastic_ModuleConfig_DetectionSensorConfig_TriggerType_LOGIC_HIGH;
|
moduleConfig.detection_sensor.detection_trigger_type = meshtastic_ModuleConfig_DetectionSensorConfig_TriggerType_LOGIC_HIGH;
|
||||||
|
#endif
|
||||||
moduleConfig.detection_sensor.minimum_broadcast_secs = 45;
|
moduleConfig.detection_sensor.minimum_broadcast_secs = 45;
|
||||||
|
|
||||||
moduleConfig.has_ambient_lighting = true;
|
moduleConfig.has_ambient_lighting = true;
|
||||||
@@ -1650,6 +1659,25 @@ uint32_t sinceReceived(const meshtastic_MeshPacket *p)
|
|||||||
return delta;
|
return delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HopStartStatus classifyHopStart(const meshtastic_MeshPacket &p)
|
||||||
|
{
|
||||||
|
// Guard against invalid values.
|
||||||
|
if (p.hop_start < p.hop_limit)
|
||||||
|
return HopStartStatus::INVALID;
|
||||||
|
|
||||||
|
if (p.hop_start == 0) {
|
||||||
|
// Firmware prior to 2.3.0 (585805c) lacked a hop_start field. Firmware version 2.5.0 (bf34329) introduced a
|
||||||
|
// bitfield that is always present. Use the presence of the bitfield to determine if the origin's firmware
|
||||||
|
// version is guaranteed to have hop_start populated. Note that this can only be done for decoded packets as
|
||||||
|
// the bitfield is encrypted under the channel encryption key.
|
||||||
|
if (p.which_payload_variant == meshtastic_MeshPacket_decoded_tag && p.decoded.has_bitfield)
|
||||||
|
return HopStartStatus::VALID;
|
||||||
|
return HopStartStatus::MISSING_OR_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return HopStartStatus::VALID;
|
||||||
|
}
|
||||||
|
|
||||||
int8_t getHopsAway(const meshtastic_MeshPacket &p, int8_t defaultIfUnknown)
|
int8_t getHopsAway(const meshtastic_MeshPacket &p, int8_t defaultIfUnknown)
|
||||||
{
|
{
|
||||||
// Firmware prior to 2.3.0 (585805c) lacked a hop_start field. Firmware version 2.5.0 (bf34329) introduced a
|
// Firmware prior to 2.3.0 (585805c) lacked a hop_start field. Firmware version 2.5.0 (bf34329) introduced a
|
||||||
@@ -1687,6 +1715,22 @@ size_t NodeDB::getNumOnlineMeshNodes(bool localOnly)
|
|||||||
#include "MeshModule.h"
|
#include "MeshModule.h"
|
||||||
#include "Throttle.h"
|
#include "Throttle.h"
|
||||||
|
|
||||||
|
static constexpr uint32_t HOPSTART_DROP_LOG_INTERVAL_MS = 15000;
|
||||||
|
|
||||||
|
void logHopStartDrop(const meshtastic_MeshPacket &p, const char *context)
|
||||||
|
{
|
||||||
|
static uint32_t lastLogMs = 0;
|
||||||
|
if (Throttle::isWithinTimespanMs(lastLogMs, HOPSTART_DROP_LOG_INTERVAL_MS)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastLogMs = millis();
|
||||||
|
const bool decoded = (p.which_payload_variant == meshtastic_MeshPacket_decoded_tag);
|
||||||
|
const bool hasBitfield = decoded && p.decoded.has_bitfield;
|
||||||
|
LOG_DEBUG(
|
||||||
|
"Drop packet (%s): hop_start invalid/missing (from=0x%x id=%u hop_start=%u hop_limit=%u decoded=%d has_bitfield=%d)",
|
||||||
|
context ? context : "unknown", p.from, p.id, p.hop_start, p.hop_limit, decoded, hasBitfield);
|
||||||
|
}
|
||||||
|
|
||||||
/** Update position info for this node based on received position data
|
/** Update position info for this node based on received position data
|
||||||
*/
|
*/
|
||||||
void NodeDB::updatePosition(uint32_t nodeId, const meshtastic_Position &p, RxSource src)
|
void NodeDB::updatePosition(uint32_t nodeId, const meshtastic_Position &p, RxSource src)
|
||||||
|
|||||||
@@ -114,6 +114,27 @@ uint32_t sinceReceived(const meshtastic_MeshPacket *p);
|
|||||||
/// Returns defaultIfUnknown if the number of hops couldn't be determined.
|
/// Returns defaultIfUnknown if the number of hops couldn't be determined.
|
||||||
int8_t getHopsAway(const meshtastic_MeshPacket &p, int8_t defaultIfUnknown = -1);
|
int8_t getHopsAway(const meshtastic_MeshPacket &p, int8_t defaultIfUnknown = -1);
|
||||||
|
|
||||||
|
enum class HopStartStatus : uint8_t { VALID = 0, MISSING_OR_UNKNOWN, INVALID };
|
||||||
|
|
||||||
|
/// Classify hop_start validity for forwarding decisions.
|
||||||
|
HopStartStatus classifyHopStart(const meshtastic_MeshPacket &p);
|
||||||
|
|
||||||
|
inline bool shouldDropPacketForPreHop(const meshtastic_MeshPacket &p)
|
||||||
|
{
|
||||||
|
#if !MESHTASTIC_PREHOP_DROP
|
||||||
|
(void)p;
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
|
if (isFromUs(&p)) {
|
||||||
|
return false; // local-originated packets should never be dropped by pre-hop drop policy
|
||||||
|
}
|
||||||
|
return classifyHopStart(p) != HopStartStatus::VALID;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Rate-limited debug log when hop_start is invalid/missing and packet is dropped.
|
||||||
|
void logHopStartDrop(const meshtastic_MeshPacket &p, const char *context);
|
||||||
|
|
||||||
enum LoadFileResult {
|
enum LoadFileResult {
|
||||||
// Successfully opened the file
|
// Successfully opened the file
|
||||||
LOAD_SUCCESS = 1,
|
LOAD_SUCCESS = 1,
|
||||||
|
|||||||
@@ -449,6 +449,11 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf)
|
|||||||
fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_paxcounter_tag;
|
fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_paxcounter_tag;
|
||||||
fromRadioScratch.moduleConfig.payload_variant.paxcounter = moduleConfig.paxcounter;
|
fromRadioScratch.moduleConfig.payload_variant.paxcounter = moduleConfig.paxcounter;
|
||||||
break;
|
break;
|
||||||
|
case meshtastic_ModuleConfig_traffic_management_tag:
|
||||||
|
LOG_DEBUG("Send module config: traffic management");
|
||||||
|
fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_traffic_management_tag;
|
||||||
|
fromRadioScratch.moduleConfig.payload_variant.traffic_management = moduleConfig.traffic_management;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
LOG_ERROR("Unknown module config type %d", config_state);
|
LOG_ERROR("Unknown module config type %d", config_state);
|
||||||
}
|
}
|
||||||
|
|||||||
+48
-1
@@ -11,6 +11,9 @@
|
|||||||
#include "mesh-pb-constants.h"
|
#include "mesh-pb-constants.h"
|
||||||
#include "meshUtils.h"
|
#include "meshUtils.h"
|
||||||
#include "modules/RoutingModule.h"
|
#include "modules/RoutingModule.h"
|
||||||
|
#if HAS_TRAFFIC_MANAGEMENT
|
||||||
|
#include "modules/TrafficManagementModule.h"
|
||||||
|
#endif
|
||||||
#if !MESHTASTIC_EXCLUDE_MQTT
|
#if !MESHTASTIC_EXCLUDE_MQTT
|
||||||
#include "mqtt/MQTT.h"
|
#include "mqtt/MQTT.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -95,6 +98,20 @@ bool Router::shouldDecrementHopLimit(const meshtastic_MeshPacket *p)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if HAS_TRAFFIC_MANAGEMENT
|
||||||
|
// When router_preserve_hops is enabled, preserve hops for decoded packets that are not
|
||||||
|
// position or telemetry (those have their own exhaust_hop controls).
|
||||||
|
if (moduleConfig.has_traffic_management && moduleConfig.traffic_management.enabled &&
|
||||||
|
moduleConfig.traffic_management.router_preserve_hops && p->which_payload_variant == meshtastic_MeshPacket_decoded_tag &&
|
||||||
|
p->decoded.portnum != meshtastic_PortNum_POSITION_APP && p->decoded.portnum != meshtastic_PortNum_TELEMETRY_APP) {
|
||||||
|
LOG_DEBUG("Router hop preserved: port=%d from=0x%08x (traffic_management)", p->decoded.portnum, getFrom(p));
|
||||||
|
if (trafficManagementModule) {
|
||||||
|
trafficManagementModule->recordRouterHopPreserved();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// For subsequent hops, check if previous relay is a favorite router
|
// For subsequent hops, check if previous relay is a favorite router
|
||||||
// Optimized search for favorite routers with matching last byte
|
// Optimized search for favorite routers with matching last byte
|
||||||
// Check ordering optimized for IoT devices (cheapest checks first)
|
// Check ordering optimized for IoT devices (cheapest checks first)
|
||||||
@@ -785,8 +802,32 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src)
|
|||||||
p_encrypted->pki_encrypted = true;
|
p_encrypted->pki_encrypted = true;
|
||||||
// After potentially altering it, publish received message to MQTT if we're not the original transmitter of the packet
|
// After potentially altering it, publish received message to MQTT if we're not the original transmitter of the packet
|
||||||
if ((decodedState == DecodeState::DECODE_SUCCESS || p_encrypted->pki_encrypted) && moduleConfig.mqtt.enabled &&
|
if ((decodedState == DecodeState::DECODE_SUCCESS || p_encrypted->pki_encrypted) && moduleConfig.mqtt.enabled &&
|
||||||
!isFromUs(p) && mqtt)
|
!isFromUs(p) && mqtt) {
|
||||||
|
if (decodedState == DecodeState::DECODE_SUCCESS && p->decoded.portnum == meshtastic_PortNum_TRACEROUTE_APP &&
|
||||||
|
moduleConfig.mqtt.encryption_enabled) {
|
||||||
|
// For TRACEROUTE_APP packets release the original encrypted packet and encrypt a new from the changed packet
|
||||||
|
// Only release the original after successful allocation to avoid losing an incomplete but valid packet
|
||||||
|
auto *p_encrypted_new = packetPool.allocCopy(*p);
|
||||||
|
if (p_encrypted_new) {
|
||||||
|
auto encodeResult = perhapsEncode(p_encrypted_new);
|
||||||
|
if (encodeResult != meshtastic_Routing_Error_NONE) {
|
||||||
|
// Encryption failed, release the new packet and fall back to sending the original encrypted packet to
|
||||||
|
// MQTT
|
||||||
|
LOG_WARN("Encryption of new TR packet failed, sending original TR to MQTT");
|
||||||
|
packetPool.release(p_encrypted_new);
|
||||||
|
p_encrypted_new = nullptr;
|
||||||
|
} else {
|
||||||
|
// Successfully re-encrypted, release the original encrypted packet and use the new one for MQTT
|
||||||
|
packetPool.release(p_encrypted);
|
||||||
|
p_encrypted = p_encrypted_new;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Allocation failed, log a warning and fall back to sending the original encrypted packet to MQTT
|
||||||
|
LOG_WARN("Failed to allocate new encrypted packet for TR, sending original TR to MQTT");
|
||||||
|
}
|
||||||
|
}
|
||||||
mqtt->onSend(*p_encrypted, *p, p->channel);
|
mqtt->onSend(*p_encrypted, *p, p->channel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -834,6 +875,12 @@ void Router::perhapsHandleReceived(meshtastic_MeshPacket *p)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shouldDropPacketForPreHop(*p)) {
|
||||||
|
logHopStartDrop(*p, "pre-hop drop");
|
||||||
|
packetPool.release(p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (shouldFilterReceived(p)) {
|
if (shouldFilterReceived(p)) {
|
||||||
LOG_DEBUG("Incoming msg was filtered from 0x%x", p->from);
|
LOG_DEBUG("Incoming msg was filtered from 0x%x", p->from);
|
||||||
packetPool.release(p);
|
packetPool.release(p);
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ template <typename T> bool SX126xInterface<T>::init()
|
|||||||
loraFEMInterface.init();
|
loraFEMInterface.init();
|
||||||
// Apply saved FEM LNA mode from config
|
// Apply saved FEM LNA mode from config
|
||||||
if (loraFEMInterface.isLnaCanControl()) {
|
if (loraFEMInterface.isLnaCanControl()) {
|
||||||
loraFEMInterface.setLNAEnable(config.lora.fem_lna_mode == meshtastic_Config_LoRaConfig_FEM_LNA_Mode_ENABLED);
|
loraFEMInterface.setLNAEnable(config.lora.fem_lna_mode != meshtastic_Config_LoRaConfig_FEM_LNA_Mode_DISABLED);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
#include "ServerAPI.h"
|
#include "ServerAPI.h"
|
||||||
|
#include "Throttle.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
static constexpr uint32_t TCP_IDLE_TIMEOUT_MS = 15 * 60 * 1000UL;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
ServerAPI<T>::ServerAPI(T &_client) : StreamAPI(&client), concurrency::OSThread("ServerAPI"), client(_client)
|
ServerAPI<T>::ServerAPI(T &_client) : StreamAPI(&client), concurrency::OSThread("ServerAPI"), client(_client)
|
||||||
{
|
{
|
||||||
@@ -28,6 +31,12 @@ template <typename T> bool ServerAPI<T>::checkIsConnected()
|
|||||||
template <class T> int32_t ServerAPI<T>::runOnce()
|
template <class T> int32_t ServerAPI<T>::runOnce()
|
||||||
{
|
{
|
||||||
if (client.connected()) {
|
if (client.connected()) {
|
||||||
|
if (lastContactMsec > 0 && !Throttle::isWithinTimespanMs(lastContactMsec, TCP_IDLE_TIMEOUT_MS)) {
|
||||||
|
LOG_WARN("TCP connection timeout, no data for %lu ms", (unsigned long)(millis() - lastContactMsec));
|
||||||
|
close();
|
||||||
|
enabled = false;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return StreamAPI::runOncePart();
|
return StreamAPI::runOncePart();
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Client dropped connection, suspend API service");
|
LOG_INFO("Client dropped connection, suspend API service");
|
||||||
@@ -57,7 +66,7 @@ template <class T, class U> int32_t APIServerPort<T, U>::runOnce()
|
|||||||
#else
|
#else
|
||||||
auto client = U::available();
|
auto client = U::available();
|
||||||
#endif
|
#endif
|
||||||
#elif defined(ARCH_RP2040)
|
#elif defined(ARCH_RP2040) || defined(ARCH_NRF52)
|
||||||
auto client = U::accept();
|
auto client = U::accept();
|
||||||
#else
|
#else
|
||||||
auto client = U::available();
|
auto client = U::available();
|
||||||
|
|||||||
@@ -17,6 +17,15 @@ void initApiServer(int port)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void deInitApiServer()
|
||||||
|
{
|
||||||
|
if (apiPort) {
|
||||||
|
LOG_INFO("Deinit API server");
|
||||||
|
delete apiPort;
|
||||||
|
apiPort = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ethServerAPI::ethServerAPI(EthernetClient &_client) : ServerAPI(_client)
|
ethServerAPI::ethServerAPI(EthernetClient &_client) : ServerAPI(_client)
|
||||||
{
|
{
|
||||||
LOG_INFO("Incoming ethernet connection");
|
LOG_INFO("Incoming ethernet connection");
|
||||||
|
|||||||
@@ -24,4 +24,5 @@ class ethServerPort : public APIServerPort<ethServerAPI, EthernetServer>
|
|||||||
};
|
};
|
||||||
|
|
||||||
void initApiServer(int port = SERVER_API_DEFAULT_PORT);
|
void initApiServer(int port = SERVER_API_DEFAULT_PORT);
|
||||||
|
void deInitApiServer();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -32,6 +32,69 @@ static Periodic *ethEvent;
|
|||||||
static int32_t reconnectETH()
|
static int32_t reconnectETH()
|
||||||
{
|
{
|
||||||
if (config.network.eth_enabled) {
|
if (config.network.eth_enabled) {
|
||||||
|
|
||||||
|
// Detect W5100S chip reset by verifying the MAC address register.
|
||||||
|
// PoE power instability can brownout the W5100S while the MCU keeps running,
|
||||||
|
// causing all chip registers (MAC, IP, sockets) to revert to defaults.
|
||||||
|
uint8_t currentMac[6];
|
||||||
|
Ethernet.MACAddress(currentMac);
|
||||||
|
|
||||||
|
uint8_t expectedMac[6];
|
||||||
|
getMacAddr(expectedMac);
|
||||||
|
expectedMac[0] &= 0xfe;
|
||||||
|
|
||||||
|
if (memcmp(currentMac, expectedMac, 6) != 0) {
|
||||||
|
LOG_WARN("W5100S MAC mismatch (chip reset detected), reinitializing Ethernet");
|
||||||
|
|
||||||
|
syslog.disable();
|
||||||
|
#if !MESHTASTIC_EXCLUDE_SOCKETAPI
|
||||||
|
deInitApiServer();
|
||||||
|
#endif
|
||||||
|
#if HAS_UDP_MULTICAST
|
||||||
|
if (udpHandler) {
|
||||||
|
udpHandler->stop();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ethStartupComplete = false;
|
||||||
|
#ifndef DISABLE_NTP
|
||||||
|
ntp_renew = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef PIN_ETHERNET_RESET
|
||||||
|
pinMode(PIN_ETHERNET_RESET, OUTPUT);
|
||||||
|
digitalWrite(PIN_ETHERNET_RESET, LOW);
|
||||||
|
delay(100);
|
||||||
|
digitalWrite(PIN_ETHERNET_RESET, HIGH);
|
||||||
|
delay(100);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef RAK11310
|
||||||
|
ETH_SPI_PORT.setSCK(PIN_SPI0_SCK);
|
||||||
|
ETH_SPI_PORT.setTX(PIN_SPI0_MOSI);
|
||||||
|
ETH_SPI_PORT.setRX(PIN_SPI0_MISO);
|
||||||
|
ETH_SPI_PORT.begin();
|
||||||
|
#endif
|
||||||
|
Ethernet.init(ETH_SPI_PORT, PIN_ETHERNET_SS);
|
||||||
|
|
||||||
|
int status = 0;
|
||||||
|
if (config.network.address_mode == meshtastic_Config_NetworkConfig_AddressMode_DHCP) {
|
||||||
|
status = Ethernet.begin(expectedMac);
|
||||||
|
} else if (config.network.address_mode == meshtastic_Config_NetworkConfig_AddressMode_STATIC) {
|
||||||
|
Ethernet.begin(expectedMac, config.network.ipv4_config.ip, config.network.ipv4_config.dns,
|
||||||
|
config.network.ipv4_config.gateway, config.network.ipv4_config.subnet);
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status == 0) {
|
||||||
|
LOG_ERROR("Ethernet re-initialization failed, will retry");
|
||||||
|
return 5000;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_INFO("Ethernet reinitialized - IP %u.%u.%u.%u", Ethernet.localIP()[0], Ethernet.localIP()[1],
|
||||||
|
Ethernet.localIP()[2], Ethernet.localIP()[3]);
|
||||||
|
}
|
||||||
|
|
||||||
Ethernet.maintain();
|
Ethernet.maintain();
|
||||||
if (!ethStartupComplete) {
|
if (!ethStartupComplete) {
|
||||||
// Start web server
|
// Start web server
|
||||||
|
|||||||
@@ -69,6 +69,22 @@ static inline int get_max_num_nodes()
|
|||||||
/// Max number of channels allowed
|
/// Max number of channels allowed
|
||||||
#define MAX_NUM_CHANNELS (member_size(meshtastic_ChannelFile, channels) / member_size(meshtastic_ChannelFile, channels[0]))
|
#define MAX_NUM_CHANNELS (member_size(meshtastic_ChannelFile, channels) / member_size(meshtastic_ChannelFile, channels[0]))
|
||||||
|
|
||||||
|
// Traffic Management module configuration
|
||||||
|
// Enable per-variant by defining HAS_TRAFFIC_MANAGEMENT=1 in variant.h
|
||||||
|
#ifndef HAS_TRAFFIC_MANAGEMENT
|
||||||
|
#define HAS_TRAFFIC_MANAGEMENT 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Cache size for traffic management (number of nodes to track)
|
||||||
|
// Can be overridden per-variant based on available memory
|
||||||
|
#ifndef TRAFFIC_MANAGEMENT_CACHE_SIZE
|
||||||
|
#if HAS_TRAFFIC_MANAGEMENT
|
||||||
|
#define TRAFFIC_MANAGEMENT_CACHE_SIZE 1000
|
||||||
|
#else
|
||||||
|
#define TRAFFIC_MANAGEMENT_CACHE_SIZE 0
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/// helper function for encoding a record as a protobuf, any failures to encode are fatal and we will panic
|
/// helper function for encoding a record as a protobuf, any failures to encode are fatal and we will panic
|
||||||
/// returns the encoded packet size
|
/// returns the encoded packet size
|
||||||
size_t pb_encode_to_bytes(uint8_t *destbuf, size_t destbufsize, const pb_msgdesc_t *fields, const void *src_struct);
|
size_t pb_encode_to_bytes(uint8_t *destbuf, size_t destbufsize, const pb_msgdesc_t *fields, const void *src_struct);
|
||||||
@@ -90,4 +106,4 @@ bool writecb(pb_ostream_t *stream, const uint8_t *buf, size_t count);
|
|||||||
*/
|
*/
|
||||||
bool is_in_helper(uint32_t n, const uint32_t *array, pb_size_t count);
|
bool is_in_helper(uint32_t n, const uint32_t *array, pb_size_t count);
|
||||||
|
|
||||||
#define is_in_repeated(name, n) is_in_helper(n, name, name##_count)
|
#define is_in_repeated(name, n) is_in_helper(n, name, name##_count)
|
||||||
|
|||||||
@@ -73,6 +73,11 @@ class UdpMulticastHandler final
|
|||||||
LOG_DEBUG("Decoding MeshPacket from UDP len=%u", packetLength);
|
LOG_DEBUG("Decoding MeshPacket from UDP len=%u", packetLength);
|
||||||
bool isPacketDecoded = pb_decode_from_bytes(packet.data(), packetLength, &meshtastic_MeshPacket_msg, &mp);
|
bool isPacketDecoded = pb_decode_from_bytes(packet.data(), packetLength, &meshtastic_MeshPacket_msg, &mp);
|
||||||
if (isPacketDecoded && router && mp.which_payload_variant == meshtastic_MeshPacket_encrypted_tag) {
|
if (isPacketDecoded && router && mp.which_payload_variant == meshtastic_MeshPacket_encrypted_tag) {
|
||||||
|
// Drop packets with spoofed local origin — no legitimate LAN node should send from=0 or our own nodeNum
|
||||||
|
if (isFromUs(&mp)) {
|
||||||
|
LOG_WARN("UDP packet with spoofed local from=0x%x, dropping", mp.from);
|
||||||
|
return;
|
||||||
|
}
|
||||||
mp.transport_mechanism = meshtastic_MeshPacket_TransportMechanism_TRANSPORT_MULTICAST_UDP;
|
mp.transport_mechanism = meshtastic_MeshPacket_TransportMechanism_TRANSPORT_MULTICAST_UDP;
|
||||||
mp.pki_encrypted = false;
|
mp.pki_encrypted = false;
|
||||||
mp.public_key.size = 0;
|
mp.public_key.size = 0;
|
||||||
@@ -113,4 +118,4 @@ class UdpMulticastHandler final
|
|||||||
AsyncUDP udp;
|
AsyncUDP udp;
|
||||||
bool isRunning;
|
bool isRunning;
|
||||||
};
|
};
|
||||||
#endif // HAS_UDP_MULTICAST
|
#endif // HAS_UDP_MULTICAST
|
||||||
|
|||||||
@@ -800,7 +800,7 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c)
|
|||||||
#if HAS_LORA_FEM
|
#if HAS_LORA_FEM
|
||||||
// Apply FEM LNA mode from config (only meaningful on hardware that supports it)
|
// Apply FEM LNA mode from config (only meaningful on hardware that supports it)
|
||||||
if (loraFEMInterface.isLnaCanControl()) {
|
if (loraFEMInterface.isLnaCanControl()) {
|
||||||
loraFEMInterface.setLNAEnable(config.lora.fem_lna_mode == meshtastic_Config_LoRaConfig_FEM_LNA_Mode_ENABLED);
|
loraFEMInterface.setLNAEnable(config.lora.fem_lna_mode != meshtastic_Config_LoRaConfig_FEM_LNA_Mode_DISABLED);
|
||||||
} else if (config.lora.fem_lna_mode != meshtastic_Config_LoRaConfig_FEM_LNA_Mode_NOT_PRESENT) {
|
} else if (config.lora.fem_lna_mode != meshtastic_Config_LoRaConfig_FEM_LNA_Mode_NOT_PRESENT) {
|
||||||
// Hardware FEM does not support LNA control; normalize stored config to match actual capability
|
// Hardware FEM does not support LNA control; normalize stored config to match actual capability
|
||||||
LOG_WARN("FEM LNA mode configured but current FEM does not support LNA control; normalizing to NOT_PRESENT");
|
LOG_WARN("FEM LNA mode configured but current FEM does not support LNA control; normalizing to NOT_PRESENT");
|
||||||
@@ -1008,6 +1008,11 @@ bool AdminModule::handleSetModuleConfig(const meshtastic_ModuleConfig &c)
|
|||||||
moduleConfig.statusmessage = c.payload_variant.statusmessage;
|
moduleConfig.statusmessage = c.payload_variant.statusmessage;
|
||||||
shouldReboot = false;
|
shouldReboot = false;
|
||||||
break;
|
break;
|
||||||
|
case meshtastic_ModuleConfig_traffic_management_tag:
|
||||||
|
LOG_INFO("Set module config: Traffic Management");
|
||||||
|
moduleConfig.has_traffic_management = true;
|
||||||
|
moduleConfig.traffic_management = c.payload_variant.traffic_management;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
saveChanges(SEGMENT_MODULECONFIG, shouldReboot);
|
saveChanges(SEGMENT_MODULECONFIG, shouldReboot);
|
||||||
return true;
|
return true;
|
||||||
@@ -1193,6 +1198,11 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const
|
|||||||
res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_statusmessage_tag;
|
res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_statusmessage_tag;
|
||||||
res.get_module_config_response.payload_variant.statusmessage = moduleConfig.statusmessage;
|
res.get_module_config_response.payload_variant.statusmessage = moduleConfig.statusmessage;
|
||||||
break;
|
break;
|
||||||
|
case meshtastic_AdminMessage_ModuleConfigType_TRAFFICMANAGEMENT_CONFIG:
|
||||||
|
LOG_INFO("Get module config: Traffic Management");
|
||||||
|
res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_traffic_management_tag;
|
||||||
|
res.get_module_config_response.payload_variant.traffic_management = moduleConfig.traffic_management;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: The phone app needs to know the ls_secsvalue so it can properly expect sleep behavior.
|
// NOTE: The phone app needs to know the ls_secsvalue so it can properly expect sleep behavior.
|
||||||
|
|||||||
+140
-240
@@ -13,10 +13,12 @@
|
|||||||
#include "buzz.h"
|
#include "buzz.h"
|
||||||
#include "detect/ScanI2C.h"
|
#include "detect/ScanI2C.h"
|
||||||
#include "gps/RTC.h"
|
#include "gps/RTC.h"
|
||||||
|
#include "graphics/EmoteRenderer.h"
|
||||||
#include "graphics/Screen.h"
|
#include "graphics/Screen.h"
|
||||||
#include "graphics/SharedUIDisplay.h"
|
#include "graphics/SharedUIDisplay.h"
|
||||||
#include "graphics/draw/MessageRenderer.h"
|
#include "graphics/draw/MessageRenderer.h"
|
||||||
#include "graphics/draw/NotificationRenderer.h"
|
#include "graphics/draw/NotificationRenderer.h"
|
||||||
|
#include "graphics/draw/UIRenderer.h"
|
||||||
#include "graphics/emotes.h"
|
#include "graphics/emotes.h"
|
||||||
#include "graphics/images.h"
|
#include "graphics/images.h"
|
||||||
#include "input/SerialKeyboard.h"
|
#include "input/SerialKeyboard.h"
|
||||||
@@ -45,71 +47,6 @@ extern MessageStore messageStore;
|
|||||||
// Remove Canned message screen if no action is taken for some milliseconds
|
// Remove Canned message screen if no action is taken for some milliseconds
|
||||||
#define INACTIVATE_AFTER_MS 20000
|
#define INACTIVATE_AFTER_MS 20000
|
||||||
|
|
||||||
// Tokenize a message string into emote/text segments
|
|
||||||
static std::vector<std::pair<bool, String>> tokenizeMessageWithEmotes(const char *msg)
|
|
||||||
{
|
|
||||||
std::vector<std::pair<bool, String>> tokens;
|
|
||||||
int msgLen = strlen(msg);
|
|
||||||
int pos = 0;
|
|
||||||
while (pos < msgLen) {
|
|
||||||
const graphics::Emote *foundEmote = nullptr;
|
|
||||||
int foundLen = 0;
|
|
||||||
for (int j = 0; j < graphics::numEmotes; j++) {
|
|
||||||
const char *label = graphics::emotes[j].label;
|
|
||||||
int labelLen = strlen(label);
|
|
||||||
if (labelLen == 0)
|
|
||||||
continue;
|
|
||||||
if (strncmp(msg + pos, label, labelLen) == 0) {
|
|
||||||
if (!foundEmote || labelLen > foundLen) {
|
|
||||||
foundEmote = &graphics::emotes[j];
|
|
||||||
foundLen = labelLen;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (foundEmote) {
|
|
||||||
tokens.emplace_back(true, String(foundEmote->label));
|
|
||||||
pos += foundLen;
|
|
||||||
} else {
|
|
||||||
// Find next emote
|
|
||||||
int nextEmote = msgLen;
|
|
||||||
for (int j = 0; j < graphics::numEmotes; j++) {
|
|
||||||
const char *label = graphics::emotes[j].label;
|
|
||||||
if (!label || !*label)
|
|
||||||
continue;
|
|
||||||
const char *found = strstr(msg + pos, label);
|
|
||||||
if (found && (found - msg) < nextEmote) {
|
|
||||||
nextEmote = found - msg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int textLen = (nextEmote > pos) ? (nextEmote - pos) : (msgLen - pos);
|
|
||||||
if (textLen > 0) {
|
|
||||||
tokens.emplace_back(false, String(msg + pos).substring(0, textLen));
|
|
||||||
pos += textLen;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tokens;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render a single emote token centered vertically on a row
|
|
||||||
static void renderEmote(OLEDDisplay *display, int &nextX, int lineY, int rowHeight, const String &label)
|
|
||||||
{
|
|
||||||
const graphics::Emote *emote = nullptr;
|
|
||||||
for (int j = 0; j < graphics::numEmotes; j++) {
|
|
||||||
if (label == graphics::emotes[j].label) {
|
|
||||||
emote = &graphics::emotes[j];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (emote) {
|
|
||||||
int emoteYOffset = (rowHeight - emote->height) / 2; // vertically center the emote
|
|
||||||
display->drawXbm(nextX, lineY + emoteYOffset, emote->width, emote->height, emote->bitmap);
|
|
||||||
nextX += emote->width + 2; // spacing between tokens
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace graphics
|
namespace graphics
|
||||||
{
|
{
|
||||||
extern int bannerSignalBars;
|
extern int bannerSignalBars;
|
||||||
@@ -264,19 +201,20 @@ int CannedMessageModule::splitConfiguredMessages()
|
|||||||
}
|
}
|
||||||
void CannedMessageModule::drawHeader(OLEDDisplay *display, int16_t x, int16_t y, char *buffer)
|
void CannedMessageModule::drawHeader(OLEDDisplay *display, int16_t x, int16_t y, char *buffer)
|
||||||
{
|
{
|
||||||
if (graphics::currentResolution == graphics::ScreenResolution::High) {
|
(void)buffer;
|
||||||
if (this->dest == NODENUM_BROADCAST) {
|
|
||||||
display->drawStringf(x, y, buffer, "To: #%s", channels.getName(this->channel));
|
char header[96];
|
||||||
} else {
|
if (this->dest == NODENUM_BROADCAST) {
|
||||||
display->drawStringf(x, y, buffer, "To: @%s", getNodeName(this->dest));
|
const char *channelName = channels.getName(this->channel);
|
||||||
}
|
snprintf(header, sizeof(header), "To: #%s", channelName ? channelName : "?");
|
||||||
} else {
|
} else {
|
||||||
if (this->dest == NODENUM_BROADCAST) {
|
snprintf(header, sizeof(header), "To: @%s", getNodeName(this->dest));
|
||||||
display->drawStringf(x, y, buffer, "To: #%.20s", channels.getName(this->channel));
|
|
||||||
} else {
|
|
||||||
display->drawStringf(x, y, buffer, "To: @%s", getNodeName(this->dest));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int maxWidth = std::max(0, display->getWidth() - x);
|
||||||
|
char truncatedHeader[96];
|
||||||
|
graphics::UIRenderer::truncateStringWithEmotes(display, header, truncatedHeader, sizeof(truncatedHeader), maxWidth);
|
||||||
|
graphics::UIRenderer::drawStringWithEmotes(display, x, y, truncatedHeader, FONT_HEIGHT_SMALL, 1, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CannedMessageModule::resetSearch()
|
void CannedMessageModule::resetSearch()
|
||||||
@@ -370,6 +308,92 @@ bool CannedMessageModule::isCharInputAllowed() const
|
|||||||
{
|
{
|
||||||
return runState == CANNED_MESSAGE_RUN_STATE_FREETEXT || runState == CANNED_MESSAGE_RUN_STATE_DESTINATION_SELECTION;
|
return runState == CANNED_MESSAGE_RUN_STATE_FREETEXT || runState == CANNED_MESSAGE_RUN_STATE_DESTINATION_SELECTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int getRowHeightForEmoteText(const char *text, int minimumHeight, int emoteSpacing = 2)
|
||||||
|
{
|
||||||
|
// Grow the row only when an emote is taller than the font.
|
||||||
|
const auto metrics =
|
||||||
|
graphics::EmoteRenderer::analyzeLine(nullptr, text ? text : "", 0, graphics::emotes, graphics::numEmotes, emoteSpacing);
|
||||||
|
return std::max(minimumHeight, metrics.tallestHeight + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void drawCenteredEmoteText(OLEDDisplay *display, int x, int y, int rowHeight, const char *text, int emoteSpacing = 2)
|
||||||
|
{
|
||||||
|
// Center mixed text and emotes inside the row height.
|
||||||
|
const auto metrics = graphics::EmoteRenderer::analyzeLine(nullptr, text ? text : "", FONT_HEIGHT_SMALL, graphics::emotes,
|
||||||
|
graphics::numEmotes, emoteSpacing);
|
||||||
|
const int contentHeight = std::max(FONT_HEIGHT_SMALL, metrics.tallestHeight);
|
||||||
|
const int drawY = y + ((rowHeight - contentHeight) / 2);
|
||||||
|
graphics::EmoteRenderer::drawStringWithEmotes(display, x, drawY, text ? text : "", FONT_HEIGHT_SMALL, graphics::emotes,
|
||||||
|
graphics::numEmotes, emoteSpacing, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t firstWrappedTokenLen(const char *text)
|
||||||
|
{
|
||||||
|
// Fall back to one full emote or one UTF-8 glyph when width is tiny.
|
||||||
|
if (!text || !*text)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
const size_t textLen = strlen(text);
|
||||||
|
size_t matchLen = 0;
|
||||||
|
if (graphics::EmoteRenderer::findEmoteAt(text, textLen, 0, matchLen, graphics::emotes, graphics::numEmotes))
|
||||||
|
return matchLen;
|
||||||
|
|
||||||
|
return graphics::EmoteRenderer::utf8CharLen(static_cast<uint8_t>(text[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void drawWrappedEmoteText(OLEDDisplay *display, int x, int y, const char *text, int maxWidth, int minimumRowHeight,
|
||||||
|
int emoteSpacing = 2)
|
||||||
|
{
|
||||||
|
// Wrap onto multiple rows without splitting emotes.
|
||||||
|
if (!display || !text || maxWidth <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
constexpr size_t kLineBufferSize = 256;
|
||||||
|
char lineBuffer[kLineBufferSize];
|
||||||
|
const size_t textLen = strlen(text);
|
||||||
|
size_t offset = 0;
|
||||||
|
int yCursor = y;
|
||||||
|
|
||||||
|
while (offset < textLen) {
|
||||||
|
size_t copied = graphics::EmoteRenderer::truncateToWidth(display, text + offset, lineBuffer, sizeof(lineBuffer), maxWidth,
|
||||||
|
"", graphics::emotes, graphics::numEmotes, emoteSpacing);
|
||||||
|
size_t consumed = copied;
|
||||||
|
|
||||||
|
if (copied == 0) {
|
||||||
|
consumed = firstWrappedTokenLen(text + offset);
|
||||||
|
if (consumed == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
const size_t fallbackLen = std::min(consumed, sizeof(lineBuffer) - 1);
|
||||||
|
memcpy(lineBuffer, text + offset, fallbackLen);
|
||||||
|
lineBuffer[fallbackLen] = '\0';
|
||||||
|
consumed = fallbackLen;
|
||||||
|
} else if (text[offset + copied] != '\0') {
|
||||||
|
// Prefer wrapping at the last space when a full line does not fit.
|
||||||
|
size_t lastSpace = copied;
|
||||||
|
while (lastSpace > 0 && lineBuffer[lastSpace - 1] != ' ')
|
||||||
|
--lastSpace;
|
||||||
|
|
||||||
|
if (lastSpace > 0) {
|
||||||
|
consumed = lastSpace;
|
||||||
|
while (consumed > 0 && lineBuffer[consumed - 1] == ' ')
|
||||||
|
--consumed;
|
||||||
|
lineBuffer[consumed] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lineBuffer[0]) {
|
||||||
|
const int rowHeight = getRowHeightForEmoteText(lineBuffer, minimumRowHeight, emoteSpacing);
|
||||||
|
drawCenteredEmoteText(display, x, yCursor, rowHeight, lineBuffer, emoteSpacing);
|
||||||
|
yCursor += rowHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
offset += std::max<size_t>(consumed, 1);
|
||||||
|
while (offset < textLen && text[offset] == ' ')
|
||||||
|
++offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Main input event dispatcher for CannedMessageModule.
|
* Main input event dispatcher for CannedMessageModule.
|
||||||
* Routes keyboard/button/touch input to the correct handler based on the current runState.
|
* Routes keyboard/button/touch input to the correct handler based on the current runState.
|
||||||
@@ -491,18 +515,16 @@ bool CannedMessageModule::handleTabSwitch(const InputEvent *event)
|
|||||||
if (event->kbchar != 0x09)
|
if (event->kbchar != 0x09)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
updateState((runState == CANNED_MESSAGE_RUN_STATE_DESTINATION_SELECTION) ? CANNED_MESSAGE_RUN_STATE_FREETEXT
|
const cannedMessageModuleRunState targetState = (runState == CANNED_MESSAGE_RUN_STATE_DESTINATION_SELECTION)
|
||||||
: CANNED_MESSAGE_RUN_STATE_DESTINATION_SELECTION);
|
? CANNED_MESSAGE_RUN_STATE_FREETEXT
|
||||||
|
: CANNED_MESSAGE_RUN_STATE_DESTINATION_SELECTION;
|
||||||
|
|
||||||
destIndex = 0;
|
destIndex = 0;
|
||||||
scrollIndex = 0;
|
scrollIndex = 0;
|
||||||
// RESTORE THIS!
|
if (targetState == CANNED_MESSAGE_RUN_STATE_DESTINATION_SELECTION)
|
||||||
if (runState == CANNED_MESSAGE_RUN_STATE_DESTINATION_SELECTION)
|
|
||||||
updateDestinationSelectionList();
|
updateDestinationSelectionList();
|
||||||
|
|
||||||
updateState((runState == CANNED_MESSAGE_RUN_STATE_DESTINATION_SELECTION) ? CANNED_MESSAGE_RUN_STATE_FREETEXT
|
updateState(targetState, true);
|
||||||
: CANNED_MESSAGE_RUN_STATE_DESTINATION_SELECTION,
|
|
||||||
true);
|
|
||||||
|
|
||||||
UIFrameEvent e;
|
UIFrameEvent e;
|
||||||
e.action = UIFrameEvent::Action::REGENERATE_FRAMESET;
|
e.action = UIFrameEvent::Action::REGENERATE_FRAMESET;
|
||||||
@@ -1686,55 +1708,51 @@ void CannedMessageModule::drawDestinationSelectionScreen(OLEDDisplay *display, O
|
|||||||
|
|
||||||
int xOffset = 0;
|
int xOffset = 0;
|
||||||
int yOffset = row * (FONT_HEIGHT_SMALL - 4) + rowYOffset;
|
int yOffset = row * (FONT_HEIGHT_SMALL - 4) + rowYOffset;
|
||||||
char entryText[64] = "";
|
std::string entryText;
|
||||||
|
|
||||||
// Draw Channels First
|
// Draw Channels First
|
||||||
if (itemIndex < numActiveChannels) {
|
if (itemIndex < numActiveChannels) {
|
||||||
uint8_t channelIndex = this->activeChannelIndices[itemIndex];
|
uint8_t channelIndex = this->activeChannelIndices[itemIndex];
|
||||||
snprintf(entryText, sizeof(entryText), "#%s", channels.getName(channelIndex));
|
const char *channelName = channels.getName(channelIndex);
|
||||||
|
entryText = std::string("#") + (channelName ? channelName : "?");
|
||||||
}
|
}
|
||||||
// Then Draw Nodes
|
// Then Draw Nodes
|
||||||
else {
|
else {
|
||||||
int nodeIndex = itemIndex - numActiveChannels;
|
int nodeIndex = itemIndex - numActiveChannels;
|
||||||
if (nodeIndex >= 0 && nodeIndex < static_cast<int>(this->filteredNodes.size())) {
|
if (nodeIndex >= 0 && nodeIndex < static_cast<int>(this->filteredNodes.size())) {
|
||||||
meshtastic_NodeInfoLite *node = this->filteredNodes[nodeIndex].node;
|
meshtastic_NodeInfoLite *node = this->filteredNodes[nodeIndex].node;
|
||||||
if (node && node->user.long_name) {
|
if (node) {
|
||||||
strncpy(entryText, node->user.long_name, sizeof(entryText) - 1);
|
if (display->getWidth() <= 64) {
|
||||||
entryText[sizeof(entryText) - 1] = '\0';
|
entryText = node->user.short_name;
|
||||||
|
} else if (node->user.long_name[0]) {
|
||||||
|
entryText = node->user.long_name;
|
||||||
|
} else {
|
||||||
|
entryText = node->user.short_name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int availWidth = display->getWidth() -
|
int availWidth = display->getWidth() -
|
||||||
((graphics::currentResolution == graphics::ScreenResolution::High) ? 40 : 20) -
|
((graphics::currentResolution == graphics::ScreenResolution::High) ? 40 : 20) -
|
||||||
((node && node->is_favorite) ? 10 : 0);
|
((node && node->is_favorite) ? 10 : 0);
|
||||||
if (availWidth < 0)
|
if (availWidth < 0)
|
||||||
availWidth = 0;
|
availWidth = 0;
|
||||||
|
char truncatedEntry[96];
|
||||||
size_t origLen = strlen(entryText);
|
graphics::UIRenderer::truncateStringWithEmotes(display, entryText.c_str(), truncatedEntry, sizeof(truncatedEntry),
|
||||||
while (entryText[0] && display->getStringWidth(entryText) > availWidth) {
|
availWidth);
|
||||||
entryText[strlen(entryText) - 1] = '\0';
|
entryText = truncatedEntry;
|
||||||
}
|
|
||||||
if (strlen(entryText) < origLen) {
|
|
||||||
strcat(entryText, "...");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepend "* " if this is a favorite
|
// Prepend "* " if this is a favorite
|
||||||
if (node && node->is_favorite) {
|
if (node && node->is_favorite) {
|
||||||
size_t len = strlen(entryText);
|
entryText = "* " + entryText;
|
||||||
if (len + 2 < sizeof(entryText)) {
|
|
||||||
memmove(entryText + 2, entryText, len + 1);
|
|
||||||
entryText[0] = '*';
|
|
||||||
entryText[1] = ' ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (node) {
|
|
||||||
if (display->getWidth() <= 64) {
|
|
||||||
snprintf(entryText, sizeof(entryText), "%s", node->user.short_name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
graphics::UIRenderer::truncateStringWithEmotes(display, entryText.c_str(), truncatedEntry, sizeof(truncatedEntry),
|
||||||
|
availWidth);
|
||||||
|
entryText = truncatedEntry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(entryText) == 0 || strcmp(entryText, "Unknown") == 0)
|
if (entryText.empty() || entryText == "Unknown")
|
||||||
strcpy(entryText, "?");
|
entryText = "?";
|
||||||
|
|
||||||
// Highlight background (if selected)
|
// Highlight background (if selected)
|
||||||
if (itemIndex == destIndex) {
|
if (itemIndex == destIndex) {
|
||||||
@@ -1744,7 +1762,7 @@ void CannedMessageModule::drawDestinationSelectionScreen(OLEDDisplay *display, O
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw entry text
|
// Draw entry text
|
||||||
display->drawString(xOffset + 2, yOffset, entryText);
|
graphics::UIRenderer::drawStringWithEmotes(display, xOffset + 2, yOffset, entryText.c_str(), FONT_HEIGHT_SMALL, 1, false);
|
||||||
display->setColor(WHITE);
|
display->setColor(WHITE);
|
||||||
|
|
||||||
// Draw key icon (after highlight)
|
// Draw key icon (after highlight)
|
||||||
@@ -1785,15 +1803,10 @@ void CannedMessageModule::drawEmotePickerScreen(OLEDDisplay *display, OLEDDispla
|
|||||||
{
|
{
|
||||||
const int headerFontHeight = FONT_HEIGHT_SMALL; // Make sure this matches your actual small font height
|
const int headerFontHeight = FONT_HEIGHT_SMALL; // Make sure this matches your actual small font height
|
||||||
const int headerMargin = 2; // Extra pixels below header
|
const int headerMargin = 2; // Extra pixels below header
|
||||||
const int labelGap = 6;
|
const int labelGap = 4;
|
||||||
const int bitmapGapX = 4;
|
const int bitmapGapX = 4;
|
||||||
|
|
||||||
// Find max emote height (assume all same, or precalculated)
|
const int maxEmoteHeight = graphics::EmoteRenderer::maxEmoteHeight();
|
||||||
int maxEmoteHeight = 0;
|
|
||||||
for (int i = 0; i < graphics::numEmotes; ++i)
|
|
||||||
if (graphics::emotes[i].height > maxEmoteHeight)
|
|
||||||
maxEmoteHeight = graphics::emotes[i].height;
|
|
||||||
|
|
||||||
const int rowHeight = maxEmoteHeight + 2;
|
const int rowHeight = maxEmoteHeight + 2;
|
||||||
|
|
||||||
// Place header at top, then compute start of emote list
|
// Place header at top, then compute start of emote list
|
||||||
@@ -1840,14 +1853,16 @@ void CannedMessageModule::drawEmotePickerScreen(OLEDDisplay *display, OLEDDispla
|
|||||||
display->setColor(BLACK);
|
display->setColor(BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emote bitmap (left), 1px margin from highlight bar top
|
// Emote bitmap (left), centered inside the row
|
||||||
int emoteY = rowY + 1;
|
int labelStartX = x + bitmapGapX;
|
||||||
display->drawXbm(x + bitmapGapX, emoteY, emote.width, emote.height, emote.bitmap);
|
const int emoteY = rowY + ((rowHeight - emote.height) / 2);
|
||||||
|
display->drawXbm(labelStartX, emoteY, emote.width, emote.height, emote.bitmap);
|
||||||
|
labelStartX += emote.width;
|
||||||
|
|
||||||
// Emote label (right of bitmap)
|
// Emote label (right of bitmap)
|
||||||
display->setFont(FONT_MEDIUM);
|
display->setFont(FONT_MEDIUM);
|
||||||
int labelY = rowY + ((rowHeight - FONT_HEIGHT_MEDIUM) / 2);
|
int labelY = rowY + ((rowHeight - FONT_HEIGHT_MEDIUM) / 2);
|
||||||
display->drawString(x + bitmapGapX + emote.width + labelGap, labelY, emote.label);
|
display->drawString(labelStartX + labelGap, labelY, emote.label);
|
||||||
|
|
||||||
if (emoteIdx == emotePickerIndex)
|
if (emoteIdx == emotePickerIndex)
|
||||||
display->setColor(WHITE);
|
display->setColor(WHITE);
|
||||||
@@ -2007,91 +2022,7 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
|||||||
{
|
{
|
||||||
int inputY = 0 + y + FONT_HEIGHT_SMALL;
|
int inputY = 0 + y + FONT_HEIGHT_SMALL;
|
||||||
String msgWithCursor = this->drawWithCursor(this->freetext, this->cursor);
|
String msgWithCursor = this->drawWithCursor(this->freetext, this->cursor);
|
||||||
|
drawWrappedEmoteText(display, x, inputY, msgWithCursor.c_str(), display->getWidth() - x, FONT_HEIGHT_SMALL);
|
||||||
// Tokenize input into (isEmote, token) pairs
|
|
||||||
const char *msg = msgWithCursor.c_str();
|
|
||||||
std::vector<std::pair<bool, String>> tokens = tokenizeMessageWithEmotes(msg);
|
|
||||||
|
|
||||||
// Advanced word-wrapping (emotes + text, split by word, wrap inside word if needed)
|
|
||||||
std::vector<std::vector<std::pair<bool, String>>> lines;
|
|
||||||
std::vector<std::pair<bool, String>> currentLine;
|
|
||||||
int lineWidth = 0;
|
|
||||||
int maxWidth = display->getWidth();
|
|
||||||
for (auto &token : tokens) {
|
|
||||||
if (token.first) {
|
|
||||||
// Emote
|
|
||||||
int tokenWidth = 0;
|
|
||||||
for (int j = 0; j < graphics::numEmotes; j++) {
|
|
||||||
if (token.second == graphics::emotes[j].label) {
|
|
||||||
tokenWidth = graphics::emotes[j].width + 2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (lineWidth + tokenWidth > maxWidth && !currentLine.empty()) {
|
|
||||||
lines.push_back(currentLine);
|
|
||||||
currentLine.clear();
|
|
||||||
lineWidth = 0;
|
|
||||||
}
|
|
||||||
currentLine.push_back(token);
|
|
||||||
lineWidth += tokenWidth;
|
|
||||||
} else {
|
|
||||||
// Text: split by words and wrap inside word if needed
|
|
||||||
String text = token.second;
|
|
||||||
int pos = 0;
|
|
||||||
while (pos < static_cast<int>(text.length())) {
|
|
||||||
// Find next space (or end)
|
|
||||||
int spacePos = text.indexOf(' ', pos);
|
|
||||||
int endPos = (spacePos == -1) ? text.length() : spacePos + 1; // Include space
|
|
||||||
String word = text.substring(pos, endPos);
|
|
||||||
int wordWidth = display->getStringWidth(word);
|
|
||||||
|
|
||||||
if (lineWidth + wordWidth > maxWidth && lineWidth > 0) {
|
|
||||||
lines.push_back(currentLine);
|
|
||||||
currentLine.clear();
|
|
||||||
lineWidth = 0;
|
|
||||||
}
|
|
||||||
// If word itself too big, split by character
|
|
||||||
if (wordWidth > maxWidth) {
|
|
||||||
uint16_t charPos = 0;
|
|
||||||
while (charPos < word.length()) {
|
|
||||||
String oneChar = word.substring(charPos, charPos + 1);
|
|
||||||
int charWidth = display->getStringWidth(oneChar);
|
|
||||||
if (lineWidth + charWidth > maxWidth && lineWidth > 0) {
|
|
||||||
lines.push_back(currentLine);
|
|
||||||
currentLine.clear();
|
|
||||||
lineWidth = 0;
|
|
||||||
}
|
|
||||||
currentLine.push_back({false, oneChar});
|
|
||||||
lineWidth += charWidth;
|
|
||||||
charPos++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
currentLine.push_back({false, word});
|
|
||||||
lineWidth += wordWidth;
|
|
||||||
}
|
|
||||||
pos = endPos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!currentLine.empty())
|
|
||||||
lines.push_back(currentLine);
|
|
||||||
|
|
||||||
// Draw lines with emotes
|
|
||||||
int rowHeight = FONT_HEIGHT_SMALL;
|
|
||||||
int yLine = inputY;
|
|
||||||
for (const auto &line : lines) {
|
|
||||||
int nextX = x;
|
|
||||||
for (const auto &token : line) {
|
|
||||||
if (token.first) {
|
|
||||||
// Emote rendering centralized in helper
|
|
||||||
renderEmote(display, nextX, yLine, rowHeight, token.second);
|
|
||||||
} else {
|
|
||||||
display->drawString(nextX, yLine, token.second);
|
|
||||||
nextX += display->getStringWidth(token.second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
yLine += rowHeight;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
@@ -2106,7 +2037,6 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
|||||||
const int baseRowSpacing = FONT_HEIGHT_SMALL - 4;
|
const int baseRowSpacing = FONT_HEIGHT_SMALL - 4;
|
||||||
|
|
||||||
int topMsg;
|
int topMsg;
|
||||||
std::vector<int> rowHeights;
|
|
||||||
int _visibleRows;
|
int _visibleRows;
|
||||||
|
|
||||||
// Draw header (To: ...)
|
// Draw header (To: ...)
|
||||||
@@ -2122,36 +2052,15 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
|||||||
: 0;
|
: 0;
|
||||||
int countRows = std::min(messagesCount, _visibleRows);
|
int countRows = std::min(messagesCount, _visibleRows);
|
||||||
|
|
||||||
// Build per-row max height based on all emotes in line
|
|
||||||
for (int i = 0; i < countRows; i++) {
|
|
||||||
const char *msg = getMessageByIndex(topMsg + i);
|
|
||||||
int maxEmoteHeight = 0;
|
|
||||||
for (int j = 0; j < graphics::numEmotes; j++) {
|
|
||||||
const char *label = graphics::emotes[j].label;
|
|
||||||
if (!label || !*label)
|
|
||||||
continue;
|
|
||||||
const char *search = msg;
|
|
||||||
while ((search = strstr(search, label))) {
|
|
||||||
if (graphics::emotes[j].height > maxEmoteHeight)
|
|
||||||
maxEmoteHeight = graphics::emotes[j].height;
|
|
||||||
search += strlen(label); // Advance past this emote
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rowHeights.push_back(std::max(baseRowSpacing, maxEmoteHeight + 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw all message rows with multi-emote support
|
// Draw all message rows with multi-emote support
|
||||||
int yCursor = listYOffset;
|
int yCursor = listYOffset;
|
||||||
for (int vis = 0; vis < countRows; vis++) {
|
for (int vis = 0; vis < countRows; vis++) {
|
||||||
int msgIdx = topMsg + vis;
|
int msgIdx = topMsg + vis;
|
||||||
int lineY = yCursor;
|
int lineY = yCursor;
|
||||||
const char *msg = getMessageByIndex(msgIdx);
|
const char *msg = getMessageByIndex(msgIdx);
|
||||||
int rowHeight = rowHeights[vis];
|
int rowHeight = getRowHeightForEmoteText(msg, baseRowSpacing);
|
||||||
bool _highlight = (msgIdx == currentMessageIndex);
|
bool _highlight = (msgIdx == currentMessageIndex);
|
||||||
|
|
||||||
// Multi-emote tokenization
|
|
||||||
std::vector<std::pair<bool, String>> tokens = tokenizeMessageWithEmotes(msg);
|
|
||||||
|
|
||||||
// Vertically center based on rowHeight
|
// Vertically center based on rowHeight
|
||||||
int textYOffset = (rowHeight - FONT_HEIGHT_SMALL) / 2;
|
int textYOffset = (rowHeight - FONT_HEIGHT_SMALL) / 2;
|
||||||
|
|
||||||
@@ -2168,17 +2077,8 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
|||||||
int nextX = x + (_highlight ? 2 : 0);
|
int nextX = x + (_highlight ? 2 : 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Draw all tokens left to right
|
if (msg && *msg)
|
||||||
for (const auto &token : tokens) {
|
drawCenteredEmoteText(display, nextX, lineY, rowHeight, msg);
|
||||||
if (token.first) {
|
|
||||||
// Emote rendering centralized in helper
|
|
||||||
renderEmote(display, nextX, lineY, rowHeight, token.second);
|
|
||||||
} else {
|
|
||||||
// Text
|
|
||||||
display->drawString(nextX, lineY + textYOffset, token.second);
|
|
||||||
nextX += display->getStringWidth(token.second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#ifndef USE_EINK
|
#ifndef USE_EINK
|
||||||
if (_highlight)
|
if (_highlight)
|
||||||
display->setColor(WHITE);
|
display->setColor(WHITE);
|
||||||
|
|||||||
@@ -64,6 +64,11 @@ int32_t DetectionSensorModule::runOnce()
|
|||||||
if (moduleConfig.detection_sensor.enabled == false)
|
if (moduleConfig.detection_sensor.enabled == false)
|
||||||
return disable();
|
return disable();
|
||||||
|
|
||||||
|
#ifdef DETECTION_SENSOR_DEFAULT_PIN
|
||||||
|
if (moduleConfig.detection_sensor.monitor_pin == 0)
|
||||||
|
moduleConfig.detection_sensor.monitor_pin = DETECTION_SENSOR_DEFAULT_PIN;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (firstTime) {
|
if (firstTime) {
|
||||||
|
|
||||||
#ifdef DETECTION_SENSOR_EN
|
#ifdef DETECTION_SENSOR_EN
|
||||||
|
|||||||
@@ -38,6 +38,9 @@
|
|||||||
#include "modules/PowerStressModule.h"
|
#include "modules/PowerStressModule.h"
|
||||||
#endif
|
#endif
|
||||||
#include "modules/RoutingModule.h"
|
#include "modules/RoutingModule.h"
|
||||||
|
#if HAS_TRAFFIC_MANAGEMENT && !MESHTASTIC_EXCLUDE_TRAFFIC_MANAGEMENT
|
||||||
|
#include "modules/TrafficManagementModule.h"
|
||||||
|
#endif
|
||||||
#include "modules/TextMessageModule.h"
|
#include "modules/TextMessageModule.h"
|
||||||
#if !MESHTASTIC_EXCLUDE_TRACEROUTE
|
#if !MESHTASTIC_EXCLUDE_TRACEROUTE
|
||||||
#include "modules/TraceRouteModule.h"
|
#include "modules/TraceRouteModule.h"
|
||||||
@@ -120,6 +123,14 @@ void setupModules()
|
|||||||
#if !MESHTASTIC_EXCLUDE_REPLYBOT
|
#if !MESHTASTIC_EXCLUDE_REPLYBOT
|
||||||
new ReplyBotModule();
|
new ReplyBotModule();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if HAS_TRAFFIC_MANAGEMENT && !MESHTASTIC_EXCLUDE_TRAFFIC_MANAGEMENT
|
||||||
|
// Instantiate only when enabled to avoid extra memory use and background work.
|
||||||
|
if (moduleConfig.has_traffic_management && moduleConfig.traffic_management.enabled) {
|
||||||
|
trafficManagementModule = new TrafficManagementModule();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !MESHTASTIC_EXCLUDE_ADMIN
|
#if !MESHTASTIC_EXCLUDE_ADMIN
|
||||||
adminModule = new AdminModule();
|
adminModule = new AdminModule();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ bool SEN5XSensor::getVersion()
|
|||||||
}
|
}
|
||||||
delay(20); // From Sensirion Datasheet
|
delay(20); // From Sensirion Datasheet
|
||||||
|
|
||||||
uint8_t versionBuffer[12];
|
uint8_t versionBuffer[12]{};
|
||||||
size_t charNumber = readBuffer(&versionBuffer[0], 3);
|
size_t charNumber = readBuffer(&versionBuffer[0], 3);
|
||||||
if (charNumber == 0) {
|
if (charNumber == 0) {
|
||||||
LOG_ERROR("SEN5X: Error getting data ready flag value");
|
LOG_ERROR("SEN5X: Error getting data ready flag value");
|
||||||
@@ -638,7 +638,7 @@ bool SEN5XSensor::readValues()
|
|||||||
LOG_DEBUG("SEN5X: Reading PM Values");
|
LOG_DEBUG("SEN5X: Reading PM Values");
|
||||||
delay(20); // From Sensirion Datasheet
|
delay(20); // From Sensirion Datasheet
|
||||||
|
|
||||||
uint8_t dataBuffer[16];
|
uint8_t dataBuffer[16]{};
|
||||||
size_t receivedNumber = readBuffer(&dataBuffer[0], 24);
|
size_t receivedNumber = readBuffer(&dataBuffer[0], 24);
|
||||||
if (receivedNumber == 0) {
|
if (receivedNumber == 0) {
|
||||||
LOG_ERROR("SEN5X: Error getting values");
|
LOG_ERROR("SEN5X: Error getting values");
|
||||||
@@ -691,7 +691,7 @@ bool SEN5XSensor::readPNValues(bool cumulative)
|
|||||||
LOG_DEBUG("SEN5X: Reading PN Values");
|
LOG_DEBUG("SEN5X: Reading PN Values");
|
||||||
delay(20); // From Sensirion Datasheet
|
delay(20); // From Sensirion Datasheet
|
||||||
|
|
||||||
uint8_t dataBuffer[20];
|
uint8_t dataBuffer[20]{};
|
||||||
size_t receivedNumber = readBuffer(&dataBuffer[0], 30);
|
size_t receivedNumber = readBuffer(&dataBuffer[0], 30);
|
||||||
if (receivedNumber == 0) {
|
if (receivedNumber == 0) {
|
||||||
LOG_ERROR("SEN5X: Error getting PN values");
|
LOG_ERROR("SEN5X: Error getting PN values");
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,434 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "MeshModule.h"
|
||||||
|
#include "concurrency/Lock.h"
|
||||||
|
#include "concurrency/OSThread.h"
|
||||||
|
#include "mesh/generated/meshtastic/mesh.pb.h"
|
||||||
|
#include "mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
|
||||||
|
#if HAS_TRAFFIC_MANAGEMENT
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TrafficManagementModule - Packet inspection and traffic shaping for mesh networks.
|
||||||
|
*
|
||||||
|
* This module provides:
|
||||||
|
* - Position deduplication (drop redundant position broadcasts)
|
||||||
|
* - Per-node rate limiting (throttle chatty nodes)
|
||||||
|
* - Unknown packet filtering (drop undecoded packets from repeat offenders)
|
||||||
|
* - NodeInfo direct response (answer queries from cache to reduce mesh chatter)
|
||||||
|
* - Local-only telemetry/position (exhaust hop_limit for local broadcasts)
|
||||||
|
* - Router hop preservation (maintain hop_limit for router-to-router traffic)
|
||||||
|
*
|
||||||
|
* Memory Optimization:
|
||||||
|
* Uses a unified cache with cuckoo hashing for O(1) lookups and 56% memory reduction
|
||||||
|
* compared to separate per-feature caches. Timestamps are stored as 8-bit relative
|
||||||
|
* offsets from a rolling epoch to further reduce memory footprint.
|
||||||
|
*/
|
||||||
|
class TrafficManagementModule : public MeshModule, private concurrency::OSThread
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TrafficManagementModule();
|
||||||
|
~TrafficManagementModule();
|
||||||
|
|
||||||
|
// Singleton — no copying or moving
|
||||||
|
TrafficManagementModule(const TrafficManagementModule &) = delete;
|
||||||
|
TrafficManagementModule &operator=(const TrafficManagementModule &) = delete;
|
||||||
|
|
||||||
|
meshtastic_TrafficManagementStats getStats() const;
|
||||||
|
void resetStats();
|
||||||
|
void recordRouterHopPreserved();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this packet should have its hops exhausted.
|
||||||
|
* Called from perhapsRebroadcast() to force hop_limit = 0 regardless of
|
||||||
|
* router_preserve_hops or favorite node logic.
|
||||||
|
*/
|
||||||
|
bool shouldExhaustHops(const meshtastic_MeshPacket &mp) const
|
||||||
|
{
|
||||||
|
return exhaustRequested && exhaustRequestedFrom == getFrom(&mp) && exhaustRequestedId == mp.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override;
|
||||||
|
bool wantPacket(const meshtastic_MeshPacket *p) override { return true; }
|
||||||
|
void alterReceived(meshtastic_MeshPacket &mp) override;
|
||||||
|
int32_t runOnce() override;
|
||||||
|
// Protected so test shims can force epoch rollover behavior.
|
||||||
|
void resetEpoch(uint32_t nowMs);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// =========================================================================
|
||||||
|
// Unified Cache Entry (10 bytes) - Same for ALL platforms
|
||||||
|
// =========================================================================
|
||||||
|
//
|
||||||
|
// A single compact structure used across ESP32, NRF52, and all other platforms.
|
||||||
|
// Memory: 10 bytes × 2048 entries = 20KB
|
||||||
|
//
|
||||||
|
// Position Fingerprinting:
|
||||||
|
// Instead of storing full coordinates (8 bytes) or a computed hash,
|
||||||
|
// we store an 8-bit fingerprint derived deterministically from the
|
||||||
|
// truncated lat/lon. This extracts the lower 4 significant bits from
|
||||||
|
// each coordinate: fingerprint = (lat_low4 << 4) | lon_low4
|
||||||
|
//
|
||||||
|
// Benefits over hash:
|
||||||
|
// - Adjacent grid cells have sequential fingerprints (no collision)
|
||||||
|
// - Two positions only collide if 16+ grid cells apart in BOTH dimensions
|
||||||
|
// - Deterministic: same input always produces same output
|
||||||
|
//
|
||||||
|
// Adaptive Timestamp Resolution:
|
||||||
|
// All timestamps use 8-bit values with adaptive resolution calculated
|
||||||
|
// from config at startup. Resolution = max(60, min(339, interval/2)).
|
||||||
|
// - Min 60 seconds ensures reasonable precision
|
||||||
|
// - Max 339 seconds allows ~24 hour range (255 * 339 = 86445 sec)
|
||||||
|
// - interval/2 ensures at least 2 ticks per configured interval
|
||||||
|
//
|
||||||
|
// Layout:
|
||||||
|
// [0-3] node - NodeNum (4 bytes)
|
||||||
|
// [4] pos_fingerprint - 4 bits lat + 4 bits lon (1 byte)
|
||||||
|
// [5] rate_count - Packets in current window (1 byte)
|
||||||
|
// [6] unknown_count - Unknown packets count (1 byte)
|
||||||
|
// [7] pos_time - Position timestamp (1 byte, adaptive resolution)
|
||||||
|
// [8] rate_time - Rate window start (1 byte, adaptive resolution)
|
||||||
|
// [9] unknown_time - Unknown tracking start (1 byte, adaptive resolution)
|
||||||
|
//
|
||||||
|
struct __attribute__((packed)) UnifiedCacheEntry {
|
||||||
|
NodeNum node; // 4 bytes - Node identifier (0 = empty slot)
|
||||||
|
uint8_t pos_fingerprint; // 1 byte - Lower 4 bits of lat + lon
|
||||||
|
uint8_t rate_count; // 1 byte - Packet count (saturates at 255)
|
||||||
|
uint8_t unknown_count; // 1 byte - Unknown packet count (saturates at 255)
|
||||||
|
uint8_t pos_time; // 1 byte - Position timestamp (adaptive resolution)
|
||||||
|
uint8_t rate_time; // 1 byte - Rate window start (adaptive resolution)
|
||||||
|
uint8_t unknown_time; // 1 byte - Unknown tracking start (adaptive resolution)
|
||||||
|
};
|
||||||
|
static_assert(sizeof(UnifiedCacheEntry) == 10, "UnifiedCacheEntry should be 10 bytes");
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// Cuckoo Hash Table Implementation
|
||||||
|
// =========================================================================
|
||||||
|
//
|
||||||
|
// Cuckoo hashing provides O(1) worst-case lookup time using two hash functions.
|
||||||
|
// Each key can be in one of two possible locations (h1 or h2). On collision,
|
||||||
|
// the existing entry is "kicked" to its alternate location.
|
||||||
|
//
|
||||||
|
// Benefits over linear scan:
|
||||||
|
// - O(1) lookup vs O(n) - critical at packet processing rates
|
||||||
|
// - O(1) insertion (amortized) with simple eviction on cycles
|
||||||
|
// - ~95% load factor achievable
|
||||||
|
//
|
||||||
|
// Cache size rounds to power-of-2 for fast modulo via bitmask.
|
||||||
|
// TRAFFIC_MANAGEMENT_CACHE_SIZE=2000 → cacheSize()=2048
|
||||||
|
//
|
||||||
|
static constexpr uint16_t cacheSize();
|
||||||
|
static constexpr uint16_t cacheMask();
|
||||||
|
|
||||||
|
// Hash functions for cuckoo hashing
|
||||||
|
inline uint16_t cuckooHash1(NodeNum node) const { return node & cacheMask(); }
|
||||||
|
inline uint16_t cuckooHash2(NodeNum node) const { return ((node * 2654435769u) >> (32 - cuckooHashBits())) & cacheMask(); }
|
||||||
|
static constexpr uint8_t cuckooHashBits();
|
||||||
|
|
||||||
|
// NodeInfo cache configuration (PSRAM path):
|
||||||
|
// - Payload lives in PSRAM
|
||||||
|
// - DRAM keeps packed 12-bit tags with 4-way bucketed cuckoo hashing
|
||||||
|
// (Fan et al., CoNEXT 2014). Tag value 0 is reserved as "empty".
|
||||||
|
static constexpr uint16_t kNodeInfoIndexMetadataBudgetBytes = 3072; // 3KB DRAM tag store
|
||||||
|
static constexpr uint8_t kNodeInfoTargetOccupancyPercent = 95;
|
||||||
|
static constexpr uint8_t kNodeInfoBucketSize = 4;
|
||||||
|
static constexpr uint8_t kNodeInfoTagBits = 12;
|
||||||
|
static constexpr uint16_t kNodeInfoTagMask = static_cast<uint16_t>((1u << kNodeInfoTagBits) - 1u);
|
||||||
|
static constexpr uint16_t kNodeInfoIndexSlotsRaw =
|
||||||
|
static_cast<uint16_t>((kNodeInfoIndexMetadataBudgetBytes * 8u) / kNodeInfoTagBits);
|
||||||
|
static constexpr uint16_t kNodeInfoIndexSlots =
|
||||||
|
static_cast<uint16_t>(kNodeInfoIndexSlotsRaw - (kNodeInfoIndexSlotsRaw % kNodeInfoBucketSize));
|
||||||
|
static constexpr uint16_t kNodeInfoTargetEntries =
|
||||||
|
static_cast<uint16_t>((kNodeInfoIndexSlots * kNodeInfoTargetOccupancyPercent) / 100u);
|
||||||
|
static_assert((kNodeInfoIndexSlots % kNodeInfoBucketSize) == 0, "NodeInfo slot count must align to bucket size");
|
||||||
|
static_assert(kNodeInfoTargetEntries < (1u << kNodeInfoTagBits), "NodeInfo tag bits must encode payload index");
|
||||||
|
|
||||||
|
static constexpr uint16_t nodeInfoTargetEntries();
|
||||||
|
static constexpr uint16_t nodeInfoIndexMetadataBudgetBytes();
|
||||||
|
static constexpr uint8_t nodeInfoTargetOccupancyPercent();
|
||||||
|
static constexpr uint8_t nodeInfoBucketSize();
|
||||||
|
static constexpr uint8_t nodeInfoTagBits();
|
||||||
|
static constexpr uint16_t nodeInfoTagMask();
|
||||||
|
static constexpr uint16_t nodeInfoIndexSlots();
|
||||||
|
static constexpr uint16_t nodeInfoBucketCount();
|
||||||
|
static constexpr uint16_t nodeInfoBucketMask();
|
||||||
|
static constexpr uint8_t nodeInfoBucketHashBits();
|
||||||
|
inline uint16_t nodeInfoHash1(NodeNum node) const { return node & nodeInfoBucketMask(); }
|
||||||
|
inline uint16_t nodeInfoHash2(NodeNum node) const
|
||||||
|
{
|
||||||
|
return ((node * 2246822519u) >> (32 - nodeInfoBucketHashBits())) & nodeInfoBucketMask();
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// Adaptive Timestamp Resolution
|
||||||
|
// =========================================================================
|
||||||
|
//
|
||||||
|
// All timestamps use 8-bit values with adaptive resolution calculated from
|
||||||
|
// config at startup. This allows ~24 hour range while maintaining precision.
|
||||||
|
//
|
||||||
|
// Resolution formula: max(60, min(339, interval/2))
|
||||||
|
// - 60 sec minimum ensures reasonable precision
|
||||||
|
// - 339 sec maximum allows 24 hour range (255 * 339 ≈ 86400 sec)
|
||||||
|
// - interval/2 ensures at least 2 ticks per configured interval
|
||||||
|
//
|
||||||
|
// Since config changes require reboot, resolution is calculated once.
|
||||||
|
//
|
||||||
|
uint32_t cacheEpochMs = 0;
|
||||||
|
uint16_t posTimeResolution = 60; // Seconds per tick for position
|
||||||
|
uint16_t rateTimeResolution = 60; // Seconds per tick for rate limiting
|
||||||
|
uint16_t unknownTimeResolution = 60; // Seconds per tick for unknown tracking
|
||||||
|
|
||||||
|
// Calculate resolution from configured interval (called once at startup)
|
||||||
|
static uint16_t calcTimeResolution(uint32_t intervalSecs)
|
||||||
|
{
|
||||||
|
// Resolution = interval/2 to ensure at least 2 ticks per interval
|
||||||
|
// Clamped to [60, 339] for min precision and max 24h range
|
||||||
|
uint32_t res = (intervalSecs > 0) ? (intervalSecs / 2) : 60;
|
||||||
|
if (res < 60)
|
||||||
|
res = 60;
|
||||||
|
if (res > 339)
|
||||||
|
res = 339;
|
||||||
|
return static_cast<uint16_t>(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert to/from 8-bit relative timestamps with given resolution
|
||||||
|
uint8_t toRelativeTime(uint32_t nowMs, uint16_t resolutionSecs) const
|
||||||
|
{
|
||||||
|
uint32_t ticks = (nowMs - cacheEpochMs) / (resolutionSecs * 1000UL);
|
||||||
|
return (ticks > UINT8_MAX) ? UINT8_MAX : static_cast<uint8_t>(ticks);
|
||||||
|
}
|
||||||
|
uint32_t fromRelativeTime(uint8_t ticks, uint16_t resolutionSecs) const
|
||||||
|
{
|
||||||
|
return cacheEpochMs + (static_cast<uint32_t>(ticks) * resolutionSecs * 1000UL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convenience wrappers for each timestamp type
|
||||||
|
uint8_t toRelativePosTime(uint32_t nowMs) const { return toRelativeTime(nowMs, posTimeResolution); }
|
||||||
|
uint32_t fromRelativePosTime(uint8_t t) const { return fromRelativeTime(t, posTimeResolution); }
|
||||||
|
|
||||||
|
uint8_t toRelativeRateTime(uint32_t nowMs) const { return toRelativeTime(nowMs, rateTimeResolution); }
|
||||||
|
uint32_t fromRelativeRateTime(uint8_t t) const { return fromRelativeTime(t, rateTimeResolution); }
|
||||||
|
|
||||||
|
uint8_t toRelativeUnknownTime(uint32_t nowMs) const { return toRelativeTime(nowMs, unknownTimeResolution); }
|
||||||
|
uint32_t fromRelativeUnknownTime(uint8_t t) const { return fromRelativeTime(t, unknownTimeResolution); }
|
||||||
|
|
||||||
|
// Epoch reset when any timestamp approaches overflow
|
||||||
|
// With max resolution of 339 sec, 200 ticks = ~19 hours (safe margin for 24h max)
|
||||||
|
bool needsEpochReset(uint32_t nowMs) const
|
||||||
|
{
|
||||||
|
uint16_t maxRes = posTimeResolution;
|
||||||
|
if (rateTimeResolution > maxRes)
|
||||||
|
maxRes = rateTimeResolution;
|
||||||
|
if (unknownTimeResolution > maxRes)
|
||||||
|
maxRes = unknownTimeResolution;
|
||||||
|
return (nowMs - cacheEpochMs) > (200UL * maxRes * 1000UL);
|
||||||
|
}
|
||||||
|
// =========================================================================
|
||||||
|
// Position Fingerprint
|
||||||
|
// =========================================================================
|
||||||
|
//
|
||||||
|
// Computes 8-bit fingerprint from truncated lat/lon coordinates.
|
||||||
|
// Extracts lower 4 significant bits from each coordinate.
|
||||||
|
//
|
||||||
|
// fingerprint = (lat_low4 << 4) | lon_low4
|
||||||
|
//
|
||||||
|
// Unlike a hash, adjacent grid cells have sequential fingerprints,
|
||||||
|
// so nearby positions never collide. Collisions only occur for
|
||||||
|
// positions 16+ grid cells apart in both dimensions.
|
||||||
|
//
|
||||||
|
// Guards: If precision < 4 bits, uses min(precision, 4) bits.
|
||||||
|
//
|
||||||
|
static uint8_t computePositionFingerprint(int32_t lat_truncated, int32_t lon_truncated, uint8_t precision);
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// Cache Storage
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
|
mutable concurrency::Lock cacheLock; // Protects all cache access
|
||||||
|
UnifiedCacheEntry *cache = nullptr; // Cuckoo hash table (unified for all platforms)
|
||||||
|
bool cacheFromPsram = false; // Tracks allocator for correct deallocation
|
||||||
|
|
||||||
|
struct NodeInfoPayloadEntry {
|
||||||
|
// Node identifier associated with this payload slot.
|
||||||
|
// 0 means the slot is currently unused.
|
||||||
|
NodeNum node;
|
||||||
|
|
||||||
|
// Cached NODEINFO_APP payload body. This is separate from NodeDB and is only
|
||||||
|
// used by the PSRAM-backed direct-response path in this module.
|
||||||
|
meshtastic_User user;
|
||||||
|
|
||||||
|
// Extra response metadata captured from the latest observed NODEINFO_APP
|
||||||
|
// packet for this node. shouldRespondToNodeInfo() uses this metadata when
|
||||||
|
// building spoofed replies for requesting clients.
|
||||||
|
|
||||||
|
// Last local uptime tick (millis) when this entry was refreshed.
|
||||||
|
uint32_t lastObservedMs;
|
||||||
|
|
||||||
|
// Last RTC/packet timestamp (seconds) observed for this NodeInfo frame.
|
||||||
|
// If unavailable in packet, remains 0.
|
||||||
|
uint32_t lastObservedRxTime;
|
||||||
|
|
||||||
|
// Channel where we most recently heard this node's NodeInfo.
|
||||||
|
uint8_t sourceChannel;
|
||||||
|
|
||||||
|
// Cached decoded bitfield metadata from the source packet.
|
||||||
|
// We preserve non-OK_TO_MQTT bits in direct replies when available.
|
||||||
|
bool hasDecodedBitfield;
|
||||||
|
uint8_t decodedBitfield;
|
||||||
|
};
|
||||||
|
|
||||||
|
NodeInfoPayloadEntry *nodeInfoPayload = nullptr; // NodeInfo payloads in PSRAM
|
||||||
|
bool nodeInfoPayloadFromPsram = false; // Tracks allocator for correct deallocation
|
||||||
|
uint8_t *nodeInfoIndex = nullptr; // Packed 12-bit NodeInfo tags in DRAM
|
||||||
|
uint16_t nodeInfoAllocHint = 0;
|
||||||
|
uint16_t nodeInfoEvictCursor = 0;
|
||||||
|
|
||||||
|
meshtastic_TrafficManagementStats stats;
|
||||||
|
|
||||||
|
// Flag set during alterReceived() when packet should be exhausted.
|
||||||
|
// Checked by perhapsRebroadcast() to force hop_limit = 0 only for the
|
||||||
|
// matching packet key (from + id). Reset at start of handleReceived().
|
||||||
|
bool exhaustRequested = false;
|
||||||
|
NodeNum exhaustRequestedFrom = 0;
|
||||||
|
PacketId exhaustRequestedId = 0;
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// Cache Operations
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
|
// Find or create entry for node using cuckoo hashing
|
||||||
|
// Returns nullptr if cache is full and eviction fails
|
||||||
|
UnifiedCacheEntry *findOrCreateEntry(NodeNum node, bool *isNew);
|
||||||
|
|
||||||
|
// Find existing entry (no creation)
|
||||||
|
UnifiedCacheEntry *findEntry(NodeNum node);
|
||||||
|
|
||||||
|
// NodeInfo cache operations (bucketed cuckoo index + PSRAM payloads)
|
||||||
|
const NodeInfoPayloadEntry *findNodeInfoEntry(NodeNum node) const;
|
||||||
|
NodeInfoPayloadEntry *findOrCreateNodeInfoEntry(NodeNum node, bool *usedEmptySlot);
|
||||||
|
uint16_t findNodeInfoPayloadIndex(NodeNum node) const;
|
||||||
|
bool removeNodeInfoIndexEntry(NodeNum node, uint16_t payloadIndex);
|
||||||
|
uint16_t allocateNodeInfoPayloadSlot();
|
||||||
|
uint16_t evictNodeInfoPayloadSlot();
|
||||||
|
bool tryInsertNodeInfoEntryInBucket(uint16_t bucket, uint16_t tag);
|
||||||
|
uint16_t encodeNodeInfoTag(uint16_t payloadIndex) const;
|
||||||
|
uint16_t decodeNodeInfoPayloadIndex(uint16_t tag) const;
|
||||||
|
uint16_t getNodeInfoTag(uint16_t slot) const;
|
||||||
|
void setNodeInfoTag(uint16_t slot, uint16_t tag);
|
||||||
|
uint16_t countNodeInfoEntriesLocked() const;
|
||||||
|
void cacheNodeInfoPacket(const meshtastic_MeshPacket &mp);
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// Traffic Management Logic
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
|
bool shouldDropPosition(const meshtastic_MeshPacket *p, const meshtastic_Position *pos, uint32_t nowMs);
|
||||||
|
bool shouldRespondToNodeInfo(const meshtastic_MeshPacket *p, bool sendResponse);
|
||||||
|
bool isMinHopsFromRequestor(const meshtastic_MeshPacket *p) const;
|
||||||
|
bool isRateLimited(NodeNum from, uint32_t nowMs);
|
||||||
|
bool shouldDropUnknown(const meshtastic_MeshPacket *p, uint32_t nowMs);
|
||||||
|
|
||||||
|
void logAction(const char *action, const meshtastic_MeshPacket *p, const char *reason) const;
|
||||||
|
void incrementStat(uint32_t *field);
|
||||||
|
};
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// Compile-time Cache Size Calculations
|
||||||
|
// =========================================================================
|
||||||
|
//
|
||||||
|
// Round TRAFFIC_MANAGEMENT_CACHE_SIZE up to next power of 2 for efficient
|
||||||
|
// cuckoo hash indexing (allows bitmask instead of modulo).
|
||||||
|
//
|
||||||
|
// These use C++11-compatible constexpr (single return statement).
|
||||||
|
//
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
// Helper: round up to next power of 2 using bit manipulation
|
||||||
|
constexpr uint16_t nextPow2(uint16_t n)
|
||||||
|
{
|
||||||
|
return n == 0 ? 0 : (((n - 1) | ((n - 1) >> 1) | ((n - 1) >> 2) | ((n - 1) >> 4) | ((n - 1) >> 8)) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper: floor(log2(n)) for n >= 0, C++11-compatible constexpr.
|
||||||
|
constexpr uint8_t log2Floor(uint16_t n)
|
||||||
|
{
|
||||||
|
return n <= 1 ? 0 : static_cast<uint8_t>(1 + log2Floor(static_cast<uint16_t>(n >> 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper: ceil(log2(n)) for n >= 1, C++11-compatible constexpr.
|
||||||
|
constexpr uint8_t log2Ceil(uint16_t n)
|
||||||
|
{
|
||||||
|
return n <= 1 ? 0 : static_cast<uint8_t>(1 + log2Floor(static_cast<uint16_t>(n - 1)));
|
||||||
|
}
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
constexpr uint16_t TrafficManagementModule::cacheSize()
|
||||||
|
{
|
||||||
|
return detail::nextPow2(TRAFFIC_MANAGEMENT_CACHE_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr uint16_t TrafficManagementModule::cacheMask()
|
||||||
|
{
|
||||||
|
return cacheSize() > 0 ? cacheSize() - 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr uint8_t TrafficManagementModule::cuckooHashBits()
|
||||||
|
{
|
||||||
|
return detail::log2Floor(cacheSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr uint16_t TrafficManagementModule::nodeInfoTargetEntries()
|
||||||
|
{
|
||||||
|
return kNodeInfoTargetEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr uint16_t TrafficManagementModule::nodeInfoIndexMetadataBudgetBytes()
|
||||||
|
{
|
||||||
|
return kNodeInfoIndexMetadataBudgetBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr uint8_t TrafficManagementModule::nodeInfoTargetOccupancyPercent()
|
||||||
|
{
|
||||||
|
return kNodeInfoTargetOccupancyPercent;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr uint8_t TrafficManagementModule::nodeInfoBucketSize()
|
||||||
|
{
|
||||||
|
return kNodeInfoBucketSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr uint8_t TrafficManagementModule::nodeInfoTagBits()
|
||||||
|
{
|
||||||
|
return kNodeInfoTagBits;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr uint16_t TrafficManagementModule::nodeInfoTagMask()
|
||||||
|
{
|
||||||
|
return kNodeInfoTagMask;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr uint16_t TrafficManagementModule::nodeInfoIndexSlots()
|
||||||
|
{
|
||||||
|
return kNodeInfoIndexSlots;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr uint16_t TrafficManagementModule::nodeInfoBucketCount()
|
||||||
|
{
|
||||||
|
return static_cast<uint16_t>(nodeInfoIndexSlots() / nodeInfoBucketSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr uint16_t TrafficManagementModule::nodeInfoBucketMask()
|
||||||
|
{
|
||||||
|
return nodeInfoBucketCount() > 0 ? nodeInfoBucketCount() - 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr uint8_t TrafficManagementModule::nodeInfoBucketHashBits()
|
||||||
|
{
|
||||||
|
return detail::log2Floor(nodeInfoBucketCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
extern TrafficManagementModule *trafficManagementModule;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
#include "ICM20948Sensor.h"
|
#include "ICM20948Sensor.h"
|
||||||
#include "LIS3DHSensor.h"
|
#include "LIS3DHSensor.h"
|
||||||
#include "LSM6DS3Sensor.h"
|
#include "LSM6DS3Sensor.h"
|
||||||
|
#include "LSM6DSOSensor.h"
|
||||||
#include "MPU6050Sensor.h"
|
#include "MPU6050Sensor.h"
|
||||||
#include "MotionSensor.h"
|
#include "MotionSensor.h"
|
||||||
#ifdef HAS_QMA6100P
|
#ifdef HAS_QMA6100P
|
||||||
@@ -103,6 +104,9 @@ class AccelerometerThread : public concurrency::OSThread
|
|||||||
case ScanI2C::DeviceType::LSM6DS3:
|
case ScanI2C::DeviceType::LSM6DS3:
|
||||||
sensor = new LSM6DS3Sensor(device);
|
sensor = new LSM6DS3Sensor(device);
|
||||||
break;
|
break;
|
||||||
|
case ScanI2C::DeviceType::LSM6DSOX:
|
||||||
|
sensor = new LSM6DSOSensor(device);
|
||||||
|
break;
|
||||||
#ifdef HAS_STK8XXX
|
#ifdef HAS_STK8XXX
|
||||||
case ScanI2C::DeviceType::STK8BAXX:
|
case ScanI2C::DeviceType::STK8BAXX:
|
||||||
sensor = new STK8XXXSensor(device);
|
sensor = new STK8XXXSensor(device);
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
#include "LSM6DSOSensor.h"
|
||||||
|
#include "NodeDB.h"
|
||||||
|
|
||||||
|
#if !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C && __has_include(<Adafruit_LSM6DSOX.h>)
|
||||||
|
|
||||||
|
LSM6DSOSensor::LSM6DSOSensor(ScanI2C::FoundDevice foundDevice) : MotionSensor::MotionSensor(foundDevice) {}
|
||||||
|
|
||||||
|
bool LSM6DSOSensor::init()
|
||||||
|
{
|
||||||
|
if (sensor.begin_I2C(deviceAddress())) {
|
||||||
|
|
||||||
|
sensor.setAccelRange(LSM6DS_ACCEL_RANGE_2_G);
|
||||||
|
sensor.enableWakeup(config.display.wake_on_tap_or_motion, 1, LSM6DSO_WAKE_THRESH);
|
||||||
|
|
||||||
|
LOG_DEBUG("LSM6DSO init ok");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
LOG_DEBUG("LSM6DSO init failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t LSM6DSOSensor::runOnce()
|
||||||
|
{
|
||||||
|
if (sensor.shake()) {
|
||||||
|
wakeScreen();
|
||||||
|
return 500;
|
||||||
|
}
|
||||||
|
return MOTION_SENSOR_CHECK_INTERVAL_MS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifndef _LSM6DSO_SENSOR_H_
|
||||||
|
#define _LSM6DSO_SENSOR_H_
|
||||||
|
|
||||||
|
#include "MotionSensor.h"
|
||||||
|
|
||||||
|
#if !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C && __has_include(<Adafruit_LSM6DSOX.h>)
|
||||||
|
|
||||||
|
#ifndef LSM6DSO_WAKE_THRESH
|
||||||
|
#define LSM6DSO_WAKE_THRESH 20
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <Adafruit_LSM6DSOX.h>
|
||||||
|
|
||||||
|
class LSM6DSOSensor : public MotionSensor
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Adafruit_LSM6DSOX sensor;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit LSM6DSOSensor(ScanI2C::FoundDevice foundDevice);
|
||||||
|
virtual bool init() override;
|
||||||
|
virtual int32_t runOnce() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
+10
-4
@@ -429,8 +429,13 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more r
|
|||||||
gpio_num_t pin = (gpio_num_t)(config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN);
|
gpio_num_t pin = (gpio_num_t)(config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN);
|
||||||
gpio_wakeup_enable(pin, GPIO_INTR_LOW_LEVEL);
|
gpio_wakeup_enable(pin, GPIO_INTR_LOW_LEVEL);
|
||||||
#endif
|
#endif
|
||||||
#ifdef INPUTDRIVER_ENCODER_BTN
|
#if defined(INPUTDRIVER_TWO_WAY_ROCKER_BTN) || defined(INPUTDRIVER_ENCODER_BTN)
|
||||||
gpio_wakeup_enable((gpio_num_t)INPUTDRIVER_ENCODER_BTN, GPIO_INTR_LOW_LEVEL);
|
#if defined(INPUTDRIVER_TWO_WAY_ROCKER_BTN)
|
||||||
|
#define INPUTDRIVER_WAKE_BTN_PIN INPUTDRIVER_TWO_WAY_ROCKER_BTN
|
||||||
|
#else
|
||||||
|
#define INPUTDRIVER_WAKE_BTN_PIN INPUTDRIVER_ENCODER_BTN
|
||||||
|
#endif
|
||||||
|
gpio_wakeup_enable((gpio_num_t)INPUTDRIVER_WAKE_BTN_PIN, GPIO_INTR_LOW_LEVEL);
|
||||||
#endif
|
#endif
|
||||||
#if defined(WAKE_ON_TOUCH)
|
#if defined(WAKE_ON_TOUCH)
|
||||||
gpio_wakeup_enable((gpio_num_t)SCREEN_TOUCH_INT, GPIO_INTR_LOW_LEVEL);
|
gpio_wakeup_enable((gpio_num_t)SCREEN_TOUCH_INT, GPIO_INTR_LOW_LEVEL);
|
||||||
@@ -471,8 +476,9 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more r
|
|||||||
// Disable wake-on-button interrupt. Re-attach normal button-interrupts
|
// Disable wake-on-button interrupt. Re-attach normal button-interrupts
|
||||||
gpio_wakeup_disable(pin);
|
gpio_wakeup_disable(pin);
|
||||||
#endif
|
#endif
|
||||||
#if defined(INPUTDRIVER_ENCODER_BTN)
|
#ifdef INPUTDRIVER_WAKE_BTN_PIN
|
||||||
gpio_wakeup_disable((gpio_num_t)INPUTDRIVER_ENCODER_BTN);
|
gpio_wakeup_disable((gpio_num_t)INPUTDRIVER_WAKE_BTN_PIN);
|
||||||
|
#undef INPUTDRIVER_WAKE_BTN_PIN
|
||||||
#endif
|
#endif
|
||||||
#if defined(WAKE_ON_TOUCH)
|
#if defined(WAKE_ON_TOUCH)
|
||||||
gpio_wakeup_disable((gpio_num_t)SCREEN_TOUCH_INT);
|
gpio_wakeup_disable((gpio_num_t)SCREEN_TOUCH_INT);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -29,6 +29,14 @@
|
|||||||
#define SX126X_DIO2_AS_RF_SWITCH
|
#define SX126X_DIO2_AS_RF_SWITCH
|
||||||
#define SX126X_DIO3_TCXO_VOLTAGE 1.8
|
#define SX126X_DIO3_TCXO_VOLTAGE 1.8
|
||||||
|
|
||||||
|
// Enable Traffic Management Module for Heltec V4
|
||||||
|
#ifndef HAS_TRAFFIC_MANAGEMENT
|
||||||
|
#define HAS_TRAFFIC_MANAGEMENT 1
|
||||||
|
#endif
|
||||||
|
#ifndef TRAFFIC_MANAGEMENT_CACHE_SIZE
|
||||||
|
#define TRAFFIC_MANAGEMENT_CACHE_SIZE 2048
|
||||||
|
#endif
|
||||||
|
|
||||||
// ---- GC1109 RF FRONT END CONFIGURATION ----
|
// ---- GC1109 RF FRONT END CONFIGURATION ----
|
||||||
// The Heltec V4.2 uses a GC1109 FEM chip with integrated PA and LNA
|
// The Heltec V4.2 uses a GC1109 FEM chip with integrated PA and LNA
|
||||||
// RF path: SX1262 -> Pi attenuator -> GC1109 PA -> Antenna
|
// RF path: SX1262 -> Pi attenuator -> GC1109 PA -> Antenna
|
||||||
@@ -89,4 +97,4 @@
|
|||||||
// Seems to be missing on this new board
|
// Seems to be missing on this new board
|
||||||
#define GPS_TX_PIN (38) // This is for bits going TOWARDS the CPU
|
#define GPS_TX_PIN (38) // This is for bits going TOWARDS the CPU
|
||||||
#define GPS_RX_PIN (39) // This is for bits going TOWARDS the GPS
|
#define GPS_RX_PIN (39) // This is for bits going TOWARDS the GPS
|
||||||
#define GPS_THREAD_INTERVAL 50
|
#define GPS_THREAD_INTERVAL 50
|
||||||
|
|||||||
@@ -0,0 +1,131 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "configuration.h"
|
||||||
|
|
||||||
|
#ifdef MESHTASTIC_INCLUDE_NICHE_GRAPHICS
|
||||||
|
|
||||||
|
// InkHUD-specific components
|
||||||
|
#include "graphics/niche/InkHUD/InkHUD.h"
|
||||||
|
|
||||||
|
// Applets
|
||||||
|
#include "graphics/niche/InkHUD/Applet.h"
|
||||||
|
#include "graphics/niche/InkHUD/Applets/User/AllMessage/AllMessageApplet.h"
|
||||||
|
#include "graphics/niche/InkHUD/Applets/User/DM/DMApplet.h"
|
||||||
|
#include "graphics/niche/InkHUD/Applets/User/FavoritesMap/FavoritesMapApplet.h"
|
||||||
|
#include "graphics/niche/InkHUD/Applets/User/Heard/HeardApplet.h"
|
||||||
|
#include "graphics/niche/InkHUD/Applets/User/Positions/PositionsApplet.h"
|
||||||
|
#include "graphics/niche/InkHUD/Applets/User/RecentsList/RecentsListApplet.h"
|
||||||
|
#include "graphics/niche/InkHUD/Applets/User/ThreadedMessage/ThreadedMessageApplet.h"
|
||||||
|
#include "graphics/niche/InkHUD/SystemApplet.h"
|
||||||
|
|
||||||
|
// Shared NicheGraphics components
|
||||||
|
#include "graphics/niche/Drivers/EInk/GDEW0102T4.h"
|
||||||
|
#include "graphics/niche/Inputs/TwoButtonExtended.h"
|
||||||
|
|
||||||
|
void setupNicheGraphics()
|
||||||
|
{
|
||||||
|
using namespace NicheGraphics;
|
||||||
|
|
||||||
|
// Power-enable the E-Ink panel on this board before any SPI traffic.
|
||||||
|
pinMode(PIN_EINK_EN, OUTPUT);
|
||||||
|
digitalWrite(PIN_EINK_EN, HIGH);
|
||||||
|
delay(10);
|
||||||
|
|
||||||
|
// Display uses HSPI on this board
|
||||||
|
SPIClass *hspi = new SPIClass(HSPI);
|
||||||
|
hspi->begin(PIN_EINK_SCLK, -1, PIN_EINK_MOSI, PIN_EINK_CS);
|
||||||
|
|
||||||
|
Drivers::GDEW0102T4 *displayDriver = new Drivers::GDEW0102T4;
|
||||||
|
displayDriver->begin(hspi, PIN_EINK_DC, PIN_EINK_CS, PIN_EINK_BUSY, PIN_EINK_RES);
|
||||||
|
// Tuned fast-refresh values reg30 reg50 reg82 lutW2 lutB2 = 11 F2 04 11 0D
|
||||||
|
displayDriver->setFastConfig({0x11, 0xF2, 0x04, 0x11, 0x0D});
|
||||||
|
Drivers::EInk *driver = displayDriver;
|
||||||
|
|
||||||
|
InkHUD::InkHUD *inkhud = InkHUD::InkHUD::getInstance();
|
||||||
|
inkhud->setDriver(driver);
|
||||||
|
// Slightly stricter FAST/FULL
|
||||||
|
inkhud->setDisplayResilience(5, 1.5);
|
||||||
|
inkhud->twoWayRocker = true;
|
||||||
|
|
||||||
|
// Fonts
|
||||||
|
InkHUD::Applet::fontLarge = FREESANS_9PT_WIN1252;
|
||||||
|
InkHUD::Applet::fontMedium = FREESANS_6PT_WIN1252;
|
||||||
|
InkHUD::Applet::fontSmall = FREESANS_6PT_WIN1252;
|
||||||
|
|
||||||
|
// Small display defaults
|
||||||
|
inkhud->persistence->settings.rotation = 0;
|
||||||
|
inkhud->persistence->settings.userTiles.maxCount = 1;
|
||||||
|
inkhud->persistence->settings.userTiles.count = 1;
|
||||||
|
inkhud->persistence->settings.joystick.enabled = true;
|
||||||
|
inkhud->persistence->settings.joystick.aligned = true;
|
||||||
|
inkhud->persistence->settings.optionalMenuItems.nextTile = false;
|
||||||
|
|
||||||
|
// Pick applets
|
||||||
|
// Note: order of applets determines priority of "auto-show" feature
|
||||||
|
inkhud->addApplet("All Messages", new InkHUD::AllMessageApplet, false, false); // -
|
||||||
|
inkhud->addApplet("DMs", new InkHUD::DMApplet, true, false); // Activated, not autoshown
|
||||||
|
inkhud->addApplet("Channel 0", new InkHUD::ThreadedMessageApplet(0), true, true); // Activated, Autoshown
|
||||||
|
inkhud->addApplet("Channel 1", new InkHUD::ThreadedMessageApplet(1), false, false); // -
|
||||||
|
inkhud->addApplet("Positions", new InkHUD::PositionsApplet, true); // Activated
|
||||||
|
inkhud->addApplet("Favorites Map", new InkHUD::FavoritesMapApplet, false, false); // -
|
||||||
|
inkhud->addApplet("Recents List", new InkHUD::RecentsListApplet, false, false); // -
|
||||||
|
inkhud->addApplet("Heard", new InkHUD::HeardApplet, true, false, 0); // Activated, not autoshown, default on tile 0
|
||||||
|
// Start running InkHUD
|
||||||
|
inkhud->begin();
|
||||||
|
|
||||||
|
// Enforce two-way rocker behavior regardless of persisted settings.
|
||||||
|
inkhud->persistence->settings.joystick.enabled = true;
|
||||||
|
inkhud->persistence->settings.joystick.aligned = true;
|
||||||
|
inkhud->persistence->settings.optionalMenuItems.nextTile = false;
|
||||||
|
|
||||||
|
// Inputs
|
||||||
|
Inputs::TwoButtonExtended *buttons = Inputs::TwoButtonExtended::getInstance();
|
||||||
|
|
||||||
|
// Center press (boot button)
|
||||||
|
buttons->setWiring(0, INPUTDRIVER_TWO_WAY_ROCKER_BTN, true);
|
||||||
|
// Match baseUI encoder long-press feel.
|
||||||
|
buttons->setTiming(0, 75, 300);
|
||||||
|
buttons->setHandlerShortPress(0, [inkhud]() { inkhud->shortpress(); });
|
||||||
|
buttons->setHandlerLongPress(0, [inkhud]() { inkhud->longpress(); });
|
||||||
|
|
||||||
|
// LEFT rocker pin is IO4; RIGHT rocker pin is IO3.
|
||||||
|
buttons->setTwoWayRockerWiring(INPUTDRIVER_TWO_WAY_ROCKER_LEFT, INPUTDRIVER_TWO_WAY_ROCKER_RIGHT, true);
|
||||||
|
buttons->setJoystickDebounce(50);
|
||||||
|
|
||||||
|
// Two-way rocker behavior:
|
||||||
|
// - when a system applet is handling input (menu, tips, etc): LEFT=up, RIGHT=down
|
||||||
|
// - otherwise: LEFT=previous applet, RIGHT=next applet
|
||||||
|
buttons->setTwoWayRockerPressHandlers(
|
||||||
|
[inkhud]() {
|
||||||
|
bool systemHandlingInput = false;
|
||||||
|
for (InkHUD::SystemApplet *sa : inkhud->systemApplets) {
|
||||||
|
if (sa->handleInput) {
|
||||||
|
systemHandlingInput = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (systemHandlingInput)
|
||||||
|
inkhud->navUp();
|
||||||
|
else
|
||||||
|
inkhud->prevApplet();
|
||||||
|
},
|
||||||
|
[inkhud]() {
|
||||||
|
bool systemHandlingInput = false;
|
||||||
|
for (InkHUD::SystemApplet *sa : inkhud->systemApplets) {
|
||||||
|
if (sa->handleInput) {
|
||||||
|
systemHandlingInput = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (systemHandlingInput)
|
||||||
|
inkhud->navDown();
|
||||||
|
else
|
||||||
|
inkhud->nextApplet();
|
||||||
|
});
|
||||||
|
|
||||||
|
buttons->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -3,24 +3,23 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define USB_VID 0x303a
|
#define USB_VID 0x303A
|
||||||
#define USB_PID 0x1001
|
#define USB_PID 0x1001
|
||||||
|
|
||||||
// The default Wire will be mapped to PMU and RTC
|
// The default Wire will be mapped to PMU and RTC
|
||||||
static const uint8_t SDA = 18;
|
static const uint8_t SDA = 18;
|
||||||
static const uint8_t SCL = 9;
|
static const uint8_t SCL = 9;
|
||||||
|
|
||||||
// Default SPI will be mapped to Radio
|
// Default SPI (LoRa bus)
|
||||||
static const uint8_t SS = -1;
|
static const uint8_t SS = -1;
|
||||||
static const uint8_t MOSI = 17;
|
static const uint8_t MOSI = 17;
|
||||||
static const uint8_t MISO = 6;
|
static const uint8_t MISO = 6;
|
||||||
static const uint8_t SCK = 8;
|
static const uint8_t SCK = 8;
|
||||||
|
|
||||||
|
// SD card SPI bus
|
||||||
#define SPI_MOSI (39)
|
#define SPI_MOSI (39)
|
||||||
#define SPI_SCK (41)
|
#define SPI_SCK (41)
|
||||||
#define SPI_MISO (38)
|
#define SPI_MISO (38)
|
||||||
#define SPI_CS (40)
|
#define SPI_CS (40)
|
||||||
|
|
||||||
#define SDCARD_CS SPI_CS
|
|
||||||
|
|
||||||
#endif /* Pins_Arduino_h */
|
#endif /* Pins_Arduino_h */
|
||||||
|
|||||||
@@ -17,11 +17,15 @@ upload_protocol = esptool
|
|||||||
build_flags =
|
build_flags =
|
||||||
${esp32s3_base.build_flags}
|
${esp32s3_base.build_flags}
|
||||||
-I variants/esp32s3/mini-epaper-s3
|
-I variants/esp32s3/mini-epaper-s3
|
||||||
-DMINI_EPAPER_S3
|
-D MINI_EPAPER_S3
|
||||||
-DUSE_EINK
|
-D USE_EINK
|
||||||
-DEINK_DISPLAY_MODEL=GxEPD2_102
|
-D EINK_DISPLAY_MODEL=GxEPD2_102
|
||||||
-DEINK_WIDTH=128
|
-D EINK_WIDTH=128
|
||||||
-DEINK_HEIGHT=80
|
-D EINK_HEIGHT=80
|
||||||
|
-D USE_EINK_DYNAMICDISPLAY
|
||||||
|
-D EINK_LIMIT_FASTREFRESH=3
|
||||||
|
-D EINK_BACKGROUND_USES_FAST
|
||||||
|
-D EINK_HASQUIRK_GHOSTING
|
||||||
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${esp32s3_base.lib_deps}
|
${esp32s3_base.lib_deps}
|
||||||
@@ -29,3 +33,22 @@ lib_deps =
|
|||||||
https://github.com/meshtastic/GxEPD2/archive/c7eb4c3c167cf396ef4f541cc5d4c6aa42f3c46b.zip
|
https://github.com/meshtastic/GxEPD2/archive/c7eb4c3c167cf396ef4f541cc5d4c6aa42f3c46b.zip
|
||||||
# renovate: datasource=custom.pio depName=SensorLib packageName=lewisxhe/library/SensorLib
|
# renovate: datasource=custom.pio depName=SensorLib packageName=lewisxhe/library/SensorLib
|
||||||
lewisxhe/SensorLib@0.3.4
|
lewisxhe/SensorLib@0.3.4
|
||||||
|
|
||||||
|
[env:mini-epaper-s3-inkhud]
|
||||||
|
extends = esp32s3_base, inkhud
|
||||||
|
board = mini-epaper-s3
|
||||||
|
board_check = true
|
||||||
|
upload_protocol = esptool
|
||||||
|
build_src_filter =
|
||||||
|
${esp32s3_base.build_src_filter}
|
||||||
|
${inkhud.build_src_filter}
|
||||||
|
build_flags =
|
||||||
|
${esp32s3_base.build_flags}
|
||||||
|
${inkhud.build_flags}
|
||||||
|
-I variants/esp32s3/mini-epaper-s3
|
||||||
|
-D MINI_EPAPER_S3
|
||||||
|
lib_deps =
|
||||||
|
${inkhud.lib_deps} ; InkHUD libs first, so we get GFXRoot instead of AdafruitGFX
|
||||||
|
${esp32s3_base.lib_deps}
|
||||||
|
# renovate: datasource=custom.pio depName=SensorLib packageName=lewisxhe/library/SensorLib
|
||||||
|
lewisxhe/SensorLib@0.3.4
|
||||||
|
|||||||
@@ -1,46 +1,46 @@
|
|||||||
// Display (E-Ink)
|
#pragma once
|
||||||
|
|
||||||
#define PIN_EINK_CS 13
|
#define GPS_DEFAULT_NOT_PRESENT 1
|
||||||
#define PIN_EINK_BUSY 10
|
|
||||||
#define PIN_EINK_RES 11
|
|
||||||
#define PIN_EINK_SCLK 14
|
|
||||||
#define PIN_EINK_MOSI 15
|
|
||||||
#define PIN_EINK_DC 12
|
|
||||||
#define PIN_EINK_EN 42
|
|
||||||
|
|
||||||
#define SPI_INTERFACES_COUNT 2
|
// SD card (TF)
|
||||||
#define PIN_SPI1_MISO -1
|
#define HAS_SDCARD
|
||||||
#define PIN_SPI1_MOSI PIN_EINK_MOSI
|
#define SDCARD_USE_SPI1
|
||||||
#define PIN_SPI1_SCK PIN_EINK_SCLK
|
#define SDCARD_CS 40
|
||||||
#define DISPLAY_FORCE_SMALL_FONTS
|
#define SD_SPI_FREQUENCY 25000000U
|
||||||
|
|
||||||
|
// Built-in RTC (I2C)
|
||||||
|
#define PCF8563_RTC 0x51
|
||||||
|
#define HAS_RTC 1
|
||||||
#define I2C_SDA SDA
|
#define I2C_SDA SDA
|
||||||
#define I2C_SCL SCL
|
#define I2C_SCL SCL
|
||||||
|
|
||||||
|
// Battery voltage monitoring
|
||||||
#define BATTERY_PIN 2 // A battery voltage measurement pin, voltage divider connected here to
|
#define BATTERY_PIN 2 // A battery voltage measurement pin, voltage divider connected here to
|
||||||
// measure battery voltage ratio of voltage divider = 2.0 (assumption)
|
// measure battery voltage ratio of voltage divider = 2.0 (assumption)
|
||||||
#define ADC_MULTIPLIER 2.11 // 2.0 + 10% for correction of display undervoltage.
|
#define ADC_MULTIPLIER 2.11 // 2.0 + 10% for correction of display undervoltage.
|
||||||
#define ADC_CHANNEL ADC1_GPIO2_CHANNEL
|
#define ADC_CHANNEL ADC1_GPIO2_CHANNEL
|
||||||
|
|
||||||
#define HAS_GPS 0
|
// Display (E-Ink)
|
||||||
#undef GPS_RX_PIN
|
#define PIN_EINK_EN 42
|
||||||
#undef GPS_TX_PIN
|
#define PIN_EINK_CS 13
|
||||||
|
#define PIN_EINK_BUSY 10
|
||||||
|
#define PIN_EINK_DC 12
|
||||||
|
#define PIN_EINK_RES 11
|
||||||
|
#define PIN_EINK_SCLK 14
|
||||||
|
#define PIN_EINK_MOSI 15
|
||||||
|
#define DISPLAY_FORCE_SMALL_FONTS
|
||||||
|
|
||||||
#define BUTTON_PIN 3
|
// Two-Way Rocker input (left/right + boot as press)
|
||||||
#define BUTTON_NEED_PULLUP
|
#define INPUTDRIVER_TWO_WAY_ROCKER
|
||||||
#define ALT_BUTTON_PIN 4
|
#define INPUTDRIVER_ENCODER_TYPE 2
|
||||||
#define ALT_BUTTON_ACTIVE_LOW true
|
#define INPUTDRIVER_TWO_WAY_ROCKER_RIGHT 3
|
||||||
#define ALT_BUTTON_ACTIVE_PULLUP true
|
#define INPUTDRIVER_TWO_WAY_ROCKER_LEFT 4
|
||||||
#define PIN_BUTTON3 0
|
#define INPUTDRIVER_TWO_WAY_ROCKER_BTN 0
|
||||||
|
#define UPDOWN_LONG_PRESS_REPEAT_INTERVAL 150
|
||||||
// #define HAS_SDCARD 1
|
|
||||||
// #define SDCARD_USE_SOFT_SPI
|
|
||||||
|
|
||||||
// PCF85063 RTC Module
|
|
||||||
#define PCF85063_RTC 0x51
|
|
||||||
#define HAS_RTC 1
|
|
||||||
|
|
||||||
|
// LoRa (SX1262)
|
||||||
#define USE_SX1262
|
#define USE_SX1262
|
||||||
|
|
||||||
#define LORA_DIO1 5
|
#define LORA_DIO1 5
|
||||||
#define LORA_SCK 8
|
#define LORA_SCK 8
|
||||||
#define LORA_MISO 6
|
#define LORA_MISO 6
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ L76K GPS Module Information : https://www.seeedstudio.com/L76K-GNSS-Module-for-S
|
|||||||
#define GPS_RX_PIN 44
|
#define GPS_RX_PIN 44
|
||||||
#define GPS_TX_PIN 43
|
#define GPS_TX_PIN 43
|
||||||
#define HAS_GPS 1
|
#define HAS_GPS 1
|
||||||
#define GPS_BAUDRATE 9600
|
|
||||||
#define GPS_THREAD_INTERVAL 50
|
#define GPS_THREAD_INTERVAL 50
|
||||||
#define PIN_SERIAL1_RX PIN_GPS_TX
|
#define PIN_SERIAL1_RX PIN_GPS_TX
|
||||||
#define PIN_SERIAL1_TX PIN_GPS_RX
|
#define PIN_SERIAL1_TX PIN_GPS_RX
|
||||||
|
|||||||
@@ -40,6 +40,14 @@ Board Information: https://wiki.uniteng.com/en/meshtastic/station-g2
|
|||||||
#define SX126X_MAX_POWER 19
|
#define SX126X_MAX_POWER 19
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Enable Traffic Management Module for Station G2
|
||||||
|
#ifndef HAS_TRAFFIC_MANAGEMENT
|
||||||
|
#define HAS_TRAFFIC_MANAGEMENT 1
|
||||||
|
#endif
|
||||||
|
#ifndef TRAFFIC_MANAGEMENT_CACHE_SIZE
|
||||||
|
#define TRAFFIC_MANAGEMENT_CACHE_SIZE 2048
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#define BATTERY_PIN 4 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage
|
#define BATTERY_PIN 4 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage
|
||||||
#define ADC_CHANNEL ADC1_GPIO4_CHANNEL
|
#define ADC_CHANNEL ADC1_GPIO4_CHANNEL
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ build_flags = ${esp32s3_base.build_flags}
|
|||||||
-D T_LORA_PAGER
|
-D T_LORA_PAGER
|
||||||
-D BOARD_HAS_PSRAM
|
-D BOARD_HAS_PSRAM
|
||||||
-D HAS_SDCARD
|
-D HAS_SDCARD
|
||||||
-D SDCARD_USE_SPI1
|
|
||||||
-D ENABLE_ROTARY_PULLUP
|
-D ENABLE_ROTARY_PULLUP
|
||||||
-D ENABLE_BUTTON_PULLUP
|
-D ENABLE_BUTTON_PULLUP
|
||||||
-D ROTARY_BUXTRONICS
|
-D ROTARY_BUXTRONICS
|
||||||
|
|||||||
@@ -8,3 +8,11 @@
|
|||||||
|
|
||||||
// RAK12002 RTC Module
|
// RAK12002 RTC Module
|
||||||
#define RV3028_RTC (uint8_t)0b1010010
|
#define RV3028_RTC (uint8_t)0b1010010
|
||||||
|
|
||||||
|
// Enable Traffic Management Module for native/portduino
|
||||||
|
#ifndef HAS_TRAFFIC_MANAGEMENT
|
||||||
|
#define HAS_TRAFFIC_MANAGEMENT 1
|
||||||
|
#endif
|
||||||
|
#ifndef TRAFFIC_MANAGEMENT_CACHE_SIZE
|
||||||
|
#define TRAFFIC_MANAGEMENT_CACHE_SIZE 2048
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -154,6 +154,15 @@ extern "C" {
|
|||||||
|
|
||||||
#define HAS_SCREEN 0
|
#define HAS_SCREEN 0
|
||||||
|
|
||||||
|
// Enable Traffic Management Module for testing on T1000-E
|
||||||
|
// NRF52840 has 256KB RAM - 1024 entries uses ~10KB
|
||||||
|
#ifndef HAS_TRAFFIC_MANAGEMENT
|
||||||
|
#define HAS_TRAFFIC_MANAGEMENT 1
|
||||||
|
#endif
|
||||||
|
#ifndef TRAFFIC_MANAGEMENT_CACHE_SIZE
|
||||||
|
#define TRAFFIC_MANAGEMENT_CACHE_SIZE 1024
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
[env:tracker-t2000-c]
|
||||||
|
custom_meshtastic_support_level = 1
|
||||||
|
custom_meshtastic_tags = Seeed
|
||||||
|
|
||||||
|
extends = nrf52840_base
|
||||||
|
board = tracker-t2000-c
|
||||||
|
board_level = pr
|
||||||
|
custom_meshtastic_architecture = nrf52840
|
||||||
|
custom_meshtastic_display_name = Seeed SenseCAP T2000-C
|
||||||
|
custom_meshtastic_actively_supported = true
|
||||||
|
build_flags = ${nrf52840_base.build_flags}
|
||||||
|
-Ivariants/nrf52840/tracker-t2000-c
|
||||||
|
-Isrc/platform/nrf52/softdevice
|
||||||
|
-Isrc/platform/nrf52/softdevice/nrf52
|
||||||
|
-DTRACKER_T2000_C
|
||||||
|
-DPRIVATE_HW
|
||||||
|
-DMESHTASTIC_EXCLUDE_CANNEDMESSAGES=1
|
||||||
|
-DMESHTASTIC_EXCLUDE_SCREEN=1
|
||||||
|
-DMESHTASTIC_EXCLUDE_WIFI=1
|
||||||
|
board_build.ldscript = src/platform/nrf52/nrf52840_s140_v7.ld
|
||||||
|
build_src_filter = ${nrf52_base.build_src_filter} +<../variants/nrf52840/tracker-t2000-c>
|
||||||
|
lib_deps =
|
||||||
|
${nrf52840_base.lib_deps}
|
||||||
|
debug_tool = jlink
|
||||||
|
; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm)
|
||||||
|
upload_protocol = nrfutil
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
|
||||||
|
Copyright (c) 2016 Sandeep Mistry All right reserved.
|
||||||
|
Copyright (c) 2018, Adafruit Industries (adafruit.com)
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "variant.h"
|
||||||
|
#include "nrf.h"
|
||||||
|
#include "wiring_constants.h"
|
||||||
|
#include "wiring_digital.h"
|
||||||
|
|
||||||
|
const uint32_t g_ADigitalPinMap[] = {
|
||||||
|
// P0
|
||||||
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
||||||
|
|
||||||
|
// P1
|
||||||
|
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47};
|
||||||
|
|
||||||
|
void initVariant()
|
||||||
|
{
|
||||||
|
// Main power control
|
||||||
|
pinMode(PIN_PWR_CTR, OUTPUT);
|
||||||
|
digitalWrite(PIN_PWR_CTR, HIGH);
|
||||||
|
|
||||||
|
// Accelerometer enable
|
||||||
|
pinMode(ACC_EN_PIN, OUTPUT);
|
||||||
|
digitalWrite(ACC_EN_PIN, HIGH);
|
||||||
|
|
||||||
|
// GPS power off at init
|
||||||
|
pinMode(PIN_GPS_EN, OUTPUT);
|
||||||
|
digitalWrite(PIN_GPS_EN, LOW);
|
||||||
|
|
||||||
|
// GPS reset low at init
|
||||||
|
pinMode(PIN_GPS_RESET, OUTPUT);
|
||||||
|
digitalWrite(PIN_GPS_RESET, LOW);
|
||||||
|
|
||||||
|
// Flash power control
|
||||||
|
pinMode(nRF_FLASH_POWER_CTR, OUTPUT);
|
||||||
|
digitalWrite(nRF_FLASH_POWER_CTR, HIGH);
|
||||||
|
}
|
||||||
@@ -0,0 +1,172 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
|
||||||
|
Copyright (c) 2016 Sandeep Mistry All right reserved.
|
||||||
|
Copyright (c) 2018, Adafruit Industries (adafruit.com)
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _VARIANT_TRACKER_T2000_C_
|
||||||
|
#define _VARIANT_TRACKER_T2000_C_
|
||||||
|
|
||||||
|
/** Master clock frequency */
|
||||||
|
#define VARIANT_MCK (64000000ul)
|
||||||
|
|
||||||
|
#define USE_LFXO // Board uses 32khz crystal for LF
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
* Headers
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "WVariant.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
#define SERIAL_PRINT_PORT 0
|
||||||
|
|
||||||
|
// Number of pins defined in PinDescription array
|
||||||
|
#define PINS_COUNT (48)
|
||||||
|
#define NUM_DIGITAL_PINS (48)
|
||||||
|
#define NUM_ANALOG_INPUTS (6)
|
||||||
|
#define NUM_ANALOG_OUTPUTS (0)
|
||||||
|
|
||||||
|
// Use the native nrf52 usb power detection
|
||||||
|
#define NRF_APM
|
||||||
|
|
||||||
|
// Power control
|
||||||
|
#define PIN_PWR_CTR (0 + 12) // P0.12, main power control
|
||||||
|
|
||||||
|
// LEDs (active HIGH)
|
||||||
|
#define PIN_LED1 (32 + 2) // P1.02, Green
|
||||||
|
#define PIN_LED2 (32 + 3) // P1.03, Blue
|
||||||
|
#define PIN_LED3 (0 + 19) // P0.19, Red
|
||||||
|
#define LED_GREEN PIN_LED1
|
||||||
|
#define LED_BLUE PIN_LED2
|
||||||
|
#define LED_RED PIN_LED3
|
||||||
|
#define LED_POWER PIN_LED1
|
||||||
|
#define LED_STATE_ON 1 // State when LED is lit
|
||||||
|
|
||||||
|
// Button
|
||||||
|
#define BUTTON_PIN (0 + 11) // P0.11, USER_BTN
|
||||||
|
#define BUTTON_ACTIVE_LOW false
|
||||||
|
#define BUTTON_ACTIVE_PULLUP false
|
||||||
|
#define BUTTON_SENSE_TYPE 0x5 // enable input pull-down
|
||||||
|
|
||||||
|
// Theft protection / tamper switch
|
||||||
|
#define TP_BUTTON_PIN (0 + 8) // P0.08
|
||||||
|
|
||||||
|
// Default detection sensor pin: tamper switch
|
||||||
|
#define DETECTION_SENSOR_DEFAULT_PIN TP_BUTTON_PIN
|
||||||
|
|
||||||
|
// I2C
|
||||||
|
#define HAS_WIRE 1
|
||||||
|
#define WIRE_INTERFACES_COUNT 1
|
||||||
|
#define PIN_WIRE_SDA (0 + 6) // P0.06
|
||||||
|
#define PIN_WIRE_SCL (0 + 5) // P0.05
|
||||||
|
#define I2C_NO_RESCAN
|
||||||
|
|
||||||
|
// Accelerometer enable (used in initVariant)
|
||||||
|
#define ACC_EN_PIN (0 + 15) // P0.15
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Serial interfaces
|
||||||
|
*/
|
||||||
|
// Serial1: GPS (GNSS)
|
||||||
|
#define PIN_SERIAL1_RX (0 + 26) // P0.26
|
||||||
|
#define PIN_SERIAL1_TX (0 + 27) // P0.27
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SPI Interfaces (LoRa SX1262)
|
||||||
|
*/
|
||||||
|
#define SPI_INTERFACES_COUNT 1
|
||||||
|
|
||||||
|
#define PIN_SPI_MISO (0 + 3) // P0.03
|
||||||
|
#define PIN_SPI_MOSI (0 + 28) // P0.28
|
||||||
|
#define PIN_SPI_SCK (0 + 30) // P0.30
|
||||||
|
#define PIN_SPI_NSS (32 + 14) // P1.14
|
||||||
|
|
||||||
|
// LoRa SX1262
|
||||||
|
#define LORA_RESET (32 + 7) // P1.07, RST
|
||||||
|
#define LORA_DIO1 (0 + 7) // P0.07, IRQ/DIO1
|
||||||
|
#define LORA_DIO2 (32 + 10) // P1.10, BUSY
|
||||||
|
#define LORA_SCK PIN_SPI_SCK
|
||||||
|
#define LORA_MISO PIN_SPI_MISO
|
||||||
|
#define LORA_MOSI PIN_SPI_MOSI
|
||||||
|
#define LORA_CS PIN_SPI_NSS
|
||||||
|
|
||||||
|
// Supported modules list
|
||||||
|
#define USE_SX1262
|
||||||
|
|
||||||
|
#define SX126X_CS LORA_CS
|
||||||
|
#define SX126X_DIO1 LORA_DIO1
|
||||||
|
#define SX126X_BUSY LORA_DIO2
|
||||||
|
#define SX126X_RESET LORA_RESET
|
||||||
|
#define SX126X_DIO2_AS_RF_SWITCH
|
||||||
|
#define SX126X_DIO3_TCXO_VOLTAGE 1.8
|
||||||
|
|
||||||
|
// GPS L76K
|
||||||
|
#define HAS_GPS 1
|
||||||
|
#define GPS_L76K
|
||||||
|
#define GPS_RX_PIN PIN_SERIAL1_RX
|
||||||
|
#define GPS_TX_PIN PIN_SERIAL1_TX
|
||||||
|
|
||||||
|
#define GPS_BAUDRATE 9600
|
||||||
|
|
||||||
|
#define PIN_GPS_EN (32 + 5) // P1.05, GNSS power control
|
||||||
|
#define GPS_EN_ACTIVE HIGH
|
||||||
|
|
||||||
|
#define PIN_GPS_RESET (32 + 6) // P1.06, GNSS reset
|
||||||
|
#define GPS_RESET_MODE HIGH
|
||||||
|
|
||||||
|
#define PIN_GPS_STANDBY (32 + 9) // P1.09, GNSS wakeup/standby
|
||||||
|
|
||||||
|
// Battery
|
||||||
|
#define BATTERY_PIN (0 + 31) // P0.31/AIN7, BAT_ADC
|
||||||
|
#define ADC_CTRL (0 + 2) // P0.02, BAT_ADC enable
|
||||||
|
#define ADC_CTRL_ENABLED HIGH
|
||||||
|
#define BATTERY_IMMUTABLE
|
||||||
|
#define ADC_MULTIPLIER (2.0F)
|
||||||
|
|
||||||
|
#define ADC_RESOLUTION 14
|
||||||
|
#define BATTERY_SENSE_RESOLUTION_BITS 12
|
||||||
|
|
||||||
|
#undef AREF_VOLTAGE
|
||||||
|
#define AREF_VOLTAGE 3.0
|
||||||
|
#define VBAT_AR_INTERNAL AR_INTERNAL_3_0
|
||||||
|
|
||||||
|
#define OCV_ARRAY 4000, 3951, 3910, 3867, 3772, 3687, 3593, 3519, 3463, 3297, 3100
|
||||||
|
|
||||||
|
#define nRF_FLASH_POWER_CTR (32 + 13) // P1.13
|
||||||
|
|
||||||
|
#define HAS_SCREEN 0
|
||||||
|
|
||||||
|
// Enable Traffic Management Module
|
||||||
|
// NRF52840 has 256KB RAM - 1024 entries uses ~10KB
|
||||||
|
#ifndef HAS_TRAFFIC_MANAGEMENT
|
||||||
|
#define HAS_TRAFFIC_MANAGEMENT 1
|
||||||
|
#endif
|
||||||
|
#ifndef TRAFFIC_MANAGEMENT_CACHE_SIZE
|
||||||
|
#define TRAFFIC_MANAGEMENT_CACHE_SIZE 1024
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
* Arduino objects - C++ only
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#endif // _VARIANT_TRACKER_T2000_C_
|
||||||
Reference in New Issue
Block a user