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: BLE_API mbed nRF51822
Fork of BLE_HeartRate_IDB0XA1 by
Revision 24:359e85e758c3, committed 2017-01-08
- Comitter:
- hux
- Date:
- Sun Jan 08 23:16:12 2017 +0000
- Parent:
- 23:2e73c391bb12
- Child:
- 25:339931243be4
- Commit message:
- A cute tiny piece of code implementing an Iot NAND device, demonstrating how to setup and advertise a cute GATT (NAND) service.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bricks/blink.cpp Sun Jan 08 23:16:12 2017 +0000
@@ -0,0 +1,82 @@
+// blink.cpp - send a morse pattern to LED1
+//
+// Function morse() is one way for running LED1 with a blinking sequence using
+// a busy wait, until the sequence is completed.
+//
+// morse(" x xxx x "); send one time morse sequence, interval = 0.2
+// morse(" x xxx x ",0.5); send one time morse sequence, interval = 0.5
+//
+// Function morse() got the additional feature to stop an ongoing timer based
+// blinking sequence.
+//
+// The alternative is to setup an ever repeating blink sequence via LED1 using
+// function blink(), which is non waiting.
+//
+// blink(" x xxx x "); repeating blink sequence, interval = 0.2
+// blink(" x xxx x ",0.5); repeating blink sequence, interval = 0.5
+// blink(0); stops blinking sequence
+//
+
+#include "bricks/target.h"
+#include "bricks/blink.h"
+
+#ifndef LED_INVERTED
+# define LED_ON 1
+# define LED_OFF 0
+#else
+# define LED_ON 0
+# define LED_OFF 1
+#endif
+
+ static DigitalOut led(LED1); // LED1, being used for morse sequence
+ static Ticker ticker; // triggers periodic callbacks
+ static const char *pointer = 0; // 0 means morse activity disabled
+ static const char *sequence = 0; // next morse sequence for repeats
+
+
+ void morse(const char *pattern, double interval)
+ {
+ pointer = 0; // disable ticker based blinking
+ sequence = 0; // set also empty sequence
+
+ for (; *pattern; pattern++)
+ {
+ led = (*pattern == ' ') ? LED_OFF : LED_ON;
+ wait(interval); // busy waiting for interval time
+ }
+ }
+
+// callback for LED1 ticker controlled blinking
+
+ static void callback(void)
+ {
+ if (pointer != 0)
+ {
+ if (*pointer == 0)
+ {
+ pointer = sequence; // reset pointer to followup sequence
+ }
+
+ if (*pointer)
+ {
+ led = (*pointer++ == ' ') ? LED_OFF : LED_ON;
+ }
+ }
+ }
+
+ void blink(const char *pattern, const char* next, double interval)
+ {
+ pointer = 0; // stop current activities
+ led = LED_OFF; // reset led with LED_OFF
+
+ sequence = next; // init morse sequence
+
+ ticker.attach(callback,interval); // next LED state after every interval
+ pointer = pattern; // enable callback activty
+ }
+
+ void blink(const char *pattern, double interval)
+ {
+ blink(pattern,pattern,interval);
+ }
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bricks/blink.h Sun Jan 08 23:16:12 2017 +0000
@@ -0,0 +1,44 @@
+// blink.h - blinking sequences for LED1
+#ifndef _BLINK_H_
+#define _BLINK_H_
+
+#include <mbed.h>
+#include "bricks/o.h"
+
+# define BLINK_SEQUENCE_IDLE "x "
+# define BLINK_SEQUENCE_ADVERTISE "x xxx "
+# define BLINK_SEQUENCE_CONNECTED " xxx "
+# define BLINK_SEQUENCE_ACTION "x x x x x "
+# define BLINK_SEQUENCE_ERROR "x x x x xxx "
+# define BLINK_SEQUENCE_TRANSITION "x x x "
+
+ void morse(const char *pattern, double periode = 0.2);
+ void blink(const char *pattern, const char* next, double interval = 0.2);
+ void blink(const char *pattern, double periode = 0.2);
+
+ inline void blinkIdle(O&o) // 'idle' blink sequence
+ {
+ blink(BLINK_SEQUENCE_IDLE);
+ }
+
+ inline void blinkAdvertise(O&o) // 'advertise' blink sequence
+ {
+ blink(BLINK_SEQUENCE_ADVERTISE);
+ }
+
+ inline void blinkConnected(O&o) // 'connected' blink sequence
+ {
+ blink(BLINK_SEQUENCE_TRANSITION, BLINK_SEQUENCE_CONNECTED);
+ }
+
+ inline void blinkAction(O&o) // 'action' blink sequence
+ {
+ blink(BLINK_SEQUENCE_ACTION, BLINK_SEQUENCE_IDLE);
+ }
+
+ inline void blinkError(O&o) // 'error' blink sequence
+ {
+ blink(BLINK_SEQUENCE_ERROR);
+ }
+
+#endif // _BLINK_H_
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bricks/blob.h Sun Jan 08 23:16:12 2017 +0000
@@ -0,0 +1,59 @@
+// blob.h - 'BLOBs' are BLuetooth OBjects
+#ifndef _BLOB_H_
+#define _BLOB_H_
+
+#include "ble/BLE.h"
+#include "ble/Gap.h"
+
+#define _ICCC BLE::InitializationCompleteCallbackContext // pure short hand
+#define _GDCP Gap::DisconnectionCallbackParams_t // pure short hand
+#define _GCCP Gap::ConnectionCallbackParams_t // pure short hand
+#define _GWCP GattWriteCallbackParams // pure short hand
+
+ class Blob : public BLE
+ {
+ public:
+ const _ICCC *pComplete; // params to _ICCC context
+ const _GCCP *pConnect; // params to _GCCP context
+ const _GDCP *pDisconnect; // params to _GDPC context
+ const _GWCP *pWritten; // params to _GWCP context
+
+ public: // construction
+ Blob() : BLE() // standard constructor
+ {
+ pComplete = 0; pDisconnect = 0;
+ }
+ };
+
+
+// Setup Advertising Name (syntactic sugar)
+
+ inline void name(Blob &o, const char *str)
+ {
+ o.gap().accumulateAdvertisingPayload(
+ GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)str, strlen(str)+1);
+ }
+
+
+// Setup Device Name (syntactic sugar)
+
+ inline void device(Blob &o, const char *text)
+ {
+ o.gap().setDeviceName((const uint8_t *)text);
+ }
+
+
+// Setup Advertising Data (syntactic sugar)
+
+ inline void data(Blob &o, const uint8_t *buf, size_t buflen)
+ {
+ o.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, buf, buflen);
+ }
+
+ inline void data(Blob &o, const char *text)
+ {
+ size_t len = strlen(text);
+ data(o,(const uint8_t*)text,len);
+ }
+
+#endif // _BLOB_H_
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bricks/target.h Sun Jan 08 23:16:12 2017 +0000 @@ -0,0 +1,19 @@ +// bricks/target.h - define target specifics + +#ifndef _BRICKS_TARGET_H_ +#define _BRICKS_TARGET_H_ + +// platform specific defines - comment out platforms which are not used +// We work only with two kinds of platform: +// +// a) a NUCLEO platform from STMicroelectronics +// b) a nRF51 platform from Nordic Semiconductor +// +// If we have not a nRF51 target then we coclude it is a NUCLEO target. This is +// not really clean, but under above assumptions it works so far! + +#ifdef TARGET_NRF51822 +# define LED_INVERTED // inverted LED for nRF51 targets +#endif + +#endif // _BRICKS_TARGET_H_
