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.
Fork of location-puck by
Diff: main.cpp
- Revision:
- 3:4cb285fb29e7
- Parent:
- 2:67d603617000
- Child:
- 4:4324d5acd5d8
diff -r 67d603617000 -r 4cb285fb29e7 main.cpp
--- a/main.cpp Thu Jun 19 10:47:28 2014 +0200
+++ b/main.cpp Thu Jun 19 11:17:30 2014 +0200
@@ -1,48 +1,52 @@
#include <mbed.h>
+#include <nRF51822.h>
-DigitalOut led1(LED1);
-DigitalOut led2(LED2);
+#define DEBUG 1
-void clear() {
- led1 = 0;
- led2 = 0;
-}
+#ifdef DEBUG
+ #define LOG(args...) pc.printf(args)
+#else
+ #define LOG(args...)
+#endif
-void cycle(float delta) {
- clear();
- led1 = 1;
- wait(delta);
+nRF51822n nrf;
+DigitalOut led1(p1);
+DigitalOut advertisiingStateLed(p30);
- clear();
- led1 = 1;
- wait(delta);
-
- clear();
- led2 = 1;
- wait(delta);
-
- clear();
- led2 = 1;
- wait(delta);
-}
+GapAdvertisingData advData;
+GapAdvertisingData scanResponse;
+GapAdvertisingParams advParams(GapAdvertisingOParams::ADV_CONNECTABLE_UNDIRECTED);
-void drums(float delta) {
- clear();
- led1 = 1;
- wait(delta);
+class GapEventHandler : public GapEvents {
+ virtual void onConnected(void) {
+ advertisingStateLed = 0;
+ LOG("Connected!\n\r");
+ }
- clear();
- led2 = 1;
- wait(delta);
-
- clear();
- led2 = 1;
- wait(delta);
+ virtual void onDisconnected(void) {
+ nrf.getGap().startAdvertising(advParams);
+ advertisingStateLed = 1;
+ LOG("Disconnected!\n\r");
+ LOG("Restarting the advertising process\n\r");
+ }
}
int main() {
- while(1) {
- drums(0.3);
- cycle(0.3);
+ nrf.getGap().setEventHandler(new GapEventHandler());
+
+ nrf.init();
+ nrf.reset();
+
+ advData.addFlags(GapAdvertisingData::BREDR_NOT_SUPPORTED);
+ advData.addData(GapAdvertisingData::SHORTENED_LOCAL_NAME,
+ (uint8_t*)"phlemz", sizeof("phlemz") - 1);
+ advData.addAppearance(GapAdvertisingData::UNKNOWN);
+ nrf.getGap().setAdvertisingData(advData. scanResponse);
+
+ nrf.getGap().startAdvertising(advParams);
+
+ for(;;) {
+ led1 = !led1;
+ wait(1);
}
}
