Skip to content

Commit da5b0f8

Browse files
committed
add basic alert system to companion UI
Adds `_alert[80]` which can be set along with `_needs_refresh` to trigger a simple on screen alert that lasts 1s at this time. Implements POC with double press to advert action
1 parent e0483c0 commit da5b0f8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

examples/companion_radio/UITask.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,16 @@ void UITask::renderCurrScreen() {
162162
if (_display == NULL) return; // assert() ??
163163

164164
char tmp[80];
165-
if (_origin[0] && _msg[0]) { // message preview
165+
if (_alert[0]) {
166+
uint16_t textWidth = _display->getTextWidth(_alert);
167+
_display->setCursor((_display->width() - textWidth) / 2, 22);
168+
_display->setTextSize(1.4);
169+
_display->setColor(DisplayDriver::GREEN);
170+
_display->print(_alert);
171+
_alert[0] = 0;
172+
_need_refresh = true;
173+
return;
174+
} else if (_origin[0] && _msg[0]) { // message preview
166175
// render message preview
167176
_display->setCursor(0, 0);
168177
_display->setTextSize(1);
@@ -343,11 +352,17 @@ void UITask::handleButtonShortPress() {
343352
void UITask::handleButtonDoublePress() {
344353
MESH_DEBUG_PRINTLN("UITask: double press triggered, sending advert");
345354
// ADVERT
355+
#ifdef PIN_BUZZER
356+
soundBuzzer(UIEventType::ack);
357+
#endif
346358
if (the_mesh.advert()) {
347359
MESH_DEBUG_PRINTLN("Advert sent!");
360+
sprintf(_alert, "Advert sent!");
348361
} else {
349362
MESH_DEBUG_PRINTLN("Advert failed!");
363+
sprintf(_alert, "Advert failed..");
350364
}
365+
_need_refresh = true;
351366
}
352367

353368
void UITask::handleButtonTriplePress() {

examples/companion_radio/UITask.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class UITask {
3333
char _version_info[32];
3434
char _origin[62];
3535
char _msg[80];
36+
char _alert[80];
3637
int _msgcount;
3738
bool _need_refresh = true;
3839
bool _displayWasOn = false; // Track display state before button press

0 commit comments

Comments
 (0)