Коррекции по алгоритму:
выставлены границы заряда аккума (3.0-4.2 В) добавлена функция выставления принудительной яркости добавлен функционал моргания диода при коннекте мышки по ble
This commit is contained in:
parent
51224b7059
commit
4539a0787f
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
@ -130,3 +131,27 @@ void loop() {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user