limit number of devices to monitor

Signed-off-by: dragonchaser <christian@boltares.de>
This commit is contained in:
dragonchaser
2025-07-08 17:53:01 +02:00
parent 6a05e7e00b
commit b02614bd04

View File

@@ -18,6 +18,7 @@
#define FRAMES_PER_SECOND 24
#define MAX_VANISH_COUNTER 50
#define MAX_MONITOR_DEVICES 10
CRGB leds[NUM_LEDS];
@@ -29,13 +30,17 @@ std::map<String,uint8_t> deviceDatabase;
std::mutex callBackMutex;
CRGBPalette16 MyPalette;
class AdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
String addr = advertisedDevice.getAddress().toString();
String color = String("0x"+addr.substring(9,11)+addr.substring(12,14)+addr.substring(15,17));
color.toUpperCase();
color[1] = 'x';
if (deviceDatabase.contains(color) || deviceDatabase.size() + 1 < MAX_MONITOR_DEVICES) {
deviceDatabase[color] = MAX_VANISH_COUNTER;
}
Serial.printf("Address: %s RSSI: %d TX Power: %d Calculated color: %s \n", addr.c_str(), advertisedDevice.getRSSI(), advertisedDevice.getTXPower(), color.c_str());
for(int i=0; i<NUM_LEDS;i++) {
leds[i] = strtol(color.c_str(), NULL, 0);
@@ -53,6 +58,7 @@ class AdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
deviceDatabase.erase(itr);
Serial.printf("Have not seen %s for %d ticks, removing!\n", itr, MAX_VANISH_COUNTER);
}
Serial.printf("Devicedatabase size: %d\n", deviceDatabase.size());
}
};