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:
1 parent
86c4849e55
commit
f3c81b559b
12 files changed
+120
-9
No files matched your search
@@ -27,6 +27,8 @@ public:
|
||||
virtual void turnOff() = 0;
|
||||
virtual void clear() = 0;
|
||||
virtual void startFrame(ColorVal bkg = UIColor::window_bkg) = 0;
|
||||
// Rotate 180 degrees from the compiled orientation. No-op where unsupported.
|
||||
virtual void setFlipped(bool flipped) { }
|
||||
virtual void setTextSize(int sz) = 0;
|
||||
virtual void setColor(ColorVal c) = 0;
|
||||
virtual void setCursor(int x, int y) = 0;
|
||||
|
||||
@@ -33,6 +33,19 @@ static DisplayViewport::Geometry portraitViewport(int16_t physical_width, int16_
|
||||
}
|
||||
#endif
|
||||
|
||||
// The compiled orientation, optionally turned 180 degrees by `display.flip`.
|
||||
// Adding 2 keeps portrait portrait and landscape landscape, so the viewport
|
||||
// geometry below never has to change with it.
|
||||
uint8_t ST7789LCDDisplay::effectiveRotation() const {
|
||||
return (uint8_t)((DISPLAY_ROTATION + (_flipped ? 2 : 0)) & 3);
|
||||
}
|
||||
|
||||
void ST7789LCDDisplay::setFlipped(bool flipped) {
|
||||
if (_flipped == flipped) return;
|
||||
_flipped = flipped;
|
||||
if (_panel_ready) display.setRotation(effectiveRotation());
|
||||
}
|
||||
|
||||
bool ST7789LCDDisplay::i2c_probe(TwoWire& wire, uint8_t addr) {
|
||||
return true;
|
||||
}
|
||||
@@ -88,7 +101,7 @@ bool ST7789LCDDisplay::begin() {
|
||||
#endif
|
||||
|
||||
display.init(DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||
display.setRotation(DISPLAY_ROTATION);
|
||||
display.setRotation(effectiveRotation());
|
||||
|
||||
display.setSPISpeed(40e6);
|
||||
|
||||
@@ -107,9 +120,9 @@ bool ST7789LCDDisplay::begin() {
|
||||
if (PIN_TFT_LEDA_CTL != -1) {
|
||||
digitalWrite(PIN_TFT_LEDA_CTL, PIN_TFT_LEDA_CTL_ACTIVE);
|
||||
}
|
||||
_panel_ready = true;
|
||||
#endif
|
||||
|
||||
_panel_ready = true;
|
||||
_isOn = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,8 @@ class ST7789LCDDisplay : public DisplayDriver {
|
||||
#endif
|
||||
Adafruit_ST7789 display;
|
||||
bool _isOn;
|
||||
#ifdef HELTEC_V4_R8_TFT
|
||||
bool _panel_ready = false; // panel configured once; wake is backlight-only
|
||||
#endif
|
||||
bool _panel_ready = false; // panel has been configured at least once
|
||||
bool _flipped = false;
|
||||
uint16_t _color;
|
||||
RefCountedDigitalPin* _peripher_power;
|
||||
|
||||
@@ -27,6 +26,7 @@ class ST7789LCDDisplay : public DisplayDriver {
|
||||
void printFitted(const char* str, uint16_t available_width);
|
||||
#endif
|
||||
|
||||
uint8_t effectiveRotation() const;
|
||||
bool i2c_probe(TwoWire& wire, uint8_t addr);
|
||||
public:
|
||||
#ifdef USE_PIN_TFT
|
||||
@@ -59,6 +59,7 @@ public:
|
||||
void turnOff() override;
|
||||
void clear() override;
|
||||
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
|
||||
void setFlipped(bool flipped) override;
|
||||
void setTextSize(int sz) override;
|
||||
void setColor(ColorVal c) override;
|
||||
void setCursor(int x, int y) override;
|
||||
|
||||
Reference in new issue
Block a user