add support for vibration motor

Signed-off-by: dragonchaser <christian@boltares.de>
This commit is contained in:
dragonchaser
2025-07-14 16:09:07 +02:00
parent 942c28add4
commit b9c56702a0

View File

@@ -12,6 +12,7 @@ uint64_t StrToHex(const char* str);
void CleanDatabase(); void CleanDatabase();
void FillLEDsFromPaletteColors( uint8_t colorIndex); void FillLEDsFromPaletteColors( uint8_t colorIndex);
void UpdatePalette(); void UpdatePalette();
void Vibrate();
// Bluetooth configuration // Bluetooth configuration
@@ -30,6 +31,12 @@ void UpdatePalette();
#define LED_FRAMES_PER_SECOND 24 #define LED_FRAMES_PER_SECOND 24
#define LED_SETUP_DISPLAY_DELAY 500 #define LED_SETUP_DISPLAY_DELAY 500
// VIBRATION MOTOR configuration
#define VIBRO_PIN 2
#define VIBRO_REPEAT 3
#define VIBRO_SMALL_DELAY 100
#define VIBRO_BIG_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?
@@ -49,18 +56,18 @@ const std::map<String, void*> blackList = {
//{ "36E898", nullptr }, //{ "36E898", nullptr },
}; };
#define PUBLIC_LAMP 1 #define DEVICE_TYPE_PUBLIC_LAMP 1
#define PRIVATE_LAMP 2 #define DEVICE_TYPE_PRIVATE_LAMP 2
#define AMULETT 3 #define DEVICE_TYPE_AMULETT 3
#define DEVICE_TYPE PUBLIC_LAMP #define DEVICE_TYPE DEVICE_TYPE_AMULETT
#ifndef DEVICE_TYPE #ifndef DEVICE_TYPE
// WE DO NOT HAVE A DEVICETYPE, so we do not have any variables here // WE DO NOT HAVE A DEVICETYPE, so we do not have any variables here
// to make sure the code compile fails // to make sure the code compile fails
#error "DEVICE_TYPE is not defined" #error "DEVICE_TYPE is not defined"
#elif DEVICE_TYPE == PUBLIC_LAMP #elif DEVICE_TYPE == DEVICE_TYPE_PUBLIC_LAMP
// This is a PUBLIC LAMP, no restrictions here // This is a PUBLIC LAMP, no restrictions here
// Does not have a vibration motor // Does not have a vibration motor
static const bool useVibro = false; static const bool useVibro = false;
@@ -68,7 +75,7 @@ const std::map<String, void*> blackList = {
// IF THIS LIST IS EMPTY IT WILL NOT BE USED // IF THIS LIST IS EMPTY IT WILL NOT BE USED
static const std::map<String, void*> whiteList = {}; static const std::map<String, void*> whiteList = {};
#elif DEVICE_TYPE == PRIVATE_LAMP #elif DEVICE_TYPE == DEVICE_TYPE_PRIVATE_LAMP
// This is a PRIVATE LAMP, restricted to a list of users // This is a PRIVATE LAMP, restricted to a list of users
// Does not have a vibration motor // Does not have a vibration motor
static const bool useVibro = false; static const bool useVibro = false;
@@ -78,7 +85,7 @@ const std::map<String, void*> blackList = {
{ "36E898", nullptr }, { "36E898", nullptr },
}; };
#elif DEVICE_TYPE == AMULETT #elif DEVICE_TYPE == DEVICE_TYPE_AMULETT
// This is an portable device, restricted to a list of users // This is an portable device, restricted to a list of users
// Comes with a vibration motor to alert wearer // Comes with a vibration motor to alert wearer
static const bool useVibro = true; static const bool useVibro = true;
@@ -143,6 +150,15 @@ class AdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
color = it->second; color = it->second;
} }
} }
// when the device is not in the database yet, vibrate on first connect
if (useVibro) {
auto it = deviceDatabase.find(color);
if (it != deviceDatabase.end()) {
Vibrate();
}
}
if (deviceDatabase.contains(color) || deviceDatabase.size() + 1 < MAX_MONITOR_DEVICES) { if (deviceDatabase.contains(color) || deviceDatabase.size() + 1 < MAX_MONITOR_DEVICES) {
deviceDatabase[color] = MAX_VANISH_COUNTER; deviceDatabase[color] = MAX_VANISH_COUNTER;
} }
@@ -154,6 +170,10 @@ class AdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
if (useVibro) {
pinMode(VIBRO_PIN, OUTPUT);
}
UpdatePalette(); UpdatePalette();
FastLED.setBrightness(LED_BRIGHTNESS); FastLED.setBrightness(LED_BRIGHTNESS);
@@ -252,3 +272,16 @@ void UpdatePalette() {
} }
} }
} }
// Causes the vibration motor to vibrate
void Vibrate() {
for (int i = 0; i < VIBRO_REPEAT; i++) {
for (int j = 0; j < 3; j++) {
delay(VIBRO_SMALL_DELAY);
digitalWrite(VIBRO_PIN, HIGH);
delay(VIBRO_SMALL_DELAY);
digitalWrite(VIBRO_PIN, LOW);
}
delay(VIBRO_BIG_DELAY);
}
}