Skip to content

Commit 7010e8c

Browse files
committed
BLE_LONG_PRESS macro to allow hiding of the PIN on home screen behind long press
1 parent 5ae574b commit 7010e8c

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

examples/companion_radio/ui-new/UITask.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class HomeScreen : public UIScreen {
9191
NodePrefs* _node_prefs;
9292
uint8_t _page;
9393
bool _shutdown_init;
94+
bool _show_ble_pin;
9495
AdvertPath recent[UI_RECENT_LIST_SIZE];
9596

9697

@@ -149,8 +150,8 @@ class HomeScreen : public UIScreen {
149150

150151
public:
151152
HomeScreen(UITask* task, mesh::RTCClock* rtc, SensorManager* sensors, NodePrefs* node_prefs)
152-
: _task(task), _rtc(rtc), _sensors(sensors), _node_prefs(node_prefs), _page(0),
153-
_shutdown_init(false), sensors_lpp(200) { }
153+
: _task(task), _rtc(rtc), _sensors(sensors), _node_prefs(node_prefs), _page(0),
154+
_shutdown_init(false), sensors_lpp(200), _show_ble_pin(false) { }
154155

155156
void poll() override {
156157
if (_shutdown_init && !_task->isButtonPressed()) { // must wait for USR button to be released
@@ -193,10 +194,23 @@ class HomeScreen : public UIScreen {
193194
display.setTextSize(1);
194195
display.drawTextCentered(display.width() / 2, 43, "< Connected >");
195196
} else if (the_mesh.getBLEPin() != 0) { // BT pin
197+
#ifdef BLE_LONG_PRESS
198+
if (_show_ble_pin) {
199+
display.setColor(DisplayDriver::RED);
200+
display.setTextSize(2);
201+
sprintf(tmp, "Pin:%d", the_mesh.getBLEPin());
202+
display.drawTextCentered(display.width() / 2, 43, tmp);
203+
} else {
204+
display.setColor(DisplayDriver::ORANGE);
205+
display.setTextSize(1);
206+
display.drawTextCentered(display.width() / 2, 43, "show pin: " PRESS_LABEL);
207+
}
208+
#else
196209
display.setColor(DisplayDriver::RED);
197210
display.setTextSize(2);
198211
sprintf(tmp, "Pin:%d", the_mesh.getBLEPin());
199212
display.drawTextCentered(display.width() / 2, 43, tmp);
213+
#endif
200214
}
201215
} else if (_page == HomePage::RECENT) {
202216
the_mesh.getRecentlyHeard(recent, UI_RECENT_LIST_SIZE);
@@ -213,10 +227,10 @@ class HomeScreen : public UIScreen {
213227
} else {
214228
sprintf(tmp, "%dh", secs / (60*60));
215229
}
216-
230+
217231
int timestamp_width = display.getTextWidth(tmp);
218232
int max_name_width = display.width() - timestamp_width - 1;
219-
233+
220234
char filtered_recent_name[sizeof(a->name)];
221235
display.translateUTF8ToBlocks(filtered_recent_name, a->name, sizeof(filtered_recent_name));
222236
display.drawTextEllipsized(0, y, max_name_width, filtered_recent_name);
@@ -271,7 +285,7 @@ class HomeScreen : public UIScreen {
271285
display.drawTextRightAlign(display.width()-1, y, buf);
272286
y = y + 12;
273287
display.drawTextLeftAlign(0, y, "pos");
274-
sprintf(buf, "%.4f %.4f",
288+
sprintf(buf, "%.4f %.4f",
275289
nmea->getLatitude()/1000000., nmea->getLongitude()/1000000.);
276290
display.drawTextRightAlign(display.width()-1, y, buf);
277291
y = y + 12;
@@ -378,6 +392,12 @@ class HomeScreen : public UIScreen {
378392
}
379393
return true;
380394
}
395+
#ifdef BLE_LONG_PRESS
396+
if (c == KEY_ENTER && _page == HomePage::FIRST) {
397+
_show_ble_pin = !_show_ble_pin; // toggle PIN visibility on long press
398+
return true;
399+
}
400+
#endif
381401
if (c == KEY_ENTER && _page == HomePage::BLUETOOTH) {
382402
if (_task->isSerialEnabled()) { // toggle Bluetooth on/off
383403
_task->disableSerial();
@@ -818,7 +838,7 @@ bool UITask::getGPSState() {
818838
return !strcmp(_sensors->getSettingValue(i), "1");
819839
}
820840
}
821-
}
841+
}
822842
return false;
823843
}
824844

0 commit comments

Comments
 (0)