switch to repeated dotted display; add RSSI filter

Signed-off-by: dragonchaser <christian@boltares.de>
This commit is contained in:
dragonchaser
2025-07-14 11:36:31 +02:00
parent a4cc5e3e8e
commit 45fab1fc4c

View File

@@ -29,14 +29,18 @@ void UpdatePalette();
#define LED_COLOR_ORDER RGB
#define LED_BRIGHTNESS 96
#define LED_FRAMES_PER_SECOND 24
#define LED_FRAMES_PER_SECOND 144
#define LED_SETUP_DISPLAY_DELAY 500
// DATA maintenance configuration
#define UPDATE_INTERVAL 10000 // how often do we update de database?
#define MAX_VANISH_COUNTER 3 // if updateinterval is 10000 => 30s
#define MAX_MONITOR_DEVICES 10
// Number of devices that can be monitored (might cause a reset because of memory oversaturation!)
#define MAX_MONITOR_DEVICES 5
// Minimum transmit power the device needs to be recognice (this defines the min proximity needed for the device to be used)
#define MIN_RSSI_POWER -50
// VARIABLES
@@ -57,6 +61,7 @@ TimerEvent updateTimer;
class AdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
if (advertisedDevice.getRSSI() < MIN_RSSI_POWER) {
String addr = advertisedDevice.getAddress().toString();
String color = String(addr.substring(9,11)+addr.substring(12,14)+addr.substring(15,17));
color.toUpperCase();
@@ -66,6 +71,7 @@ class AdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
Serial.printf("Address: %s RSSI: %d TX Power: %d Calculated color: %s \n", addr.c_str(), advertisedDevice.getRSSI(), advertisedDevice.getTXPower(), color.c_str());
UpdatePalette();
}
}
};
void setup() {
@@ -154,16 +160,37 @@ void CleanDatabase() {
// Renderes Colors from the calculated palette to the led strip
void FillLEDsFromPaletteColors( uint8_t colorIndex) {
uint8_t brightness = 255;
for( int i = 0; i < LED_NUM_LEDS; ++i) {
leds[i] = ColorFromPalette( pal, colorIndex, brightness, LINEARBLEND);
leds[i] = pal[i+colorIndex];
}
}
// Renderes Colors from the calculated palette to the led strip
void FillLEDsFromPaletteColorsOld( uint8_t colorIndex) {
for( int i = 0; i < LED_NUM_LEDS; ++i) {
leds[i] = ColorFromPalette( pal, colorIndex, LED_BRIGHTNESS, LINEARBLEND);
colorIndex += stepSegments;
}
}
// Updates the palette with gradients calculated from the lower 24 bits of the btle address
// Updates the palette using module to create a repeated fillpatern of all detected devices using the lower 24bits of the btle address
void UpdatePalette() {
std::lock_guard<std::mutex> lock(blendMutex);
String colors[MAX_MONITOR_DEVICES];
int numColors = deviceDatabase.size();
int pos = 0 ;
for (auto itr: deviceDatabase) {
colors[pos++] = itr.first;
}
if (deviceDatabase.size() > 0 ) {
for (int i=0; i<256; i++) {
pal[i] = CRGB(StrToHex(colors[ i % deviceDatabase.size() ].c_str()));
}
}
}
// Updates the palette with gradients calculated from the lower 24 bits of the btle address
void UpdatePaletteOld() {
std::lock_guard<std::mutex> lock(blendMutex);
uint8_t numColors = 2;
String colors[MAX_MONITOR_DEVICES];
@@ -174,14 +201,14 @@ void UpdatePalette() {
colors[1] = "000000";
case 1:
numColors = 2;
colors[0] = deviceDatabase.begin()->first.substring(2,8);
colors[1] = deviceDatabase.begin()->first.substring(2,8);
colors[0] = deviceDatabase.begin()->first;
colors[1] = deviceDatabase.begin()->first;
break;
default:
numColors = deviceDatabase.size();
int pos = 0 ;
for (auto itr: deviceDatabase) {
colors[pos++] = itr.first.substring(2,8);
colors[pos++] = itr.first;
}
break;
}