feat(display): add runtime display.flip for panel orientation

`set display.flip 0|1` (also off/on) turns the panel 180 degrees from its
compiled DISPLAY_ROTATION, persisted in MQTTPrefs alongside display.timeout
and applied live without a reboot.

Adding 2 to the compiled rotation rather than setting an absolute value keeps
portrait portrait and landscape landscape, so the DisplayViewport geometry
never changes with it and the setting cannot produce a nonsensical mix.
DisplayDriver gains a defaulted no-op setFlipped(), so no other display
driver is affected.

The compiled rotation was verified identical across `pio run` and `build.sh`
on two machines (movi a11, 2 at the setRotation call site), yet the panel read
upside down for one tester and upright for another - which is what a board
mounted either way up looks like. No single compiled constant satisfies both,
so orientation becomes a setting rather than another rebuild.

Runtime-only, like display_timeout_secs: LegacyV1MQTTPrefs and the frozen
binary payload sizes are untouched, and the JSON group is an append that older
firmware skips.
This commit is contained in:
agessaman committed 2026-08-28 14:37:03 -07:00
1 parent 11d7551ccd
commit ca17c2980c
12 files changed
+120 -9

No files matched your search

@@ -79,6 +79,7 @@ static MQTTPrefs defaults() {
prefs.alert_min_interval_min = 60;
prefs.mqtt_neighbors_interval = MQTT_NEIGHBORS_DEFAULT_INTERVAL_MS;
prefs.display_timeout_secs = DISPLAY_TIMEOUT_DEFAULT_SECS;
prefs.display_flip = 0;
strcpy(prefs.snmp_community, "public");
for (int i = 0; i < MQTT_PREFS_SLOT_COUNT; ++i) {
strcpy(prefs.mqtt_slot_preset[i], "none");
@@ -396,6 +397,34 @@ TEST(MQTTPrefsSerializer, DisplayTimeoutRoundTrips) {
}
}
TEST(MQTTPrefsSerializer, DisplayFlipRoundTripsAndRepairs) {
MQTTPrefs source = defaults();
EXPECT_EQ(0, source.display_flip);
source.display_flip = 1;
OutputStream output;
MQTTPrefsSerializer writer(&source);
ASSERT_TRUE(writer.saveSerial(output));
MQTTPrefs loaded = defaults();
InputStream input(output.text());
MQTTPrefsSerializer reader(&loaded);
ASSERT_TRUE(reader.loadSerial(input));
bool repaired = false;
ASSERT_TRUE(reader.apply(&repaired));
EXPECT_FALSE(repaired);
EXPECT_EQ(1, loaded.display_flip);
MQTTPrefs prefs = defaults();
InputStream bogus("{version:1,display:{flip:7}}");
MQTTPrefsSerializer bogus_serializer(&prefs);
ASSERT_TRUE(bogus_serializer.loadSerial(bogus));
repaired = false;
ASSERT_TRUE(bogus_serializer.apply(&repaired));
EXPECT_TRUE(repaired);
EXPECT_EQ(0, prefs.display_flip);
}
TEST(MQTTPrefsSerializer, RepairsDisplayTimeoutOutOfRange) {
MQTTPrefs prefs = defaults();
InputStream input("{version:1,display:{timeout_s:99999}}");