MCPcopy Create free account
hub / github.com/BruceDevices/firmware / selectTargetFromScan

Function selectTargetFromScan

src/modules/ble/BLE_Suite.cpp:3619–3897  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3617//=============================================================================
3618
3619String selectTargetFromScan(const char *title) {
3620 scannerData.clear();
3621
3622 tft.fillScreen(bruceConfig.bgColor);
3623 tft.drawRect(5, 5, tftWidth - 10, tftHeight - 10, TFT_WHITE);
3624
3625 tft.setTextColor(TFT_WHITE, bruceConfig.bgColor);
3626 tft.setTextSize(2);
3627 tft.setCursor((tftWidth - tft.textWidth(title)) / 2, 15);
3628 tft.print(title);
3629 tft.setTextSize(1);
3630
3631 tft.setCursor(20, 60);
3632 tft.print("Initializing BLE...");
3633
3634 if (isBLEInitialized()) {
3635 BLEStateManager::deinitBLE(true);
3636 delay(500);
3637 }
3638
3639 NimBLEDevice::init("Bruce-Scanner");
3640 NimBLEDevice::setPower(ESP_PWR_LVL_P9);
3641
3642 NimBLEScan *pBLEScan = NimBLEDevice::getScan();
3643 if (!pBLEScan) {
3644 tft.fillScreen(TFT_RED);
3645 tft.drawRect(5, 5, tftWidth - 10, tftHeight - 10, TFT_BLACK);
3646 tft.setTextColor(TFT_WHITE, TFT_RED);
3647 tft.setTextSize(2);
3648 tft.setCursor((tftWidth - tft.textWidth("ERROR")) / 2, 15);
3649 tft.print("ERROR");
3650 tft.setTextSize(1);
3651 tft.setCursor(20, 60);
3652 tft.print("Failed to create BLE scanner!");
3653 delay(2000);
3654 return "";
3655 }
3656
3657 pBLEScan->setActiveScan(true);
3658 pBLEScan->setInterval(97);
3659 pBLEScan->setWindow(67);
3660 pBLEScan->setDuplicateFilter(false);
3661
3662 tft.setCursor(20, 100);
3663 tft.print("Scanning for devices...");
3664
3665 const int ACTIVE_SCAN_TIME = 15, PASSIVE_SCAN_TIME = 15;
3666
3667 tft.setCursor(20, 120);
3668 tft.print("Active scan (15s)...");
3669
3670#ifdef NIMBLE_V2_PLUS
3671 NimBLEScanResults results = pBLEScan->getResults(ACTIVE_SCAN_TIME * 1000, false);
3672#else
3673 NimBLEScanResults results = pBLEScan->start(ACTIVE_SCAN_TIME, false);
3674#endif
3675
3676 tft.setCursor(20, 140);

Callers 2

Calls 15

isBLEInitializedFunction · 0.85
initFunction · 0.85
checkFunction · 0.85
startMethod · 0.80
getCountMethod · 0.80
getNameMethod · 0.80
sizeMethod · 0.80
clearMethod · 0.45
fillScreenMethod · 0.45
drawRectMethod · 0.45
setTextColorMethod · 0.45
setTextSizeMethod · 0.45

Tested by

no test coverage detected