Skip to content

Commit 6e5e4bc

Browse files
committed
Fix: Move status bar state to drvBase/drivers, 240x135 logo showing up
1 parent 7465948 commit 6e5e4bc

File tree

7 files changed

+367
-459
lines changed

7 files changed

+367
-459
lines changed

src/components/display/assets/splash.h

Lines changed: 257 additions & 340 deletions
Large diffs are not rendered by default.

src/components/display/controller.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,24 +155,13 @@ void DisplayController::update(int32_t rssi, bool is_connected) {
155155
return;
156156
_last_bar_update = now;
157157

158-
// Early-out if nothing has changed
159-
// and only consider WiFi changes +/-3dB
160-
bool rssi_changed = abs(rssi - _statusbar_rssi) >= 3;
161-
if (!rssi_changed && is_connected == _statusbar_mqtt_connected && 100 == _statusbar_bat) {
162-
return;
163-
}
164-
165158
// Get the driver instance for the display
166159
for (DisplayHardware *hw_instance : _hw_instances) {
167160
// Note: For now, battery is always 100% as we don't have a way to read it
168161
// yet.
169162
hw_instance->updateStatusBar(rssi, 100, is_connected);
170163
}
171164

172-
// Update the cached status bar values
173-
_statusbar_rssi = rssi;
174-
_statusbar_mqtt_connected = is_connected;
175-
_statusbar_bat = 100; // NOTE: Always 100%, for now
176165
WS.feedWDT();
177166
WS.runNetFSM();
178167
}

src/components/display/controller.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ class DisplayController {
4040
private:
4141
std::vector<DisplayHardware *>
4242
_hw_instances; ///< Holds pointers to DisplayHardware instances
43-
int8_t _statusbar_rssi; ///< RSSI value for status bar
44-
uint8_t _statusbar_bat; ///< Battery level, as a percentage, for the status bar
45-
bool _statusbar_mqtt_connected; ///< MQTT connection status for the status bar
4643
unsigned long _last_bar_update; ///< Timestamp of last status bar update
4744
};
4845
extern Wippersnapper Ws; ///< Global WS instance

src/components/display/drivers/dispDrvBase.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ class dispDrvBase {
175175
int16_t _height; ///< Height of the display
176176
int16_t _width; ///< Width of the display
177177
uint8_t _rotation; ///< Rotation of the display
178+
// statusbar properties
179+
int _statusbar_icons_y; ///< Y position of status bar icons
180+
int _statusbar_icon_battery_x; ///< X position of battery icon
181+
int _statusbar_icon_wifi_x; ///< X position of WiFi icon
182+
int _statusbar_icon_cloud_x; ///< X position of cloud icon
183+
int8_t _statusbar_rssi; ///< RSSI value for status bar
184+
uint8_t _statusbar_bat; ///< Battery level, as a percentage, for the status bar
185+
bool _statusbar_mqtt_connected; ///< MQTT connection status for the status bar
178186
};
179187

180188
#endif // WS_DISP_DRV_BASE_H

src/components/display/drivers/dispDrvSt7789.h

Lines changed: 82 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818
#include "dispDrvBase.h"
1919
#include <Adafruit_ST7789.h>
2020

21-
#define ST7789_TEXT_SZ_DEFAULT 2 ///< Default text size for ST7789 displays
21+
#define ST7789_TEXT_SZ_DEFAULT 2 ///< Default text size for ST7789 displays
22+
#define ST7789_STATUSBAR_HEIGHT 20 ///< Default status bar height
23+
#define ST7789_STATUSBAR_ICON_SZ 16 ///< Default status bar icon size
24+
#define ST7789_STATUSBAR_ICON_SPACING \
25+
4 ///< Default spacing between status bar icons
26+
#define ST7789_STATUSBAR_ICON_MARGIN \
27+
5 ///< Default margin from edge of display to status bar icons
2228

2329
/*!
2430
@brief Driver for ST7789-based TFT displays.
@@ -52,8 +58,14 @@ class dispDrvSt7789 : public dispDrvBase {
5258
delete _display;
5359
_display = nullptr;
5460
}
61+
// Turn off backlight
5562
#if defined(ARDUINO_FUNHOUSE_ESP32S2)
5663
digitalWrite(TFT_BACKLIGHT, LOW);
64+
#elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S3_REVTFT) || \
65+
defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S3_TFT) || \
66+
defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2_REVTFT) || \
67+
defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2_TFT)
68+
digitalWrite(TFT_BACKLITE, LOW);
5769
#endif
5870
}
5971

@@ -73,10 +85,16 @@ class dispDrvSt7789 : public dispDrvBase {
7385
_display->fillScreen(ST77XX_BLACK);
7486
_display->setTextColor(ST77XX_WHITE);
7587

88+
// Turn on backlight
7689
#if defined(ARDUINO_FUNHOUSE_ESP32S2)
77-
// Turn backlight on
7890
pinMode(TFT_BACKLIGHT, OUTPUT);
7991
digitalWrite(TFT_BACKLIGHT, HIGH);
92+
#elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S3_REVTFT) || \
93+
defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S3_TFT) || \
94+
defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2_REVTFT) || \
95+
defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2_TFT)
96+
pinMode(TFT_BACKLITE, OUTPUT);
97+
digitalWrite(TFT_BACKLITE, HIGH);
8098
#endif
8199

82100
return true;
@@ -106,8 +124,8 @@ class dispDrvSt7789 : public dispDrvBase {
106124
// Display the appropriate splash screen based on resolution
107125
if (_width == 240 && _height == 240) {
108126
_display->drawBitmap(0, 0, tft_bmp_logo_240240, 240, 240, ST77XX_WHITE);
109-
} else if (_width == 240 && _height == 135) {
110-
_display->drawBitmap(0, 0, tft_bmp_logo_240135, 240, 135, ST77XX_BLACK);
127+
} else if (_width == 135 && _height == 240) {
128+
_display->drawBitmap(0, 0, tft_bmp_logo_240135, 240, 135, ST77XX_WHITE);
111129
} else {
112130
// Unsupported resolution
113131
return;
@@ -123,28 +141,11 @@ class dispDrvSt7789 : public dispDrvBase {
123141
if (!_display)
124142
return;
125143

126-
// Configure status bar parameters based on resolution
127-
if (_width == 240 && _height == 240) {
128-
_status_bar_height = 20;
129-
_status_bar_icon_sz = 16;
130-
_status_bar_icon_spacing = 4;
131-
_status_bar_icon_margin = 5;
132-
} else if (_width == 240 && _height == 135) {
133-
// TODO: The required icons are not added/implemented for 12px icons
134-
_status_bar_height = 16;
135-
_status_bar_icon_sz = 12;
136-
_status_bar_icon_spacing = 3;
137-
_status_bar_icon_margin = 4;
138-
} else {
139-
// Unsupported resolution
140-
return;
141-
}
142-
143144
// Clear the entire display buffer to remove splash screen
144145
_display->fillScreen(ST77XX_BLACK);
145146

146147
// Draw status bar
147-
_display->fillRect(0, 0, _display->width(), _status_bar_height,
148+
_display->fillRect(0, 0, _display->width(), ST7789_STATUSBAR_HEIGHT,
148149
ST77XX_WHITE);
149150

150151
// Draw username on left side of the status bar
@@ -153,26 +154,23 @@ class dispDrvSt7789 : public dispDrvBase {
153154
_display->setCursor(5, 6);
154155
_display->print(io_username);
155156

156-
// Calculate icon positions and center vertically
157-
int iconY = (_status_bar_height - _status_bar_icon_sz) / 2;
158-
int batteryX =
159-
_display->width() - _status_bar_icon_sz - _status_bar_icon_margin;
160-
int wifiX = batteryX - _status_bar_icon_sz - _status_bar_icon_spacing;
161-
int cloudX = wifiX - _status_bar_icon_sz - _status_bar_icon_spacing;
162-
if (_height == 240) {
163-
// Draw 16px icons on right side of the status bar
164-
_display->drawBitmap(cloudX, iconY, epd_bmp_cloud_online,
165-
_status_bar_icon_sz, _status_bar_icon_sz, ST77XX_BLACK);
166-
_display->drawBitmap(wifiX, iconY, epd_bmp_wifi_full, _status_bar_icon_sz,
167-
_status_bar_icon_sz, ST77XX_BLACK);
168-
_display->drawBitmap(batteryX, iconY, epd_bmp_bat_full,
169-
_status_bar_icon_sz, _status_bar_icon_sz, ST77XX_BLACK);
170-
} else if (_height == 135) {
171-
// TODO: Draw 12px icons on right side of the status bar
172-
} else {
173-
// Unsupported resolution
174-
return;
175-
}
157+
// Calculate icon positions (rightmost side of status bar), center
158+
// vertically
159+
_statusbar_icons_y = (ST7789_STATUSBAR_HEIGHT - ST7789_STATUSBAR_ICON_SZ) / 2;
160+
_statusbar_icon_battery_x = _display->width() - ST7789_STATUSBAR_ICON_SZ -
161+
ST7789_STATUSBAR_ICON_MARGIN;
162+
_statusbar_icon_wifi_x = _statusbar_icon_battery_x - ST7789_STATUSBAR_ICON_SZ - ST7789_STATUSBAR_ICON_SPACING;
163+
_statusbar_icon_cloud_x = _statusbar_icon_wifi_x - ST7789_STATUSBAR_ICON_SZ - ST7789_STATUSBAR_ICON_SPACING;
164+
// Draw icons
165+
_display->drawBitmap(_statusbar_icon_cloud_x, _statusbar_icons_y, epd_bmp_cloud_online,
166+
ST7789_STATUSBAR_ICON_SZ, ST7789_STATUSBAR_ICON_SZ,
167+
ST77XX_BLACK);
168+
_display->drawBitmap(_statusbar_icon_wifi_x, _statusbar_icons_y, epd_bmp_wifi_full,
169+
ST7789_STATUSBAR_ICON_SZ, ST7789_STATUSBAR_ICON_SZ,
170+
ST77XX_BLACK);
171+
_display->drawBitmap(_statusbar_icon_battery_x, _statusbar_icons_y, epd_bmp_bat_full,
172+
ST7789_STATUSBAR_ICON_SZ, ST7789_STATUSBAR_ICON_SZ,
173+
ST77XX_BLACK);
176174
}
177175

178176
/*!
@@ -189,41 +187,52 @@ class dispDrvSt7789 : public dispDrvBase {
189187
if (!_display)
190188
return;
191189

192-
WS_DEBUG_PRINTLN("Updating ST7789 status bar");
190+
// Only update wifi icon if the RSSI has changed significantly (+/-3dB)
191+
bool update_rssi = abs(rssi - _statusbar_rssi) >= 3;
192+
// Only update cloud icon if MQTT status has changed
193+
bool update_mqtt = mqtt_status != _statusbar_mqtt_connected;
193194

194-
int iconY = (_status_bar_height - _status_bar_icon_sz) / 2;
195-
int batteryX = _display->width() - _status_bar_icon_sz - _status_bar_icon_margin;
196-
int wifiX = batteryX - _status_bar_icon_sz - _status_bar_icon_spacing;
197-
int cloudX = wifiX - _status_bar_icon_sz - _status_bar_icon_spacing;
195+
// No need to update if nothing has changed
196+
if (!update_rssi && !update_mqtt)
197+
return;
198198

199+
if (update_mqtt) {
199200
// Clear and draw the new cloud icon, based on MQTT connection status
200-
_display->fillRect(cloudX, iconY, _status_bar_icon_sz, _status_bar_icon_sz,
201-
ST77XX_WHITE);
201+
_display->fillRect(_statusbar_icon_cloud_x, _statusbar_icons_y, ST7789_STATUSBAR_ICON_SZ,
202+
ST7789_STATUSBAR_ICON_SZ, ST77XX_WHITE);
202203
if (mqtt_status) {
203-
_display->drawBitmap(cloudX, iconY, epd_bmp_cloud_online,
204-
_status_bar_icon_sz, _status_bar_icon_sz, ST77XX_BLACK);
204+
_display->drawBitmap(_statusbar_icon_cloud_x, _statusbar_icons_y, epd_bmp_cloud_online,
205+
ST7789_STATUSBAR_ICON_SZ, ST7789_STATUSBAR_ICON_SZ,
206+
ST77XX_BLACK);
205207
} else {
206-
_display->drawBitmap(cloudX, iconY, epd_bmp_cloud_offline,
207-
_status_bar_icon_sz, _status_bar_icon_sz, ST77XX_BLACK);
208+
_display->drawBitmap(_statusbar_icon_cloud_x, _statusbar_icons_y, epd_bmp_cloud_offline,
209+
ST7789_STATUSBAR_ICON_SZ, ST7789_STATUSBAR_ICON_SZ,
210+
ST77XX_BLACK);
208211
}
212+
_statusbar_mqtt_connected = mqtt_status;
213+
}
209214

210-
// Update WiFi icon only if RSSI has changed significantly (+/-3dB)
211-
const unsigned char* wifi_icon = epd_bmp_wifi_no_signal;
212-
if (rssi >= -50) {
213-
wifi_icon = epd_bmp_wifi_full;
214-
} else if (rssi < -50 && rssi >= -60) {
215-
wifi_icon = epd_bmp_wifi_fair;
216-
} else if (rssi < -60 && rssi >= -70) {
217-
wifi_icon = epd_bmp_wifi_weak;
218-
} else if (rssi < -70 && rssi >= -80) {
219-
wifi_icon = epd_bmp_wifi_no_signal;
220-
} else {
221-
wifi_icon = epd_bmp_wifi_no_signal;
222-
}
223-
// Clear and draw the new WiFi icon, based on RSSI
224-
_display->fillRect(wifiX, iconY, _status_bar_icon_sz, _status_bar_icon_sz,
225-
ST77XX_WHITE);
226-
_display->drawBitmap(wifiX, iconY, wifi_icon, _status_bar_icon_sz, _status_bar_icon_sz, ST77XX_BLACK);
215+
// Update WiFi icon only if RSSI has changed significantly (+/-3dB)
216+
if (update_rssi) {
217+
const unsigned char *wifi_icon = epd_bmp_wifi_no_signal;
218+
if (rssi >= -50) {
219+
wifi_icon = epd_bmp_wifi_full;
220+
} else if (rssi < -50 && rssi >= -60) {
221+
wifi_icon = epd_bmp_wifi_fair;
222+
} else if (rssi < -60 && rssi >= -70) {
223+
wifi_icon = epd_bmp_wifi_weak;
224+
} else if (rssi < -70 && rssi >= -80) {
225+
wifi_icon = epd_bmp_wifi_no_signal;
226+
} else {
227+
wifi_icon = epd_bmp_wifi_no_signal;
228+
}
229+
// Clear and draw the new WiFi icon, based on RSSI
230+
_display->fillRect(_statusbar_icon_wifi_x, _statusbar_icons_y, ST7789_STATUSBAR_ICON_SZ,
231+
ST7789_STATUSBAR_ICON_SZ, ST77XX_WHITE);
232+
_display->drawBitmap(_statusbar_icon_wifi_x, _statusbar_icons_y, wifi_icon, ST7789_STATUSBAR_ICON_SZ,
233+
ST7789_STATUSBAR_ICON_SZ, ST77XX_BLACK);
234+
_statusbar_rssi = rssi;
235+
}
227236
}
228237

229238
/*!
@@ -240,9 +249,9 @@ class dispDrvSt7789 : public dispDrvBase {
240249
_display->setTextColor(ST77XX_WHITE);
241250

242251
// Clear only the area below the status bar
243-
_display->fillRect(0, _status_bar_height, _width,
244-
_height - _status_bar_height, ST77XX_BLACK);
245-
int16_t y_idx = _status_bar_height;
252+
_display->fillRect(0, ST7789_STATUSBAR_HEIGHT, _width,
253+
_height - ST7789_STATUSBAR_HEIGHT, ST77XX_BLACK);
254+
int16_t y_idx = ST7789_STATUSBAR_HEIGHT;
246255

247256
// Calculate the line height based on the text size (NOTE: base height is
248257
// 8px)
@@ -285,12 +294,6 @@ class dispDrvSt7789 : public dispDrvBase {
285294

286295
private:
287296
Adafruit_ST7789 *_display;
288-
uint8_t _status_bar_height; ///< Height of the status bar, in pixels
289-
uint8_t _status_bar_icon_sz; ///< Size of status bar icons, in pixels
290-
uint8_t
291-
_status_bar_icon_spacing; ///< Spacing between status bar icons, in pixels
292-
uint8_t
293-
_status_bar_icon_margin; ///< Right margin for status bar icons, in pixels
294297
};
295298

296299
#endif // WS_DISP_DRV_ST7789

src/components/display/drivers/dispDrvThinkInkGrayscale4Eaamfgn.h

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
20 ///< Height of the status bar in pixels, assumes 16px icons
2323
#define STATUS_BAR_BORDER 1 ///< Border around the status bar in pixels
2424
#define STATUS_BAR_ICON_SZ 16 ///< Size of status bar icons in pixels
25+
#define STATUS_BAR_ICON_SPACING 4 ///< Spacing between status bar icons in pixels
26+
#define STATUS_BAR_ICON_MARGIN 5 ///< Margin from edge of display to status bar icons in pixels
2527

2628
/*!
2729
@brief Driver for a ThinkInk 2.9" Grayscale 4-level EAAMFGN display.
@@ -113,21 +115,17 @@ class drvDispThinkInkGrayscale4Eaamfgn : public dispDrvBase {
113115
_display->setCursor(5, 6);
114116
_display->print(io_username);
115117

116-
// Calculate icon positions and center vertically
117-
int iconSpacing = 4;
118-
int rightMargin = 5;
119-
int iconY =
120-
STATUS_BAR_BORDER +
121-
((STATUS_BAR_HEIGHT - 2 * STATUS_BAR_BORDER - STATUS_BAR_ICON_SZ) / 2);
122-
int batteryX = _display->width() - STATUS_BAR_ICON_SZ - rightMargin;
123-
int wifiX = batteryX - STATUS_BAR_ICON_SZ - iconSpacing;
124-
int cloudX = wifiX - STATUS_BAR_ICON_SZ - iconSpacing;
118+
// Calculate status bar icon positions and center vertically
119+
_statusbar_icons_y = STATUS_BAR_BORDER + ((STATUS_BAR_HEIGHT - 2 * STATUS_BAR_BORDER - STATUS_BAR_ICON_SZ) / 2);
120+
_statusbar_icon_battery_x = _display->width() - STATUS_BAR_ICON_SZ - STATUS_BAR_ICON_MARGIN;
121+
_statusbar_icon_wifi_x = _statusbar_icon_battery_x - STATUS_BAR_ICON_SZ - STATUS_BAR_ICON_SPACING;
122+
_statusbar_icon_cloud_x = _statusbar_icon_wifi_x - STATUS_BAR_ICON_SZ - STATUS_BAR_ICON_SPACING;
125123
// Draw icons on right side of the status bar
126-
_display->drawBitmap(cloudX, iconY, epd_bmp_cloud_online,
124+
_display->drawBitmap(_statusbar_icon_cloud_x, _statusbar_icons_y, epd_bmp_cloud_online,
127125
STATUS_BAR_ICON_SZ, STATUS_BAR_ICON_SZ, EPD_BLACK);
128-
_display->drawBitmap(wifiX, iconY, epd_bmp_wifi_full, STATUS_BAR_ICON_SZ,
126+
_display->drawBitmap(_statusbar_icon_wifi_x, _statusbar_icons_y, epd_bmp_wifi_full, STATUS_BAR_ICON_SZ,
129127
STATUS_BAR_ICON_SZ, EPD_BLACK);
130-
_display->drawBitmap(batteryX, iconY, epd_bmp_bat_full, STATUS_BAR_ICON_SZ,
128+
_display->drawBitmap(_statusbar_icon_battery_x, _statusbar_icons_y, epd_bmp_bat_full, STATUS_BAR_ICON_SZ,
131129
STATUS_BAR_ICON_SZ, EPD_BLACK);
132130

133131
_display->display();
@@ -152,24 +150,14 @@ class drvDispThinkInkGrayscale4Eaamfgn : public dispDrvBase {
152150
// For EPD - redraws take 1-2 seconds, so only update the cloud state
153151

154152
// Update cloud icon only if it changed state
155-
int iconSpacing = 4;
156-
int rightMargin = 5;
157-
int iconY =
158-
STATUS_BAR_BORDER +
159-
((STATUS_BAR_HEIGHT - 2 * STATUS_BAR_BORDER - STATUS_BAR_ICON_SZ) /
160-
2);
161-
int batteryX = _display->width() - STATUS_BAR_ICON_SZ - rightMargin;
162-
int wifiX = batteryX - STATUS_BAR_ICON_SZ - iconSpacing;
163-
int cloudX = wifiX - STATUS_BAR_ICON_SZ - iconSpacing;
164-
165153
// Clear and draw the new cloud icon, based on MQTT connection status
166-
_display->fillRect(cloudX, iconY, STATUS_BAR_ICON_SZ, STATUS_BAR_ICON_SZ,
154+
_display->fillRect(_statusbar_icon_cloud_x, _statusbar_icons_y, STATUS_BAR_ICON_SZ, STATUS_BAR_ICON_SZ,
167155
EPD_WHITE);
168156
if (mqtt_status == 21) {
169-
_display->drawBitmap(cloudX, iconY, epd_bmp_cloud_online,
157+
_display->drawBitmap(_statusbar_icon_cloud_x, _statusbar_icons_y, epd_bmp_cloud_online,
170158
STATUS_BAR_ICON_SZ, STATUS_BAR_ICON_SZ, EPD_BLACK);
171159
} else {
172-
_display->drawBitmap(cloudX, iconY, epd_bmp_cloud_offline,
160+
_display->drawBitmap(_statusbar_icon_cloud_x, _statusbar_icons_y, epd_bmp_cloud_offline,
173161
STATUS_BAR_ICON_SZ, STATUS_BAR_ICON_SZ, EPD_BLACK);
174162
}
175163

src/components/display/hardware.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static const std::map<std::string, FnCreateDispDrvTft> FactoryDrvDispTft = {
4949
int16_t miso) -> dispDrvBase * {
5050
return new dispDrvSt7789(cs, dc, mosi, sck, rst, miso);
5151
}},
52-
{"tft-154-wide-angle",
52+
{"tft-114",
5353
[](int16_t cs, int16_t dc, int16_t mosi, int16_t sck, int16_t rst,
5454
int16_t miso) -> dispDrvBase * {
5555
return new dispDrvSt7789(cs, dc, mosi, sck, rst, miso);
@@ -341,7 +341,13 @@ bool DisplayHardware::beginTft(
341341

342342
_drvDisp->setWidth(config->width);
343343
_drvDisp->setHeight(config->height);
344+
WS_DEBUG_PRINT("[display] TFT Resolution: ");
345+
WS_DEBUG_PRINT(config->width);
346+
WS_DEBUG_PRINT("x");
347+
WS_DEBUG_PRINTLN(config->height);
344348
_drvDisp->setRotation(config->rotation);
349+
WS_DEBUG_PRINT("[display] TFT Rotation: ");
350+
WS_DEBUG_PRINTLN(config->rotation);
345351
_drvDisp->begin();
346352

347353
return true;

0 commit comments

Comments
 (0)