|
11 | 11 | // |
12 | 12 | // MIT License |
13 | 13 | // |
14 | | -// Copyright (c) 2023 Matthias Prinke |
| 14 | +// Copyright (c) 2025 Matthias Prinke |
15 | 15 | // |
16 | 16 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
17 | 17 | // of this software and associated documentation files (the "Software"), to deal |
|
36 | 36 | // |
37 | 37 | // 20230211 Created |
38 | 38 | // 20240417 Added additional constructor and method setAddresses() |
39 | | -// 20240427 Added paramter activeScan to getData() |
| 39 | +// 20240427 Added parameter activeScan to getData() |
40 | 40 | // 20250121 Updated for NimBLE-Arduino v2.x |
| 41 | +// 20250808 Added specific logging macros in scan callback to avoid WDT reset |
| 42 | +// 20250926 Changed getData() to return number of known sensors found |
41 | 43 | // |
42 | 44 | // ToDo: |
43 | | -// - |
| 45 | +// - |
44 | 46 | // |
45 | 47 | /////////////////////////////////////////////////////////////////////////////// |
46 | 48 |
|
| 49 | +/*! \file BleSensors.h |
| 50 | + * \brief Wrapper class for Theeengs Decoder (https://github.com/theengs/decoder) |
| 51 | + */ |
| 52 | + |
47 | 53 | #if !defined(BLE_SENSORS) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) \ |
48 | 54 | && !defined(ARDUINO_ARCH_RP2040) |
49 | 55 | #define BLE_SENSORS |
|
52 | 58 | #include <NimBLEDevice.h> //!< https://github.com/h2zero/NimBLE-Arduino |
53 | 59 | #include <decoder.h> //!< https://github.com/theengs/decoder |
54 | 60 |
|
| 61 | +// Extensive logging in the callback may lead to a watchdog reset |
| 62 | +// see |
| 63 | +// https://github.com/h2zero/NimBLE-Arduino/issues/329 |
| 64 | +// https://github.com/h2zero/NimBLE-Arduino/issues/351 |
| 65 | + |
| 66 | +//#define CB_LOGGING |
| 67 | +#if defined(CB_LOGGING) |
| 68 | +#define cb_log_i log_i //!< Info |
| 69 | +#define cb_log_w log_w //!< Warn |
| 70 | +#define cb_log_d log_d //!< Debug |
| 71 | +#define cb_log_e log_e //!< Error |
| 72 | +#define cb_log_v log_v //!< Verbose |
| 73 | +#else |
| 74 | +#define cb_log_i {} //!< Info |
| 75 | +#define cb_log_w {} //!< Warn |
| 76 | +#define cb_log_d {} //!< Debug |
| 77 | +#define cb_log_e {} //!< Error |
| 78 | +#define cb_log_v {} //!< Verbose |
| 79 | +#endif |
| 80 | + |
55 | 81 | /*! |
56 | 82 | * \brief BLE sensor data |
57 | 83 | */ |
@@ -113,21 +139,23 @@ class BleSensors { |
113 | 139 | * |
114 | 140 | * \param duration Scan duration in seconds |
115 | 141 | * \param activeScan 0: passive scan / 1: active scan |
116 | | - */ |
| 142 | + * |
| 143 | + * \return Number of known sensors found (max. size of known_sensors vector) |
| 144 | + */ |
117 | 145 | unsigned getData(uint32_t duration, bool activeScan = true); |
118 | 146 |
|
119 | 147 | /*! |
120 | 148 | * \brief Set sensor data invalid. |
121 | | - */ |
| 149 | + */ |
122 | 150 | void resetData(void); |
123 | 151 |
|
124 | 152 | /*! |
125 | 153 | * \brief Sensor data. |
126 | 154 | */ |
127 | | - std::vector<ble_sensors_t> data; |
| 155 | + std::vector<ble_sensors_t> data; |
128 | 156 |
|
129 | 157 | protected: |
130 | 158 | std::vector<std::string> _known_sensors; /// MAC addresses of known sensors |
131 | 159 | NimBLEScan* _pBLEScan; /// NimBLEScan object |
132 | 160 | }; |
133 | | -#endif // !defined(BLE_SENSORS) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) && !defined(ARDUINO_ARCH_RP2040) |
| 161 | +#endif |
0 commit comments