Modification into 17th July New display demo code

Dependencies:   SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217

Fork of Ext_Demo_17July2017_newdis by SenseSemi

Files at this revision

API Documentation at this revision

Comitter:
nikitateggi
Date:
Sat Jun 17 09:36:18 2017 +0000
Parent:
19:1650bbc923cc
Child:
21:7ef1b0b40841
Commit message:
poc code with finger detect and leadoff

Changed in this revision

bp.cpp Show annotated file Show diff for this revision Revisions of this file
display_modules.cpp Show annotated file Show diff for this revision Revisions of this file
display_modules.h Show annotated file Show diff for this revision Revisions of this file
ec_bp.cpp Show annotated file Show diff for this revision Revisions of this file
ec_bp.h Show annotated file Show diff for this revision Revisions of this file
ecgg.cpp Show annotated file Show diff for this revision Revisions of this file
glc.cpp 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
sdcard.cpp Show annotated file Show diff for this revision Revisions of this file
sdcard.h Show annotated file Show diff for this revision Revisions of this file
touch_modules.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/bp.cpp	Fri Jun 09 17:12:21 2017 +0000
+++ b/bp.cpp	Sat Jun 17 09:36:18 2017 +0000
@@ -37,7 +37,7 @@
     
     uint8_t uch_dummy;
     uint32_t ppgdata; 
-
+    uint8_t lead_reg=0;
     //int dummyconcat = 700000;
     int concatenate_value2 = 0;
     unsigned char chk = 1;
@@ -134,7 +134,7 @@
 
     freqset();               // setting the frequency
     setupfunc();              
-    ecgsetupfunc();
+    lead_reg=ecgsetupfunc();    // lead contact // 14/06
         
     maxim_max30102_reset();  // PPG reset
     wait_ms(20);
@@ -155,6 +155,28 @@
         maxim_max30102_read_fifo(&ppgdata); 
             
     }   
+// BP Finger detect Function Added Nidhin 16/6/17 
+// START    
+ uint32_t un_max, un_min; // Declare two VARIABLE FOR MAX AND MIN
+ un_max = 0;
+un_min = 0x3FFF;
+       
+for(int i=0; i<500; i++)    // READS 500 SAMPLES TO SEE MAX AND MIN VAL DIFFERENCE
+{        
+maxim_max30102_read_reg(0,&uch_dummy);
+while(INTR.read()==1); 
+maxim_max30102_read_fifo(&ppgdata); 
+
+if(un_min>ppgdata)
+un_min=ppgdata;    //update signal min
+if(un_max<ppgdata)
+un_max=ppgdata; 
+
+}  
+
+if (((un_max -un_min) > 300) && (lead_reg==0)) // Checking for threshold 300 Added Nidhin 16/6/17
+
+{ //Added Nidhin 16/6/17
 
     sd_open_BPfilee(pid);
     sd_open_BP_ECGfile(pid) ; //   sd_open_BP_ECGfile(123) draft file for testing
@@ -253,7 +275,17 @@
     bpfile_mainfile(pid);
     
     screen_bp1(SBP,DBP);
-    
+  
+  }  //Added Nidhin 16/6/17  
+  
+  else  //Added Nidhin 16/6/17 
+  {     //Added Nidhin 16/6/17 
+    // Add display sequence for Finger detect fail  //Added Nidhin 16/6/17 
+    maxim_max30102_reset();
+    bpr.printf("no finger detect\n");
+      screen_ecg_lead_bp_fingerdetect();
+  }  //Added Nidhin 16/6/17 
+     screen_ecg_bp() ; 
     // Only for testing
- }
- 
\ No newline at end of file
+ //} //Commented Nidhin 16/6/17 
+} 
\ No newline at end of file
--- a/display_modules.cpp	Fri Jun 09 17:12:21 2017 +0000
+++ b/display_modules.cpp	Sat Jun 17 09:36:18 2017 +0000
@@ -13,8 +13,8 @@
 //BusOut dataBus( PTC12, PTC13, PTB10, PTC9, PTD4, PTD5, PTD6, PTD7 ); // 16 pins//POC DISPALY 240*320 pixels
 //ILI9325_LCD lcd( PTC5, PTB9, PTC0, PTB0, &dataBus, NC, PTE31);
 
- PinName buspins[8]={PTC12, PTC13, PTB10, PTC9, PTD4, PTD5, PTD6, PTD7 };
- ILI932x TFT(BUS_8, buspins, PTC5, PTB9, PTC0, PTB0,PTE31,"SPFD5408_2.4") ;
+PinName buspins[8]={PTC12, PTC13, PTB10, PTC9, PTD4, PTD5, PTD6, PTD7 };
+ILI932x TFT(BUS_8, buspins, PTC5, PTB9, PTC0, PTB0,PTE31,"SPFD5408_2.4") ;
 DigitalOut backlight(PTC9) ;
 
  void init_screen()     // initializing the screen
@@ -36,29 +36,29 @@
     backlight = 0 ;
     TFT.BusEnable(true) ;
     TFT.background(White) ;
-       TFT.cls() ;
-      wait(0.1) ;
+    TFT.cls() ;
+    wait(0.1) ;
     TFT.set_font((unsigned char*) Arial12x12);
     TFT.foreground(Red);
     TFT.locate(20,100) ;
-     TFT.printf(buff1);
-      TFT.set_font((unsigned char*) Arial24x23);  
-       TFT.foreground(Black);
-     TFT.locate(35,20) ;
+    TFT.printf(buff1);
+    TFT.set_font((unsigned char*) Arial24x23);  
+    TFT.foreground(Black);
+    TFT.locate(35,20) ;
     TFT.printf("SENSESEMI") ;
     TFT.locate(45,60) ;
-    TFT.printf("SenseSmart") ;
-      TFT.background(Olive) ;
-     TFT.fillrect( 60,130,180,200,Olive);
-       TFT.locate(100,140) ;
+    TFT.printf("Sense POC") ;
+    TFT.background(Olive) ;
+    TFT.fillrect( 60,130,180,200,Olive);
+    TFT.locate(100,140) ;
     TFT.printf("SYS") ;    
-       TFT.locate(65,170) ;
+    TFT.locate(65,170) ;
     TFT.printf("CONFIG") ;    
-        TFT.fillrect( 60,230,180,300,Olive);
-       TFT.locate(90,250) ;        
-       TFT.printf("TEST") ;          
+    TFT.fillrect( 60,230,180,300,Olive);
+    TFT.locate(90,250) ;        
+    TFT.printf("TEST") ;          
     TFT.BusEnable(false) ;
-     backlight = 1 ;
+    backlight = 1 ;
      
   }
      
@@ -66,86 +66,84 @@
     
     void screen_main_2(int pid)     // test main screen
  {
-    char buff2[10];   
-       backlight = 0 ;
+    char buff2[10];     
+    backlight = 0 ;
     TFT.BusEnable(true) ;
-  TFT.background(White) ;
-  sprintf(buff2 ,"%d", pid);
-  TFT.fillrect(5,20,250,150,White ); 
-     TFT.fillrect(60,130,180,200,White );  
-      TFT.fillrect(60,230,180,300,White ); 
+    TFT.background(White) ;
+    sprintf(buff2 ,"%d", pid);
+    TFT.fillrect(5,20,250,150,White ); 
+    TFT.fillrect(60,130,180,200,White );  
+    TFT.fillrect(60,230,180,320,White );      // changed from 300 to 320
     TFT.set_font((unsigned char*) Arial24x23);
-     TFT.foreground(Black);
-     TFT.locate(10,50) ;
+    TFT.foreground(Black);
+    TFT.locate(10,50) ;
     TFT.printf("PATIENTID") ;
-     TFT.locate(180,50) ;
+    TFT.locate(180,50) ;
     TFT.printf(buff2) ;
-      TFT.background(Orange) ;
-     TFT.foreground(Black);
-      TFT.fillrect( 10,130,100,200,Orange);
-       TFT.locate(40,160) ;
-    TFT.printf("BG") ;   
-       TFT.fillrect( 130,130,220,200,Orange);
-       TFT.locate(145,160) ;
+    TFT.background(Orange) ;
+    TFT.foreground(Black);
+    TFT.fillrect( 10,130,100,200,Orange);
+    TFT.locate(40,160) ;
+    TFT.printf("BG") ;      
+    TFT.fillrect( 130,130,220,200,Orange);
+    TFT.locate(145,160) ;
     TFT.printf("ECG") ;    
-        TFT.fillrect( 10,215,100,285,Orange);
-       TFT.locate(40,245) ;        
-       TFT.printf("BP") ;    
-        TFT.fillrect(130,215,220,285,Orange);
-       TFT.locate(130,245) ;        
-        TFT.printf("HOME") ;    
-             
+    TFT.fillrect( 10,215,100,285,Orange);
+    TFT.locate(40,245) ;        
+    TFT.printf("BP") ;    
+    TFT.fillrect(130,215,220,285,Orange);
+    TFT.locate(130,245) ;        
+    TFT.printf("HOME") ;    
     TFT.BusEnable(false) ;
-     backlight = 1 ;
+    backlight = 1 ;
 }         
                 
                 
                 
     void screen_main_1() // System Configuration main screen
  {
-     backlight = 0 ;
+    backlight = 0 ;
     TFT.BusEnable(true) ;
     TFT.background(GreenYellow) ;
-      TFT.fillrect(5,127,230,320,White );  
+    TFT.fillrect(5,127,230,320,White );  
     // wait(0.1) ;
     TFT.set_font((unsigned char*) Arial24x23);
-   TFT.foreground(Black);
-      TFT.fillrect( 10,130,100,200,GreenYellow);
-       TFT.locate(40,160) ;
+    TFT.foreground(Black);
+    TFT.fillrect( 10,130,100,200,GreenYellow);
+    TFT.locate(40,160) ;
     TFT.printf("BLE") ;   
-       TFT.fillrect( 130,130,220,200,GreenYellow);
-       TFT.locate(135,160) ;
+    TFT.fillrect( 130,130,220,200,GreenYellow);
+    TFT.locate(135,160) ;
     TFT.printf("ERASE") ;    
-        TFT.fillrect( 10,215,100,285,GreenYellow);
-       TFT.locate(30,245) ;        
-       TFT.printf("FILE") ;    
-        TFT.fillrect(130,215,220,285,GreenYellow);
-       TFT.locate(130,245) ;        
-       TFT.printf("HOME") ;    
-             
+    TFT.fillrect( 10,215,100,285,GreenYellow);
+    TFT.locate(30,245) ;        
+    TFT.printf("FILE") ;    
+    TFT.fillrect(130,215,220,285,GreenYellow);
+    TFT.locate(130,245) ;        
+    TFT.printf("HOME") ;    
     TFT.BusEnable(false) ;
-     backlight = 1 ;
+    backlight = 1 ;
  }                  
        
                 
   void screen_ecg()    //ECG screen 1
    {
-       backlight = 0 ;
+    backlight = 0 ;
     TFT.BusEnable(true) ;
-      TFT.fillrect(10,130,100,200,White);
-     TFT.fillrect(130,130,220,200,White);
-      TFT.fillrect(130,215,220,285,White);
-       TFT.fillrect(10,215,100,285,White);
-       TFT.fillrect(60,130,180,200,White);
-     TFT.background(Green) ;   
+    TFT.fillrect(10,130,100,200,White);
+    TFT.fillrect(130,130,220,200,White);
+    TFT.fillrect(130,215,220,285,White);
+    TFT.fillrect(10,215,100,285,White);
+    TFT.fillrect(60,130,180,200,White);
+    TFT.background(Green) ;   
     TFT.fillrect( 60,130,180,200,Green);
-       TFT.locate(80,150) ;
+    TFT.locate(80,150) ;
     TFT.printf("START") ;    
-         TFT.fillrect( 60,230,180,300,Green);
-       TFT.locate(85,250) ;        
-       TFT.printf("RET") ;          
+    TFT.fillrect( 60,230,180,300,Green);
+    TFT.locate(85,250) ;        
+    TFT.printf("MAIN") ;          
     TFT.BusEnable(false) ;
-     backlight = 1 ;  
+    backlight = 1 ;  
               
               
               
@@ -156,27 +154,75 @@
                 
  void screen_ecg_2(float heart_rate)   // ECG screen 2
    {
-              char buf[5];
-              backlight = 0 ;
-            TFT.BusEnable(true) ;
-            TFT.background(White) ;
-            TFT.foreground(Green) ;
-          sprintf (buf, "%.0f bpm",heart_rate);
-          TFT.fillrect(5,90,230,150,White);  
-          TFT.locate(3,100) ;  
-            TFT.printf("  Tst is Done  ") ;   
-            TFT.locate(3,150) ;  
-            TFT.printf("   HeartRate   ") ;        
-            TFT.locate(30,180);  
-            TFT.printf(buf) ;    
-            TFT.background(Green) ;
-            TFT.fillrect(10,215,230,290,White);  
-            TFT.fillrect(60,230,180,300,Green); 
-            TFT.locate(100,250) ;  
-            TFT.foreground(Black) ;
-            TFT.printf("RET") ;   
-            TFT.BusEnable(false) ;
-            backlight = 1 ;
+    char buf[5];
+    backlight = 0 ;
+    TFT.BusEnable(true) ;
+    TFT.background(White) ;
+    TFT.foreground(Green) ;
+    sprintf (buf, "%.0f bpm",heart_rate);
+    TFT.fillrect(5,90,230,150,White);  
+    TFT.locate(3,100) ;  
+    TFT.printf(" ECG Tst Done  ") ;   
+    TFT.locate(3,150) ;  
+    TFT.printf("   HeartRate   ") ;        
+    TFT.locate(50,180);                            // changed from 30 
+    TFT.printf(buf) ; 
+    TFT.BusEnable(false) ;
+    backlight = 1 ;
+    }
+    
+    void screen_ecg_lead()   // ECG screen for displaying no lead proper lead contact
+   {
+     backlight = 0 ;
+    TFT.BusEnable(true) ;
+    TFT.background(White) ;
+    TFT.foreground(Red) ;
+    TFT.fillrect(5,90,230,150,White);  
+    TFT.locate(50,100) ;  
+    TFT.printf("Re-check") ;   
+    TFT.locate(3,130) ;  
+    TFT.printf("Lead Connection") ; 
+    TFT.BusEnable(false) ;
+    backlight = 1 ;
+}
+ 
+ 
+   void screen_ecg_lead_bp_fingerdetect()   // ECG screen for displaying no lead proper lead contact
+   {
+     backlight = 0 ;
+    TFT.BusEnable(true) ;
+    TFT.background(White) ;
+    TFT.foreground(Red) ;
+    TFT.fillrect(5,90,230,150,White);  
+    TFT.locate(20,100) ;  
+    TFT.printf("Re-check Leads") ;   
+    TFT.locate(50,130) ;  
+    TFT.printf("& finger ") ; 
+    TFT.locate(45,160) ;  
+    TFT.printf("placement") ; 
+    TFT.BusEnable(false) ;
+    backlight = 1 ;
+}
+ 
+  void screen_ecg_bp()            // added screen dispaly text //14/06
+  {    backlight = 0 ;
+    TFT.BusEnable(true) ;
+    TFT.background(Green) ;
+    TFT.fillrect(10,215,230,290,White);  
+    //TFT.fillrect(60,230,180,300,Green); 
+    //TFT.locate(100,250) ;  
+    TFT.foreground(Black) ;
+    // TFT.printf("RET") ; 
+    TFT.fillrect( 10,215,100,285,Green);
+    TFT.locate(30,245) ;        
+    TFT.printf("MAIN") ;    
+    TFT.fillrect(130,215,220,285,Green);
+    TFT.locate(155,235) ;           // changed // points // 13/06
+    TFT.printf("RE-") ;  
+    TFT.locate(145,255) ; 
+    TFT.printf("TEST") ; 
+    TFT.BusEnable(false) ;
+    backlight = 1 ;
         
     }                
        
@@ -197,9 +243,9 @@
     TFT.printf("START") ;    
     TFT.fillrect( 60,230,180,300,Green);
     TFT.locate(100,250) ;        
-    TFT.printf("RET") ;          
+    TFT.printf("MAIN") ;          
     TFT.BusEnable(false) ;
-     backlight = 1 ;     
+    backlight = 1 ;     
  
     }
     
@@ -208,24 +254,34 @@
  {
     backlight = 0 ;
     TFT.BusEnable(true) ;
-       TFT.background(White) ;
-        TFT.foreground(Green) ;
-        char buf[10];  
-        TFT.fillrect(3,130,200,200,White);
-         TFT.fillrect(60,230,180,300,White);
-        sprintf (buf, "SBP: %.0f   ",SBP);          // changed to display 2 digits after decimal point, 2May'17 Changed to Integer
-        TFT.locate(5,100) ;
+    TFT.background(White) ;
+    TFT.foreground(Green) ;
+    char buf[10];  
+    TFT.fillrect(3,130,200,200,White);
+    TFT.fillrect(60,230,180,300,White);
+    TFT.locate(3,100) ;  
+    TFT.printf(" BP Tst Done  ") ; 
+    sprintf (buf, "SBP: %.0f   ",SBP);          // changed to display 2 digits after decimal point, 2May'17 Changed to Integer
+    TFT.locate(5,140) ;                         // changed 100 to 150
     TFT.printf(buf) ; 
-         sprintf (buf, "DBP: %.0f",DBP);           // changed to display 2 digits after decimal point, 2May'17, Changed to integer
-          TFT.locate(5,150) ;
-        TFT.printf(buf) ;
-        TFT.fillrect(60,230,180,300,Green);
-         TFT.locate(85,250) ;  
-            TFT.foreground(Black) ;
-             TFT.background(Green) ;
-         TFT.printf("RET") ;    
-          TFT.BusEnable(false) ;
-     backlight = 1 ; 
+    sprintf (buf, "DBP: %.0f",DBP);           // changed to display 2 digits after decimal point, 2May'17, Changed to integer
+    TFT.locate(5,170) ;                       // CHANGED from 150 to 170
+    TFT.printf(buf) ;
+    //TFT.fillrect(60,230,180,300,Green);
+    //TFT.locate(85,250) ;  
+ /*   TFT.foreground(Black) ;    // commented //16/06
+    TFT.background(Green) ;
+    //TFT.printf("RET") ;
+    TFT.fillrect( 10,215,100,285,Green);
+    TFT.locate(30,245) ;        
+    TFT.printf("RET") ;    
+    TFT.fillrect(130,215,220,285,Green);
+    TFT.locate(155,235) ;           // changed // points // 13/06
+    TFT.printf("RE-") ;  
+    TFT.locate(145,255) ; 
+      TFT.printf("TEST") ;  */
+    TFT.BusEnable(false) ;
+    backlight = 1 ; 
 }   
     
     
@@ -235,22 +291,34 @@
  void screen_glc()     // glc main screen
  {
         
-         backlight = 0 ;
+    backlight = 0 ;
     TFT.BusEnable(true) ;
-      TFT.background(Green) ;
-        TFT.foreground(Black) ;
-     TFT.fillrect(10,130,100,200,White);
-       TFT.fillrect(130,130,220,200,White);
-         TFT.fillrect(10,215,100,285,White);
-           TFT.fillrect(130,215,220,285,White);
-        TFT.fillrect( 60,130,180,200,Green);
-       TFT.locate(80,150) ;
-    TFT.printf("START") ;    
-         TFT.fillrect( 60,230,180,300,Green);
-       TFT.locate(100,250) ;        
-       TFT.printf("RET") ;          
+    TFT.background(Green) ;
+    TFT.foreground(Black) ;
+    TFT.fillrect(10,130,100,200,White);
+    TFT.fillrect(130,130,220,200,White);
+    TFT.fillrect(10,215,100,285,White);
+    TFT.fillrect(130,215,220,285,White);
+   // TFT.fillrect( 60,130,180,200,Green);
+   // TFT.locate(80,150) ;
+   // TFT.printf("START") ;   
+    TFT.fillrect( 10,130,100,200,Green);
+    TFT.locate(30,160) ;                           // changed to 30 from 40
+    TFT.printf("FBS") ;      
+    TFT.fillrect( 130,130,220,200,Green);
+    TFT.locate(155,160) ;
+    TFT.printf("PP") ;     
+    TFT.fillrect( 10,215,100,285,Green);
+    TFT.locate(20,245) ;        
+    TFT.printf("RAN") ;   
+    TFT.fillrect(130,215,220,285,Green); 
+    TFT.locate(155,245);       
+    TFT.printf("MAIN") ;
+  //  TFT.fillrect( 60,230,180,300,Green);
+  //  TFT.locate(100,250) ;        
+  //  TFT.printf("RET") ;          
     TFT.BusEnable(false) ;
-     backlight = 1 ; 
+    backlight = 1 ; 
         
     }               
 
@@ -267,23 +335,23 @@
      
  void ecg_countdown()   // ECG measurement countdown 
  {    
-        backlight = 0 ;
+    backlight = 0 ;
     TFT.BusEnable(true) ;
-       TFT.background(White) ;
-        TFT.foreground(Green) ;
-        char tim1[5];
-           TFT.fillrect(3,130,200,200,White);
-           TFT.fillrect(60,230,180,300,White);
-           TFT.fillrect(5,215,230,290,White);
-         TFT.locate(25,100) ;        
-       TFT.printf("ECG starts in") ; 
-         for(int i=5;i>=0;i--)
-            {
+    TFT.background(White) ;
+    TFT.foreground(Green) ;
+    char tim1[5];
+    TFT.fillrect(3,130,200,200,White);
+    TFT.fillrect(60,230,180,300,White);
+    TFT.fillrect(5,215,230,290,White);
+    TFT.locate(25,100) ;        
+    TFT.printf("ECG starts in") ; 
+    for(int i=5;i>=0;i--)
+         {
                 wait(1);
                 sprintf (tim1, "%d",i);
                 TFT.locate(120,120) ;        
-                 TFT.printf(tim1) ; 
-            }
+                TFT.printf(tim1) ; 
+         }
      TFT.BusEnable(false) ;
      backlight = 1 ; 
         
@@ -292,22 +360,22 @@
   
    void bp_countdown()   // ECG measurement countdown 
  {    
-     backlight = 0 ;
+    backlight = 0 ;
     TFT.BusEnable(true) ;
-       TFT.background(White) ;
-        TFT.foreground(Green) ;
-        char tim1[5];
-           TFT.fillrect(3,130,200,200,White);
-           TFT.fillrect(60,230,180,300,White);
-           TFT.fillrect(5,215,230,290,White);
-         TFT.locate(25,100) ;        
-       TFT.printf("BP starts in") ; 
-         for(int i=5;i>=0;i--)
+    TFT.background(White) ;
+    TFT.foreground(Green) ;
+    char tim1[5];
+    TFT.fillrect(3,130,200,200,White);
+    TFT.fillrect(60,230,180,300,White);
+    TFT.fillrect(1,80,240,290,White);           //changed the points// 13/06
+    TFT.locate(25,100) ;        
+    TFT.printf("BP starts in") ; 
+    for(int i=5;i>=0;i--)
             {
                 wait(1);
                 sprintf (tim1, "%d",i);
                 TFT.locate(120,120) ;        
-       TFT.printf(tim1) ; 
+                TFT.printf(tim1) ; 
             }
      TFT.BusEnable(false) ;
      backlight = 1 ; 
@@ -315,21 +383,21 @@
   
  void screen_again()    // screen to press 'yes' or 'no' to repeat the test 
  { 
-   backlight = 0 ;
-   TFT.BusEnable(true) ;
-   TFT.background(White) ;
-        TFT.foreground(Black) ;
-            TFT.fillrect(5,127,230,200,White);
-            TFT.locate(50,130) ; 
-            TFT.printf("Take test") ;
-             TFT.locate(75,160) ; 
-            TFT.printf("again?") ;
-             TFT.background(Orange) ;
-            TFT.locate(30,245) ;  
-               TFT.printf("YES") ;
-                 TFT.locate(135,245) ;  
-               TFT.printf(" NO ") ;
-     backlight = 1 ; 
+    backlight = 0 ;
+    TFT.BusEnable(true) ;
+    TFT.background(White) ;
+    TFT.foreground(Black) ;
+    TFT.fillrect(5,127,230,200,White);
+    TFT.locate(50,130) ; 
+    TFT.printf("Take test") ;
+    TFT.locate(75,160) ; 
+    TFT.printf("again?") ;
+    TFT.background(Orange) ;
+    TFT.locate(30,245) ;  
+    TFT.printf("YES") ;
+    TFT.locate(135,245) ;  
+    TFT.printf(" NO ") ;
+    backlight = 1 ; 
     TFT.BusEnable(false) ;
    
   }
@@ -338,17 +406,25 @@
   void screen_glc_2()   // GLC screen 3 after test 
    {
        
-     backlight = 0 ;
+    backlight = 0 ;
     TFT.BusEnable(true) ;
-       TFT.background(White) ;
-        TFT.foreground(Black) ;
-            TFT.fillrect(5,127,230,320,White);
-          TFT.fillrect(60,230,180,300,Green);
-         TFT.locate(85,250) ;  
-          TFT.background(Green); 
-        TFT.printf("RET") ;    
-          backlight = 1 ; 
-          TFT.BusEnable(false) ;
+    TFT.background(White) ;
+    TFT.foreground(Black) ;
+    TFT.fillrect(5,127,230,320,White);
+    //TFT.fillrect(60,230,180,300,Green);
+    //TFT.locate(85,250) ;  
+    TFT.background(Green); 
+    //TFT.printf("RET") ;  
+    TFT.fillrect( 10,215,100,285,Green);
+    TFT.locate(30,245) ;        
+    TFT.printf("MAIN") ;    
+    TFT.fillrect(130,215,220,285,Green);
+    TFT.locate(155,235) ;           // changed // points // 13/06
+    TFT.printf("RE-") ;  
+    TFT.locate(140,255) ;           // changed from 145 to 140
+    TFT.printf("TEST") ; 
+    backlight = 1 ; 
+    TFT.BusEnable(false) ;
    
           
           
@@ -357,19 +433,20 @@
   
   void glc_1()     // GLC screen 
   { 
-        backlight = 0 ;
-       TFT.BusEnable(true) ;
-       TFT.background(White) ;
-        TFT.foreground(Magenta ) ;
-        TFT.fillrect(3,130,200,200,White);
-        TFT.fillrect(60,230,180,300,White);
-         TFT.fillrect(5,215,230,290,White);
-         TFT.locate(5,130) ;  
-        TFT.printf("Blood Glucose") ; 
-        TFT.locate(5,160) ;  
-        TFT.printf("Insert strip") ; 
-      TFT.BusEnable(false) ;
-     backlight = 1 ; 
+    backlight = 0 ;
+    TFT.BusEnable(true) ;
+    TFT.background(White) ;
+    TFT.foreground(Magenta ) ;
+    TFT.fillrect(3,130,200,200,White);
+    TFT.fillrect(60,230,180,300,White);
+    TFT.fillrect(5,215,230,290,White);
+    TFT.fillrect( 130,130,220,200,White);
+    TFT.locate(5,130) ;  
+    TFT.printf("Blood Glucose") ; 
+    TFT.locate(5,160) ;  
+    TFT.printf("Insert strip") ; 
+    TFT.BusEnable(false) ;
+    backlight = 1 ; 
   
   
   
@@ -377,39 +454,45 @@
   
    void glc_2()     // GLC screen 
   {
-      backlight = 0 ;
-       TFT.BusEnable(true) ;
-        TFT.locate(5,160) ;  
-        TFT.printf("Strip Detected") ; 
-        TFT.locate(5,190) ;  
-        TFT.printf("Insert Blood") ; 
-      TFT.BusEnable(false) ;
-     backlight = 1 ; 
+    backlight = 0 ;
+    TFT.BusEnable(true) ;
+    TFT.locate(5,160) ;  
+    TFT.printf("Strip Detected") ; 
+    TFT.locate(5,190) ;  
+    TFT.printf("Insert Blood") ; 
+    TFT.BusEnable(false) ;
+    backlight = 1 ; 
    }
    
  
   void glc_3()     // GLC screen 
   {
-      backlight = 0 ;
-       TFT.BusEnable(true) ;    
-        TFT.locate(5,190) ;  
-        TFT.printf("Blood Detected") ; 
-        TFT.locate( 5,220) ;  
-        TFT.printf("computing") ; 
-      TFT.BusEnable(false) ;
-     backlight = 1 ; 
+    backlight = 0 ;
+    TFT.BusEnable(true) ;    
+    TFT.locate(5,190) ;  
+    TFT.printf("Blood Detected") ; 
+    TFT.locate( 5,220) ;  
+    TFT.printf("computing") ; 
+    TFT.BusEnable(false) ;
+    backlight = 1 ; 
      }
    
   
   void glc_4(uint16_t mgdl)   // GLC screen to display blood glucose level on the LCD
    { 
-      char buf[10];
-     sprintf (buf, " BG %d mg/dl",mgdl);
-       backlight = 0 ;
-       TFT.BusEnable(true) ;
-        TFT.fillrect(5,127,230,320,White);
-      TFT.locate(5,100) ;  
+    char buf[10];
+    sprintf (buf, " BG %d mg/dl",mgdl);
+    backlight = 0 ;
+    TFT.BusEnable(true) ;
+    TFT.fillrect(5,127,230,320,White);
+    TFT.locate(3,100) ;  
+    TFT.printf(" BG Tst Done  ") ;
+    TFT.locate(5,130) ;  
     TFT.printf(buf) ; 
-      TFT.BusEnable(false) ;
-     backlight = 1 ; 
-   }
\ No newline at end of file
+    TFT.locate(5,160) ;  
+    TFT.printf("(Range 70-120 mg/dl)") ;   // added 16/06
+    TFT.BusEnable(false) ;
+    backlight = 1 ; 
+   }
+   
+   
\ No newline at end of file
--- a/display_modules.h	Fri Jun 09 17:12:21 2017 +0000
+++ b/display_modules.h	Sat Jun 17 09:36:18 2017 +0000
@@ -11,6 +11,9 @@
 void screen_glc();
 void init_screen();
 void screen_ecg_2(float heart_rate);
+//void screen_ecg_3();
+ void screen_ecg_bp(); //changed the name 
+void screen_ecg_lead();
 void ecg_countdown();
 void bp_countdown();
 void glc_1();
@@ -20,6 +23,6 @@
 void screen_again();
 void screen_glc_2();
 void screen_bp1(float SBP, float DBP) ;
-
+ void screen_ecg_lead_bp_fingerdetect();
 
 #endif 
--- a/ec_bp.cpp	Fri Jun 09 17:12:21 2017 +0000
+++ b/ec_bp.cpp	Sat Jun 17 09:36:18 2017 +0000
@@ -19,7 +19,7 @@
  unsigned int value4;
  unsigned int value5;
  unsigned int value6;
- unsigned int data1;
+ uint8_t data1;
  unsigned int count;
 
 //unsigned char chk2= 0;
@@ -173,6 +173,7 @@
 wait(0.5);
 regRead(REG_LOFF_STAT);//Read LOFF_STAT register
 printf("REG_LOFF_STAT register read from ADS for ecg setup is= 0x%X\n",data1); 
+
 }
 
 void doHelp(void) 
@@ -312,12 +313,13 @@
     ADS_START = 1;
   } 
   
-   void ecgsetupfunc()
+uint8_t ecgsetupfunc()
 { 
+  // uint8_t lead=0;
    ecgsetup();   // To set the ADS1291 registers for ECG signal generation
    cmdWrite(CMD_RDATAC) ;
    ADS_START = 1; 
-  
+   return data1;            // returns lead off reg value // 14/06
   }
   
     void ecgtestsetupfunc()
--- a/ec_bp.h	Fri Jun 09 17:12:21 2017 +0000
+++ b/ec_bp.h	Sat Jun 17 09:36:18 2017 +0000
@@ -14,7 +14,7 @@
 void doLoop(void) ;
 void setup(void);
 void testsetup(void);
-void ecgsetup(void);
+void ecgsetup();
 void regWrite(int,int);
 void cmdWrite(int);
 void regRead(int);
@@ -92,7 +92,7 @@
 //PPG DECLARATION
 #define MAX_BRIGHTNESS 255 // BP ADD
  void setupfunc();
- void ecgsetupfunc();
+uint8_t ecgsetupfunc();
  int readvalue();
 #endif
 
--- a/ecgg.cpp	Fri Jun 09 17:12:21 2017 +0000
+++ b/ecgg.cpp	Sat Jun 17 09:36:18 2017 +0000
@@ -21,6 +21,8 @@
 
 float ecg(int pid) 
  {
+    
+    uint8_t lead_reg=0;      // added on 14/06 to check lead -off 
     //----------------------- Structure for Bluetooth  Added Nidhin 1/6/2017-------------------//
     
     //BLUETOOTH STRUCTURE
@@ -119,9 +121,10 @@
     pc.baud(baud_rate);
     freqset();               // setting the frequency
     setupfunc();              
-    ecgsetupfunc();
+    lead_reg=ecgsetupfunc();                 // added a return function to read leadoff // 14/06
  //   chk = 1;
- 
+ if (lead_reg==0)                    // checking for proper lead contact// 14/06
+ {
    //ORIGINAL sd_open_ECGfile(pid);        // opening the ecg file  COMMENTED Nidhin 1/6/2017
    sd_open_ECGfilee(pid);  // REPLACED Nidhin 1/6/2017 Nidhin 
    
@@ -134,7 +137,7 @@
      sd_ecgwrite(ecg_ptr); // REPLACED Nidhin 1/6/2017
      
      ecg_buf[i] = concatenate_value2;
-     pc.printf( "%d\n", concatenate_value2); //COMMENTED Nidhin 1/6/2017
+  ////   pc.printf( "%d\n", concatenate_value2); //COMMENTED Nidhin 1/6/2017
    } 
   
    //sd_close();          // closing the file COMMENTED Nidhin 1/6/2017
@@ -176,9 +179,9 @@
    //  if(a_dif <= 0) ------------------------ add this condition if needed ----------------------
    //  {
      pk_val[j] = hi_val; //if condition satisfied, put the "pk" value into "pk_val" buffer
-     pc.printf("peak value= %d\n",pk_val[j]);
+   ////  pc.printf("peak value= %d\n",pk_val[j]);
      pk_pos[j]=a; // also save the peak's position
-     pc.printf("peak position is = %d\n",pk_pos[j]);
+   ////  pc.printf("peak position is = %d\n",pk_pos[j]);
      i = a+120;  // once confirmed that this is the necessary peak, skip the next 120 input values
      n = j; // where n is the number of peaks detected
      j = j+1;
@@ -236,6 +239,13 @@
  
   return HR1;
   // return HR_avg; 
+  }
+  
+ else 
+     {
+        pc.printf("no - leadoff");
+        return 0;
+    } 
   
 }          // End of main function
 
--- a/glc.cpp	Fri Jun 09 17:12:21 2017 +0000
+++ b/glc.cpp	Sat Jun 17 09:36:18 2017 +0000
@@ -180,6 +180,7 @@
 //#include "touch_modules.h"
 #include "rtc.h"
 #include "sdcard.h"
+#include "eeprom_pgm.h"   // Nidhin 12/6/17
 
 #include "struct.h" //Nidhin 31/5/2017
 //#include "test_type.h" //Nidhin 31/5/2017
@@ -217,6 +218,7 @@
 
 uint32_t glcraw[2]; // Nidhin 31/5/2017
 uint8_t chk_glc_data = 0;
+uint16_t glc_testtype; // Nidhin 12/6/2017
 
 Serial ble(PTC4,PTC3);
 
@@ -429,8 +431,9 @@
         
        sd_glcwrite(glcraw, pid);  //Writes the raw data into GLC file 
  
-        //Results Stored to Bluetooth structure 
-        BLEMsg_info_glc.cal_data.cal_sbp_dummy = 0;
+        //Results Stored to Bluetooth structure
+        glc_testtype = eprom_read(2);  // Reads the test type (before meal = 0 / after meal = 1 OR Random = 2 from location 2 of the EEPROM) Nidhin 12/6/17
+        BLEMsg_info_glc.cal_data.cal_sbp_dummy = (uint16_t) glc_testtype;  // Data stored into structure
         BLEMsg_info_glc.cal_data.cal_dbp_OTtyp = (uint16_t) mgdll;  //To be checked for reliable results           
             
         structure_file(ptr_BLEMsg_info_glc, pid);           // Copy the structure into the GLC file 
--- a/main.cpp	Fri Jun 09 17:12:21 2017 +0000
+++ b/main.cpp	Sat Jun 17 09:36:18 2017 +0000
@@ -57,7 +57,7 @@
          case 1:  state_display=touch(state_touch);           // touch state
                 
                   
-                if(state_display==10)
+                if(state_display==12)
                     main_state=3;
                     
                 else 
@@ -119,7 +119,7 @@
                 
       case 3:  
                state1=touch_main_2();     //// determining the touch for TEST screen 
-                                    
+                                 
                 state=0;
                 nstate1=state1;
                 break;
@@ -137,6 +137,10 @@
                  break;   
      case 6: 
                 state1=touch_ret();     // determining the touch for returning back to the main screen 
+               /* if (ecg_flag==1)
+                     state1=8;
+                else if (glc_flag==1)
+                    state1=7; */     
                 state=0;
                 nstate1=state1;
                 break;
@@ -299,7 +303,8 @@
                 wait(5); 
                 state1=0;
                 screen_glc_2();
-                 state=6;;
+                 state=6;
+                 eprom_write(3,0);
               //  gc.printf("%d", state);
               nstate=state;         //////////////
                EnableTouch();
@@ -309,11 +314,22 @@
                 ecg_countdown();    // countdown before ecg capture
                 heart_rate=ecg(pid);           // capturing ecg
                 state1=0;
-                screen_ecg_2(heart_rate);
+                if (heart_rate==0)
+                    {
+                       gc.printf("hi");
+                       screen_ecg_lead();  
+                     }
+                     
+                     else 
+                     {
+                        gc.printf("hif");
+                         screen_ecg_2(heart_rate);
+                         ecg_flag=1;
+                         }   
                 state=6;
-                 nstate=state;
-                 ecg_flag=1;
-        //    ble.printf("ecg");
+                eprom_write(3,1);
+                nstate=state;
+                screen_ecg_bp();
                 EnableTouch();
                 break;
      
@@ -335,6 +351,7 @@
                 state1=0;
                // wait(1);
                 state=6;
+                eprom_write(3,2);
                 nstate=state;
                 EnableTouch();
                  break;
--- a/sdcard.cpp	Fri Jun 09 17:12:21 2017 +0000
+++ b/sdcard.cpp	Sat Jun 17 09:36:18 2017 +0000
@@ -44,7 +44,7 @@
   
   
   
- void sd_open_GLCfile(int pid)     // opening the glc file
+ /*void sd_open_GLCfile(int pid)     // opening the glc file
  {
      
   char buffer[32];
@@ -58,7 +58,7 @@
   fprintf(fp,"%s\n",ctime(&epoch_time1) );  //writing the date, time into the file
   
  
- }   
+ }   */
  
   void sd_open_GLCfilee(int pid)    // only opening the glc file after entering TEST screen
  {
@@ -70,7 +70,7 @@
  
  
  
-  void sd_open_ECGfile(int pid)         
+  /*void sd_open_ECGfile(int pid)         
  {
      
  // char buffer[32];
@@ -84,7 +84,7 @@
   fprintf(fp,"%s\n",ctime(&epoch_time1) );
  
  } 
- 
+ */
   void sd_open_ECGfilee(int pid)          // only opening the ECG file after entering TEST screen
  {
      
@@ -96,7 +96,7 @@
  } 
  
  
-  void sd_open_BPfile(int pid)         
+  /*void sd_open_BPfile(int pid)         
  {
      
   char buffer[32];
@@ -108,7 +108,7 @@
   sprintf(buffer1,"/sd/%d_BP.csv",pid);
   fp = fopen(buffer1,"a"); 
   fprintf(fp,"%s\n",ctime(&epoch_time1) );
- } 
+ } */
 
 void sd_open_BPfilee(int pid)          // only opening the BP file after entering TEST screen
  {
--- a/sdcard.h	Fri Jun 09 17:12:21 2017 +0000
+++ b/sdcard.h	Sat Jun 17 09:36:18 2017 +0000
@@ -6,12 +6,12 @@
 
 #include "struct.h"
 
-void sd_open_ECGfile(int pid);
+//void sd_open_ECGfile(int pid);
 void sd_open_ECGfilee(int pid);
-void sd_open_GLCfile(int pid);
+//void sd_open_GLCfile(int pid);
 void sd_open_GLCfilee(int pid);
 void sd_open_BPfilee(int pid);
-void sd_open_BPfile(int pid);
+//void sd_open_BPfile(int pid);
 void sd_write (int value);
 int file_size() ;
 int file_size1() ;
--- a/touch_modules.cpp	Fri Jun 09 17:12:21 2017 +0000
+++ b/touch_modules.cpp	Sat Jun 17 09:36:18 2017 +0000
@@ -1,4 +1,5 @@
 #include "mbed.h"
+#include "eeprom_pgm.h"
 //#include "ili9325.h"
 //#include "lcd_base.h"
 #include "display_modules.h"
@@ -75,7 +76,7 @@
                   if ( ((xt >=35) && (xt<=100)) && ( (yt>= 135) && (yt<= 185) ) ) // ble
                        {
                           
-                         // state=3;
+                          state=12;
                         }
     
                  else if ( ((xt >=130) && (xt<=195)) && ( (yt>= 135) && (yt<= 185) ) ) // erase
@@ -165,13 +166,23 @@
 {
       
       unsigned char state;
+      int8_t type=0;
+       type=eprom_read(3);
                  
-    
-            if ( ((xt >=70) && (xt<=170)) && ( (yt>=70) && (yt<=140) ) ) // press on return box
+                  if ( ((xt >= 35) && (xt<=100)) && ( (yt>= 65) && (yt<= 118) ) ) // RET   //CHANGED 12/06/17// 
                       {
-                           state=3;
-                 } 
-              
+                                state=3;
+                         
+                       }
+                 else if ( ((xt >= 130) && (xt<=195)) && ( (yt>= 65) && (yt<= 118) ) ) // RETEST
+                       {
+                                 if (type==0)
+                                     state=7;
+                                 else if (type==1)
+                                     state=8;
+                                     else if (type==2)
+                                     state=9;
+                       }
               else 
                      state=10;                      
            return state;
@@ -206,7 +217,7 @@
     {
         unsigned char state;
 
-                if ( ((xt >=70) && (xt<=170)) && ( (yt>= 140) && (yt<= 195) ) ) // START
+               /* if ( ((xt >=70) && (xt<=170)) && ( (yt>= 140) && (yt<= 195) ) ) // START
                        {
                           
                           state=7;
@@ -215,9 +226,37 @@
                  else if ( ((xt >=70) && (xt<=170)) && ( (yt>=70) && (yt<=140) ) ) // RETURN
                       {
                            state=3;
-                 }  
-            else 
-                  state=10;
+                 } */
+                 
+                   if ( ((xt >=35) && (xt<=100)) && ( (yt>= 135) && (yt<= 185) ) ) //fasting     // 12/06/17       newly added
+                       {
+                          
+                          state=7;
+                          eprom_write(2,0);  
+                        }
+    
+                 else if ( ((xt >=130) && (xt<=195)) && ( (yt>= 135) && (yt<= 185) ) ) // pp
+                      {
+                           state=7;
+                           eprom_write(2,1);    
+                        
+                          
+                       }
+                 else if ( ((xt >= 35) && (xt<=100)) && ( (yt>= 65) && (yt<= 118) ) ) // random
+                      {
+                           state=7;
+                           eprom_write(2,2); 
+                         
+                       }
+                 else if ( ((xt >= 130) && (xt<=195)) && ( (yt>= 65) && (yt<= 118) ) ) // return
+                       {
+                           state=3;         //////////
+                 
+                       }
+                 
+                 
+              else 
+                     state=10;
            
            return state;
     }