Update examples

This commit is contained in:
h2zero authored and h2zero committed 2024-12-10 13:15:43 -07:00
1 parent e4d2e991f1
commit 49769f4aeb
66 files changed
+629 -1705

No files matched your search

@@ -5,26 +5,27 @@
*
* Created: on November 28, 2024
* Author: H2zero
*
*/
*/
#include <NimBLEDevice.h>
static uint32_t scanTime = 10 * 1000; // In milliseconds, 0 = scan forever
static NimBLEScan::Phy scanPhy = NimBLEScan::Phy::SCAN_ALL;
static uint32_t scanTime = 10 * 1000; // In milliseconds, 0 = scan forever
static NimBLEScan::Phy scanPhy = NimBLEScan::Phy::SCAN_ALL;
// Define a class to handle the callbacks when advertisements are received
class scanCallbacks: public NimBLEScanCallbacks {
/** Define a class to handle the callbacks when advertisements are received */
class ScanCallbacks : public NimBLEScanCallbacks {
void onResult(const NimBLEAdvertisedDevice* advertisedDevice) {
printf("Advertised Device found: %s\n PHY1: %d\n PHY2: %d\n", advertisedDevice->toString().c_str(),
advertisedDevice->getPrimaryPhy(), advertisedDevice->getSecondaryPhy());
printf("Advertised Device found: %s\n PHY1: %d\n PHY2: %d\n",
advertisedDevice->toString().c_str(),
advertisedDevice->getPrimaryPhy(),
advertisedDevice->getSecondaryPhy());
}
// Callback to process the results of the completed scan or restart it
/** Callback to process the results of the completed scan or restart it */
void onScanEnd(const NimBLEScanResults& scanResults, int reason) {
printf("Scan Ended, reason: %d; found %d devices\n", reason, scanResults.getCount());
// Try Different PHY's
/** Try Different PHY's */
switch (scanPhy) {
case NimBLEScan::Phy::SCAN_ALL:
printf("Scanning only 1M PHY\n");
@@ -44,25 +45,25 @@ class scanCallbacks: public NimBLEScanCallbacks {
pScan->setPhy(scanPhy);
pScan->start(scanTime);
}
} scanCb;
} scanCallbacks;
extern "C" void app_main (void) {
extern "C" void app_main(void) {
printf("Starting Extended Scanner\n");
// Initialize NimBLE, no device name specified as we are not advertising
NimBLEDevice::init("");
/** Initialize NimBLE and set the device name */
NimBLEDevice::init("NimBLE Extended Scanner");
NimBLEScan* pScan = NimBLEDevice::getScan();
// Set the callbacks that the scanner will call on events.
pScan->setScanCallbacks(&scanCb);
/** Set the callbacks that the scanner will call on events. */
pScan->setScanCallbacks(&scanCallbacks);
// Use active scanning to obtain scan response data from advertisers
/** Use active scanning to obtain scan response data from advertisers */
pScan->setActiveScan(true);
// Set the initial PHY's to scan on, default is SCAN_ALL
/** Set the initial PHY's to scan on, default is SCAN_ALL */
pScan->setPhy(scanPhy);
// Start scanning for scanTime, 0 = forever
/** Start scanning for scanTime */
pScan->start(scanTime);
printf("Scanning for peripherals\n");
}