T-vK / ESP32-BLE-Keyboard

Bluetooth LE Keyboard library for the ESP32 (Arduino IDE compatible)
2.28k stars 379 forks source link

Incompatible with usb keyboard demo from esp library #196

Open PeterHindes opened 1 year ago

PeterHindes commented 1 year ago

The following imports conflict with eachother. This is an issue as I would like to use usb and bluetooth keyboards in the same program.

// Bluetooth Libraries
#include <BleKeyboard.h>

// USB Libraries
#include "USB.h"
#include "USBHIDKeyboard.h"

The full program looks somewhat like this

// Bluetooth Libraries
#include <BleKeyboard.h>
BleKeyboard bleKeyboard;

// USB Libraries
#include "USB.h"
#include "USBHIDKeyboard.h"
USBHIDKeyboard Keyboard;

// Button On Board Feather
const int buttonPin = 0;
int buttonState = 0;  // variable for reading the pushbutton status

String msg = "Hello Gamer";

void setup() {
  Serial.begin(115200);
  delay(1000);

  Serial.println("Starting BLE work!");
  bleKeyboard.begin();

  Keyboard.begin();
  USB.begin();

  pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
  bleKeyboard.setBatteryLevel(98);
  buttonState = digitalRead(buttonPin);
  // Serial.println("checking button");
  // Serial.println(buttonState == LOW);
  if (buttonState == LOW){
    if(bleKeyboard.isConnected()) {
      Serial.println("Using Bluetooth");
      bleKeyboard.print(msg);
    } 
    else {
      Serial.println("Using USB");
      Keyboard.print(msg);
    }
    delay(500);
  }
  delay(10);
}
PeterHindes commented 1 year ago

This seems to be related to two overlapping variables KeyReport and HID_SUBCLASS_NONE. HID_SUBCLASS_NONE is part of the esp library, it can just be removed from there. as for KeyReport it can be renamed KeyReportBLE in this repo and will avoid conflicts with the stock usb keyboard implementation from espresif.

PeterHindes commented 1 year ago

I have opened a pr with espresif for the collision in their repo https://github.com/espressif/arduino-esp32/pull/7463

PeterHindes commented 1 year ago

Now I have a pr for this repo to fix the naming conflicts present here. https://github.com/T-vK/ESP32-BLE-Keyboard/pull/197