final

Dependencies:   MAX30003 max32630fthr DS1307

Revision:
11:300afaf2696b
Parent:
10:54aa50490b15
Child:
12:10b49ad3c492
--- a/main.cpp	Mon Sep 21 23:13:36 2020 +0000
+++ b/main.cpp	Fri Sep 25 16:42:40 2020 +0000
@@ -3,9 +3,13 @@
 #include "mbed.h"
 #include "max32630fthr.h"
 #include "ds1307.h"
-#include <BufferedSerial.h>
+//#include <BufferedSerial.h>
 #include <string>
 //#include <Serial.h>
+
+#define TARGET_TX_PIN P3_1
+#define TARGET_RX_PIN P3_0
+
 Timer timer_fast;
 Timer t;
 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
@@ -13,20 +17,28 @@
 void task_fast(void);
 DigitalOut ledA(LED2);
 void ecg_config(MAX30003 &ecgAFE);
-BufferedSerial pc(P3_1,P3_0);            // Use USB debug probe for serial link static Unbuffered
+//BufferedSerial pc(P3_1,P3_0);            // Use USB debug probe for serial link static Unbuffered
+static BufferedSerial pc(TARGET_TX_PIN, TARGET_RX_PIN, 115200);
+
 //Serial uart_1(USBTX, USBRX);            // Use USB debug probe for serial link static Unbuffered
 //
 //Serial pc(P3_1,P3_0);
 volatile bool ecgFIFOIntFlag = 0; 
 volatile bool timerflag = 0;
+
+FileHandle *mbed::mbed_override_console(int fd)
+{
+    return &pc;
+}
+
 void ecgFIFO_callback_1()  { // Triggered when the ECG FIFO is about to be full
     
     ecgFIFOIntFlag = 1;
 }  
 
-int main()
+int main(void)
 {   
-    // Constants
+   // Constants
     const int EINT_STATUS_MASK =  1 << 23;
     const int FIFO_OVF_MASK =  0x7;
     const int FIFO_VALID_SAMPLE_MASK =  0x0;
@@ -36,12 +48,12 @@
     DigitalOut rLed(LED1, LED_OFF);
 //    pc.baud(9600);
     
-    pc.set_baud(115200);                    // Baud rate = 115200
-    pc.set_format(
-        /* bits */ 8,   
-        /* parity */ BufferedSerial::None,
-        /* stop bit */ 1 //1
-    );
+    //pc.set_baud(115200);                    // Baud rate = 115200
+    //pc.set_format(
+    //    /* bits */ 8,   
+    //    /* parity */ BufferedSerial::None,
+    //    /* stop bit */ 1 //1
+    //);
     //uart_1.baud(115200);  
     InterruptIn ecgFIFO_int(P5_4);          // Config P5_4 as int. in for the
     ecgFIFO_int.fall(&ecgFIFO_callback_1);    // ecg FIFO interrupt at falling edge
@@ -86,15 +98,30 @@
     
     uint8_t ending[5] = {'@','#','%','!','7'};
     
-    char buf[5];
+    char buf[20];
+    pc.write("Welcome",8*sizeof(char));
+    printf("In the main loop");
+     bool flag_first = false;
+       
+      do
+      {
+        if (pc.readable()) {
+        scanf("%s",buf);
+     printf("The entered string is %s : \n ",buf);
+     uint32_t packet_1 = atoi(buf);
+     flag_first = true;
     
-    while(1) 
+        }
+        
+        }while (flag_first==false);
+        
+         while(1) 
     {
        
     
     if (timer_fast.read() > .9) 
     {
-     t.start();
+     //t.start();
      //ledA = !ledA;   
 
       
@@ -129,9 +156,9 @@
               
         pc.write((uint8_t *)ending, sizeof(ending));
         checksum_ = 0;
-        t.stop();
-        auto us = t.elapsed_time().count();
-        printf("Timer time: %llu ms \n", us);
+       // t.stop();
+       // auto us = t.elapsed_time().count();
+       // printf("Timer time: %llu ms \n", us);
       timer_fast.reset();
        } 
         // Read back ECG samples from the FIFO 
@@ -181,8 +208,7 @@
                     checksum_ += cksm_1 + cksm_2;
                     onesec_counter++;      
                 } 
-                //onesec_counter += readECGSamples;
-                               
+                              
             }
            
         }