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.
Revision 1:f317db48f9e8, committed 2021-12-02
- Comitter:
 - zhihanzhang
 - Date:
 - Thu Dec 02 18:45:42 2021 +0000
 - Parent:
 - 0:e80a245c4d0d
 - Commit message:
 - 4781 Final Project
 
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 f317db48f9e8 PulseSensor.cpp
--- a/PulseSensor.cpp	Sun Feb 09 15:37:19 2014 +0000
+++ b/PulseSensor.cpp	Thu Dec 02 18:45:42 2021 +0000
@@ -1,7 +1,7 @@
 #include "PulseSensor.h"
 
 
-PulseSensor::PulseSensor(PinName analogPin, void (*printDataCallback)(char,int), int callbackRateMs)
+PulseSensor::PulseSensor(PinName analogPin, void (*printDataCallback)(int), int callbackRateMs)
 {
     _started = false;
     
@@ -21,11 +21,12 @@
 
 void PulseSensor::process_data_ticker_callback(void)
 {
-    _printDataCallback('S', Signal);     // send Processing the raw Pulse Sensor data
+    //_printDataCallback('S', Signal);     // send Processing the raw Pulse Sensor data
     if (QS == true) { // Quantified Self flag is true when a heartbeat is found
         //fadeRate = 255;                  // Set 'fadeRate' Variable to 255 to fade LED with pulse
-        _printDataCallback('B',BPM);   // send heart rate with a 'B' prefix
-        _printDataCallback('Q',IBI);   // send time between beats with a 'Q' prefix
+        //_printDataCallback('B',BPM);   // send heart rate with a 'B' prefix
+        _printDataCallback(BPM);
+        //_printDataCallback('Q',IBI);   // send time between beats with a 'Q' prefix
         QS = false;                      // reset the Quantified Self flag for next time
     }
 }
@@ -149,4 +150,8 @@
     {
         return false;
     }
+}
+
+uint8_t PulseSensor::get_bpm(){
+    return BPM;
 }
\ No newline at end of file
diff -r e80a245c4d0d -r f317db48f9e8 PulseSensor.h
--- a/PulseSensor.h	Sun Feb 09 15:37:19 2014 +0000
+++ b/PulseSensor.h	Thu Dec 02 18:45:42 2021 +0000
@@ -28,14 +28,14 @@
         volatile bool secondBeat;       // used to seed rate array so we startup with reasonable BPM
         
         // these variables are volatile because they are used during the interrupt service routine!
-        volatile int BPM;                   // used to hold the pulse rate
+        volatile uint8_t BPM;                   // used to hold the pulse rate
         volatile int Signal;                // holds the incoming raw data
         volatile int IBI;             // holds the time between beats, the Inter-Beat Interval
         volatile bool Pulse;        // true when pulse wave is high, false when it's low
         volatile bool QS;           // becomes true when a beat is found
     
     
-        void (*_printDataCallback)(char,int);
+        void (*_printDataCallback)(int);
         static const int _sensorTickRateMs = 2;
         int       _callbackRateMs;
         bool      _started;
@@ -53,7 +53,9 @@
          * @param   printDataCallback Pointer to function which will be called to print the latest data. Output format available here: http://pulsesensor.myshopify.com/pages/code-and-guide
          * @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);
+        //volatile uint8_t BPM;
+        
+        PulseSensor(PinName analogPin, void (*printDataCallback)(int), int callbackRateMs=20);
         
         /** Destructor */
         ~PulseSensor();
@@ -67,6 +69,8 @@
          * @return true if reading is stopped, false if reading was already stopped.
          */
         bool stop();
+        
+        uint8_t get_bpm();
 };
 
 #endif
\ No newline at end of file