Komut
setEventHandler()
Açıklama
Belirtilen olay gerçekleştiğinde çağrılacak olay işleyici (geri arama) işlevini ayarlayın.
Sözdizimi
BLE.setEventHandler (eventType, geri arama)
Parametreler
eventType: olay türü ( BLEConnected , BLEDisconnected )
callback: olay meydana geldiğinde çağrılacak işlev
İadeler
Hiçbir şey değil.
Misal
…
// begin initialization
if (!BLE.begin()) {
Serial.println("starting BLE failed!");
while (1);
}
// ...
// assign event handlers for connected, disconnected to peripheral
BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
// …
void blePeripheralConnectHandler(BLEDevice central) {
// central connected event handler
Serial.print("Connected event, central: ");
Serial.println(central.address());
}
void blePeripheralDisconnectHandler(BLEDevice central) {
// central disconnected event handler
Serial.print("Disconnected event, central: ");
Serial.println(central.address());
}
…
// begin initialization
if (!BLE.begin()) {
Serial.println("starting BLE failed!");
while (1);
}
// ...
// assign event handlers for connected, disconnected to peripheral
BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
// …
void blePeripheralConnectHandler(BLEDevice central) {
// central connected event handler
Serial.print("Connected event, central: ");
Serial.println(central.address());
}
void blePeripheralDisconnectHandler(BLEDevice central) {
// central disconnected event handler
Serial.print("Disconnected event, central: ");
Serial.println(central.address());
}
…
See Also
- connected()
- disconnect()
- address()
- rssi()
- setAdvertisedServiceUuid()
- setAdvertisedService()
- setManufacturerData()
- setLocalName()
- setDeviceName()
- setAppearance()
- addService()
- advertise()
- stopAdvertise()
- central()
- setAdvertisingInterval()
- setConnectionInterval()
- setConnectable()