sandeepmistry / arduino-BLEPeripheral

An Arduino library for creating custom BLE peripherals with Nordic Semiconductor's nRF8001 or nR51822.
MIT License
462 stars 179 forks source link

HID not working when flashed with OTA DFU #239

Open paveljanecek opened 5 years ago

paveljanecek commented 5 years ago

Hello, I'm struggling with little problem. I'm trying to create HID device similar to mouse. I work with RedBear BLE nano V2. And for DFU I use this SoftDevice.

#include <SPI.h>
#include <BLEHIDPeripheral.h>
#include <BLEMouse.h>

#define BLE_REQ   6
#define BLE_RDY   7
#define BLE_RST   8

BLEHIDPeripheral bleHIDPeripheral = BLEHIDPeripheral(BLE_REQ, BLE_RDY, BLE_RST);
BLEMouse bleMouse;

void setup() {

  bleHIDPeripheral.clearBondStoreData();
  bleHIDPeripheral.setReportIdOffset(1);

  bleHIDPeripheral.setLocalName("mouse");
  bleHIDPeripheral.addHID(bleMouse);
  bleHIDPeripheral.begin();

}

void loop() {
   BLECentral central = bleHIDPeripheral.central();

  if (central) {

    while (bleHIDPeripheral.connected()) {

        bleMouse.move(100, -100, 0);
        delay (200);
        bleMouse.move(-100, 100, 0);
        delay (200);
    }
  }
}

The problem is, when flashed through DFU the app is working only up to the power is down, after restart the device fall dawn to DFUTarg mode. If I use this sketch through DAPLink, there is no problem. If I, for example, use another sketch which use Bluetooth UART communication, there is no problem.

Can someone help me please?