add white and blacklist feature, add color replacement
Signed-off-by: dragonchaser <christian@boltares.de>
This commit is contained in:
122
btcontrol.ino
122
btcontrol.ino
@@ -29,7 +29,7 @@ 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 144
|
#define LED_FRAMES_PER_SECOND 24
|
||||||
#define LED_SETUP_DISPLAY_DELAY 500
|
#define LED_SETUP_DISPLAY_DELAY 500
|
||||||
|
|
||||||
// DATA maintenance configuration
|
// DATA maintenance configuration
|
||||||
@@ -37,11 +37,27 @@ void UpdatePalette();
|
|||||||
|
|
||||||
#define MAX_VANISH_COUNTER 3 // if updateinterval is 10000 => 30s
|
#define MAX_VANISH_COUNTER 3 // if updateinterval is 10000 => 30s
|
||||||
// Number of devices that can be monitored (might cause a reset because of memory oversaturation!)
|
// Number of devices that can be monitored (might cause a reset because of memory oversaturation!)
|
||||||
#define MAX_MONITOR_DEVICES 5
|
#define MAX_MONITOR_DEVICES 7
|
||||||
// Minimum transmit power the device needs to be recognice (this defines the min proximity needed for the device to be used)
|
// Minimum transmit power the device needs to be recognice (this defines the min proximity needed for the device to be used)
|
||||||
|
// TODO: add a table here that defines distance in meters for scenarios where the device is in plain sight
|
||||||
#define MIN_RSSI_POWER -50
|
#define MIN_RSSI_POWER -50
|
||||||
|
|
||||||
|
// CONSTS
|
||||||
|
const std::map<String, String> overrideColors = {
|
||||||
|
{"36E898", "FF0000"}, // MiiBand Klaas
|
||||||
|
{"0C873F", "00FF00"}, // Tester 1
|
||||||
|
{"D050CF", "0000FF"}, // Tester 2
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::map<String, void*> blackList = {
|
||||||
|
//{ "36E898", nullptr },
|
||||||
|
};
|
||||||
|
|
||||||
|
// WARNING: IF THIS LIST CONTAINS > 0 VALUES, NO OTHER DEVICES WILL BE ALLOWED
|
||||||
|
// IF THIS LIST IS EMPTY IT WILL NOT BE USED
|
||||||
|
const std::map<String, void*> whiteList = {
|
||||||
|
//{ "36E898", nullptr },
|
||||||
|
};
|
||||||
|
|
||||||
// VARIABLES
|
// VARIABLES
|
||||||
BLEScan *pBLEScan;
|
BLEScan *pBLEScan;
|
||||||
@@ -61,16 +77,44 @@ TimerEvent updateTimer;
|
|||||||
|
|
||||||
class AdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
|
class AdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
|
||||||
void onResult(BLEAdvertisedDevice advertisedDevice) {
|
void onResult(BLEAdvertisedDevice advertisedDevice) {
|
||||||
if (advertisedDevice.getRSSI() < MIN_RSSI_POWER) {
|
if (advertisedDevice.getRSSI() > MIN_RSSI_POWER) {
|
||||||
String addr = advertisedDevice.getAddress().toString();
|
return;
|
||||||
String color = String(addr.substring(9,11)+addr.substring(12,14)+addr.substring(15,17));
|
|
||||||
color.toUpperCase();
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String addr = advertisedDevice.getAddress().toString();
|
||||||
|
String color = String(addr.substring(9,11)+addr.substring(12,14)+addr.substring(15,17));
|
||||||
|
color.toUpperCase();
|
||||||
|
|
||||||
|
// check if whitelist applies and device is allowed
|
||||||
|
{
|
||||||
|
if (whiteList.size() > 0) {
|
||||||
|
auto it = whiteList.find(color);
|
||||||
|
if (it == whiteList.end()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if device is blacklisted
|
||||||
|
{
|
||||||
|
auto it = blackList.find(color);
|
||||||
|
if (it != blackList.end()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if an override color for the found device exists
|
||||||
|
{
|
||||||
|
auto it = overrideColors.find(color);
|
||||||
|
if (it != overrideColors.end() && !it->second.isEmpty()) {
|
||||||
|
color = it->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -165,14 +209,6 @@ void FillLEDsFromPaletteColors( uint8_t 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 using module to create a repeated fillpatern of all detected devices using the lower 24bits 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() {
|
void UpdatePalette() {
|
||||||
std::lock_guard<std::mutex> lock(blendMutex);
|
std::lock_guard<std::mutex> lock(blendMutex);
|
||||||
@@ -188,51 +224,3 @@ void UpdatePalette() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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];
|
|
||||||
switch (deviceDatabase.size()) {
|
|
||||||
case 0:
|
|
||||||
numColors = 2;
|
|
||||||
colors[0] = "000000";
|
|
||||||
colors[1] = "000000";
|
|
||||||
case 1:
|
|
||||||
numColors = 2;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
uint8_t segmentSize = 255 / (numColors - 1); // Divide the palette into segments
|
|
||||||
|
|
||||||
if(numColors < 1) {
|
|
||||||
Serial.println("Less than 2 colors? Something is fucky?");
|
|
||||||
}
|
|
||||||
for (uint8_t i = 0; i < numColors - 1; i++) {
|
|
||||||
CRGB startColor = CRGB(StrToHex(colors[i].c_str()));
|
|
||||||
CRGB endColor = CRGB(StrToHex(colors[i + 1].c_str()));
|
|
||||||
|
|
||||||
for (uint8_t j = 0; j < segmentSize; j++) {
|
|
||||||
uint16_t index = i * segmentSize + j;
|
|
||||||
if (index >= 256) break;
|
|
||||||
|
|
||||||
uint8_t blendAmount = (j * 255) / segmentSize; // Integer blend factor
|
|
||||||
pal[index] = BlendCRGB(startColor, endColor, blendAmount);
|
|
||||||
|
|
||||||
if (index % 16 == 0) yield(); // Prevent watchdog reset
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stepSegments = segmentSize;
|
|
||||||
|
|
||||||
// Make sure the last color slot is correctly set
|
|
||||||
pal[255] = CRGB(StrToHex(colors[numColors - 1].c_str()));
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user