MCPcopy Create free account
hub / github.com/cifertech/nRFBox / blescanLoop

Function blescanLoop

nRFBox_V2/blescan.cpp:67–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65}
66
67void blescanLoop() {
68 unsigned long currentMillis = millis();
69 if (currentMillis - scanStartTime >= scanDuration && !scanComplete) {
70 scanComplete = true;
71 results = scan->getResults();
72 scan->stop();
73 u8g2.clearBuffer();
74 u8g2.drawStr(0, 10, "Scan complete.");
75 u8g2.sendBuffer();
76 }
77
78 if (currentMillis - lastDebounce > debounce_Delay) {
79 if (digitalRead(BUTTON_PIN_UP) == LOW) {
80 if (selectedIndex > 0) {
81 selectedIndex--;
82 if (selectedIndex < displayStartIndex) {
83 displayStartIndex--;
84 }
85 }
86 lastDebounce = currentMillis;
87 } else if (digitalRead(BUTTON_PIN_DOWN) == LOW) {
88 if (selectedIndex < results.getCount() - 1) {
89 selectedIndex++;
90 if (selectedIndex >= displayStartIndex + 5) {
91 displayStartIndex++;
92 }
93 }
94 lastDebounce = currentMillis;
95 } else if (digitalRead(BUTTON_PIN_SELECT) == LOW) {
96 showDetails = true;
97 lastDebounce = currentMillis;
98 }
99 }
100
101 if (!showDetails && scanComplete) {
102 u8g2.clearBuffer();
103 u8g2.setFont(u8g2_font_6x10_tr);
104 u8g2.drawStr(0, 10, "BLE Devices:");
105
106 int deviceCount = results.getCount();
107 for (int i = 0; i < 5; i++) {
108 int deviceIndex = i + displayStartIndex;
109 if (deviceIndex >= deviceCount) break;
110 BLEAdvertisedDevice device = results.getDevice(deviceIndex);
111 String deviceName = device.getName().c_str();
112 if (deviceName.length() == 0) {
113 deviceName = "No Name";
114 }
115 String deviceInfo = deviceName.substring(0, 7) + " | RSSI " + String(device.getRSSI());
116 if (deviceIndex == selectedIndex) {
117 u8g2.drawStr(0, 20 + i * 10, ">");
118 }
119 u8g2.drawStr(10, 20 + i * 10, deviceInfo.c_str());
120 }
121 u8g2.sendBuffer();
122 }
123
124 if (showDetails) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected