Publish keypad code and rolling log
This commit is contained in:
@@ -22,11 +22,14 @@ Scanner::Scanner(int reservedSubscribers) {
|
||||
|
||||
void Scanner::initialize(const std::string& deviceName, const bool wantDuplicates, const uint16_t interval, const uint16_t window) {
|
||||
if (!BLEDevice::getInitialized()) {
|
||||
if (wantDuplicates) {
|
||||
// reduce memory footprint, cache is not used anyway
|
||||
NimBLEDevice::setScanDuplicateCacheSize(10);
|
||||
}
|
||||
BLEDevice::init(deviceName);
|
||||
}
|
||||
bleScan = BLEDevice::getScan();
|
||||
bleScan->setAdvertisedDeviceCallbacks(this, wantDuplicates);
|
||||
bleScan->setActiveScan(true);
|
||||
bleScan->setInterval(interval);
|
||||
bleScan->setWindow(window);
|
||||
}
|
||||
@@ -36,15 +39,20 @@ void Scanner::update() {
|
||||
return;
|
||||
}
|
||||
|
||||
bleScan->clearResults();
|
||||
if (scanDuration == 0) {
|
||||
// Avoid unbridled growth of results vector
|
||||
bleScan->setMaxResults(0);
|
||||
} else {
|
||||
log_w("Ble scanner max results not 0. Be aware of memory issue due to unbridled growth of results vector");
|
||||
}
|
||||
|
||||
bool result = bleScan->start(scanDuration, nullptr, false);
|
||||
if (!result) {
|
||||
scanErrors++;
|
||||
if (scanErrors % 100 == 0) {
|
||||
log_w("BLE Scan error (100x)");
|
||||
}
|
||||
}
|
||||
// if (!result) {
|
||||
// scanErrors++;
|
||||
// if (scanErrors % 100 == 0) {
|
||||
// log_w("BLE Scan error (100x)");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
void Scanner::enableScanning(bool enable) {
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
#include <NimBLEDevice.h>
|
||||
#include "BleInterfaces.h"
|
||||
|
||||
// Access to a globally available instance of BleScanner, created when first used
|
||||
// Note that BLESCANNER.initialize() has to be called somewhere
|
||||
#define BLESCANNER BleScanner::Scanner::instance()
|
||||
|
||||
namespace BleScanner {
|
||||
|
||||
class Scanner : public Publisher, BLEAdvertisedDeviceCallbacks {
|
||||
@@ -23,6 +27,11 @@ class Scanner : public Publisher, BLEAdvertisedDeviceCallbacks {
|
||||
Scanner(int reservedSubscribers = 10);
|
||||
~Scanner() = default;
|
||||
|
||||
static Scanner& instance() {
|
||||
static Scanner* scanner = new Scanner(); // only initialized once on first call
|
||||
return *scanner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes the BLE scanner
|
||||
*
|
||||
@@ -77,7 +86,7 @@ class Scanner : public Publisher, BLEAdvertisedDeviceCallbacks {
|
||||
void onResult(NimBLEAdvertisedDevice* advertisedDevice) override;
|
||||
|
||||
private:
|
||||
uint32_t scanDuration = 3;
|
||||
uint32_t scanDuration = 0; //default indefinite scanning time
|
||||
BLEScan* bleScan = nullptr;
|
||||
std::vector<Subscriber*> subscribers;
|
||||
uint16_t scanErrors = 0;
|
||||
|
||||
Reference in New Issue
Block a user