update libs

This commit is contained in:
technyon
2022-05-04 22:54:36 +02:00
parent 345e5bf620
commit 05f0d3ad0f
13 changed files with 812 additions and 44 deletions

View File

@@ -1,25 +1,79 @@
#pragma once
/**
* @file BleScanner.h
*
* Created: 2022
* License: GNU GENERAL PUBLIC LICENSE (see LICENSE)
*
* This library provides a BLE scanner to be used by other libraries to
* receive advertisements from BLE devices
*
*/
#include "Arduino.h"
#include <string>
#include <NimBLEDevice.h>
#include "BleInterfaces.h"
class BleScanner : public BLEScannerPublisher, BLEAdvertisedDeviceCallbacks {
public:
BleScanner(int reservedSubscribers = 10);
~BleScanner() = default;
namespace BleScanner {
void initialize(const std::string& deviceName = "blescanner", const bool wantDuplicates = false, const uint16_t interval = 40, const uint16_t window = 40);
class Scanner : public Publisher, BLEAdvertisedDeviceCallbacks {
public:
Scanner(int reservedSubscribers = 10);
~Scanner() = default;
/**
* @brief Initializes the BLE scanner
*
* @param deviceName
* @param wantDuplicates true if you want to receive advertisements from devices for which an advertisement was allready received within the same scan (scanduration)
* @param interval Time in ms from the start of a window until the start of the next window (so the interval time = window + time to wait until next window)
* @param window time in ms to scan
*
* The default (same) interval and window parameters means continuesly scanning without delay between windows
*/
void initialize(const std::string& deviceName = "blescanner", const bool wantDuplicates = true, const uint16_t interval = 23, const uint16_t window = 23);
/**
* @brief starts the scan if not allready running, this should be called in loop() or a task;
*
*/
void update();
/**
* @brief Set the Scan Duration
*
* @param value scan duration in seconds
*/
void setScanDuration(const uint32_t value);
void subscribe(BLEScannerSubscriber* subscriber) override;
void unsubscribe(BLEScannerSubscriber* subscriber) override;
/**
* @brief Subscribe to the scanner and receive results
*
* @param subscriber
*/
void subscribe(Subscriber* subscriber) override;
/**
* @brief Un-Subscribe the scanner
*
* @param subscriber
*/
void unsubscribe(Subscriber* subscriber) override;
/**
* @brief Forwards the scan result to the subcriber which has the onResult implemented
*
* @param advertisedDevice
*/
void onResult(NimBLEAdvertisedDevice* advertisedDevice) override;
private:
uint32_t scanDuration = 3;
BLEScan* bleScan = nullptr;
std::vector<BLEScannerSubscriber*> subscribers;
std::vector<Subscriber*> subscribers;
};
} // namespace BleScanner