update nuki lib

This commit is contained in:
technyon
2022-05-18 19:07:55 +02:00
parent 27d88db79c
commit cef472e32d
5 changed files with 28 additions and 20 deletions

View File

@@ -25,6 +25,7 @@ class Publisher {
public:
virtual void subscribe(Subscriber* subscriber) = 0;
virtual void unsubscribe(Subscriber* subscriber) = 0;
virtual void enableScanning(bool enable) = 0;
};
} // namespace BleScanner

View File

@@ -32,12 +32,23 @@ void Scanner::initialize(const std::string& deviceName, const bool wantDuplicate
}
void Scanner::update() {
if (bleScan->isScanning()) {
if (!scanningEnabled || bleScan->isScanning()) {
return;
}
bool result = bleScan->start(scanDuration, nullptr, false);
if (!result) {
log_w("BLE Scan error");
scanErrors++;
if (scanErrors % 100 == 0) {
log_w("BLE Scan error (100x)");
}
}
}
void Scanner::enableScanning(bool enable) {
scanningEnabled = enable;
if (!enable) {
bleScan->stop();
}
}

View File

@@ -6,7 +6,7 @@
* Created: 2022
* License: GNU GENERAL PUBLIC LICENSE (see LICENSE)
*
* This library provides a BLE scanner to be used by other libraries to
* This library provides a BLE scanner to be used by other libraries to
* receive advertisements from BLE devices
*
*/
@@ -44,10 +44,17 @@ class Scanner : public Publisher, BLEAdvertisedDeviceCallbacks {
/**
* @brief Set the Scan Duration
*
* @param value scan duration in seconds
* @param value scan duration in seconds, 0 for indefinite scan
*/
void setScanDuration(const uint32_t value);
/**
* @brief enable/disable scanning
*
* @param enable
*/
void enableScanning(bool enable);
/**
* @brief Subscribe to the scanner and receive results
*
@@ -73,6 +80,8 @@ class Scanner : public Publisher, BLEAdvertisedDeviceCallbacks {
uint32_t scanDuration = 3;
BLEScan* bleScan = nullptr;
std::vector<Subscriber*> subscribers;
uint16_t scanErrors = 0;
bool scanningEnabled = true;
};
} // namespace BleScanner