Use compact message text and sender lines on all small displays

This commit is contained in:
mikecarper committed 2026-09-08 13:36:40 -07:00
1 parent a7f088290b
commit eeea15ef01
19 files changed
+507 -141

No files matched your search

+21 -42
View File
@@ -1,9 +1,11 @@
#include <helpers/ui/SSD1306Display.h>
#include <helpers/ui/Pixel5Text.h>
#include <Fonts/Picopixel.h>
#include <cassert>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
void save(const char* file) {
auto& c=*Adafruit_SSD1306::last;
std::ofstream f(file);
@@ -15,56 +17,33 @@ int main(int argc, char** argv) {
assert(d.begin());
auto& c=*Adafruit_SSD1306::last;
const char* message="GIANT KILLER: Out on the Mercerwood mesh today, just the V4 and a small battery Checking the smaller font so the rest of this message is visible. 0123456789 END";
assert(std::string(message).size()==160);
d.startFrame();
d.setCursor(0,0); d.print("Message 3/29");
d.setCursor(86,0); d.print("1m ago");
d.drawRect(0,11,128,1);
d.setCursor(0,14); d.print("Ch 0 Public [4h]:");
d.setCursor(0,25);
#if UI_SSD1306_PICOPIXEL_MESSAGES == 1
d.printWordWrap(message,128);
#if UI_SMALL_MESSAGE_FONT == 1
mesh::ui::drawSmallMessageBody(d,"Ch 0 Public [4h]:",message);
#else
d.print(std::string(message,77).c_str());
d.setCursor(0,14); d.print("Ch 0 Public [4h]:");
d.setCursor(0,25); d.print(std::string(message,77).c_str());
#endif
if (argc > 1) save(argv[1]);
#if UI_SSD1306_PICOPIXEL_MESSAGES == 1
std::string shown;
for (const auto& g:c.glyphs) {
shown += g.c;
if (g.w && g.h) assert(g.x>=0 && g.x+g.w<=128 && g.y>=25 && g.y+g.h<=64);
}
assert(shown==message);
#if UI_SMALL_MESSAGE_FONT == 1
assert(c.outside==0);
assert(d.getTextWidth("ABC")==18); // regular font restored
d.setCursor(0,0); d.print("Regular font");
assert(d.getTextWidth("ABC")==18);
int checks=1;
for (int rotation:{0,90,180,270}) for (int top:{0,25,55,58,59,63,64}) {
d.setRotationDegrees(rotation);
d.startFrame(); d.setCursor(0,top);
d.printWordWrap(std::string(160,'W').c_str(),d.width());
for (const auto& g:c.glyphs) {
if (g.w && g.h) assert(g.x>=0 && g.x+g.w<=d.width() && g.y>=top && g.y+g.h<=d.height());
}
if (!c.glyphs.empty()) {
std::string row;
for (const auto& g:c.glyphs) row += g.c;
while (!row.empty() && row.back()==' ') row.pop_back();
assert(row==std::string(160, 'W') || (row.size()>=3 && row.substr(row.size()-3)=="..."));
}
assert(c.outside==0);
++checks;
}
d.setRotationDegrees(0);
assert(d.getTextWidth("ABC")==18); // regular driver font untouched
mesh::ui::Pixel5Text text(d);
GFXcanvas1 reference(128,64);
reference.setFont(&Picopixel);
reference.setTextColor(1);
for (int ch=32;ch<=126;ch++) {
d.startFrame(); d.setCursor(0,25);
d.printWordWrap(std::string(160,char(ch)).c_str(),128);
assert(c.outside==0);
++checks;
d.startFrame(); text.setCursor(3,25);
text.print(std::string(1,char(ch)).c_str());
reference.fillScreen(0); reference.setCursor(3,29); reference.write(ch);
for (int y=0;y<64;y++) for (int x=0;x<128;x++)
assert(c.getPixel(x,y)==reference.getPixel(x,y));
assert(text.getTextWidth(std::string(1,char(ch)).c_str())==PicopixelGlyphs[ch-32].xAdvance);
}
d.startFrame(); d.setCursor(0,25);
d.printWordWrap("A\xDB" "B",128);
assert(c.glyphs.size()==3 && c.glyphs[1].c=='?');
std::cout << "Checks: " << checks+1 << "; sample characters: " << shown.size() << "; sample: " << shown << '\n';
std::cout << "95 glyphs match Adafruit GFX Picopixel pixel for pixel; normal font preserved\n";
#endif
}
@@ -3,6 +3,7 @@
#include <helpers/ui/DisplayDriver.h>
#include <helpers/ui/CompanionHomeLayout.h>
#include <helpers/ui/DisplayTextLayout.h>
#include <helpers/ui/Pixel5Text.h>
#include <helpers/ui/WiFiSetupQrDisplay.h>
#include <helpers/ui/WiFiSetupQrPayload.h>
@@ -133,6 +134,66 @@ TEST(DisplayDriver, EllipsizesOnlyAtUTF8CodepointBoundaries) {
EXPECT_TRUE(isValidUTF8(display.printed.c_str()));
}
TEST(Pixel5Text, CapitalsAreFivePixelsAndNormalFontIsUntouched) {
TestDisplay display(128, 64, 6);
mesh::ui::Pixel5Text text(display);
text.setCursor(0, 0);
text.print("A");
const char* rows[] = {"010", "101", "111", "101", "101"};
bool pixels[5][3] = {};
for (const auto& pixel : display.fills) {
ASSERT_GE(pixel.x, 0); ASSERT_LT(pixel.x, 3);
ASSERT_GE(pixel.y, 0); ASSERT_LT(pixel.y, 5);
pixels[pixel.y][pixel.x] = true;
}
for (int y = 0; y < 5; ++y) for (int x = 0; x < 3; ++x)
EXPECT_EQ(rows[y][x] == '1', pixels[y][x]);
EXPECT_EQ(12, text.getTextWidth("ABC"));
EXPECT_EQ(18, display.getTextWidth("ABC"));
}
TEST(Pixel5Text, CompactOriginAllowsSixCompleteMessageRows) {
TestDisplay display(128, 64);
mesh::ui::drawSmallMessageBody(display, std::string(61, 'W').c_str(),
std::string(160, 'W').c_str());
ASSERT_FALSE(display.fills.empty());
bool final_dots[3] = {};
for (const auto& pixel : display.fills) {
EXPECT_GE(pixel.x, 0); EXPECT_LT(pixel.x, 128);
EXPECT_GE(pixel.y, 14); EXPECT_LT(pixel.y, 64);
// The origin stays in its own line; its long name cannot cover the body.
EXPECT_TRUE(pixel.y < 20 || pixel.y >= 21);
for (int i = 0; i < 3; ++i)
if (pixel.y == 60 && pixel.x == 120 + 2 * i) final_dots[i] = true;
}
for (bool dot : final_dots) EXPECT_TRUE(dot);
EXPECT_EQ(5, mesh::ui::smallMessageLineCount(64, 25));
EXPECT_EQ(6, mesh::ui::smallMessageLineCount(64, 21));
EXPECT_EQ(3, mesh::ui::smallMessageLineCount(40, 17));
EXPECT_EQ(0, mesh::ui::smallMessageLineCount(64, 59));
}
TEST(Pixel5Text, GlyphsStayInsideTinyAndRotatedScreens) {
for (auto dimensions : {std::pair<int, int>{72, 40}, {64, 128}, {128, 64}}) {
TestDisplay display(dimensions.first, dimensions.second);
mesh::ui::Pixel5Text text(display);
for (int c = 32; c <= 126; ++c) {
display.fills.clear();
text.setCursor(0, display.height() - 6);
text.printWordWrap(std::string(160, char(c)).c_str(), display.width());
for (const auto& pixel : display.fills) {
EXPECT_GE(pixel.x, 0); EXPECT_LT(pixel.x, display.width());
EXPECT_GE(pixel.y, display.height() - 6);
EXPECT_LT(pixel.y, display.height());
}
}
display.fills.clear();
text.setCursor(0, display.height() - 5);
text.printWordWrap("must not start a clipped final line", display.width());
EXPECT_TRUE(display.fills.empty());
}
}
TEST(DisplayDriver, QrCodeIsOptionalByDefault) {
TestDisplay display;
EXPECT_FALSE(display.drawQrCode("WIFI:T:nopass;S:MC-Set-90DF;;",
+7 -2
View File
@@ -67,7 +67,7 @@ def esp_fixture(path, modern=False, fragmented=False):
class FirmwareRamTest(unittest.TestCase):
def test_longer_display_previews_reserve_heap_and_contiguous_history(self):
defines = {"DISPLAY_CLASS": "SSD1306Display"}
defines = {"DISPLAY_CLASS": "SSD1306Display", "UI_SMALL_MESSAGE_FONT": 0}
base = ram.requirements("ESP32_PLATFORM", defines, "v4_companion")
expanded = ram.requirements("ESP32_PLATFORM", {
**defines, "UI_MSG_PREVIEW_SIZE": 161,
@@ -80,6 +80,10 @@ class FirmwareRamTest(unittest.TestCase):
**defines, "UI_MSG_PREVIEW_SIZE": 32,
}, "v4_companion")
self.assertEqual(smaller, base)
default = ram.requirements("ESP32_PLATFORM", {
"DISPLAY_CLASS": "SSD1306Display",
}, "v4_companion")
self.assertEqual(default, expanded)
def test_published_image_tables_match_elf_and_use_its_own_reservations(self):
with tempfile.TemporaryDirectory() as temp:
@@ -166,7 +170,8 @@ int main() {
subprocess.run([str(binary)], check=True)
def test_t096_release_fails_and_exact_boundary_passes(self):
flags = {"COMPANION_RADIO_FULL": 1, "DISPLAY_CLASS": "ST7735Display", "BLE_PIN_CODE": 123456}
flags = {"COMPANION_RADIO_FULL": 1, "DISPLAY_CLASS": "ST7735Display",
"BLE_PIN_CODE": 123456, "UI_SMALL_MESSAGE_FONT": 0}
with tempfile.TemporaryDirectory() as temp, contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
path = Path(temp) / "firmware.elf"
for available, accepted in ((54724, False), (73727, False), (73728, True), (74060, True)):
+2 -3
View File
@@ -3,8 +3,7 @@
Build a V4 environment first to install Adafruit GFX, or point
MESHCORE_GFX_LIBRARY to that library's directory. Only the hardware panel,
Arduino strings and Print glue are replaced; font metrics and drawing come
from the library used by the firmware.
Arduino strings and Print glue are replaced; the shared pixel renderer is compared with the original Adafruit font.
"""
import os
@@ -35,7 +34,7 @@ class SSD1306PicopixelTest(unittest.TestCase):
result = subprocess.run([
"c++", "-std=c++17", "-g",
"-fsanitize=address,undefined", "-DARDUINO=10819",
f"-DUI_SSD1306_PICOPIXEL_MESSAGES={enabled}",
f"-DUI_SMALL_MESSAGE_FONT={enabled}",
"-I", str(FIXTURE / "mocks"),
"-I", str(ROOT / "src"), "-I", str(library),
str(ROOT / "src/helpers/ui/SSD1306Display.cpp"),