workss
Dependencies: mbed BLE_API nRF51822 VL53L0X
Diff: main.cpp
- Revision:
- 28:ca14866eec64
- Parent:
- 27:903ec28ea7a0
- Child:
- 29:6ba8491c1dab
--- a/main.cpp Wed Mar 13 14:19:08 2019 +0000 +++ b/main.cpp Wed Mar 13 15:16:25 2019 +0000 @@ -31,14 +31,19 @@ int status1; int status2; -const static char DEVICE_NAME[] = "OCCUPY-CRICHTON-ST"; // change this -static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE}; //Custom UUID, FFFF is reserved for development +const static char DEVICE_NAME[] = "OCCUPY-CRICHTON-ST"; +static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE}; HeartRateService *hrService; uint8_t hrmCounter = 0; +void connectionCallback(const Gap::ConnectionCallbackParams_t *) { + printf("Bluetooth connected\n"); +} + void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *) { + printf("Bluetooth disconnected\n"); BLE::Instance(BLE::DEFAULT_INSTANCE).gap().startAdvertising(); } @@ -50,22 +55,21 @@ if (error != BLE_ERROR_NONE) { return; } - + + ble.gap().onConnection(connectionCallback); ble.gap().onDisconnection(disconnectionCallback); hrService = new HeartRateService(ble, hrmCounter, HeartRateService::LOCATION_FINGER); - ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); // BLE only, no classic BT - ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); // advertising type - ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); // add name - ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); // UUID's broadcast in advertising packet - ble.gap().setAdvertisingInterval(100); // 100ms. + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); + ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR); ble.gap().startAdvertising(); } int format_dist(int distance) { - // local variable declaration int result; if (distance > 1270) @@ -84,9 +88,10 @@ dist1 = format_dist(distance1); dist2 = format_dist(distance2); - + if (status1 == VL53L0X_ERROR_NONE) { printf("Range1 [mm]: %6ld\r\n", dist1); + if (dist1 > 4 && dist1 < 220) { led1 = 0; hrmCounter = dist1; @@ -123,7 +128,6 @@ ble.init(bleInitComplete); Ticker ticker; - ticker.attach(wakeup_event_cb, 0.3); while (ble.hasInitialized()) {