![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
aidanReceiver
Dependencies: mbed BLE_API nRF51822
Diff: receiver_main.cpp
- Revision:
- 0:50406b29435a
- Child:
- 1:3ad5b46f9abc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/receiver_main.cpp Wed Apr 17 19:55:43 2019 +0000 @@ -0,0 +1,62 @@ +#include "mbed.h" +#include "ble/BLE.h" +#define LED_RED p21 +#define LED_GREEN p22 +#define LED_BLUE p23 +#define BUTTON_PIN p17 +#define BATTERY_PIN p1 +DigitalOut led1(LED_RED); +DigitalOut blueLed(LED_BLUE); +const static char DEVICE_NAME[] = "Joe-Aidan"; +// void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) +void scanCallback(const Gap::AdvertisementCallbackParams_t *params) +{ + if (*(params->Gap::AdvertisementCallbackParams_t::peerAddr) == (std::uint8_t)0xF34F887FED4E) { + char * buf = (char*) params->advertisingData; + + if (buf[0] == GapAdvertisingData::COMPLETE_LOCAL_NAME) { + blueLed = 0; + } + + /* + for (int i=0; i < params->advertisingDataLen; i++) { + if ( i >= params->advertisingDataLen-2 && buf[i] == 'n' ) { + blueLed = 0; + } + } + */ + + led1 = 0; + } + +// ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); + return; +} +void bleInitComplete(BLE::InitializationCompleteCallbackContext *params) +{ + BLE &ble = params->ble; + ble_error_t error = params->error; + if (error != BLE_ERROR_NONE) { + return; + } + + led1 = 1; + blueLed = 1; + + /* Set up scanning prodedure */ + ble.gap().setScanParams(GapScanningParams::SCAN_INTERVAL_MAX, GapScanningParams::SCAN_WINDOW_MAX, 0, false); + ble.gap().startScan(scanCallback); +} +int main(void) +{ + BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE); + ble.init(bleInitComplete); + + /* SpinWait for initialization to complete. This is necessary because the + * BLE object is used in the main loop below. */ + while (ble.hasInitialized() == false) { /* spin loop */ } + + while (1) { + ble.waitForEvent(); // low power wait for event + } +} \ No newline at end of file