Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/companion_radio/DataStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no
file.read(pad, 2); // 78
file.read((uint8_t *)&_prefs.ble_pin, sizeof(_prefs.ble_pin)); // 80
file.read((uint8_t *)&_prefs.buzzer_quiet, sizeof(_prefs.buzzer_quiet)); // 84
file.read((uint8_t *)&_prefs.invert_display, sizeof(_prefs.invert_display)); // 85

file.close();
}
Expand Down Expand Up @@ -254,6 +255,7 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_
file.write(pad, 2); // 78
file.write((uint8_t *)&_prefs.ble_pin, sizeof(_prefs.ble_pin)); // 80
file.write((uint8_t *)&_prefs.buzzer_quiet, sizeof(_prefs.buzzer_quiet)); // 84
file.write((uint8_t *)&_prefs.invert_display, sizeof(_prefs.invert_display)); // 85

file.close();
}
Expand Down
1 change: 1 addition & 0 deletions examples/companion_radio/NodePrefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ struct NodePrefs { // persisted to file
uint32_t ble_pin;
uint8_t advert_loc_policy;
uint8_t buzzer_quiet;
uint8_t invert_display; // 0 = normal (black on white), 1 = inverted (white on black)
};
24 changes: 24 additions & 0 deletions examples/companion_radio/ui-new/UITask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class HomeScreen : public UIScreen {
RADIO,
BLUETOOTH,
ADVERT,
INVERT,
#if ENV_INCLUDE_GPS == 1
GPS,
#endif
Expand Down Expand Up @@ -257,6 +258,12 @@ class HomeScreen : public UIScreen {
display.setColor(DisplayDriver::GREEN);
display.drawXbm((display.width() - 32) / 2, 18, advert_icon, 32, 32);
display.drawTextCentered(display.width() / 2, 64 - 11, "advert: " PRESS_LABEL);
} else if (_page == HomePage::INVERT) {
display.setColor(DisplayDriver::GREEN);
char buf[24];
sprintf(buf, "Invert: %s", _node_prefs->invert_display ? "ON" : "OFF");
display.drawTextCentered(display.width() / 2, 32, buf);
display.drawTextCentered(display.width() / 2, 64 - 11, "toggle: " PRESS_LABEL);
#if ENV_INCLUDE_GPS == 1
} else if (_page == HomePage::GPS) {
LocationProvider* nmea = sensors.getLocationProvider();
Expand Down Expand Up @@ -423,6 +430,10 @@ class HomeScreen : public UIScreen {
return true;
}
#endif
if (c == KEY_ENTER && _page == HomePage::INVERT) {
_task->toggleInvertDisplay();
return true;
}
if (c == KEY_ENTER && _page == HomePage::SHUTDOWN) {
_shutdown_init = true; // need to wait for button to be released
return true;
Expand Down Expand Up @@ -538,6 +549,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no

_node_prefs = node_prefs;
if (_display != NULL) {
_display->setInverted(_node_prefs->invert_display); // apply saved inversion state
_display->turnOn();
}

Expand Down Expand Up @@ -893,3 +905,15 @@ void UITask::toggleBuzzer() {
_next_refresh = 0; // trigger refresh
#endif
}

void UITask::toggleInvertDisplay() {
// Toggle display inversion
_node_prefs->invert_display = !_node_prefs->invert_display;
if (_display != NULL) {
_display->setInverted(_node_prefs->invert_display);
}
notify(UIEventType::ack);
showAlert(_node_prefs->invert_display ? "Invert: ON" : "Invert: OFF", 800);
the_mesh.savePrefs();
_next_refresh = 0; // trigger immediate refresh
}
1 change: 1 addition & 0 deletions examples/companion_radio/ui-new/UITask.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class UITask : public AbstractUITask {
void toggleBuzzer();
bool getGPSState();
void toggleGPS();
void toggleInvertDisplay();


// from AbstractUITask
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/ui/DisplayDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
class DisplayDriver {
int _w, _h;
protected:
bool _inverted = false; // display inversion state
DisplayDriver(int w, int h) { _w = w; _h = h; }
public:
enum Color { DARK=0, LIGHT, RED, GREEN, BLUE, YELLOW, ORANGE }; // on b/w screen, colors will be !=0 synonym of light

int width() const { return _w; }
int height() const { return _h; }
bool isInverted() const { return _inverted; }
virtual void setInverted(bool inv) { _inverted = inv; }

virtual bool isOn() = 0;
virtual void turnOn() = 0;
Expand Down
24 changes: 17 additions & 7 deletions src/helpers/ui/GxEPDDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ void GxEPDDisplay::turnOff() {
}

void GxEPDDisplay::clear() {
display.fillScreen(GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK);
display.fillScreen(_inverted ? GxEPD_BLACK : GxEPD_WHITE);
display.setTextColor(_inverted ? GxEPD_WHITE : GxEPD_BLACK);
display_crc.reset();
}

void GxEPDDisplay::startFrame(Color bkg) {
display.fillScreen(GxEPD_WHITE);
display.setTextColor(_curr_color = GxEPD_BLACK);
// use inverted background if inversion is enabled
display.fillScreen(_inverted ? GxEPD_BLACK : GxEPD_WHITE);
display.setTextColor(_curr_color = (_inverted ? GxEPD_WHITE : GxEPD_BLACK));
display_crc.reset();
display_crc.update<bool>(_inverted); // include inversion state in CRC
}

void GxEPDDisplay::setTextSize(int sz) {
Expand All @@ -87,11 +89,13 @@ void GxEPDDisplay::setTextSize(int sz) {

void GxEPDDisplay::setColor(Color c) {
display_crc.update<Color> (c);
// colours need to be inverted for epaper displays
// On e-paper: GxEPD_WHITE = white pixels, GxEPD_BLACK = black pixels
// Normal mode (white bg): DARK->white (bg), others->black (visible)
// Inverted mode (black bg): DARK->black (bg), others->white (visible)
if (c == DARK) {
display.setTextColor(_curr_color = GxEPD_WHITE);
display.setTextColor(_curr_color = _inverted ? GxEPD_BLACK : GxEPD_WHITE);
} else {
display.setTextColor(_curr_color = GxEPD_BLACK);
display.setTextColor(_curr_color = _inverted ? GxEPD_WHITE : GxEPD_BLACK);
}
}

Expand Down Expand Up @@ -177,3 +181,9 @@ void GxEPDDisplay::endFrame() {
last_display_crc_value = crc;
}
}

void GxEPDDisplay::setInverted(bool inv) {
_inverted = inv;
// Invalidate CRC to force redraw on next frame
last_display_crc_value = 0;
}
1 change: 1 addition & 0 deletions src/helpers/ui/GxEPDDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ class GxEPDDisplay : public DisplayDriver {
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override;
uint16_t getTextWidth(const char* str) override;
void endFrame() override;
void setInverted(bool inv) override;
};