Skip to content

Commit 142d021

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

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

examples/companion_radio/ui-new/UITask.cpp

Lines changed: 28 additions & 10 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,21 @@ 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
196-
display.setColor(DisplayDriver::RED);
197-
display.setTextSize(2);
198-
sprintf(tmp, "Pin:%d", the_mesh.getBLEPin());
199-
display.drawTextCentered(display.width() / 2, 43, tmp);
197+
#ifdef BLE_LONG_PRESS
198+
bool show_pin = _show_ble_pin;
199+
#else
200+
bool show_pin = true;
201+
#endif
202+
if (show_pin) {
203+
display.setColor(DisplayDriver::RED);
204+
display.setTextSize(2);
205+
sprintf(tmp, "Pin:%d", the_mesh.getBLEPin());
206+
display.drawTextCentered(display.width() / 2, 43, tmp);
207+
} else {
208+
display.setColor(DisplayDriver::ORANGE);
209+
display.setTextSize(1);
210+
display.drawTextCentered(display.width() / 2, 43, "show pin: " PRESS_LABEL);
211+
}
200212
}
201213
} else if (_page == HomePage::RECENT) {
202214
the_mesh.getRecentlyHeard(recent, UI_RECENT_LIST_SIZE);
@@ -213,10 +225,10 @@ class HomeScreen : public UIScreen {
213225
} else {
214226
sprintf(tmp, "%dh", secs / (60*60));
215227
}
216-
228+
217229
int timestamp_width = display.getTextWidth(tmp);
218230
int max_name_width = display.width() - timestamp_width - 1;
219-
231+
220232
char filtered_recent_name[sizeof(a->name)];
221233
display.translateUTF8ToBlocks(filtered_recent_name, a->name, sizeof(filtered_recent_name));
222234
display.drawTextEllipsized(0, y, max_name_width, filtered_recent_name);
@@ -271,7 +283,7 @@ class HomeScreen : public UIScreen {
271283
display.drawTextRightAlign(display.width()-1, y, buf);
272284
y = y + 12;
273285
display.drawTextLeftAlign(0, y, "pos");
274-
sprintf(buf, "%.4f %.4f",
286+
sprintf(buf, "%.4f %.4f",
275287
nmea->getLatitude()/1000000., nmea->getLongitude()/1000000.);
276288
display.drawTextRightAlign(display.width()-1, y, buf);
277289
y = y + 12;
@@ -378,6 +390,12 @@ class HomeScreen : public UIScreen {
378390
}
379391
return true;
380392
}
393+
#ifdef BLE_LONG_PRESS
394+
if (c == KEY_ENTER && _page == HomePage::FIRST) {
395+
_show_ble_pin = !_show_ble_pin; // toggle PIN visibility on long press
396+
return true;
397+
}
398+
#endif
381399
if (c == KEY_ENTER && _page == HomePage::BLUETOOTH) {
382400
if (_task->isSerialEnabled()) { // toggle Bluetooth on/off
383401
_task->disableSerial();
@@ -818,7 +836,7 @@ bool UITask::getGPSState() {
818836
return !strcmp(_sensors->getSettingValue(i), "1");
819837
}
820838
}
821-
}
839+
}
822840
return false;
823841
}
824842

0 commit comments

Comments
 (0)