switch to repeated dotted display; add RSSI filter
Signed-off-by: dragonchaser <christian@boltares.de>
This commit is contained in:
@@ -29,14 +29,18 @@ void UpdatePalette();
|
|||||||
#define LED_COLOR_ORDER RGB
|
#define LED_COLOR_ORDER RGB
|
||||||
|
|
||||||
#define LED_BRIGHTNESS 96
|
#define LED_BRIGHTNESS 96
|
||||||
#define LED_FRAMES_PER_SECOND 24
|
#define LED_FRAMES_PER_SECOND 144
|
||||||
#define LED_SETUP_DISPLAY_DELAY 500
|
#define LED_SETUP_DISPLAY_DELAY 500
|
||||||
|
|
||||||
// DATA maintenance configuration
|
// DATA maintenance configuration
|
||||||
#define UPDATE_INTERVAL 10000 // how often do we update de database?
|
#define UPDATE_INTERVAL 10000 // how often do we update de database?
|
||||||
|
|
||||||
#define MAX_VANISH_COUNTER 3 // if updateinterval is 10000 => 30s
|
#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
|
// VARIABLES
|
||||||
@@ -57,14 +61,16 @@ TimerEvent updateTimer;
|
|||||||
|
|
||||||
class AdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
|
class AdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
|
||||||
void onResult(BLEAdvertisedDevice advertisedDevice) {
|
void onResult(BLEAdvertisedDevice advertisedDevice) {
|
||||||
String addr = advertisedDevice.getAddress().toString();
|
if (advertisedDevice.getRSSI() < MIN_RSSI_POWER) {
|
||||||
String color = String(addr.substring(9,11)+addr.substring(12,14)+addr.substring(15,17));
|
String addr = advertisedDevice.getAddress().toString();
|
||||||
color.toUpperCase();
|
String color = String(addr.substring(9,11)+addr.substring(12,14)+addr.substring(15,17));
|
||||||
if (deviceDatabase.contains(color) || deviceDatabase.size() + 1 < MAX_MONITOR_DEVICES) {
|
color.toUpperCase();
|
||||||
deviceDatabase[color] = MAX_VANISH_COUNTER;
|
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());
|
||||||
|
UpdatePalette();
|
||||||
}
|
}
|
||||||
Serial.printf("Address: %s RSSI: %d TX Power: %d Calculated color: %s \n", addr.c_str(), advertisedDevice.getRSSI(), advertisedDevice.getTXPower(), color.c_str());
|
|
||||||
UpdatePalette();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -154,16 +160,37 @@ void CleanDatabase() {
|
|||||||
|
|
||||||
// Renderes Colors from the calculated palette to the led strip
|
// Renderes Colors from the calculated palette to the led strip
|
||||||
void FillLEDsFromPaletteColors( uint8_t colorIndex) {
|
void FillLEDsFromPaletteColors( uint8_t colorIndex) {
|
||||||
uint8_t brightness = 255;
|
|
||||||
|
|
||||||
for( int i = 0; i < LED_NUM_LEDS; ++i) {
|
for( int i = 0; i < LED_NUM_LEDS; ++i) {
|
||||||
leds[i] = ColorFromPalette( pal, colorIndex, brightness, LINEARBLEND);
|
leds[i] = pal[i+colorIndex];
|
||||||
colorIndex += stepSegments;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates the palette with gradients calculated from the lower 24 bits of the btle address
|
// 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 using module to create a repeated fillpatern of all detected devices using the lower 24bits of the btle address
|
||||||
void UpdatePalette() {
|
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);
|
std::lock_guard<std::mutex> lock(blendMutex);
|
||||||
uint8_t numColors = 2;
|
uint8_t numColors = 2;
|
||||||
String colors[MAX_MONITOR_DEVICES];
|
String colors[MAX_MONITOR_DEVICES];
|
||||||
@@ -174,14 +201,14 @@ void UpdatePalette() {
|
|||||||
colors[1] = "000000";
|
colors[1] = "000000";
|
||||||
case 1:
|
case 1:
|
||||||
numColors = 2;
|
numColors = 2;
|
||||||
colors[0] = deviceDatabase.begin()->first.substring(2,8);
|
colors[0] = deviceDatabase.begin()->first;
|
||||||
colors[1] = deviceDatabase.begin()->first.substring(2,8);
|
colors[1] = deviceDatabase.begin()->first;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
numColors = deviceDatabase.size();
|
numColors = deviceDatabase.size();
|
||||||
int pos = 0 ;
|
int pos = 0 ;
|
||||||
for (auto itr: deviceDatabase) {
|
for (auto itr: deviceDatabase) {
|
||||||
colors[pos++] = itr.first.substring(2,8);
|
colors[pos++] = itr.first;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -194,7 +221,7 @@ void UpdatePalette() {
|
|||||||
CRGB startColor = CRGB(StrToHex(colors[i].c_str()));
|
CRGB startColor = CRGB(StrToHex(colors[i].c_str()));
|
||||||
CRGB endColor = CRGB(StrToHex(colors[i + 1].c_str()));
|
CRGB endColor = CRGB(StrToHex(colors[i + 1].c_str()));
|
||||||
|
|
||||||
for (uint8_t j = 0; j < segmentSize; j++) {
|
for (uint8_t j = 0; j < segmentSize; j++) {
|
||||||
uint16_t index = i * segmentSize + j;
|
uint16_t index = i * segmentSize + j;
|
||||||
if (index >= 256) break;
|
if (index >= 256) break;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user