MH / Mbed OS MAX30003WING_monitorhealth_customboard_batterycode

Dependencies:   MAX30003 max32630fthr DS1307

Files at this revision

API Documentation at this revision

Comitter:
parthsagar2010
Date:
Wed Aug 19 19:38:17 2020 +0000
Parent:
8:6b9359f81cc0
Child:
10:54aa50490b15
Commit message:
Updated the code with 1 sec packets

Changed in this revision

DS1307.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DS1307.lib	Wed Aug 19 19:38:17 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/harrypowers/code/DS1307/#c3e4da8feb10
--- a/main.cpp	Wed Aug 05 04:33:07 2020 +0000
+++ b/main.cpp	Wed Aug 19 19:38:17 2020 +0000
@@ -2,13 +2,18 @@
 #include "MAX30003.h"
 #include "mbed.h"
 #include "max32630fthr.h"
+#include "ds1307.h"
 
-
+Timer timer_fast;
 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
 
+void task_fast(void);
+DigitalOut ledA(LED2);
 void ecg_config(MAX30003 &ecgAFE);
 
 volatile bool ecgFIFOIntFlag = 0; 
+volatile int16_t onesec_counter = 0;
+volatile bool timerflag = 0;
 void ecgFIFO_callback_1()  { // Triggered when the ECG FIFO is about to be full
     
     ecgFIFOIntFlag = 1;
@@ -24,6 +29,7 @@
     const int FIFO_VALID_SAMPLE_MASK =  0x0;
     const int FIFO_FAST_SAMPLE_MASK =  0x1;
     const int ETAG_BITS_MASK = 0x7;
+    timer_fast.start();
     DigitalOut rLed(LED1, LED_OFF);
     
     Serial pc(USBTX, USBRX);            // Use USB debug probe for serial link
@@ -44,17 +50,41 @@
     
     uint32_t ecgFIFO, readECGSamples, idx, ETAG[32], status;
     int16_t ecgSample[32];
+    //bool timerflag = false;
+    int16_t ecgSample_1sec[700];
+   int16_t onesec_counter = 0;
+    int16_t sample = 300;
     
-    while(1) {
-        
+    while(1) 
+    {
+    
+    if (timer_fast.read() > 1) 
+    {
+      //timerflag = 1;
+     ledA = !ledA;
+      timer_fast.reset();
+      int8_t header_device_id[3] = {0,0,210};
+      int8_t header_packet_type[2] = {0,2};
+      int8_t header_packet_id[4] = {0,0,0,0};
+      int8_t header_ecg_datalen[2] = {0,onesec_counter};
+      int8_t header_ecg_checksum[2] = {0,0};
+      
+      
+      //pc.printf("%6d\r\n", sample);
+      //pc.printf("%6d\r\n", onesec_counter);
+      
+      onesec_counter = 0;
+       } 
         // Read back ECG samples from the FIFO 
-        if( ecgFIFOIntFlag ) {
+        else if( (ecgFIFOIntFlag==1))// && (timerflag == 0)) 
+        {
             
             ecgFIFOIntFlag = 0; 
             status = ecgAFE.readRegister( MAX30003::STATUS );      // Read the STATUS register
              
             // Check if EINT interrupt asserted
-            if ( ( status & EINT_STATUS_MASK ) == EINT_STATUS_MASK ) {     
+            if ( ( status & EINT_STATUS_MASK ) == EINT_STATUS_MASK ) 
+            {     
             
                 readECGSamples = 0;                        // Reset sample counter
                 
@@ -69,17 +99,36 @@
                           ETAG[readECGSamples-1] == FIFO_FAST_SAMPLE_MASK ); 
                 
                 // Check if FIFO has overflowed
-                if( ETAG[readECGSamples - 1] == FIFO_OVF_MASK ){                  
+                if( ETAG[readECGSamples - 1] == FIFO_OVF_MASK )
+                {                  
                     ecgAFE.writeRegister( MAX30003::FIFO_RST , 0); // Reset FIFO
                     rLed = 1;//notifies the user that an over flow occured
                 }
                 
                 // Print results 
-                for( idx = 0; idx < readECGSamples; idx++ ) {
-                    pc.printf("%6d\r\n", ecgSample[idx]);           
+                for( idx = 0; idx < readECGSamples; idx++ ) 
+                {
+                    //pc.printf("%6d\r\n", ecgSample[idx]);     
+                    ecgSample_1sec[onesec_counter] = ecgSample[idx];
+                    onesec_counter++;      
                 } 
                                
             }
+        //    else
+          //  {
+            //    timerflag = 0;
+              //  }
+            //else if (timerflag == 1)
+            //{
+                //timerflag = 0;
+                //pc.printf("1 sec ends :\n");
+                //onesec_counter = 0;
+                //timer_fast.reset();
+                //timer_fast.start();
+                //delete[] ecgSample_1sec;
+                //}
+              
+            
         }
     }
 }