diff --git a/mouse/LedControl.cpp b/mouse/LedControl.cpp index 43937a1..c688640 100644 --- a/mouse/LedControl.cpp +++ b/mouse/LedControl.cpp @@ -116,6 +116,11 @@ uint8_t LedControl::correctedBrightness(uint8_t percent) { void LedControl::forceColor(uint8_t r, uint8_t g, uint8_t b) { rgbLed.setPixelColor(0, rgbLed.Color(r, g, b)); - rgbLed.setBrightness(correctedBrightness(currentBrightness)); rgbLed.show(); } +void LedControl::forceBrightness(uint8_t percent) +{ + rgbLed.setBrightness(correctedBrightness(percent)); + rgbLed.show(); +} + diff --git a/mouse/LedControl.h b/mouse/LedControl.h index 509b863..0e5fced 100644 --- a/mouse/LedControl.h +++ b/mouse/LedControl.h @@ -29,6 +29,7 @@ public: void setupBLEService(BLEServer *server); void applyColor(); void forceColor(uint8_t r, uint8_t g, uint8_t b); + void forceBrightness(uint8_t percent); #ifndef RED_DEFAULT diff --git a/mouse/mouse.ino b/mouse/mouse.ino index 7a64bf7..10ca762 100644 --- a/mouse/mouse.ino +++ b/mouse/mouse.ino @@ -25,8 +25,8 @@ LedControl ledControl(rgbLed); #define BATTERY_UPDATE_INTERVAL 5000 // например, 30000 мс = 30 секунд #define BATTERY_ADC_PIN 6 #define BATTERY_VOLTAGE_DIVIDER_RATIO 2.0f - #define BATTERY_VOLTAGE_MAX 5.0f - #define BATTERY_VOLTAGE_MIN 3.5f + #define BATTERY_VOLTAGE_MAX 4.2f + #define BATTERY_VOLTAGE_MIN 3.0f BatteryMonitor battery(BATTERY_ADC_PIN, BATTERY_VOLTAGE_DIVIDER_RATIO, BATTERY_VOLTAGE_MAX, BATTERY_VOLTAGE_MIN); #endif//SHOW_REAL_BATTERY @@ -102,6 +102,7 @@ void setup() { } void loop() { + handleBleConnectionBlink(); #ifndef DISABLE_USB // чтение мыши usbHost.task(); @@ -129,4 +130,28 @@ void loop() { } } #endif -} \ No newline at end of file +} + +bool lastBleStatus = false; +bool blinkInProgress = false; +unsigned long blinkStartTime = 0; +const unsigned long blinkDuration = 250; // длительность моргания (мс) +void handleBleConnectionBlink() { + bool currentStatus = bleMouse.isConnected(); + + // Обнаружили подключение + if (currentStatus && !lastBleStatus) { + blinkInProgress = true; + blinkStartTime = millis(); + ledControl.forceBrightness(100); // максимальная яркость + ledControl.forceColor(255, 255, 255); // белая вспышка + } + + // Завершаем вспышку + if (blinkInProgress && (millis() - blinkStartTime > blinkDuration)) { + blinkInProgress = false; + ledControl.applyColor(); // восстанавливаем предыдущий цвет + } + + lastBleStatus = currentStatus; +}