feat: complete Cascade Indicator companion support
Add native-resolution Indicator UI, touch navigation, SD-backed pixel and emoji fonts, LoRa radio support, dual-slot WiFi Companion provisioning, and mesh clock fallback. Harden radio recovery and build defaults, normalize ESP32 setup-AP protocols, and document/test the operator workflows.
This commit is contained in:
1 parent
1792acda6a
commit
9d57a3a4f8
55 files changed
+4185
-175
No files matched your search
@@ -0,0 +1,93 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <helpers/ui/ColorEmojiAtlas.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
using mesh::ui::ColorEmojiAtlas;
|
||||
|
||||
namespace {
|
||||
|
||||
void append16(std::vector<uint8_t>& data, uint16_t value) {
|
||||
data.push_back((uint8_t)value);
|
||||
data.push_back((uint8_t)(value >> 8));
|
||||
}
|
||||
|
||||
void append32(std::vector<uint8_t>& data, uint32_t value) {
|
||||
data.push_back((uint8_t)value);
|
||||
data.push_back((uint8_t)(value >> 8));
|
||||
data.push_back((uint8_t)(value >> 16));
|
||||
data.push_back((uint8_t)(value >> 24));
|
||||
}
|
||||
|
||||
uint32_t crc32(const uint8_t* data, size_t size) {
|
||||
uint32_t crc = 0xFFFFFFFFUL;
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
crc ^= data[i];
|
||||
for (uint8_t bit = 0; bit < 8; ++bit) {
|
||||
crc = (crc >> 1) ^ (0xEDB88320UL & (0U - (crc & 1U)));
|
||||
}
|
||||
}
|
||||
return ~crc;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> sampleFont() {
|
||||
std::vector<uint8_t> font(24, 0x55);
|
||||
const uint32_t map_offset = font.size();
|
||||
std::vector<uint8_t> map = {
|
||||
'E', 'M', '0', '1', 1, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
font.insert(font.end(), map.begin(), map.end());
|
||||
|
||||
const uint32_t atlas_offset = font.size();
|
||||
std::vector<uint8_t> atlas = {
|
||||
'C', 'E', '0', '1',
|
||||
2, 0, 2, 2, 0xE3, 3, 4, 0,
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
};
|
||||
font.insert(font.end(), atlas.begin(), atlas.end());
|
||||
|
||||
font.insert(font.end(), {'M', 'C', 'E', 'M', 'A', 'P', '2', 0});
|
||||
append32(font, map_offset);
|
||||
append32(font, map.size());
|
||||
append32(font, crc32(map.data(), map.size()));
|
||||
append32(font, atlas_offset);
|
||||
append32(font, atlas.size());
|
||||
append32(font, crc32(atlas.data(), atlas.size()));
|
||||
append32(font, 0);
|
||||
append32(font, 0);
|
||||
return font;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(ColorEmojiAtlas, ReadsGlyphsAndMetrics) {
|
||||
std::vector<uint8_t> font = sampleFont();
|
||||
ColorEmojiAtlas atlas;
|
||||
ASSERT_TRUE(atlas.begin(font.data(), font.size()));
|
||||
EXPECT_EQ(2, atlas.width());
|
||||
EXPECT_EQ(2, atlas.height());
|
||||
EXPECT_EQ(3, atlas.textScale());
|
||||
EXPECT_EQ(0xE3, atlas.transparent());
|
||||
ASSERT_NE(nullptr, atlas.glyph(0xE000));
|
||||
EXPECT_EQ(1, atlas.glyph(0xE000)[0]);
|
||||
EXPECT_EQ(8, atlas.glyph(0xE001)[3]);
|
||||
EXPECT_EQ(nullptr, atlas.glyph(0xDFFF));
|
||||
EXPECT_EQ(nullptr, atlas.glyph(0xE002));
|
||||
}
|
||||
|
||||
TEST(ColorEmojiAtlas, RejectsCorruptAtlas) {
|
||||
std::vector<uint8_t> font = sampleFont();
|
||||
font[50] ^= 0x80;
|
||||
ColorEmojiAtlas atlas;
|
||||
EXPECT_FALSE(atlas.begin(font.data(), font.size()));
|
||||
EXPECT_FALSE(atlas.isReady());
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <helpers/ui/DisplayDriver.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
|
||||
bool isValidUTF8(const char* text) {
|
||||
for (size_t offset = 0; text[offset] != 0;) {
|
||||
uint8_t first = (uint8_t)text[offset];
|
||||
size_t length = 1;
|
||||
if (first >= 0xC2 && first <= 0xDF) {
|
||||
length = 2;
|
||||
} else if (first >= 0xE0 && first <= 0xEF) {
|
||||
length = 3;
|
||||
} else if (first >= 0xF0 && first <= 0xF4) {
|
||||
length = 4;
|
||||
} else if (first >= 0x80) {
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 1; i < length; ++i) {
|
||||
if (text[offset + i] == 0
|
||||
|| ((uint8_t)text[offset + i] & 0xC0) != 0x80) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
offset += length;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
class TestDisplay : public DisplayDriver {
|
||||
public:
|
||||
std::string printed;
|
||||
|
||||
TestDisplay() : DisplayDriver(100, 100) {}
|
||||
|
||||
bool isOn() override { return true; }
|
||||
void turnOn() override {}
|
||||
void turnOff() override {}
|
||||
void clear() override {}
|
||||
void startFrame(ColorVal) override {}
|
||||
void setTextSize(int) override {}
|
||||
void setColor(ColorVal) override {}
|
||||
void setCursor(int, int) override {}
|
||||
void print(const char* str) override { printed = str; }
|
||||
void fillRect(int, int, int, int) override {}
|
||||
void drawRect(int, int, int, int) override {}
|
||||
void drawXbm(int, int, const uint8_t*, int, int) override {}
|
||||
uint16_t getTextWidth(const char* str) override {
|
||||
uint16_t width = 0;
|
||||
for (size_t i = 0; str[i] != 0; ++i) {
|
||||
if (((uint8_t)str[i] & 0xC0) != 0x80) ++width;
|
||||
}
|
||||
return width;
|
||||
}
|
||||
void endFrame() override {}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(DisplayDriver, EllipsizesOnlyAtUTF8CodepointBoundaries) {
|
||||
TestDisplay display;
|
||||
display.drawTextEllipsized(0, 0, 5, "AB\xF0\x9F\x98\x80" "CDE");
|
||||
EXPECT_EQ("AB...", display.printed);
|
||||
EXPECT_TRUE(isValidUTF8(display.printed.c_str()));
|
||||
}
|
||||
|
||||
TEST(DisplayDriver, FixedBufferDoesNotSplitUTF8Codepoint) {
|
||||
TestDisplay display;
|
||||
std::string text(254, 'A');
|
||||
text += "\xF0\x9F\x98\x80";
|
||||
text += 'B';
|
||||
display.drawTextEllipsized(0, 0, 255, text.c_str());
|
||||
EXPECT_EQ(std::string(254, 'A'), display.printed);
|
||||
EXPECT_TRUE(isValidUTF8(display.printed.c_str()));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <helpers/ui/EmojiFontMap.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
|
||||
using mesh::ui::EmojiFontMap;
|
||||
|
||||
namespace {
|
||||
|
||||
void append16(std::vector<uint8_t>& data, uint16_t value) {
|
||||
data.push_back((uint8_t)value);
|
||||
data.push_back((uint8_t)(value >> 8));
|
||||
}
|
||||
|
||||
void append32(std::vector<uint8_t>& data, uint32_t value) {
|
||||
data.push_back((uint8_t)value);
|
||||
data.push_back((uint8_t)(value >> 8));
|
||||
data.push_back((uint8_t)(value >> 16));
|
||||
data.push_back((uint8_t)(value >> 24));
|
||||
}
|
||||
|
||||
uint32_t crc32(const uint8_t* data, size_t size) {
|
||||
uint32_t crc = 0xFFFFFFFFUL;
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
crc ^= data[i];
|
||||
for (uint8_t bit = 0; bit < 8; ++bit) {
|
||||
crc = (crc >> 1) ^ (0xEDB88320UL & (0U - (crc & 1U)));
|
||||
}
|
||||
}
|
||||
return ~crc;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> sampleFont() {
|
||||
std::vector<uint8_t> font(32, 0x55);
|
||||
const uint32_t map_offset = font.size();
|
||||
std::vector<uint8_t> map;
|
||||
map.insert(map.end(), {'E', 'M', '0', '1'});
|
||||
append16(map, 6); // nodes
|
||||
append16(map, 5); // edges
|
||||
append32(map, 0);
|
||||
|
||||
// Root: F0 -> 1
|
||||
append16(map, 0); append16(map, 1); append16(map, 0);
|
||||
// F0: 9F -> 2
|
||||
append16(map, 1); append16(map, 1); append16(map, 0);
|
||||
// F0 9F: 98 -> 3
|
||||
append16(map, 2); append16(map, 1); append16(map, 0);
|
||||
// F0 9F 98: 80 -> 4
|
||||
append16(map, 3); append16(map, 1); append16(map, 0);
|
||||
// Grinning face, also prefix of the test sequence below.
|
||||
append16(map, 4); append16(map, 1); append16(map, 0xE000);
|
||||
// Grinning face followed by '!'.
|
||||
append16(map, 5); append16(map, 0); append16(map, 0xE001);
|
||||
|
||||
map.push_back(0xF0); append16(map, 1);
|
||||
map.push_back(0x9F); append16(map, 2);
|
||||
map.push_back(0x98); append16(map, 3);
|
||||
map.push_back(0x80); append16(map, 4);
|
||||
map.push_back('!'); append16(map, 5);
|
||||
|
||||
font.insert(font.end(), map.begin(), map.end());
|
||||
font.insert(font.end(), {'M', 'C', 'E', 'M', 'A', 'P', '1', 0});
|
||||
append32(font, map_offset);
|
||||
append32(font, map.size());
|
||||
append32(font, crc32(map.data(), map.size()));
|
||||
append32(font, 0);
|
||||
return font;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> sampleVersion2Font() {
|
||||
std::vector<uint8_t> font = sampleFont();
|
||||
font.resize(font.size() - 24);
|
||||
const uint32_t map_offset = 32;
|
||||
const uint32_t map_size = font.size() - map_offset;
|
||||
const uint32_t map_crc = crc32(font.data() + map_offset, map_size);
|
||||
font.insert(font.end(), {'M', 'C', 'E', 'M', 'A', 'P', '2', 0});
|
||||
append32(font, map_offset);
|
||||
append32(font, map_size);
|
||||
append32(font, map_crc);
|
||||
for (int i = 0; i < 5; ++i) append32(font, 0);
|
||||
return font;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(EmojiFontMap, UsesLongestSequenceMatch) {
|
||||
std::vector<uint8_t> font = sampleFont();
|
||||
EmojiFontMap map;
|
||||
ASSERT_TRUE(map.begin(font.data(), font.size()));
|
||||
|
||||
const uint8_t text[] = {0xF0, 0x9F, 0x98, 0x80, '!', 'x'};
|
||||
uint16_t output = 0;
|
||||
EXPECT_EQ(5U, map.longestMatch(text, sizeof(text), output));
|
||||
EXPECT_EQ(0xE001, output);
|
||||
|
||||
EXPECT_EQ(4U, map.longestMatch(text, 4, output));
|
||||
EXPECT_EQ(0xE000, output);
|
||||
}
|
||||
|
||||
TEST(EmojiFontMap, RejectsCorruptMappingData) {
|
||||
std::vector<uint8_t> font = sampleFont();
|
||||
font[40] ^= 0x80;
|
||||
EmojiFontMap map;
|
||||
EXPECT_FALSE(map.begin(font.data(), font.size()));
|
||||
EXPECT_FALSE(map.isReady());
|
||||
}
|
||||
|
||||
TEST(EmojiFontMap, RejectsMissingFooter) {
|
||||
uint8_t data[64] = {};
|
||||
EmojiFontMap map;
|
||||
EXPECT_FALSE(map.begin(data, sizeof(data)));
|
||||
}
|
||||
|
||||
TEST(EmojiFontMap, AcceptsVersion2Footer) {
|
||||
std::vector<uint8_t> font = sampleVersion2Font();
|
||||
EmojiFontMap map;
|
||||
ASSERT_TRUE(map.begin(font.data(), font.size()));
|
||||
|
||||
const uint8_t text[] = {0xF0, 0x9F, 0x98, 0x80};
|
||||
uint16_t output = 0;
|
||||
EXPECT_EQ(sizeof(text), map.longestMatch(text, sizeof(text), output));
|
||||
EXPECT_EQ(0xE000, output);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <helpers/ui/TouchInput.h>
|
||||
|
||||
using mesh::ui::TouchAction;
|
||||
using mesh::ui::TouchInput;
|
||||
|
||||
namespace {
|
||||
|
||||
TouchAction release(TouchInput& input, int width = 137, int height = 137) {
|
||||
EXPECT_EQ(input.update(false, -1, -1, width, height), TouchAction::None);
|
||||
return input.update(false, -1, -1, width, height);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(TouchInput, EmitsOnlyAfterRelease) {
|
||||
TouchInput input;
|
||||
EXPECT_EQ(input.update(true, 70, 50, 137, 137), TouchAction::None);
|
||||
EXPECT_EQ(input.update(true, 72, 51, 137, 137), TouchAction::None);
|
||||
EXPECT_EQ(release(input), TouchAction::Select);
|
||||
EXPECT_EQ(input.update(false, -1, -1, 137, 137), TouchAction::None);
|
||||
}
|
||||
|
||||
TEST(TouchInput, MapsTapZonesToAllActions) {
|
||||
TouchInput input;
|
||||
|
||||
input.update(true, 10, 60, 137, 137);
|
||||
input.update(true, 10, 60, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Previous);
|
||||
|
||||
input.update(true, 68, 60, 137, 137);
|
||||
input.update(true, 68, 60, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Select);
|
||||
|
||||
input.update(true, 125, 60, 137, 137);
|
||||
input.update(true, 125, 60, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Next);
|
||||
}
|
||||
|
||||
TEST(TouchInput, CanUseAWiderCenterTapZone) {
|
||||
TouchInput input(false, false, 70);
|
||||
|
||||
input.update(true, 25, 60, 137, 137);
|
||||
input.update(true, 25, 60, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Select);
|
||||
|
||||
input.update(true, 10, 60, 137, 137);
|
||||
input.update(true, 10, 60, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Previous);
|
||||
|
||||
input.update(true, 127, 60, 137, 137);
|
||||
input.update(true, 127, 60, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Next);
|
||||
}
|
||||
|
||||
TEST(TouchInput, MapsHorizontalSwipesToPageNavigation) {
|
||||
TouchInput input;
|
||||
|
||||
input.update(true, 110, 60, 137, 137);
|
||||
input.update(true, 40, 62, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Next);
|
||||
|
||||
input.update(true, 30, 60, 137, 137);
|
||||
input.update(true, 105, 58, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Previous);
|
||||
}
|
||||
|
||||
TEST(TouchInput, MapsVerticalSwipesToPageNavigation) {
|
||||
TouchInput input;
|
||||
|
||||
input.update(true, 60, 110, 137, 137);
|
||||
input.update(true, 62, 35, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Next);
|
||||
|
||||
input.update(true, 60, 25, 137, 137);
|
||||
input.update(true, 58, 105, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Previous);
|
||||
}
|
||||
|
||||
TEST(TouchInput, CanRouteVerticalSwipesToASeparateSelector) {
|
||||
TouchInput input(true, true);
|
||||
|
||||
input.update(true, 60, 110, 137, 137);
|
||||
input.update(true, 62, 35, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::VerticalPrevious);
|
||||
|
||||
input.update(true, 60, 25, 137, 137);
|
||||
input.update(true, 58, 105, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::VerticalNext);
|
||||
|
||||
input.update(true, 110, 60, 137, 137);
|
||||
input.update(true, 40, 62, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Previous);
|
||||
}
|
||||
|
||||
TEST(TouchInput, BottomSelectorHasLargeArrowTapTargets) {
|
||||
TouchInput input(true, true, 70);
|
||||
|
||||
input.update(true, 15, 125, 137, 137, true);
|
||||
input.update(true, 15, 125, 137, 137, true);
|
||||
EXPECT_EQ(input.update(false, -1, -1, 137, 137, true),
|
||||
TouchAction::None);
|
||||
EXPECT_EQ(input.update(false, -1, -1, 137, 137, true),
|
||||
TouchAction::VerticalPrevious);
|
||||
|
||||
input.update(true, 122, 125, 137, 137, true);
|
||||
input.update(true, 122, 125, 137, 137, true);
|
||||
EXPECT_EQ(input.update(false, -1, -1, 137, 137, true),
|
||||
TouchAction::None);
|
||||
EXPECT_EQ(input.update(false, -1, -1, 137, 137, true),
|
||||
TouchAction::VerticalNext);
|
||||
|
||||
input.update(true, 68, 125, 137, 137, true);
|
||||
input.update(true, 68, 125, 137, 137, true);
|
||||
EXPECT_EQ(input.update(false, -1, -1, 137, 137, true),
|
||||
TouchAction::None);
|
||||
EXPECT_EQ(input.update(false, -1, -1, 137, 137, true),
|
||||
TouchAction::None);
|
||||
}
|
||||
|
||||
TEST(TouchInput, CanReverseSwipesWithoutReversingTapZones) {
|
||||
TouchInput input(true);
|
||||
|
||||
input.update(true, 110, 60, 137, 137);
|
||||
input.update(true, 40, 62, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Previous);
|
||||
|
||||
input.update(true, 30, 60, 137, 137);
|
||||
input.update(true, 105, 58, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Next);
|
||||
|
||||
input.update(true, 10, 60, 137, 137);
|
||||
input.update(true, 10, 60, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Previous);
|
||||
|
||||
input.update(true, 125, 60, 137, 137);
|
||||
input.update(true, 125, 60, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Next);
|
||||
}
|
||||
|
||||
TEST(TouchInput, KeepsGestureAcrossOneMissingTouchSample) {
|
||||
TouchInput input;
|
||||
|
||||
input.update(true, 110, 60, 137, 137);
|
||||
input.update(true, 80, 61, 137, 137);
|
||||
EXPECT_EQ(input.update(false, -1, -1, 137, 137), TouchAction::None);
|
||||
input.update(true, 40, 62, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Next);
|
||||
}
|
||||
|
||||
TEST(TouchInput, IgnoresContactWithNoDirectionSample) {
|
||||
TouchInput input;
|
||||
|
||||
input.update(true, 120, 60, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::None);
|
||||
}
|
||||
|
||||
TEST(TouchInput, UsesStartZoneForShortAmbiguousMovement) {
|
||||
TouchInput input(true);
|
||||
|
||||
input.update(true, 40, 60, 137, 137);
|
||||
input.update(true, 52, 60, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Previous);
|
||||
}
|
||||
|
||||
TEST(TouchInput, RepeatedSwipesKeepTheSameDirection) {
|
||||
TouchInput input(true);
|
||||
|
||||
for (int attempt = 0; attempt < 10; ++attempt) {
|
||||
input.update(true, 110, 60, 137, 137);
|
||||
input.update(true, 72, 61, 137, 137);
|
||||
input.update(true, 35, 62, 137, 137);
|
||||
EXPECT_EQ(release(input), TouchAction::Previous);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in new issue
Block a user