Modification into 17th July New display demo code

Dependencies:   SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217

Fork of Ext_Demo_17July2017_newdis by SenseSemi

Revision:
19:1650bbc923cc
Parent:
14:f5c62d30c6fc
Child:
20:7c64e6ecad76
--- a/main.cpp	Fri Jun 09 09:22:32 2017 +0000
+++ b/main.cpp	Fri Jun 09 17:12:21 2017 +0000
@@ -1,6 +1,7 @@
+// changed the pid in all to int32_t;
+//added bt
+
 #include "mbed.h"
-//#include "ili9325.h"
-//#include "lcd_base.h"
 #include "display_modules.h"
 #include "touch_modules.h"
 #include "ecg_dec.h"
@@ -9,42 +10,99 @@
 #include "bp.h"
 #include "sdcard.h"
 #include "eeprom_pgm.h"
-
+#include "struct.h"
  
 Serial gc(USBTX, USBRX);
 DigitalIn q1(PTB11);
 DigitalIn q(PTB8);
-//Serial ble(PTC4,PTC3);
+DigitalIn BT(PTA5);                     //bluetooth status pin
 
+uint8_t touch(uint8_t state);           // touch state
+uint8_t display(uint8_t state1);       //  display state
+int pid=0;                // patient ID
+static uint8_t nstate=0;
+static uint8_t nstate1=0;
+static uint8_t flag=0;             //flag to indicate not to update pid as it is already done
+static uint8_t ecg_flag=0;         // ecg_flag to indicate the ecg test is already done for the same pid
+static uint8_t glc_flag=0;         // glc_flag to indicate the glc test is already done for the same pid
+uint8_t state_r=0;                 // state to receive from bluetooth
+uint8_t state_t=1;                 // state to transmit to bluetooth
+float heart_rate=0;          
 
 
 int main(){
 
 
- unsigned char state;
- unsigned char state1;
- unsigned char nstate;
- unsigned char nstate1;
- int pid=0;                // patient ID
- unsigned char flag=0;
- unsigned char ecg_flag=0;
- unsigned char glc_flag=0;
-float heart_rate=0;
+
   
    DisableTouch();
    gc.baud(115200);
   
    init_screen();    //initialize lcd
    screen_main(); // display of main screen 
-   state=1;
+   //state=10;
    flag=0;
-   nstate=state;
+   //nstate=state;
    EnableTouch();   // enable touch function
+static uint8_t main_state=1;
+static uint8_t state_display=0;
+static uint8_t state_touch=1;
+static uint8_t state_t=1;
+static uint8_t state_r=0;
 
    while(1)
    {
-      
-    detect_touch();     // determine the touch points
+     switch(main_state)                          // main state machine
+     {
+         case 1:  state_display=touch(state_touch);           // touch state
+                
+                  
+                if(state_display==10)
+                    main_state=3;
+                    
+                else 
+                    main_state=2;
+                  break;
+    
+         case 2:  state_touch=display(state_display);          //display state
+                  main_state=1;
+                 break;
+                
+                
+         case 3: DisableTouch();                             // bluetooth send 
+                 if(BT==1)
+                 {
+                    state_r=bt_send(state_t);
+                    main_state=4;
+                 }
+               else   
+                 gc.printf("timeout");
+                 break;
+                 
+         case 4:  
+                 state_t=bt_receive(state_r);               // bluetooth receive
+                 main_state=3;
+                // gc.printf("statet=%d",state_t);
+                 if(state_t ==0)
+                 {
+                    EnableTouch();
+                    main_state=1;
+                   } 
+                 break;    
+                
+                
+    }
+
+
+}
+
+}
+
+
+uint8_t touch(uint8_t state)
+{
+   static  uint8_t state1=0;
+   detect_touch();     // determine the touch points
     
     switch(state)    // state for touch
   {
@@ -121,9 +179,13 @@
                           
     }         
      
-
+return state1;
+  }
   
   
+uint8_t display(uint8_t state1)
+{
+  static uint8_t state=0;
   
  switch(state1)    // state for display screens
   {
@@ -141,6 +203,7 @@
                 break;
       
       case 2: DisableTouch();
+                 // bt();
                 screen_main_1();     // System configration screen 
                 state1=0;
                 state=2;
@@ -153,15 +216,12 @@
               {
                 //pid=pid+1;
                 pid=eprom_read(1);         // reading the patient id from eeprom
+                gc.printf("pidinit=%d",pid);
                 pid=pid+1;
+                gc.printf("pid+1=%d",pid);
                eprom_write(1,pid);         // writing the patient id to eeprom
                 screen_main_2(pid);
-                
-                sd_open_mainfile(pid);    //ADDED on 1/6/2017 - NIDHIN
-                sd_close();
-                
-                
-                /*sd_open_GLCfilee(pid);     // only opening the glc,bp and ecg file // COMMENTED Nidhin 1/6/17
+              /*  sd_open_GLCfilee(pid);     // only opening the glc,bp and ecg file
                  sd_close();
                  sd_open_ECGfilee(pid);
                  sd_close();
@@ -189,7 +249,8 @@
                  nstate=state;
                  }
             else
-                { screen_glc();       // glc screen
+                { 
+                 screen_glc();       // glc screen
                  state1=0;
                  state=4;
                  nstate=state;
@@ -233,6 +294,7 @@
      
      case 7:    DisableTouch();     
                 glc(pid);        // glc measurement
+             //  bt();
                 glc_flag=1;
                 wait(5); 
                 state1=0;
@@ -265,7 +327,7 @@
                 EnableTouch();
                  break;*/
         
-     case 9: 
+    case 9: 
                 DisableTouch();
                 screen_bp2();      // bp main screen
                 bp_countdown();    // countdown for bp 
@@ -277,8 +339,8 @@
                 EnableTouch();
                  break;
         
-        
-        
+               
+                 
         default :  
                   
                   state1=nstate1;
@@ -289,16 +351,9 @@
     
            
                 
-                
+         return state;       
                 
-  }              
-                
-  
 }
 
 
 
-
-
-
-