Changes done in ECG and BT

Dependencies:   SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217

Fork of merged_code2_20sept_2017_4th_oct_2017 by nikita teggi

Files at this revision

API Documentation at this revision

Comitter:
nikitateggi
Date:
Wed Sep 20 07:48:55 2017 +0000
Parent:
50:b42238e7f46d
Child:
52:7d9ff7781bdc
Commit message:
modifications done in debug mode. Unless a message is typed it does not go into debug mode. And debug option is enabled only for 10 mins

Changed in this revision

display_modules.cpp 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
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.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/display_modules.cpp	Sat Sep 16 06:54:42 2017 +0000
+++ b/display_modules.cpp	Wed Sep 20 07:48:55 2017 +0000
@@ -108,7 +108,7 @@
                 
                 
                 
-    void screen_main_1() // System Configuration main screen
+    void screen_main_1()                                                             // System Configuration main screen
  {
     backlight = 0 ;
     TFT.BusEnable(true) ;
@@ -118,18 +118,18 @@
     TFT.set_font((unsigned char*) Arial24x23);
     TFT.foreground(Black);
     TFT.fillrect( 10,130,100,200,GreenYellow);
-    TFT.locate(38,160) ;                                //changed from 30 to 38 //rashmi 24/7/17            //changed from 40 to 30 //rashmi 22/7/17     
-    TFT.printf("BT") ;                                  ////changed from BLE to BT //rashmi 24/7/17
-    if (read_debug_status()== 1)
+    TFT.locate(38,160) ;                                                              //changed from 30 to 38 //rashmi 24/7/17            //changed from 40 to 30 //rashmi 22/7/17     
+    TFT.printf("BT") ;                                                              ////changed from BLE to BT //rashmi 24/7/17
+    if ((read_debug_status()== 1) && get_timer_debug()<TIMER_ENABLE_DEBUG_MODE)     // checking for the debug status and timer 
     {
         TFT.fillrect( 130,130,220,200,GreenYellow);
-        TFT.locate(150,140) ;                               //changed from 135 to 145 //rashmi 22/7/17 //
+        TFT.locate(150,140) ;                                                        //changed from 135 to 145 //rashmi 22/7/17 //
         TFT.printf("DE-") ; 
-        TFT.locate(145,170) ;                               //changed from 135 to 145 //rashmi 22/7/17 //
-        TFT.printf("BUG");                                 //changed from ERASE to DEL //rashmi 22/7/17
+        TFT.locate(145,170) ;                                                       //changed from 135 to 145 //rashmi 22/7/17 //
+        TFT.printf("BUG");                                                          //changed from ERASE to DEL //rashmi 22/7/17
     }    
     TFT.fillrect( 10,215,100,285,GreenYellow);
-    TFT.locate(22,245) ;                                //changed from 26 to 22 //rashmi 24/7/17            //changed from 30 to 26 //rashmi 22/7/17
+    TFT.locate(22,245) ;                                                            //changed from 26 to 22 //rashmi 24/7/17            //changed from 30 to 26 //rashmi 22/7/17
     TFT.printf("P-Inf") ;    
     TFT.fillrect(130,215,220,285,GreenYellow);
     TFT.locate(130,245) ;        
@@ -860,7 +860,7 @@
     TFT.background(White) ;  
     TFT.foreground(Red);
     TFT.locate(15,140) ;
-    TFT.printf("SD read finished"); 
+    TFT.printf("SD file read"); 
     TFT.fillrect( 60,230,180,300,Green);
     TFT.background(Green) ;
     TFT.foreground(Black) ;
--- a/ecgg.cpp	Sat Sep 16 06:54:42 2017 +0000
+++ b/ecgg.cpp	Wed Sep 20 07:48:55 2017 +0000
@@ -17,6 +17,9 @@
 #include "main.h"
 //#include "test_type.h" //Added on  31/5/17_Nidhin
 
+void low_pass_filter(uint32_t pid);
+void swap(uint32_t *ptr);
+
 #define MAX_HR_THRESHOLD 205
 #define MIN_HR_THRESHOLD 25
 
@@ -30,6 +33,8 @@
  {
     
     uint8_t lead_reg=0;      // added on 14/06 to check lead -off 
+    FILE *fpeecg1;
+    pc.baud(baud_rate);
     //----------------------- Structure for Bluetooth  Added Nidhin 1/6/2017-------------------//
     
     //BLUETOOTH STRUCTURE
@@ -113,67 +118,68 @@
     //uint32_t ecg_buf[N_ECG];
     Timer t;
     
-    //------------------ Declaration for Peak value detection ------------------------------------
-  uint32_t ecg_samp1[1] ; 
-  uint32_t ecg_samp2[1]; 
-  uint32_t ecg_samp3[1];  // to Stores sample 1, 2 & 10th sample
-  uint32_t fppos;  // Variable to hold pointer position
-  uint32_t hi_val;
-  uint32_t pk_val[20];
-  uint16_t pk_pos[20]={0};
-  int32_t hi_dif = 0; //diff between high value and it's consecutive value
-  uint16_t j=0; // int count1 = N_ECG/fs, a_dif=0, fs1 = fs ,h=0;
-  int32_t m =0;       // Variable to move the file pointer in fseek fun
-  int32_t samp_10 = 28;       // Variable to move to 10th sampple from current
-  char buffer3[32];
+    /********** Declaration for Peak value detection ***************/
+
+    int32_t ecg_samp1[1] ;                                                      //changed from uint32_t to static double, because LPF output is of static double type - by Suhasini- 5-8-17
+    int32_t ecg_samp2[1];                                                       //changed from uint32_t to static double- by Suhasini- 5-8-17
+    int32_t ecg_samp3[1];                                                       // to Stores sample 1, 2 & 10th sample //changed from uint32_t to static double- by Suhasini- 5-8-17
+
+    
+    uint32_t samp_10 = 28;
+    static int32_t hi_val;                                                      //changed from uint32_t to static double- by Suhasini- 5-8-17
+    int32_t pk_val[20];                                                         //changed from uint32_t to double - Suhasini - 5-8-17
+    int32_t hi_dif = 0;                                                         //diff between high value and it's consecutive value //changed from uint32_t to static double- by Suhasini- 5-8-17
+    uint16_t pk_pos[20]= {0};                                                   // Variable to hold pointer positio
+    uint8_t j=0;                                                                // int count1 = N_ECG/fs, a_dif=0, fs1 = fs ,h=0;
+    uint32_t m = 400; 
   
     // ------------------------- Declaration for Heart Rate calculation --------------------------
- uint8_t n=0; 
- float pos_dif, HR[10], HR1,t_pos_dif;
- uint8_t t_sec = 60; 
- float HR_sum = 0,HR_avg;
-    // -------------------------------------------------------------------------------------------
-    pc.baud(baud_rate);
-    freqset();               // setting the frequency
-    setupfunc();    
-    //ecgtestsetupfunc();          // For test set up of 1Hz square wave signal
-   lead_reg= ecgsetupfunc();
-  
-   //ORIGINAL sd_open_ECGfile(pid);        // opening the ecg file  COMMENTED Nidhin 1/6/2017
- if (lead_reg==0)                    // checking for proper lead contact// 14/06
- {  
-   sd_open_ECGfilee(pid);  // REPLACED Nidhin 1/6/2017 Nidhin 
-   
-  pc.printf( "Raw data is = \n"); 
-  
- for(int i=0; i<N_ECG; i++)
-   {
-     concatenate_value2= readvalue();
-     pc.printf( "%d\n", concatenate_value2); //ADDED Nidhin 21/6/2017
-     
-     sd_ecgwrite(ecg_ptr); // REPLACED Nidhin 1/6/2017
-     
-   } 
-  
- sd_close_ecg();          // closing the ECG file REPLACED Nidhin 1/6/2017 Nidhin
+ uint8_t n=0;
+    float pos_dif;                                                              // changed from float to uint16_t- Suhasini- 8-8-17, changed back to float- 17th aug,2017
+    float HR[10],HR1,t_pos_dif;
+    uint8_t t_sec = 60;
+    float HR_sum = 0,HR_avg;
+    char buffer4[32] = {0};
+    
+
+    freqset();                                                                  // setting the frequency
+    setupfunc();
+    lead_reg = ecgsetupfunc();
     
+
+    if (lead_reg==0)
+     {                                                                          // checking for proper lead contact
+
+        sd_open_ECGfilee(pid);                                                  //open temporary ecg.csv file to write 2000 samples of data
+        pc.printf( "Raw data is = \n");
+
+        for(int i=0; i<N_ECG; i++) {
+            concatenate_value2= readvalue();
+            pc.printf( "%d\n", concatenate_value2);                            
+            
+            sd_ecgwrite(ecg_ptr);                                               //writing data to temporary file ECG.csv
+        }
+        sd_close_ecg();                                                         // closing the ECG file REPLACED Nidhin 1/6/2017 Nidhin
+       
+        low_pass_filter(pid);                                                   // low pass filter calculation function
+        
     
  //----------------------------- PEAK DETECTION AND HEART RATE CALCULATION ---------------------------------------------------
  
  // -------------------------------------- PEAK DETECTION -------------------------------------------------------------
  // ----------------------------------------- Main loop --------------------------------------------------
  
- sprintf(buffer3, "/sd/%d_ECG.csv", pid);    // For opening a specific file    
- fpeecg1 = fopen(buffer3, "r");
+ sprintf(buffer4, "/sd/%d_ECG_lpf.csv", pid);    // For opening a specific file    
+ fpeecg1 = fopen(buffer4, "r");
  
-for(uint16_t i=0;i<(N_ECG-10);i++){
+for(uint16_t i=0;i<((N_ECG-4)-10);i++){
     count++;
 rewind(fpeecg1);               // Go to start of file each time
 fseek(fpeecg1, m, SEEK_CUR);   // Update the count value according to move pointer //// after every calc. the pointer moves to 0th position, as we have used fseek, hence to make it jump to the respective position by "m" bytes this command is used
-fread(ecg_samp1, sizeof(uint32_t), 1, fpeecg1);  // Read sample 1
-fread(ecg_samp2, sizeof(uint32_t), 1, fpeecg1);  // Read Sample 2
+fread(ecg_samp1, sizeof(int32_t), 1, fpeecg1);  // Read sample 1
+fread(ecg_samp2, sizeof(int32_t), 1, fpeecg1);  // Read Sample 2
 fseek(fpeecg1, samp_10, SEEK_CUR);   // Moving to tenth sample
-fread(ecg_samp3, sizeof(uint32_t), 1, fpeecg1);  // Read 3rd sample
+fread(ecg_samp3, sizeof(int32_t), 1, fpeecg1);  // Read 3rd sample
 
 if(ecg_samp1[0]>ecg_samp2[0])
 {
@@ -181,8 +187,8 @@
 hi_dif = hi_val-ecg_samp3[0];
 
   // ---------------------------- If hi_val is greater than next ten input values, then compare the hi_val with the tenth input value. 
-  //     If the diff is greater than 10000, then it is a valid peak (pls chk the below condition)-------------------------------------
-    if(hi_dif > 10000)
+  //     If the diff is greater than 4000, then it is a valid peak (pls chk the below condition)-------------------------------------
+    if(hi_dif > 4000)
     {
      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]);
@@ -209,12 +215,13 @@
 n=n+1;
 pc.printf("n=%d\n",n);
 
+pc.printf("to enter HR loop\n");
  // ----------------- HEART RATE LOGIC --------------------------- 
  
  for(uint16_t i = 0;i < n-1;i++)
  {
   pos_dif = pk_pos[i+1] - pk_pos[i];                 // difference between two consequtive peaks
-  pc.printf("peak position diff is = %f\n",pos_dif);
+  pc.printf("peak position diff is = %d\n",pos_dif);
   t_pos_dif = pos_dif/fs;                           // sample difference between peak positions divided by sampling frequency gives the difference value in terms of actual time
   pc.printf("time in seconds is = %f\n",t_pos_dif);
   HR[i] = t_sec/t_pos_dif;                          //HR calculation
@@ -263,4 +270,91 @@
         return 0;
     } 
 pc.printf("closing temporary file\n");
-}   // End of main function
\ No newline at end of file
+}   // End of main function
+/************************* LOW PASS FILTER FUNCTION **************************/
+
+void low_pass_filter(uint32_t pid)
+{
+    FILE *fpecg1;                                                               // FILE pointer to read raw data ECG file  added by Suhasini 5-8-17
+    FILE *fpeecg_lpf;                                                           // FILE pointer to read and write into LPF output file   added by Suhasini 5-8-17
+    static uint32_t ecg_raw_temp[5];                                            // changed by rohit on 13 sep 
+    static uint32_t ecg_raw[5];                                                 // Buff of 5 samples created to Stores input samples for LPF  added by Suhasini - 5-8-17
+    static uint32_t lpf_op[5]= {0.0};                                            // for LPF output   added by Suhasini - 5-8-17 // changed from double to int32_t- 16-8-17
+
+    uint32_t lpf_4samp = 0;                                                     // Variable to move 16 samples back from current in input file - changed by Suhasini- 5-8-17
+    char buffer3[32];
+    char buffer4[32];                                                           // Added by Suhasini - 5-8-17
+    const float b[5]= {0.0000624,0.0002495,0.0003743,0.0002495,0.0000624};      //Numerator co-efficients of low-pass butter-worth filter of order=4
+    const float a[5]= {1.0000,-3.5078,4.6409,-2.7427,0.6105};                   //Denominator co-efficients of low-pass butter-worth filter of order=4
+
+
+
+    sprintf(buffer3, "/sd/%d_ECG.csv", pid);                                    // opening raw data file to read
+    fpecg1 = fopen(buffer3, "r");                                               // to read data from the above opened temp file
+    pc.printf("entered raw data file\n");
+    sprintf(buffer4, "/sd/%d_ECG_lpf.csv", pid);                                // opening empty file to write lpf data
+    fpeecg_lpf = fopen(buffer4, "a");                                           // to read data from and write data into the above opened file // changed from "a+" to "a"
+    pc.printf("entered LPF data file\n");
+    
+    fwrite(&lpf_op, sizeof(int32_t), 4, fpeecg_lpf);
+    pc.printf("first 4 LPF data %d\n %d\n %d\n %d\n", lpf_op[0],lpf_op[1],lpf_op[2],lpf_op[3]);
+
+    pc.printf("low pass filter output is= %d\n",lpf_op[4]);                     //message to display LPF output
+    
+    fread(&ecg_raw, sizeof(uint32_t), 5, fpecg1);
+   // pc.printf("first 4 RAW data %d\n %d\n %d\n %d\n %d\n", ecg_raw[0],ecg_raw[1],ecg_raw[2],ecg_raw[3],ecg_raw[4]);
+
+    for (uint16_t i = 1; i < (N_ECG-4); i++) {                                  // reduced loop length to check i/p and o/p timing
+        //fseek(fpecg1, lpf_4samp, SEEK_CUR);                                     // Update the count value according to move pointer
+       // fread(&ecg_raw, sizeof(uint32_t), 5, fpecg1);                            // Read sample 1 of i/p
+       
+       /**********rohit***************/
+        //fread(&ecg_raw_temp, sizeof(uint32_t), 5, fpecg1);
+        //memcpy(ecg_raw, ecg_raw_temp,sizeof(ecg_raw));
+        
+       // fread(ecg_raw, sizeof(uint32_t), 5, fpecg1); 
+
+    /*********** filter output for the ECG data for a low-pass butter-worth filter of order=4 is as follows******************/
+
+
+
+        (lpf_op[4]) = (int32_t)(b[0]*((ecg_raw[4]))) + (int32_t)(b[1]*((ecg_raw[3]))) + (int32_t)(b[2]*((ecg_raw[2]))) + (int32_t)(b[3]*((ecg_raw[1]))) + (int32_t)(b[4]*((ecg_raw[0]))) - (int32_t)(a[1]*lpf_op[3]) - (int32_t)(a[2]*lpf_op[2]) - (int32_t)(a[3]*lpf_op[1]) - (int32_t)(a[4]*lpf_op[0]);
+       
+     
+        fwrite(&lpf_op[4], sizeof(int32_t), 1, fpeecg_lpf);
+        
+        //pc.printf("pointer to output value is= %ld\n",ftell(fpeecg_lpf));
+        pc.printf("%d\n",lpf_op[4]);                                            // to print LPF output on hyperterminal
+        swap(lpf_op);
+      /*  
+        lpf_op[0] = lpf_op[1];
+        lpf_op[1] = lpf_op[2];
+        lpf_op[2] = lpf_op[3];
+        lpf_op[3] = lpf_op[4];
+    */
+      //  rewind(fpecg1);                                                    commented by rohit
+        // rewind(fpeecg_lpf);                                              // commented by nikita 5/09/17 // no need to rewind as single array member result is stored in the file
+     //   lpf_4samp = (i*4);                                                // commented by rohit
+     
+        //  lpfop_4samp = (i*4);  
+        swap(ecg_raw);                                                      // 8 changed to 4, because datatype has been changed from double to int32_t- suhasini- 16/8/17  /// commented by nikita 5/09/17 // not used anywhere//
+       fread(&ecg_raw[4], sizeof(uint32_t), 1, fpecg1);
+       pc.printf("5th samples: %d\n",ecg_raw[4]);
+       
+       //fseek(fpecg1, -16 , SEEK_CUR);
+       // memset(ecg_raw,0,sizeof(ecg_raw));
+    }
+
+
+    fclose(fpecg1);
+    fclose(fpeecg_lpf);
+    pc.printf("temporary file closed after LPF\n");
+
+}
+
+void swap(uint32_t *ptr)
+{
+ int i;
+ for(i=0;i<4;i++)
+ ptr[i] = ptr[i+1];   
+}
\ No newline at end of file
--- a/main.cpp	Sat Sep 16 06:54:42 2017 +0000
+++ b/main.cpp	Wed Sep 20 07:48:55 2017 +0000
@@ -17,6 +17,8 @@
 #define BATTERY_SCREEN_NO_CHARGE_CONDITION      3
 #define TIMER_ENTER_DEBUG_MODE                  10000
 
+
+
 Serial gc(USBTX, USBRX);
 DigitalIn q1(PTB11);
 DigitalIn q(PTC5);
@@ -35,8 +37,12 @@
 static uint32_t filepid_btpid[2] = {};
 Timer timer_bt;                                                         // timer for bluetooth 
 Timer timer_battery;                                                     // timer for battery
-uint8_t debug_mode=0;
-
+Timer timer_debug;                                                       // timer for entering the debug mode   
+static bool debug_mode=0;                                               // holds the status of the debug mode "1" indicates the device is in debug mode 
+char debug_message_rx[6];                                               // buffer to receive the debug message data
+char debug_message[6]={"debug"};                                        //debug message to be received
+void debug_status_monitoring();                                         // debug status monitoring
+    
 
 int main()
 {
@@ -45,40 +51,33 @@
     static uint8_t state_touch = 1;
     uint8_t state_t = 1;                                     // state to transmit to bluetooth
     uint8_t state_r = 0;                                     // state to receive from bluetooth
- 
+    
   
   
     DisableTouch();
     gc.baud(115200);
     blue1.baud(115200);
-    init_screen();                                                  //initialize lcd
+    init_screen();                                                              //initialize lcd
     pid = get_filepid();
-    screen_main();                                                  // display of main screen 
+    screen_main();                                                              // display of main screen 
     battery_monitor();                                                          // monitor battery at the start only
     battery_status_display();                                                   // display of main screen
     timer_battery.start();
-    timer_bt.start();
-    gc.printf("Press any key to enter into debug mode\n");
-
-    while(timer_bt.read_ms()<TIMER_ENTER_DEBUG_MODE)
-    {
+    timer_debug.start();
+    gc.printf("enter message to go into debug mode\n");
 
-        if (gc.readable())                                          // checking whether there is any data read 
-        {
-            gc.getc();
-            //getchar();
-            debug_mode = 1;
-            timer_bt.stop();
-            timer_bt.reset();
-            gc.printf("entered debug mode\n");
-            break;
-        }   
-    }
-    
-    timer_bt.stop();
-    timer_bt.reset();
    while(1)
    {
+    
+        if (read_debug_status() == 0)                                            // checking the debug_mode status
+        {   
+            if(timer_debug.read_ms()<TIMER_ENTER_DEBUG_MODE)
+            {
+                debug_status_monitoring();
+            }
+        }   
+      
+        
         battery_status_monitoring();                                            // to  monitior battery status after every 10 min. 
 
         if (get_battery_status() == BATTERY_SCREEN_NO_CHARGE_CONDITION)   // to check battery status and take action 
@@ -89,6 +88,7 @@
         {
 
             EnableTouch();
+             gc.printf("c");  
             switch(main_state)                                             // main state machine
              {
                 case 1:  
@@ -336,7 +336,7 @@
                 clear_filecreated_status();
                 pid = get_filepid();
                 battery_status_display();                          //Display battery status on LCD
-                debug_mode = 0;
+              //  debug_mode = 0;
                 EnableTouch();
                 break;
       
@@ -348,6 +348,7 @@
                 nstate=state;
                 battery_status_display();                                           //Display battery status on LCD
                 EnableTouch();
+                // timer_debug.stop();
                 break;
                
       case 3: 
@@ -474,10 +475,6 @@
                   
       case 11 :    
                 DisableTouch();
-                //sd_read(pid_btpid);                                         //read pid from sd card 
-                //current_test_pid=pid_btpid[0];
-                //bt_file_sent_pid=pid_btpid[1];
-                //screen_patient_info(current_test_pid, bt_file_sent_pid);
                 screen_patient_info(get_filepid(), get_btpid());
                 state1=0;
                 state=12;
@@ -505,12 +502,10 @@
                 
         case 15 :    
                 DisableTouch();
-               // screen_sdcard_read();                                                 //state to delete SD card
+                gc.printf("Total Patients' data available : %d\n",get_filepid());                                        //state to read SD card
                 gc.printf("Enter the PID number");
-               /// gc.scanf("%d", &pid_read);
-               // gc.printf("%d\n",pid_read);
                 read_sdcard_file();
-               // screen_sdcard_read();
+                screen_sdcard_read();
                 state1=0;
                 state= 12;
                 nstate=state;
@@ -626,7 +621,49 @@
     }
 }
 
-uint8_t read_debug_status()
+bool read_debug_status()
+{
+    gc.printf("debug_mode=%d\n",debug_mode); 
+    return debug_mode;
+}
+
+void debug_status_monitoring()
+{
+
+
+if(get_timer_debug()<TIMER_ENTER_DEBUG_MODE)
 {
-    return debug_mode;
-}
\ No newline at end of file
+ if (gc.readable())                                                             // check for the user input
+        {
+            
+           while (gc.readable()!= '\n')                                         // read till the newline
+            { 
+               
+                gc.scanf("%s", debug_message_rx);                               // store the message typed in buffer
+                gc.printf("%s", debug_message_rx);
+                break;
+            }
+         
+         
+            if (strcmp(debug_message_rx, debug_message) == 0)                   // compare the message with the required one
+            {
+                 debug_mode = 1;                                                // enable the debug mode status
+                 gc.printf("entered into debug mode\n");
+                 timer_debug.reset();
+                 timer_debug.start();                                           // timer is started in orede
+            } 
+        }        
+}
+    
+}  
+    
+uint32_t get_timer_debug()                                                         // timer for enabling debug option
+{
+  if(timer_debug.read_ms()>TIMER_ENABLE_DEBUG_MODE)
+    {
+        timer_debug.stop();
+    }
+  return  timer_debug.read_ms(); 
+}
+
+
--- a/main.h	Sat Sep 16 06:54:42 2017 +0000
+++ b/main.h	Wed Sep 20 07:48:55 2017 +0000
@@ -1,7 +1,7 @@
 #ifndef MAIN_H_
 #define MAIN_H_
 
-
+#define TIMER_ENABLE_DEBUG_MODE             60000
 
 bool get_filecreated_status(void);                  //get status of file created
 void set_filecreated_status(void);                  //set file created
@@ -12,6 +12,7 @@
 void store_btpid(uint32_t bt_pid);
 uint32_t get_filepid(void);
 void store_filepid(uint32_t pid);
-uint8_t read_debug_status();
+bool read_debug_status();
+uint32_t get_timer_debug();
 #endif
 
--- a/touch_modules.cpp	Sat Sep 16 06:54:42 2017 +0000
+++ b/touch_modules.cpp	Wed Sep 20 07:48:55 2017 +0000
@@ -16,14 +16,14 @@
  {
             xt = (X_MAX*readTouchX()/TOTAL1);
             yt = (Y_MAX*readTouchY()/TOTAL1);
-            //kc.printf("%d\n", xt); 
-            //  kc.printf("%d\n", yt); 
+           kc.printf("%d\n", xt); 
+            kc.printf("%d\n", yt); 
  }
 
 
 void detect_touch(unsigned char display_state)   // detect the touch //debounce
 {
-//kc.printf("display state=%d\n",display_state);
+kc.printf("display state=%d\n",display_state);
 uint32_t time_ms=0;
 switch (display_state)
 
@@ -96,20 +96,20 @@
     
     unsigned char state=0;
         
-                  if ( ((xt >=BT_MAIN_X_MIN) && (xt<=BT_MAIN_X_MAX)) && ( (yt>= BT_MAIN_Y_MIN) && (yt<=BT_MAIN_Y_MAX) ) ) // ble
+                  if ( ((xt >=BT_MAIN_X_MIN) && (xt<=BT_MAIN_X_MAX)) && ( (yt>= BT_MAIN_Y_MIN) && (yt<=BT_MAIN_Y_MAX) ) )                                                   // ble
                        {
                           
                           state = 12;
                         }
-                if (read_debug_status()== 1)
+                if ((read_debug_status()== 1) && get_timer_debug()<TIMER_ENABLE_DEBUG_MODE)                                                                              // checking for the debug status and timer 
                     {
-                        if ( ((xt >=DELETE_MAIN_X_MIN) && (xt<=DELETE_MAIN_X_MAX)) && ( (yt>=DELETE_MAIN_Y_MIN) && (yt<=DELETE_MAIN_Y_MAX) ) ) // DELETE
+                        if ( ((xt >=DELETE_MAIN_X_MIN) && (xt<=DELETE_MAIN_X_MAX)) && ( (yt>=DELETE_MAIN_Y_MIN) && (yt<=DELETE_MAIN_Y_MAX) ) )                          // DELETE
                             {
                            state=13;
                             }
                     }
                     
-                 else if ( ((xt >=PATIENT_INFO_MAIN_X_MIN) && (xt<=PATIENT_INFO_MAIN_X_MAX)) && ( (yt>=PATIENT_INFO_MAIN_Y_MIN) && (yt<=PATIENT_INFO_MAIN_Y_MAX) ) ) // file
+                 else if ( ((xt >=PATIENT_INFO_MAIN_X_MIN) && (xt<=PATIENT_INFO_MAIN_X_MAX)) && ( (yt>=PATIENT_INFO_MAIN_Y_MIN) && (yt<=PATIENT_INFO_MAIN_Y_MAX) ) )    // file
                       {
                                 state=11;