RRI data

Fork of BLENano2_AD_Serial by electric baka

Files at this revision

API Documentation at this revision

Comitter:
electricbaka
Date:
Thu Sep 20 08:19:28 2018 +0000
Parent:
2:2b070a0b5e17
Commit message:
init

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Sep 20 08:18:05 2018 +0000
+++ b/main.cpp	Thu Sep 20 08:19:28 2018 +0000
@@ -17,6 +17,21 @@
 //Definition
 //------------------------------------------------------------ 
 #define ANALOG_IN_PIN1 P0_5
+#define TICKER_TIME 1000                    //1000[us] = 1[ms]
+
+//HeartRate
+int timer_num = 0;
+int threshold_v = 650;
+int threshold_t = 300;
+
+
+//======================================================================
+//onTimeout
+//======================================================================
+void m_status_check_handle(void)
+{   
+    timer_num ++;
+}
 
 
 //------------------------------------------------------------
@@ -29,14 +44,29 @@
 {
     pc.baud(9600);
     char str[10];
-     
-    while (true) {        
+
+    //Timer Setting [us]
+    Ticker ticker;
+    ticker.attach_us(m_status_check_handle, TICKER_TIME);
+    
+    int timer_ms;     
+    
+    while(1)
+    {
         float s = ANALOG1;
         uint16_t value = s * 1024;
-        
-        sprintf(str, "%d\r\n", value);
-        pc.printf(str);
-        
-        wait_ms(1);
+                        
+        //---------------------------------------------------------------------------------------------       
+        //Detect HeartRate Peak
+        //--------------------------------------------------------------------------------------------- 
+        timer_ms = TICKER_TIME/1000 * timer_num;
+        if(value >= threshold_v && timer_ms > threshold_t)
+        {    
+            //clear timer_num
+            timer_num = 0;              
+              
+            sprintf(str, "%d\r\n", timer_ms);
+            pc.printf(str);
+        }       
     }
 }
\ No newline at end of file