From 4539a0787fb0f6c46299d03ad54e66f560495684 Mon Sep 17 00:00:00 2001 From: Razvalyaev Date: Thu, 22 May 2025 09:31:09 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=BF=D0=BE=20=D0=B0=D0=BB=D0=B3=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D1=82=D0=BC=D1=83:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit выставлены границы заряда аккума (3.0-4.2 В) добавлена функция выставления принудительной яркости добавлен функционал моргания диода при коннекте мышки по ble --- mouse/LedControl.cpp | 7 ++++++- mouse/LedControl.h | 1 + mouse/mouse.ino | 31 ++++++++++++++++++++++++++++--- 3 files changed, 35 insertions(+), 4 deletions(-) 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; +}