本文整理汇总了C++中BLECharacteristic::setValue方法的典型用法代码示例。如果您正苦于以下问题:C++ BLECharacteristic::setValue方法的具体用法?C++ BLECharacteristic::setValue怎么用?C++ BLECharacteristic::setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BLECharacteristic
的用法示例。
在下文中一共展示了BLECharacteristic::setValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void
BLEPeripheral::handleGattsEvent(ble_client_gatts_event_t event, struct ble_gatts_evt_msg *event_data)
{
if (BLE_CLIENT_GATTS_EVENT_WRITE == event) {
uint16_t handle = event_data->wr.attr_handle;
for (int i = 0; i < _num_attributes; i++) {
BLEAttribute* attribute = _attributes[i];
if (attribute->type() != BLETypeCharacteristic) {
continue;
}
BLECharacteristic* characteristic = (BLECharacteristic*)attribute;
if (characteristic->valueHandle() == handle) {
characteristic->setValue(_central, event_data->wr.data, event_data->wr.len);
break;
} else if (characteristic->cccdHandle() == handle) {
uint16_t cccdValue = 0;
memcpy(&cccdValue, event_data->wr.data, event_data->wr.len);
characteristic->setCccdValue(_central, cccdValue);
break;
}
}
}
}
示例2: sendData
void BLEHID::sendData(BLECharacteristic& characteristic, unsigned char data[], unsigned char length) {
// wait until we can notify
while(!characteristic.canNotify()) {
BLEHIDPeripheral::instance()->poll();
}
characteristic.setValue(data, length);
}
示例3: updateHeartRate
void updateHeartRate() {
/* Read the current voltage level on the A0 analog input pin.
This is used here to simulate the heart rate's measurement.
*/
int heartRateMeasurement = analogRead(A0);
int heartRate = map(heartRateMeasurement, 0, 1023, 0, 100);
if (heartRate != oldHeartRate) { // if the heart rate has changed
Serial.print("Heart Rate is now: "); // print it
Serial.println(heartRate);
const unsigned char heartRateCharArray[2] = { 0, (char)heartRate };
heartRateChar.setValue(heartRateCharArray, 2); // and update the heart rate measurement characteristic
oldHeartRate = heartRate; // save the level for next comparison
}
}
示例4: run
static void run() {
BLEDevice::init("MYDEVICE");
BLEServer *pServer = BLEDevice::createServer();
BLEService *pService = pServer->createService(BLEUUID(SERVICE_UUID_BIN, 16, true));
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
BLEUUID(CHARACTERISTIC_UUID),
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE
);
pCharacteristic->setCallbacks(new MyCallbackHandler());
pCharacteristic->setValue("Hello World");
pService->start();
BLEAdvertising *pAdvertising = pServer->getAdvertising();
pAdvertising->start();
}
示例5:
void BLEPeripheral::nRF8001CharacteristicValueChanged(nRF8001& nRF8001, BLECharacteristic& characteristic, const unsigned char* value, unsigned char valueLength) {
characteristic.setValue(this->_central, value, valueLength);
}
示例6: BLEDeviceCharacteristicValueChanged
void BLEPeripheral::BLEDeviceCharacteristicValueChanged(BLEDevice& device, BLECharacteristic& characteristic, const unsigned char* value, unsigned char valueLength) {
characteristic.setValue(this->_central, value, valueLength);
}