Вроде диоды и симуляция мышки работает, но по usb чет пока ничего
This commit is contained in:
parent
e2e78e8aeb
commit
a3a3498bc3
Binary file not shown.
@ -30,6 +30,11 @@ BLEDescriptor* createPresentationFormatDescriptor() {
|
|||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
void LedControl::setupBLEService(BLEServer *server) {
|
void LedControl::setupBLEService(BLEServer *server) {
|
||||||
|
if(server == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
BLEService *colorService = server->createService(COLOR_SERVICE_UUID);
|
BLEService *colorService = server->createService(COLOR_SERVICE_UUID);
|
||||||
|
|
||||||
// --- Красный ---
|
// --- Красный ---
|
||||||
@ -37,7 +42,7 @@ void LedControl::setupBLEService(BLEServer *server) {
|
|||||||
COLOR_CHAR_R_UUID,
|
COLOR_CHAR_R_UUID,
|
||||||
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE
|
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->setValue(currentR);
|
||||||
rChar->setCallbacks(new ColorCallbacks(this, 0));
|
rChar->setCallbacks(new ColorCallbacks(this, 0));
|
||||||
// rChar->addDescriptor(createUserDescription("Red"));
|
// rChar->addDescriptor(createUserDescription("Red"));
|
||||||
@ -47,7 +52,7 @@ void LedControl::setupBLEService(BLEServer *server) {
|
|||||||
COLOR_CHAR_G_UUID,
|
COLOR_CHAR_G_UUID,
|
||||||
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE
|
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->setValue(currentG);
|
||||||
gChar->setCallbacks(new ColorCallbacks(this, 1));
|
gChar->setCallbacks(new ColorCallbacks(this, 1));
|
||||||
// gChar->addDescriptor(createUserDescription("Green"));
|
// gChar->addDescriptor(createUserDescription("Green"));
|
||||||
@ -57,7 +62,7 @@ void LedControl::setupBLEService(BLEServer *server) {
|
|||||||
COLOR_CHAR_B_UUID,
|
COLOR_CHAR_B_UUID,
|
||||||
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE
|
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->setValue(currentB);
|
||||||
bChar->setCallbacks(new ColorCallbacks(this, 2));
|
bChar->setCallbacks(new ColorCallbacks(this, 2));
|
||||||
// bChar->addDescriptor(createUserDescription("Blue"));
|
// bChar->addDescriptor(createUserDescription("Blue"));
|
||||||
@ -67,15 +72,15 @@ void LedControl::setupBLEService(BLEServer *server) {
|
|||||||
COLOR_CHAR_BRIGHTNESS_UUID,
|
COLOR_CHAR_BRIGHTNESS_UUID,
|
||||||
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE
|
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->setValue(currentBrightness);
|
||||||
brChar->setCallbacks(new ColorCallbacks(this, 3));
|
brChar->setCallbacks(new ColorCallbacks(this, 3));
|
||||||
// brChar->addDescriptor(createUserDescription("Brightness"));
|
// brChar->addDescriptor(createUserDescription("Brightness"));
|
||||||
|
|
||||||
colorService->start();
|
colorService->start();
|
||||||
|
|
||||||
BLEAdvertising *advertising = BLEDevice::getAdvertising();
|
// BLEAdvertising *advertising = BLEDevice::getAdvertising();
|
||||||
advertising->addServiceUUID(COLOR_SERVICE_UUID);
|
// 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)
|
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.setPixelColor(0, rgbLed.Color(r, g, b));
|
||||||
rgbLed.setBrightness(correctedBrightness(currentBrightness));
|
rgbLed.setBrightness(correctedBrightness(currentBrightness));
|
||||||
rgbLed.show();
|
rgbLed.show();
|
||||||
saveSettings(); // если хочешь сразу сохранять
|
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,27 @@ public:
|
|||||||
void applyColor();
|
void applyColor();
|
||||||
void forceColor(uint8_t r, uint8_t g, uint8_t b);
|
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:
|
private:
|
||||||
Adafruit_NeoPixel &rgbLed;
|
Adafruit_NeoPixel &rgbLed;
|
||||||
Preferences preferences;
|
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;
|
BLECharacteristic *colorCharacteristic = nullptr;
|
||||||
|
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
|
@ -5,10 +5,17 @@
|
|||||||
#define LED_PIN 21 // GPIO пин светодиода (скорее всего 48)
|
#define LED_PIN 21 // GPIO пин светодиода (скорее всего 48)
|
||||||
#define NUM_LEDS 1 // Один RGB светодиод
|
#define NUM_LEDS 1 // Один RGB светодиод
|
||||||
|
|
||||||
#define SHOW_REAL_BATTERY
|
#define RED_DEFAULT 255
|
||||||
// #define RGB_LED
|
#define GREEN_DEFAULT 0
|
||||||
|
#define BLUE_DEFAULT 255
|
||||||
|
#define BRIGHT_DEFAULT 50
|
||||||
|
|
||||||
|
// #define DISABLE_RGB_UUID
|
||||||
// #define DISABLE_USB
|
// #define DISABLE_USB
|
||||||
|
|
||||||
|
#define SHOW_REAL_BATTERY
|
||||||
|
#define RGB_LED
|
||||||
|
|
||||||
BleMouse bleMouse("Ball Mouse");
|
BleMouse bleMouse("Ball Mouse");
|
||||||
|
|
||||||
#ifdef RGB_LED
|
#ifdef RGB_LED
|
||||||
@ -63,23 +70,25 @@ void setup() {
|
|||||||
#ifdef RGB_LED
|
#ifdef RGB_LED
|
||||||
// Запуск мыши — зелёный
|
// Запуск мыши — зелёный
|
||||||
ledControl.begin();
|
ledControl.begin();
|
||||||
ledControl.forceColor(0, 255, 0); // Зеленый
|
// ledControl.forceColor(0, 255, 0); // Зеленый
|
||||||
#endif//RGB_LED
|
#endif//RGB_LED
|
||||||
|
|
||||||
#ifdef RGB_LED
|
#ifdef RGB_LED
|
||||||
// Инициализация BLE - красный
|
// Инициализация BLE - красный
|
||||||
ledControl.forceColor(255, 0, 0); // Красный
|
// ledControl.forceColor(255, 0, 0); // Красный
|
||||||
#endif//RGB_LED
|
#endif//RGB_LED
|
||||||
// Запуск BLE мыши (HID)
|
// Запуск BLE мыши (HID)
|
||||||
bleMouse.init();
|
bleMouse.init();
|
||||||
// Создаём BLE-сервер для подстветки
|
|
||||||
BLEServer *server = BLEDevice::createServer();
|
|
||||||
#ifdef RGB_LED
|
#ifdef RGB_LED
|
||||||
|
#ifndef DISABLE_RGB_UUID
|
||||||
|
// Создаём BLE-сервер для подстветки
|
||||||
|
// BLEServer *server = BLEDevice::createServer();
|
||||||
// Настройка кастомного сервиса цвета
|
// Настройка кастомного сервиса цвета
|
||||||
ledControl.setupBLEService(server);
|
ledControl.setupBLEService(bleMouse.server);
|
||||||
// Добавляем UUID нашего сервиса в рекламу (важно до start)
|
#endif//DISABLE_RGB_UUID
|
||||||
BLEAdvertising *advertising = BLEDevice::getAdvertising();
|
// // Добавляем UUID нашего сервиса в рекламу (важно до start)
|
||||||
advertising->addServiceUUID(COLOR_SERVICE_UUID);
|
// BLEAdvertising *advertising = BLEDevice::getAdvertising();
|
||||||
|
// advertising->addServiceUUID(COLOR_SERVICE_UUID);
|
||||||
#endif//RGB_LED
|
#endif//RGB_LED
|
||||||
// Запуск BLE мыши (HID)
|
// Запуск BLE мыши (HID)
|
||||||
bleMouse.begin();
|
bleMouse.begin();
|
||||||
@ -87,7 +96,7 @@ void setup() {
|
|||||||
|
|
||||||
#ifdef RGB_LED
|
#ifdef RGB_LED
|
||||||
// USB — синий
|
// USB — синий
|
||||||
ledControl.forceColor(0, 0, 255); // Синий
|
// ledControl.forceColor(0, 0, 255); // Синий
|
||||||
#endif//RGB_LED
|
#endif//RGB_LED
|
||||||
#ifndef DISABLE_USB
|
#ifndef DISABLE_USB
|
||||||
usbHost.begin();
|
usbHost.begin();
|
||||||
@ -102,6 +111,12 @@ void setup() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
#ifndef DISABLE_USB
|
#ifndef DISABLE_USB
|
||||||
usbHost.task();
|
usbHost.task();
|
||||||
|
#else
|
||||||
|
if (bleMouse.isConnected())
|
||||||
|
{
|
||||||
|
bleMouse.move(5, 0, 0);
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
#endif //DISABLE_USB
|
#endif //DISABLE_USB
|
||||||
|
|
||||||
#ifdef SHOW_REAL_BATTERY
|
#ifdef SHOW_REAL_BATTERY
|
||||||
|
Loading…
Reference in New Issue
Block a user