Вроде диоды и симуляция мышки работает, но по usb чет пока ничего

This commit is contained in:
Razvalyaev 2025-05-21 02:41:42 +03:00
parent e2e78e8aeb
commit a3a3498bc3
4 changed files with 54 additions and 22 deletions

Binary file not shown.

View File

@ -30,6 +30,11 @@ BLEDescriptor* createPresentationFormatDescriptor() {
return desc;
}
void LedControl::setupBLEService(BLEServer *server) {
if(server == NULL)
{
return;
}
BLEService *colorService = server->createService(COLOR_SERVICE_UUID);
// --- Красный ---
@ -37,7 +42,7 @@ void LedControl::setupBLEService(BLEServer *server) {
COLOR_CHAR_R_UUID,
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE
);
rChar->setAccessPermissions(ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE);
// rChar->setAccessPermissions(ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE);
rChar->setValue(currentR);
rChar->setCallbacks(new ColorCallbacks(this, 0));
// rChar->addDescriptor(createUserDescription("Red"));
@ -47,7 +52,7 @@ void LedControl::setupBLEService(BLEServer *server) {
COLOR_CHAR_G_UUID,
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE
);
gChar->setAccessPermissions(ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE);
// gChar->setAccessPermissions(ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE);
gChar->setValue(currentG);
gChar->setCallbacks(new ColorCallbacks(this, 1));
// gChar->addDescriptor(createUserDescription("Green"));
@ -57,7 +62,7 @@ void LedControl::setupBLEService(BLEServer *server) {
COLOR_CHAR_B_UUID,
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE
);
bChar->setAccessPermissions(ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE);
// bChar->setAccessPermissions(ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE);
bChar->setValue(currentB);
bChar->setCallbacks(new ColorCallbacks(this, 2));
// bChar->addDescriptor(createUserDescription("Blue"));
@ -67,15 +72,15 @@ void LedControl::setupBLEService(BLEServer *server) {
COLOR_CHAR_BRIGHTNESS_UUID,
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE
);
brChar->setAccessPermissions(ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE);
// brChar->setAccessPermissions(ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE);
brChar->setValue(currentBrightness);
brChar->setCallbacks(new ColorCallbacks(this, 3));
// brChar->addDescriptor(createUserDescription("Brightness"));
colorService->start();
BLEAdvertising *advertising = BLEDevice::getAdvertising();
advertising->addServiceUUID(COLOR_SERVICE_UUID);
// BLEAdvertising *advertising = BLEDevice::getAdvertising();
// advertising->addServiceUUID(COLOR_SERVICE_UUID);
}
@ -110,11 +115,7 @@ uint8_t LedControl::correctedBrightness(uint8_t percent) {
}
void LedControl::forceColor(uint8_t r, uint8_t g, uint8_t b)
{
currentR = r;
currentG = g;
currentB = b;
rgbLed.setPixelColor(0, rgbLed.Color(r, g, b));
rgbLed.setBrightness(correctedBrightness(currentBrightness));
rgbLed.show();
saveSettings(); // если хочешь сразу сохранять
}

View File

@ -25,11 +25,27 @@ public:
void applyColor();
void forceColor(uint8_t r, uint8_t g, uint8_t b);
#ifndef RED_DEFAULT
#define RED_DEFAULT 0
#endif
#ifndef GREEN_DEFAULT
#define GREEN_DEFAULT 0
#endif
#ifndef BLUE_DEFAULT
#define BLUE_DEFAULT 0
#endif
#ifndef BRIGHT_DEFAULT
#define BRIGHT_DEFAULT 0
#endif
private:
Adafruit_NeoPixel &rgbLed;
Preferences preferences;
int currentR = 0, currentG = 0, currentB = 0, currentBrightness = 50;
int currentR = RED_DEFAULT, currentG = GREEN_DEFAULT, currentB = BLUE_DEFAULT, currentBrightness = BRIGHT_DEFAULT;
BLECharacteristic *colorCharacteristic = nullptr;
void loadSettings();

View File

@ -5,10 +5,17 @@
#define LED_PIN 21 // GPIO пин светодиода (скорее всего 48)
#define NUM_LEDS 1 // Один RGB светодиод
#define SHOW_REAL_BATTERY
// #define RGB_LED
#define RED_DEFAULT 255
#define GREEN_DEFAULT 0
#define BLUE_DEFAULT 255
#define BRIGHT_DEFAULT 50
// #define DISABLE_RGB_UUID
// #define DISABLE_USB
#define SHOW_REAL_BATTERY
#define RGB_LED
BleMouse bleMouse("Ball Mouse");
#ifdef RGB_LED
@ -63,23 +70,25 @@ void setup() {
#ifdef RGB_LED
// Запуск мыши — зелёный
ledControl.begin();
ledControl.forceColor(0, 255, 0); // Зеленый
// ledControl.forceColor(0, 255, 0); // Зеленый
#endif//RGB_LED
#ifdef RGB_LED
// Инициализация BLE - красный
ledControl.forceColor(255, 0, 0); // Красный
// ledControl.forceColor(255, 0, 0); // Красный
#endif//RGB_LED
// Запуск BLE мыши (HID)
bleMouse.init();
// Создаём BLE-сервер для подстветки
BLEServer *server = BLEDevice::createServer();
#ifdef RGB_LED
#ifndef DISABLE_RGB_UUID
// Создаём BLE-сервер для подстветки
// BLEServer *server = BLEDevice::createServer();
// Настройка кастомного сервиса цвета
ledControl.setupBLEService(server);
// Добавляем UUID нашего сервиса в рекламу (важно до start)
BLEAdvertising *advertising = BLEDevice::getAdvertising();
advertising->addServiceUUID(COLOR_SERVICE_UUID);
ledControl.setupBLEService(bleMouse.server);
#endif//DISABLE_RGB_UUID
// // Добавляем UUID нашего сервиса в рекламу (важно до start)
// BLEAdvertising *advertising = BLEDevice::getAdvertising();
// advertising->addServiceUUID(COLOR_SERVICE_UUID);
#endif//RGB_LED
// Запуск BLE мыши (HID)
bleMouse.begin();
@ -87,7 +96,7 @@ void setup() {
#ifdef RGB_LED
// USB — синий
ledControl.forceColor(0, 0, 255); // Синий
// ledControl.forceColor(0, 0, 255); // Синий
#endif//RGB_LED
#ifndef DISABLE_USB
usbHost.begin();
@ -102,6 +111,12 @@ void setup() {
void loop() {
#ifndef DISABLE_USB
usbHost.task();
#else
if (bleMouse.isConnected())
{
bleMouse.move(5, 0, 0);
delay(1000);
}
#endif //DISABLE_USB
#ifdef SHOW_REAL_BATTERY