本文整理汇总了C++中BLEDevice::onDataWritten方法的典型用法代码示例。如果您正苦于以下问题:C++ BLEDevice::onDataWritten方法的具体用法?C++ BLEDevice::onDataWritten怎么用?C++ BLEDevice::onDataWritten使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BLEDevice
的用法示例。
在下文中一共展示了BLEDevice::onDataWritten方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
ble.init();
ble.onDisconnection(disconnectionCallback);
ble.onDataWritten(onDataWritten);
ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *)deviceName, strlen(deviceName));
ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
ble.startAdvertising();
GattCharacteristic toggleCharacteristic(0x2222,
&relayState,
sizeof(relayState),
sizeof(relayState),
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE);
GattCharacteristic *charTable[] = {&toggleCharacteristic};
GattService toggleService(0x2220, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
ble.addService(toggleService);
while (true) {
if (rxPayloadUpdated)
{
relayPIN = rxPayload[0];
rxPayloadUpdated = false;
}
ble.waitForEvent();
}
}
示例2: main
int main(void)
{
led1 = 1;
DEBUG("Initialising the nRF51822\n\r");
ble.init(); // Initialise the BLE radio
/* Register callbacks */
ble.onDisconnection(disconnectionCallback);
ble.onDataWritten(writeCharCallback);
//uart = new UARTService(ble);
/* Setup Advertising */
ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
(const uint8_t *)"BLE NOTIF", sizeof("BLE NOTIF") - 1);
ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
ble.setAdvertisingInterval(1600); // 1000ms; in multiples of 0.625ms.
ble.addService(customService);
ble.startAdvertising();
while (true) {
ble.waitForEvent();
}
}
示例3: main
int main() {
ble.init();
ble.onConnection(onConnection);
ble.onDisconnection(onDisconnection);
ble.onDataWritten(onDataWritten);
ble.accumulateAdvertisingPayload(
GapAdvertisingData::BREDR_NOT_SUPPORTED);
ble.setAdvertisingType(
GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
ble.accumulateAdvertisingPayload(
GapAdvertisingData::SHORTENED_LOCAL_NAME,
(const uint8_t *)NAME,
sizeof(NAME) - 1);
ble.accumulateAdvertisingPayload(
GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
(const uint8_t *)UARTServiceUUID_reversed,
sizeof(UARTServiceUUID_reversed));
ble.accumulateScanResponse(
GapAdvertisingData::SHORTENED_LOCAL_NAME,
(const uint8_t *)NAME,
sizeof(NAME) - 1);
ble.accumulateScanResponse(
GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
(const uint8_t *)UARTServiceUUID_reversed,
sizeof(UARTServiceUUID_reversed));
ble.setDeviceName((const uint8_t *)NAME);
ble.setAdvertisingInterval(Gap::MSEC_TO_GAP_DURATION_UNITS(1000));
ble.startAdvertising();
UARTService uartService(ble);
uartServicePtr = &uartService;
while (true) {
ble.waitForEvent();
}
}
示例4: main
int main(void)
{
blue = LED_ON;
green = LED_OFF;
#if BUTTON_DOWN
button.mode(PullDown);
button.rise(button_wakeup);
#else
button.mode(PullUp);
button.fall(button_wakeup);
#endif
DEBUG("Initialising the nRF51822\n\r");
ble.init();
ble.onConnection(connectionCallback);
ble.onDisconnection(disconnectionCallback);
ble.onDataWritten(onDataWritten);
/* setup advertising */
ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
(const uint8_t *)BLE_NAME, sizeof(BLE_NAME));
ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
ble.startAdvertising();
/* Enable over-the-air firmware updates. Instantiating DFUSservice introduces a
* control characteristic which can be used to trigger the application to
* handover control to a resident bootloader. */
DFUService dfu(ble);
UARTService uartService(ble);
uartServicePtr = &uartService;
blue_led_time_to_off = 3000 / TICK_PERIOD_MS;
Ticker ticker;
ticker.attach_us(tick, TICK_PERIOD_MS * 1000);
while (true) {
if (button_event) {
int click;
blue = LED_ON;
click = button_detect();
blue = LED_OFF;
DEBUG("click type: %d\n\r", click);
button_event = false;
if (1 == click) {
single_click_input = current_input;
} else if (2 == click) {
double_click_input = current_input;
green = LED_ON;
green_led_time_to_off = 1000 / TICK_PERIOD_MS;
} else if (-1 == click) {
while (BUTTON_DOWN == button.read()) {
}
nrf_delay_us(3000);
power_down();
} else {
continue;
}
DEBUG("typical input: %f, %f\n\r", single_click_input, double_click_input);
threshold_update = 1;
} else {
ble.waitForEvent();
}
}
}