TOF based Presence Detector

Dependencies:   BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed

Fork of BLE_HeartRate_IDB0XA1 by ST

Committer:
hux
Date:
Sat Jan 14 08:43:14 2017 +0000
Revision:
27:32267cee7cb8
Parent:
22:d467526abc4a
Setup a GATT Detector Service. There is some bug in the GATT setup, resulting in different behavior between Nordic nRF51822-DK and NUCLEO-L476RG, but with the workaround it works also for the NUCLEO board. (using Bricks V1A)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hux 22:d467526abc4a 1 // blink.cpp - send a morse pattern to LED1
hux 22:d467526abc4a 2 //
hux 22:d467526abc4a 3 // Function morse() is one way for running LED1 with a blinking sequence using
hux 22:d467526abc4a 4 // a busy wait, until the sequence is completed.
hux 22:d467526abc4a 5 //
hux 27:32267cee7cb8 6 // morse(o," x xxx x "); send one time morse sequence, interval = 0.2
hux 27:32267cee7cb8 7 // morse(o," x xxx x ",0.5); send one time morse sequence, interval = 0.5
hux 22:d467526abc4a 8 //
hux 27:32267cee7cb8 9 // Function morse(o) got the additional feature to stop an ongoing timer based
hux 22:d467526abc4a 10 // blinking sequence.
hux 22:d467526abc4a 11 //
hux 22:d467526abc4a 12 // The alternative is to setup an ever repeating blink sequence via LED1 using
hux 22:d467526abc4a 13 // function blink(), which is non waiting.
hux 22:d467526abc4a 14 //
hux 27:32267cee7cb8 15 // blink(o," x xxx x "); repeating blink sequence, interval = 0.2
hux 27:32267cee7cb8 16 // blink(o," x xxx x ",0.5); repeating blink sequence, interval = 0.5
hux 27:32267cee7cb8 17 // blink(o); stops blinking sequence
hux 22:d467526abc4a 18 //
hux 22:d467526abc4a 19
hux 22:d467526abc4a 20 #include "bricks/target.h"
hux 22:d467526abc4a 21 #include "bricks/blink.h"
hux 22:d467526abc4a 22
hux 22:d467526abc4a 23 #ifndef LED_INVERTED
hux 22:d467526abc4a 24 # define LED_ON 1
hux 22:d467526abc4a 25 # define LED_OFF 0
hux 22:d467526abc4a 26 #else
hux 22:d467526abc4a 27 # define LED_ON 0
hux 22:d467526abc4a 28 # define LED_OFF 1
hux 22:d467526abc4a 29 #endif
hux 22:d467526abc4a 30
hux 22:d467526abc4a 31 static DigitalOut led(LED1); // LED1, being used for morse sequence
hux 22:d467526abc4a 32 static Ticker ticker; // triggers periodic callbacks
hux 22:d467526abc4a 33 static const char *pointer = 0; // 0 means morse activity disabled
hux 22:d467526abc4a 34 static const char *sequence = 0; // next morse sequence for repeats
hux 22:d467526abc4a 35
hux 22:d467526abc4a 36
hux 27:32267cee7cb8 37 void morse(O&o,const char *pattern, double interval)
hux 22:d467526abc4a 38 {
hux 22:d467526abc4a 39 pointer = 0; // disable ticker based blinking
hux 22:d467526abc4a 40 sequence = 0; // set also empty sequence
hux 22:d467526abc4a 41
hux 22:d467526abc4a 42 for (; *pattern; pattern++)
hux 22:d467526abc4a 43 {
hux 22:d467526abc4a 44 led = (*pattern == ' ') ? LED_OFF : LED_ON;
hux 22:d467526abc4a 45 wait(interval); // busy waiting for interval time
hux 22:d467526abc4a 46 }
hux 22:d467526abc4a 47 }
hux 22:d467526abc4a 48
hux 22:d467526abc4a 49 // callback for LED1 ticker controlled blinking
hux 22:d467526abc4a 50
hux 27:32267cee7cb8 51 static void cbBlinker(void) // blinker callback
hux 22:d467526abc4a 52 {
hux 22:d467526abc4a 53 if (pointer != 0)
hux 22:d467526abc4a 54 {
hux 22:d467526abc4a 55 if (*pointer == 0)
hux 22:d467526abc4a 56 {
hux 27:32267cee7cb8 57 pointer = sequence; // reset pointer to followup sequence
hux 22:d467526abc4a 58 }
hux 22:d467526abc4a 59
hux 22:d467526abc4a 60 if (*pointer)
hux 22:d467526abc4a 61 {
hux 22:d467526abc4a 62 led = (*pointer++ == ' ') ? LED_OFF : LED_ON;
hux 22:d467526abc4a 63 }
hux 22:d467526abc4a 64 }
hux 22:d467526abc4a 65 }
hux 22:d467526abc4a 66
hux 27:32267cee7cb8 67 void blink(O&o,const char *pattern, const char* next, double interval)
hux 22:d467526abc4a 68 {
hux 22:d467526abc4a 69 pointer = 0; // stop current activities
hux 22:d467526abc4a 70 led = LED_OFF; // reset led with LED_OFF
hux 22:d467526abc4a 71
hux 22:d467526abc4a 72 sequence = next; // init morse sequence
hux 22:d467526abc4a 73
hux 27:32267cee7cb8 74 ticker.attach(cbBlinker,interval);// next LED state after every interval
hux 22:d467526abc4a 75 pointer = pattern; // enable callback activty
hux 22:d467526abc4a 76 }
hux 22:d467526abc4a 77
hux 27:32267cee7cb8 78 void blink(O&o, const char *pattern, double interval)
hux 22:d467526abc4a 79 {
hux 27:32267cee7cb8 80 blink(o,pattern,pattern,interval);
hux 22:d467526abc4a 81 }
hux 22:d467526abc4a 82