Publish keypad code and rolling log
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||
@@ -1,46 +0,0 @@
|
||||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in a an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "BleScanner",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"description": "Generic BleScanner using NimBle listening to advertisements. Used by NukiBleEsp32 and EnOcean libraries",
|
||||
"keywords": "ble esp32 scanner",
|
||||
"authors": [
|
||||
@@ -19,7 +19,7 @@
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "NimBLE-Arduino",
|
||||
"version": "h2zero/NimBLE-Arduino @ ^1.3.8"
|
||||
"version": "h2zero/NimBLE-Arduino @ ^1.4.0"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -4,4 +4,4 @@ board = esp32dev
|
||||
framework = arduino
|
||||
|
||||
lib_deps =
|
||||
h2zero/NimBLE-Arduino @ ^1.3.8
|
||||
h2zero/NimBLE-Arduino @ ^1.4.0
|
||||
@@ -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