Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed BLE_API nRF51822
receiver_main.cpp
- Committer:
- khyein8154
- Date:
- 2019-04-17
- Revision:
- 5:45c48a82f202
- Parent:
- 4:25c53ae0ae04
- Child:
- 6:55c87c9bc90e
File content as of revision 5:45c48a82f202:
#include "mbed.h"
#include "ble/BLE.h"
#include <string>
using namespace std;
Serial pc(USBTX, USBRX);
#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";
struct Data {
uint32_t seqNum;
};
// void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
void scanCallback(const Gap::AdvertisementCallbackParams_t *params)
{
if (*(params->Gap::AdvertisementCallbackParams_t::peerAddr) == (std::uint8_t)0xF34F887FED4E) {
uint8_t * buf = (uint8_t *) params->advertisingData;
if (buf[0] == GapAdvertisingData::COMPLETE_LOCAL_NAME) {
blueLed = 0;
}
// pc.printf("Hello\n");
for (int i=0; i < params->advertisingDataLen; i++) {
//if ( i >= params->advertisingDataLen-2 && buf[i] == 'n' ) {
// blueLed = 0;
// }
pc.printf("%02x ", buf[i]);
}
pc.printf("\n");
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);
// pc.printf("Hello World!\n");
/* 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
}
}
