From 942c28add4461e85a6462e2f24174f033aa4aa6d Mon Sep 17 00:00:00 2001 From: dragonchaser Date: Mon, 14 Jul 2025 14:56:22 +0200 Subject: [PATCH] make configuratable through defs, fix bug with switch off Signed-off-by: dragonchaser --- btcontrol.ino | 72 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/btcontrol.ino b/btcontrol.ino index 867c19d..633e8be 100644 --- a/btcontrol.ino +++ b/btcontrol.ino @@ -7,8 +7,6 @@ #include // Methods -CRGB BlendCRGB(CRGB a, CRGB b, uint8_t blendAmount); - uint64_t StrToHex(const char* str); void CleanDatabase(); @@ -45,19 +43,54 @@ void UpdatePalette(); // CONSTS const std::map overrideColors = { {"36E898", "FF0000"}, // MiiBand Klaas - {"0C873F", "00FF00"}, // Tester 1 - {"D050CF", "0000FF"}, // Tester 2 }; const std::map 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 whiteList = { - //{ "36E898", nullptr }, -}; +#define PUBLIC_LAMP 1 +#define PRIVATE_LAMP 2 +#define AMULETT 3 + +#define DEVICE_TYPE PUBLIC_LAMP + +#ifndef DEVICE_TYPE + // WE DO NOT HAVE A DEVICETYPE, so we do not have any variables here + // to make sure the code compile fails + #error "DEVICE_TYPE is not defined" + +#elif DEVICE_TYPE == PUBLIC_LAMP + // This is a PUBLIC LAMP, no restrictions here + // Does not have a vibration motor + static const bool useVibro = false; + // WARNING: IF THIS LIST CONTAINS > 0 VALUES, NO OTHER DEVICES WILL BE ALLOWED + // IF THIS LIST IS EMPTY IT WILL NOT BE USED + static const std::map whiteList = {}; + +#elif DEVICE_TYPE == PRIVATE_LAMP + // This is a PRIVATE LAMP, restricted to a list of users + // Does not have a vibration motor + static const bool useVibro = false; + // WARNING: IF THIS LIST CONTAINS > 0 VALUES, NO OTHER DEVICES WILL BE ALLOWED + // IF THIS LIST IS EMPTY IT WILL NOT BE USED + static const std::map whiteList = { + { "36E898", nullptr }, + }; + +#elif DEVICE_TYPE == AMULETT + // This is an portable device, restricted to a list of users + // Comes with a vibration motor to alert wearer + static const bool useVibro = true; + // WARNING: IF THIS LIST CONTAINS > 0 VALUES, NO OTHER DEVICES WILL BE ALLOWED + // IF THIS LIST IS EMPTY IT WILL NOT BE USED + static const std::map whiteList = { + { "36E898", nullptr }, + }; + +#else + #error "Unknown DEVICE_TYPE" +#endif // VARIABLES BLEScan *pBLEScan; @@ -167,15 +200,6 @@ void loop() { FastLED.delay(1000/LED_FRAMES_PER_SECOND); } -// Blends two CRGB colors using a uint8_t blend amount (0-255) -CRGB BlendCRGB(CRGB a, CRGB b, uint8_t blendAmount) { - CRGB result; - result.r = lerp8by8(a.r, b.r, blendAmount); - result.g = lerp8by8(a.g, b.g, blendAmount); - result.b = lerp8by8(a.b, b.b, blendAmount); - return result; -} - // Converts a string to a 64bit HEX value uint64_t StrToHex(const char* str) { return (uint64_t) strtoull(str, 0, 16); @@ -196,7 +220,7 @@ void CleanDatabase() { deviceDatabase.erase(itr); Serial.printf("Have not seen %s for %d ticks, removing!\n", itr, MAX_VANISH_COUNTER); } - if (!keys.empty()) { + if (!keys.empty() || deviceDatabase.size() < 1) { // there are changes to the database, we need to update the palette UpdatePalette(); } @@ -212,13 +236,17 @@ void FillLEDsFromPaletteColors( uint8_t colorIndex) { // 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 lock(blendMutex); - String colors[MAX_MONITOR_DEVICES]; + std::vector colors; + int numColors = deviceDatabase.size(); int pos = 0 ; for (auto itr: deviceDatabase) { - colors[pos++] = itr.first; + colors.push_back(itr.first); } - if (deviceDatabase.size() > 0 ) { + + if (colors.empty()) { + fill_solid(pal.entries, 256, CRGB::Black); + } else { for (int i=0; i<256; i++) { pal[i] = CRGB(StrToHex(colors[ i % deviceDatabase.size() ].c_str())); }