T-vK / ESP32-BLE-Mouse

Bluetooth LE Mouse library for the ESP32 (Arduino IDE compatible)
755 stars 146 forks source link

Does the setBatteryLevel function actually work #31

Open lemmingDev opened 3 years ago

lemmingDev commented 3 years ago

Hi

Can anyone confirm that the setBatteryLevel function actually works?

On Windows, it doesn't seem to work

In the code below for example, I set the battery level to 90% when the device is started, and it shows up in Windows fine, but then I try to reduce the battery level by 1% every 30 seconds, but the information is not updated in Windows.

Any idea on how to get it working?

Thanks

#include <BleMouse.h>

int batteryLevel = 90;

BleMouse bleMouse("BLE Mouse", "lemmingDev", batteryLevel);

void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE work!");
  bleMouse.begin();
}

void loop() {
  if(bleMouse.isConnected()) {
    Serial.print("Battery Level: ");
    Serial.println(batteryLevel);
    bleMouse.setBatteryLevel(batteryLevel);
    delay(30000);
    batteryLevel--;
  }
}
lemmingDev commented 3 years ago

image

T-vK commented 3 years ago

I can confirm that it doesn't work properly. But I could never figure out why. I'm literally just calling BLEHIDDevice::setBatteryLevel.

https://github.com/T-vK/ESP32-BLE-Mouse/blob/8f1a15b92ff690b03a9ca45e685adc4f3a5529ad/BleMouse.cpp#L138

Maybe that's not enough or it's buggy.