Library for pulse sensor to be used in embedded pedometer device

Files at this revision

API Documentation at this revision

Comitter:
memig3
Date:
Fri Apr 10 23:57:44 2020 +0000
Parent:
0:e80a245c4d0d
Commit message:
Added constructor overloading so that you don't have to add a callback function for sending the data to the processing program;

Changed in this revision

PulseSensor.cpp Show annotated file Show diff for this revision Revisions of this file
PulseSensor.h Show annotated file Show diff for this revision Revisions of this file
diff -r e80a245c4d0d -r bb658291fa96 PulseSensor.cpp
--- a/PulseSensor.cpp	Sun Feb 09 15:37:19 2014 +0000
+++ b/PulseSensor.cpp	Fri Apr 10 23:57:44 2020 +0000
@@ -10,8 +10,18 @@
     _callbackRateMs = callbackRateMs;
     
     _printDataCallback = printDataCallback;
+    
+    proc = true;
 }
 
+PulseSensor::PulseSensor(PinName analogPin)
+{
+    _started = false;
+    
+    _pAin = new AnalogIn(analogPin);
+    
+    proc = false;
+}
 
 PulseSensor::~PulseSensor()
 {
@@ -126,7 +136,9 @@
         QS = false;
         
         _pulseSensorTicker.attach(this, &PulseSensor::sensor_ticker_callback, ((float)_sensorTickRateMs/1000));
-        _processDataTicker.attach(this, &PulseSensor::process_data_ticker_callback,  ((float)_callbackRateMs/1000));
+        if(proc) {
+            _processDataTicker.attach(this, &PulseSensor::process_data_ticker_callback,  ((float)_callbackRateMs/1000));\
+        }
         _started = true;
         return true;
     }
@@ -149,4 +161,12 @@
     {
         return false;
     }
+}
+
+int PulseSensor::get_BPM()
+{
+    if(_started)
+    {
+        return BPM;
+    }
 }
\ No newline at end of file
diff -r e80a245c4d0d -r bb658291fa96 PulseSensor.h
--- a/PulseSensor.h	Sun Feb 09 15:37:19 2014 +0000
+++ b/PulseSensor.h	Fri Apr 10 23:57:44 2020 +0000
@@ -17,6 +17,7 @@
 class PulseSensor
 {
     private:
+        volatile bool proc;
         volatile int rate[10];                    // used to hold last ten IBI values
         volatile unsigned long sampleCounter;          // used to determine pulse timing
         volatile unsigned long lastBeatTime;           // used to find the inter beat interval
@@ -54,6 +55,7 @@
          * @param   callbackRateMs Rate at which the printDataCallback is to be called, recommended is 20ms for graphing of pulse signal.
          */
         PulseSensor(PinName analogPin, void (*printDataCallback)(char,int), int callbackRateMs=20);
+        PulseSensor(PinName analogPin);
         
         /** Destructor */
         ~PulseSensor();
@@ -67,6 +69,8 @@
          * @return true if reading is stopped, false if reading was already stopped.
          */
         bool stop();
+        
+        int get_BPM();
 };
 
 #endif
\ No newline at end of file