Deniz Dosluoglu / Mbed 2 deprecated RD117_MBED_mod

Dependencies:   ToScreen mbed

Fork of RD117_MBED by Maxim Integrated

Revision:
7:7c4c5b06c805
Parent:
6:519bdb0ec306
Child:
8:e66033f2fe53
--- a/main.cpp	Sat Apr 14 20:04:56 2018 +0000
+++ b/main.cpp	Sun Apr 15 20:29:35 2018 +0000
@@ -75,19 +75,9 @@
 //#include "algorithm.h"
 #include "algorithm_by_RF.h"
 #include "MAX30102.h"
-#include "C12832.h"
+//#include "C12832.h"
 #define MAX_BRIGHTNESS 255
-/*
-#ifndef PLATFORM_H_
-#define PLATFORM_H_
- //disable application functions
-#define PL_BOARD_IS_FRDM 1
-#define PL_HAS_LOW_POWER 1
-#define PL_HAS_SHELL     0
-#define PL_HAS_LED       1
-#define PL_HAS_RTOS      0
- 
-#endif  PLATFORM_H_ */
+
 
 uint32_t aun_ir_buffer[500]; //IR LED sensor data
 int32_t n_ir_buffer_length;    //data length
@@ -107,8 +97,8 @@
 
 Serial pc(USBTX, USBRX);    //initializes the serial port
 #ifdef TARGET_KL25Z 
-PwmOut led(PTB18);  //initializes the pwm output that connects to the on board LED
-DigitalIn INT(PTD0);  //pin PTD0 connects to the interrupt output pin of the MAX30102
+//PwmOut led(PTB18);  //initializes the pwm output that connects to the on board LED
+DigitalIn INT(PTD1);  //pin PTD0 connects to the interrupt output pin of the MAX30102
 #endif
 #ifdef TARGET_K64F
 DigitalIn INT(PTD1);  //pin PTD1 connects to the interrupt output pin of the MAX30102
@@ -172,8 +162,8 @@
     
     //read the first 500 samples, and determine the signal range
     //READ 100 SAMPLES
- //calculated_ir_mean = 0.0;
-// calculated_red_mean = 0.0;
+    calculated_ir_mean = 0.0;
+    calculated_red_mean = 0.0;
     for(i=0;i<BUFFER_SIZE;i++)
     {
         while(INT.read()==1);   //wait until the interrupt pin asserts
@@ -219,29 +209,20 @@
     
     un_prev_data=aun_red_buffer[i];
     
-    
+  rf_heart_rate_and_oxygen_saturation(aun_ir_buffer, BUFFER_SIZE, aun_red_buffer, &n_sp02, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid, &ratio, &correl);
    
-   /*
-    //calculate heart rate and SpO2 after first 500 samples (first 5 seconds of samples)
-    //maxim_heart_rate_and_oxygen_saturation(aun_ir_buffer, n_ir_buffer_length, aun_red_buffer, &n_sp02, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid); 
-    rf_heart_rate_and_oxygen_saturation(aun_ir_buffer, BUFFER_SIZE, aun_red_buffer, &n_sp02, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid, &ratio, &correl, &ir_mean, &red_mean); 
-    //Continuously taking samples from MAX30102.  Heart rate and SpO2 are calculated every 1 second
-    //while(1) //infinite loop
-    for (int a = 0; a<20; a++)//acquire finite amount of data
+    while(1)
     {
         i=0;
         un_min=0x3FFFF;
         un_max=0;
         
         //dumping the first 100 sets of samples in the memory and shift the last 400 sets of samples to the top
-        //revision, dump first 25
-        //for(i=100;i<500;i++)
-        for(i=25;i<100;i++)
+        for(i=100;i<500;i++)
         {
-            aun_red_buffer[i-25]=aun_red_buffer[i];
-            aun_ir_buffer[i-25]=aun_ir_buffer[i];
-            //aun_red_buffer[i-25]=aun_red_buffer[i];
-            //aun_ir_buffer[i-25]=aun_ir_buffer[i];
+            aun_red_buffer[i-100]=aun_red_buffer[i];
+            aun_ir_buffer[i-100]=aun_ir_buffer[i];
+            
             //update the signal min and max
             if(un_min>aun_red_buffer[i])
             un_min=aun_red_buffer[i];
@@ -250,9 +231,7 @@
         }
         
         //take 100 sets of samples before calculating the heart rate.
-        //take 
-        //for(i=400;i<500;i++)
-        for(i=75;i<100;i++)
+        for(i=400;i<500;i++)
         {
             un_prev_data=aun_red_buffer[i-1];
             while(INT.read()==1);
@@ -277,28 +256,19 @@
                     n_brightness=MAX_BRIGHTNESS;
             }
 #if defined(TARGET_KL25Z) || defined(TARGET_MAX32600MBED)
-            led.write(1-(float)n_brightness/256);
+//            led.write(1-(float)n_brightness/256);
 #endif
             //send samples and calculation result to terminal program through UART
-           // pc.printf("red="); // remove heading to make compatible with MATLAB
-           
-           //write seconds to create seventh column for martins code
-           pc.printf("%i ", t.read_ms());
+//            pc.printf("red=");
             pc.printf("%i ", aun_red_buffer[i]);
-            //pc.printf(", ir=");
+ //           pc.printf(", ir=");
             pc.printf("%i ", aun_ir_buffer[i]);
-            //pc.printf(", HR=%i, ", n_heart_rate);
             pc.printf("%i ", n_heart_rate); 
-            //pc.printf("HRvalid=%i, ", ch_hr_valid);
             pc.printf("%i ", ch_hr_valid);
-            //pc.printf("SpO2=%i, ", n_sp02);
-            pc.printf("%i ", n_sp02);
-            //pc.printf("SPO2Valid=%i\n\r", ch_spo2_valid);
+            pc.printf("%f ", n_sp02);
             pc.printf("%i\n\r", ch_spo2_valid);
         }
-        //maxim_heart_rate_and_oxygen_saturation(aun_ir_buffer, n_ir_buffer_length, aun_red_buffer, &n_sp02, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid);
-        rf_heart_rate_and_oxygen_saturation(aun_ir_buffer, BUFFER_SIZE, aun_red_buffer, &n_sp02, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid, &ratio, &correl);  
+         rf_heart_rate_and_oxygen_saturation(aun_ir_buffer, BUFFER_SIZE, aun_red_buffer, &n_sp02, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid, &ratio, &correl); 
     }
-*/
 }
  
\ No newline at end of file