Arduino/Genuino101 蓝牙HID鼠标 开发准备

1314

蓝牙HID协议笔记 http://blog.sina.com.cn/s/blog_69b5d2a50101emll.html
Report Protocol Mode和Boot Protocol Mode有什么区别?

 

 

程序:

#include <CurieBLE.h>
//#include ""
BLEPeripheral blePeripheral;  // BLE Peripheral Device (the board you're programming)
BLEService mouse101("1812"); // BLE LED Service

// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEUnsignedCharCharacteristic ProtocolMode("2A4E", BLERead | BLEWriteWithoutResponse);
BLEUnsignedCharCharacteristic Report("2A4D", BLERead | BLEWrite | BLENotify);//Write Optional
BLEUnsignedCharCharacteristic ReportMap("2A4B", BLERead);
//BLEUnsignedCharCharacteristic BootKeyboardInputReport("2A22", BLERead | BLEWrite | BLENotify);//Write Optional
//BLEUnsignedCharCharacteristic BootKeyboardOutputReport("2A32", BLERead | BLEWrite | BLENotify);
BLEUnsignedCharCharacteristic BootMouseInputReport("2A33", BLERead | BLEWrite | BLENotify);//Write Optional
BLEUnsignedCharCharacteristic HIDInformation("2A4A", BLERead);
BLEUnsignedCharCharacteristic HIDControlPoint("2A4C", BLEWriteWithoutResponse);

const int ledPin = 13; // pin to use for the LED

void setup() {
  Serial.begin(9600);

  // set LED pin to output mode
  pinMode(ledPin, OUTPUT);

  // set advertised local name and service UUID:
  blePeripheral.setLocalName("mouse101");
  blePeripheral.setAdvertisedServiceUuid(mouse101.uuid());

  // add service and characteristic:
  blePeripheral.addAttribute(mouse101);
  blePeripheral.addAttribute(ProtocolMode);
  blePeripheral.addAttribute(Report);
  blePeripheral.addAttribute(ReportMap);
  blePeripheral.addAttribute(BootMouseInputReport);
  blePeripheral.addAttribute(HIDInformation);
  blePeripheral.addAttribute(HIDControlPoint);

  // set the initial value for the characeristic:
  ProtocolMode.setValue(1);
  Report.setValue(0);
  ReportMap.setValue(0);
  //BootKeyboardOutputReport.setValue(0);
  //BootMouseInputReport.setValue(0);
  HIDInformation.setValue(0);
  HIDControlPoint.setValue(0);
  
  // begin advertising BLE service:
  blePeripheral.begin();

  Serial.println("BLE LED Peripheral");
}

void loop() {
  // listen for BLE peripherals to connect:
  BLECentral central = blePeripheral.central();

  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());
    
    // while the central is still connected to peripheral:
    while (central.connected()) {

    }

    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
  }
}

 

留下一个答复

Please enter your comment!
Please enter your name here