TOF based Presence Detector

Dependencies:   BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed

Fork of BLE_HeartRate_IDB0XA1 by ST

Committer:
hux
Date:
Mon Aug 20 16:42:59 2018 +0000
Revision:
28:a23b16555909
TOF Detector - Basis for Presence Detection

Who changed what in which revision?

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