Skip to content

Commit bab1f2b

Browse files
committed
Status work
1 parent 75deb6b commit bab1f2b

File tree

9 files changed

+119
-66
lines changed

9 files changed

+119
-66
lines changed

src/Wippersnapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2915,7 +2915,7 @@ ws_status_t Wippersnapper::run() {
29152915
WS.feedWDT();
29162916

29172917
// Process display controller events, if initialized
2918-
WS._displayController->update();
2918+
WS._displayController->update(getRSSI(), networkStatus() == WS_CONNECTED);
29192919
WS.feedWDT();
29202920

29212921
return WS_NET_CONNECTED; // TODO: Make this funcn void!

src/components/display/assets/icons.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,41 @@
22
#define _ICONS_H_
33
#include <Arduino.h>
44

5-
const unsigned char epd_bmp_cloud [] PROGMEM = {
5+
const unsigned char epd_bmp_cloud_online [] PROGMEM = {
66
// 'cloud-thin-full, 16x16px
77
0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x0d, 0xc0, 0x18, 0x78, 0x10, 0x0c, 0x30, 0x04, 0x70, 0x0c,
88
0xc0, 0x06, 0xc0, 0x03, 0xc0, 0x03, 0x40, 0x03, 0x70, 0x06, 0x3f, 0xfc, 0x00, 0x00, 0x00, 0x00
99
};
1010

11-
const unsigned char epd_bmp_wifi [] PROGMEM = {
11+
const unsigned char epd_bmp_cloud_offline [] PROGMEM = {
12+
// 'cloud-xmark-thin-full, 16x16px
13+
0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x0d, 0xc0, 0x18, 0x78, 0x10, 0x0c, 0x30, 0x04, 0x73, 0xcc,
14+
0xe3, 0x86, 0xc3, 0xc3, 0xc3, 0xc3, 0x40, 0x03, 0x70, 0x06, 0x3f, 0xfc, 0x00, 0x00, 0x00, 0x00
15+
};
16+
17+
const unsigned char epd_bmp_wifi_full [] PROGMEM = {
1218
// 'wifi-thin-full, 16x16px
1319
0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x3c, 0x3c, 0x70, 0x0e, 0xc0, 0x03, 0x03, 0xc0, 0x0f, 0xf0,
1420
0x1c, 0x38, 0x18, 0x18, 0x00, 0x00, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00
1521
};
1622

23+
const unsigned char epd_bmp_wifi_fair [] PROGMEM = {
24+
// 'wifi-fair-thin-full, 16x16px
25+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x0f, 0xf0,
26+
0x1c, 0x38, 0x18, 0x18, 0x00, 0x00, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00
27+
};
28+
29+
const unsigned char epd_bmp_wifi_weak [] PROGMEM = {
30+
// 'wifi-weak-thin-full, 16x16px
31+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
32+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00
33+
};
34+
35+
const unsigned char epd_bmp_wifi_no_signal [] PROGMEM = {
36+
// 'wifi-slash-thin-full, 16x16px
37+
0x00, 0x00, 0x40, 0x00, 0x27, 0xc0, 0x1e, 0x38, 0x68, 0x00, 0x44, 0x03, 0x03, 0x00, 0x01, 0xe0,
38+
0x08, 0x90, 0x00, 0x40, 0x00, 0x20, 0x01, 0x90, 0x03, 0x88, 0x01, 0x84, 0x00, 0x02, 0x00, 0x00
39+
};
1740

1841
const unsigned char epd_bmp_bat_full [] PROGMEM = {
1942
// 'battery-full-thin-full, 16x16px

src/components/display/assets/splash.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,22 +1345,4 @@ static const unsigned char epd_bitmap_ws_logo_296128[] = {
13451345
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
13461346
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
13471347

1348-
const unsigned char epd_bmp_cloud[] PROGMEM = {
1349-
// 'cloud-thin-full, 16x16px
1350-
0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x0d, 0xc0, 0x18, 0x78, 0x10,
1351-
0x0c, 0x30, 0x04, 0x70, 0x0c, 0xc0, 0x06, 0xc0, 0x03, 0xc0, 0x03,
1352-
0x40, 0x03, 0x70, 0x06, 0x3f, 0xfc, 0x00, 0x00, 0x00, 0x00};
1353-
1354-
const unsigned char epd_bmp_wifi[] PROGMEM = {
1355-
// 'wifi-thin-full, 16x16px
1356-
0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x3c, 0x3c, 0x70, 0x0e, 0xc0,
1357-
0x03, 0x03, 0xc0, 0x0f, 0xf0, 0x1c, 0x38, 0x18, 0x18, 0x00, 0x00,
1358-
0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00};
1359-
1360-
const unsigned char epd_bmp_bat_full[] PROGMEM = {
1361-
// 'battery-full-thin-full, 16x16px
1362-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xfe, 0xc0, 0x06, 0xff,
1363-
0xfa, 0xf0, 0x0b, 0xf0, 0x0b, 0xf0, 0x0b, 0xf0, 0x0b, 0xff, 0xfa,
1364-
0xc0, 0x06, 0x7f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1365-
13661348
#endif // SPLASH_H

src/components/display/controller.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ bool DisplayController::Handle_Display_AddOrReplace(
7272
WS.feedWDT();
7373
display->showSplash();
7474
WS.feedWDT();
75-
display->drawStatusBar();
75+
display->drawStatusBar(WS._config.aio_user);
7676
WS.feedWDT();
7777

7878
_hw_instances.push_back(display); // Store the display instance
@@ -131,14 +131,16 @@ bool DisplayController::Handle_Display_Write(
131131
return true;
132132
}
133133

134-
void DisplayController::update() {
134+
void DisplayController::update(int32_t rssi, bool is_connected) {
135135
// if _hw_instances is empty, early out
136136
if (_hw_instances.size() == 0)
137137
return;
138138

139139
// Get the driver instance for the display
140140
DisplayHardware *display = nullptr;
141141
for (auto &hw_instance : _hw_instances) {
142-
hw_instance->updateStatusBar(WS.getRSSI(), 100, WS.networkStatus());
142+
// Note: For now, battery is always 100% as we don't have a way to read it
143+
// yet.
144+
hw_instance->updateStatusBar(rssi, 100, is_connected);
143145
}
144146
}

src/components/display/controller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class DisplayController {
3535
wippersnapper_display_v1_DisplayAddOrReplace *msgAdd);
3636
bool Handle_Display_Remove(wippersnapper_display_v1_DisplayRemove *msgRemove);
3737
bool Handle_Display_Write(wippersnapper_display_v1_DisplayWrite *msgWrite);
38-
void update();
38+
void update(int32_t rssi, bool is_connected);
3939

4040
private:
4141
std::vector<DisplayHardware *>

src/components/display/drivers/dispDrvBase.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,17 @@ class dispDrvBase {
148148
/*!
149149
@brief Updates the status bar with current information (battery level,
150150
connectivity status, etc).
151+
@param rssi
152+
The current WiFi RSSI (signal strength) in dB.
153+
@param bat
154+
The current battery level as a percentage (0-100).
155+
@param mqtt_status
156+
The current MQTT connection status.
151157
@note This method can be overridden by derived classes to provide
152158
specific functionality.
153159
*/
154160
virtual void updateStatusBar(int8_t rssi, uint8_t bat,
155-
ws_status_t mqtt_connected) {
161+
bool mqtt_status) {
156162
// No-op for base class
157163
}
158164

@@ -172,8 +178,7 @@ class dispDrvBase {
172178
int8_t _statusbar_rssi; ///< RSSI value for status bar
173179
uint8_t
174180
_statusbar_bat; ///< Battery level, as a percentage, for the status bar
175-
ws_status_t
176-
_statusbar_mqtt_connected; ///< MQTT connection status for the status bar
181+
bool _statusbar_mqtt_connected; ///< MQTT connection status for the status bar
177182
};
178183

179184
#endif // WS_DISP_DRV_BASE_H

src/components/display/drivers/dispDrvThinkInkGrayscale4Eaamfgn.h

Lines changed: 76 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
#include "dispDrvBase.h"
2020

21+
#define STATUS_BAR_HEIGHT 20 ///< Height of the status bar in pixels, assumes 16px icons
22+
#define STATUS_BAR_BORDER 1 ///< Border around the status bar in pixels
23+
#define STATUS_BAR_ICON_SZ 16 ///< Size of status bar icons in pixels
24+
2125
/*!
2226
@brief Driver for a ThinkInk 2.9" Grayscale 4-level EAAMFGN display.
2327
*/
@@ -84,7 +88,6 @@ class drvDispThinkInkGrayscale4Eaamfgn : public dispDrvBase {
8488
return;
8589
_display->drawBitmap(0, 0, epd_bitmap_ws_logo_296128, 296, 128, EPD_BLACK);
8690
_display->display();
87-
delay(50);
8891
}
8992

9093
/*!
@@ -94,13 +97,14 @@ class drvDispThinkInkGrayscale4Eaamfgn : public dispDrvBase {
9497
if (!_display)
9598
return;
9699

100+
// Clear the entire display buffer to remove splash screen
101+
_display->clearBuffer();
102+
97103
// Draw status bar
98-
int barHeight = 20; // Assumes 16x16 icons
99-
int borderWidth = 1;
100-
_display->fillRect(0, 0, _display->width(), barHeight, EPD_BLACK);
101-
_display->fillRect(borderWidth, borderWidth,
102-
_display->width() - (2 * borderWidth),
103-
barHeight - (2 * borderWidth), EPD_WHITE);
104+
_display->fillRect(0, 0, _display->width(), STATUS_BAR_HEIGHT, EPD_BLACK);
105+
_display->fillRect(STATUS_BAR_BORDER, STATUS_BAR_BORDER,
106+
_display->width() - (2 * STATUS_BAR_BORDER),
107+
STATUS_BAR_HEIGHT - (2 * STATUS_BAR_BORDER), EPD_WHITE);
104108

105109
// Draw username on left side of the status bar
106110
_display->setTextSize(1);
@@ -109,49 +113,86 @@ class drvDispThinkInkGrayscale4Eaamfgn : public dispDrvBase {
109113
_display->print(io_username);
110114

111115
// Calculate icon positions and center vertically
112-
int iconSize = 16;
113116
int iconSpacing = 4;
114117
int rightMargin = 5;
115-
int iconY = borderWidth + ((barHeight - 2 * borderWidth - iconSize) / 2);
116-
int batteryX = _display->width() - iconSize - rightMargin;
117-
int wifiX = batteryX - iconSize - iconSpacing;
118-
int cloudX = wifiX - iconSize - iconSpacing;
118+
int iconY = STATUS_BAR_BORDER + ((STATUS_BAR_HEIGHT - 2 * STATUS_BAR_BORDER - STATUS_BAR_ICON_SZ) / 2);
119+
int batteryX = _display->width() - STATUS_BAR_ICON_SZ - rightMargin;
120+
int wifiX = batteryX - STATUS_BAR_ICON_SZ - iconSpacing;
121+
int cloudX = wifiX - STATUS_BAR_ICON_SZ - iconSpacing;
119122
// Draw icons on right side of the status bar
120-
_display->drawBitmap(cloudX, iconY, epd_bmp_cloud, iconSize, iconSize,
121-
EPD_BLACK);
122-
_display->drawBitmap(wifiX, iconY, epd_bmp_wifi, iconSize, iconSize,
123-
EPD_BLACK);
124-
_display->drawBitmap(batteryX, iconY, epd_bmp_bat_full, iconSize, iconSize,
125-
EPD_BLACK);
123+
_display->drawBitmap(cloudX, iconY, epd_bmp_cloud_online, STATUS_BAR_ICON_SZ, STATUS_BAR_ICON_SZ, EPD_BLACK);
124+
_display->drawBitmap(wifiX, iconY, epd_bmp_wifi_full, STATUS_BAR_ICON_SZ, STATUS_BAR_ICON_SZ, EPD_BLACK);
125+
_display->drawBitmap(batteryX, iconY, epd_bmp_bat_full, STATUS_BAR_ICON_SZ, STATUS_BAR_ICON_SZ, EPD_BLACK);
126+
127+
_display->display();
126128
}
127129

128-
/*!
130+
/*!
129131
@brief Updates the status bar with current information (battery level,
130132
connectivity status, etc).
131133
@param rssi
132-
The current RSSI value to display.
134+
The current WiFi RSSI (signal strength) in dB.
133135
@param bat
134-
The current battery level (0-100) to display.
135-
@param mqtt_connected
136-
The current MQTT connection status to display.
136+
The current battery level as a percentage (0-100).
137+
@param mqtt_status
138+
The current MQTT connection status.
137139
*/
138-
void updateStatusBar(int8_t rssi, uint8_t bat,
139-
ws_status_t mqtt_connected) override {
140+
void updateStatusBar(int8_t rssi, uint8_t bat, bool mqtt_status) override {
140141
if (!_display)
141142
return;
142143

143-
if (bat != _statusbar_bat) {
144-
// Update battery icon
145-
_statusbar_bat = bat;
144+
bool do_update = false;
145+
// Update cloud icon only if it changed
146+
if (mqtt_status != _statusbar_mqtt_connected) {
147+
int iconSpacing = 4;
148+
int rightMargin = 5;
149+
int iconY = STATUS_BAR_BORDER + ((STATUS_BAR_HEIGHT - 2 * STATUS_BAR_BORDER - STATUS_BAR_ICON_SZ) / 2);
150+
int batteryX = _display->width() - STATUS_BAR_ICON_SZ - rightMargin;
151+
int wifiX = batteryX - STATUS_BAR_ICON_SZ - iconSpacing;
152+
int cloudX = wifiX - STATUS_BAR_ICON_SZ - iconSpacing;
153+
154+
// Clear and draw the new cloud icon, based on MQTT connection status
155+
_display->fillRect(cloudX, iconY, STATUS_BAR_ICON_SZ, STATUS_BAR_ICON_SZ, EPD_WHITE);
156+
if (mqtt_status == 21) {
157+
_display->drawBitmap(cloudX, iconY, epd_bmp_cloud_online, STATUS_BAR_ICON_SZ, STATUS_BAR_ICON_SZ,
158+
EPD_BLACK);
159+
} else {
160+
_display->drawBitmap(cloudX, iconY, epd_bmp_cloud_offline, STATUS_BAR_ICON_SZ,
161+
STATUS_BAR_ICON_SZ, EPD_BLACK);
146162
}
147-
if (rssi != _statusbar_rssi) {
148-
// Update WiFi icon
163+
_statusbar_mqtt_connected = mqtt_status;
164+
do_update = true;
165+
}
166+
167+
/* // Update WiFi icon only if it changed significantly (+/- 3 dB)
168+
if (abs(rssi - _statusbar_rssi) >= 3 || rssi == 0 || _statusbar_rssi == 0) {
169+
int iconSpacing = 4;
170+
int rightMargin = 5;
171+
int iconY = STATUS_BAR_BORDER + ((STATUS_BAR_HEIGHT - 2 * STATUS_BAR_BORDER - STATUS_BAR_ICON_SZ) / 2);
172+
int batteryX = _display->width() - STATUS_BAR_ICON_SZ - rightMargin;
173+
int wifiX = batteryX - STATUS_BAR_ICON_SZ - iconSpacing;
174+
175+
// Clear and draw the new WiFi icon, based on RSSI
176+
_display->fillRect(wifiX, iconY, STATUS_BAR_ICON_SZ, STATUS_BAR_ICON_SZ, EPD_WHITE);
177+
if (rssi == 0) {
178+
_display->drawBitmap(wifiX, iconY, epd_bmp_wifi_no_signal, STATUS_BAR_ICON_SZ, STATUS_BAR_ICON_SZ, EPD_BLACK);
179+
} else if (rssi > -50) {
180+
_display->drawBitmap(wifiX, iconY, epd_bmp_wifi_full, STATUS_BAR_ICON_SZ, STATUS_BAR_ICON_SZ, EPD_BLACK);
181+
} else if (rssi > -60) {
182+
_display->drawBitmap(wifiX, iconY, epd_bmp_wifi_fair, STATUS_BAR_ICON_SZ, STATUS_BAR_ICON_SZ, EPD_BLACK);
183+
} else if (rssi > -70) {
184+
_display->drawBitmap(wifiX, iconY, epd_bmp_wifi_weak, STATUS_BAR_ICON_SZ, STATUS_BAR_ICON_SZ, EPD_BLACK);
185+
} else {
186+
_display->drawBitmap(wifiX, iconY, epd_bmp_wifi_weak, STATUS_BAR_ICON_SZ, STATUS_BAR_ICON_SZ, EPD_BLACK);
187+
}
149188
_statusbar_rssi = rssi;
150-
}
151-
if (mqtt_connected != _statusbar_mqtt_connected) {
152-
// Update cloud icon
153-
_statusbar_mqtt_connected = mqtt_connected;
154-
}
189+
do_update = true;
190+
} */
191+
192+
// Temporarily removed while I get clarification on how often to refresh the epd
193+
/* if (do_update)
194+
_display->display(); */
195+
155196
}
156197

157198
/*!

src/components/display/hardware.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,11 @@ void DisplayHardware::showSplash() {
269269
void DisplayHardware::drawStatusBar(const char *io_username) {
270270
if (!_drvDisp)
271271
return;
272-
_drvDisp->drawStatusBar(const char *io_username);
272+
_drvDisp->drawStatusBar(io_username);
273273
}
274274

275275
void DisplayHardware::updateStatusBar(int8_t rssi, uint8_t bat,
276-
ws_status_t mqtt_connected) {
276+
bool mqtt_connected) {
277277
if (!_drvDisp)
278278
return;
279279
_drvDisp->updateStatusBar(rssi, bat, mqtt_connected);

src/components/display/hardware.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class DisplayHardware {
4646

4747
void showSplash();
4848
void drawStatusBar(const char *io_username);
49-
void updateStatusBar(int8_t rssi, uint8_t bat, ws_status_t mqtt_connected);
49+
void updateStatusBar(int8_t rssi, uint8_t bat, bool mqtt_connected);
5050
//
5151
// API for Adafruit_GFX that abstracts hardware functionality
5252
// NOTE: These methods are meant to be implemented within dispDrvBase and

0 commit comments

Comments
 (0)