Komut
setEventHandler()
Açıklama
Belirtilen olay gerçekleştiğinde çağrılacak olay işleyici (geri arama) işlevini ayarlayın.
Sözdizimi
bleCharacteristic.setEventHandler (eventType, geri arama)
Parametreler
eventType: olay türü ( BLESubscribed , BLEUnsubscribed , BLERead , BLEWritten ) geri arama: olay meydana geldiğinde çağrılacak işlev
İadeler
Hiçbir şey değil
Misal
…
// create switch characteristic and allow remote device to read and write
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
// …
// assign event handlers for characteristic
switchCharacteristic.setEventHandler(BLEWritten, switchCharacteristicWritten);
// …
void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) {
// central wrote new value to characteristic, update LED
Serial.print("Characteristic event, written: ");
if (switchCharacteristic.value()) {
Serial.println("LED on");
digitalWrite(ledPin, HIGH);
} else {
Serial.println("LED off");
digitalWrite(ledPin, LOW);
}
}
…
// create switch characteristic and allow remote device to read and write
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
// …
// assign event handlers for characteristic
switchCharacteristic.setEventHandler(BLEWritten, switchCharacteristicWritten);
// …
void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) {
// central wrote new value to characteristic, update LED
Serial.print("Characteristic event, written: ");
if (switchCharacteristic.value()) {
Serial.println("LED on");
digitalWrite(ledPin, HIGH);
} else {
Serial.println("LED off");
digitalWrite(ledPin, LOW);
}
}
…
See Also
- descriptorCount()
- hasDescriptor()
- descriptor()
- canRead()
- read()
- canWrite()
- canSubscribe()
- subscribe()
- canUnsubscribe()
- unsubscribe()
- valueUpdated()