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

Committer:
nikitateggi
Date:
Sat Jul 15 05:39:45 2017 +0000
Revision:
31:0f67acfc6236
Parent:
24:d992ee8369f4
Child:
34:8f6b0dc124e8
new display code 15/07/17

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nidhinvarghese 15:208b146151ba 1
nidhinvarghese 15:208b146151ba 2 /*
nidhinvarghese 15:208b146151ba 3 // Code by nikitha Commented by Nidhin
nidhinvarghese 15:208b146151ba 4
nidhinvarghese 15:208b146151ba 5 /#include "mbed.h"
nikitateggi 1:8316c23ec6b9 6 #include "glc.h"
nikitateggi 1:8316c23ec6b9 7 #include "i2c_dec.h"
nikitateggi 7:11f926351d8f 8 //#include "ili9325.h"
nikitateggi 7:11f926351d8f 9 //#include "lcd_base.h"
nikitateggi 1:8316c23ec6b9 10 #include "display_modules.h"
nikitateggi 1:8316c23ec6b9 11 //#include "touch_modules.h"
nikitateggi 1:8316c23ec6b9 12 #include "rtc.h"
nikitateggi 1:8316c23ec6b9 13 #include "sdcard.h"
nikitateggi 1:8316c23ec6b9 14
nikitateggi 1:8316c23ec6b9 15
nikitateggi 1:8316c23ec6b9 16 void sample();
nikitateggi 1:8316c23ec6b9 17 void Compute();
nikitateggi 1:8316c23ec6b9 18 void i2c_spec();
nikitateggi 1:8316c23ec6b9 19 Ticker flipper;
nikitateggi 1:8316c23ec6b9 20 Ticker flipper1;
nikitateggi 1:8316c23ec6b9 21
nikitateggi 1:8316c23ec6b9 22 //osTimerDef (sample_data, sample); // define timers
nikitateggi 1:8316c23ec6b9 23 //osTimerDef (Compute_GLC, Compute);
nikitateggi 1:8316c23ec6b9 24 DigitalIn test_strip(PTA12);
nikitateggi 1:8316c23ec6b9 25
nikitateggi 1:8316c23ec6b9 26 AnalogIn Ain(PTC1);//Electrode one
nikitateggi 1:8316c23ec6b9 27 AnalogIn Ain2(PTE29); // Electrode two
nikitateggi 1:8316c23ec6b9 28 AnalogOut DAC_signal(PTE30);
nikitateggi 4:6bd81bb1790d 29 Serial gtc(USBTX, USBRX);
nikitateggi 1:8316c23ec6b9 30 //unsigned char c;
nikitateggi 1:8316c23ec6b9 31 //unsigned char HOME = 0;
nikitateggi 4:6bd81bb1790d 32
nikitateggi 1:8316c23ec6b9 33 //signed char test_strip = 0;
nikitateggi 1:8316c23ec6b9 34 unsigned int mgdl = 0;
nikitateggi 1:8316c23ec6b9 35 unsigned int mgdll = 0;
nikitateggi 1:8316c23ec6b9 36 unsigned int daata1= 0;
nikitateggi 1:8316c23ec6b9 37 unsigned int data2 = 0;
nikitateggi 1:8316c23ec6b9 38
nikitateggi 1:8316c23ec6b9 39 unsigned int data1n= 0;
nikitateggi 1:8316c23ec6b9 40 unsigned int data2n = 0;
nikitateggi 1:8316c23ec6b9 41 unsigned int datafinal1 = 0;
nikitateggi 1:8316c23ec6b9 42 unsigned int datafinal2 = 0;
nikitateggi 1:8316c23ec6b9 43 //unsigned int data_diff = 0;
nikitateggi 1:8316c23ec6b9 44 unsigned char err = 0;
nikitateggi 1:8316c23ec6b9 45
nikitateggi 1:8316c23ec6b9 46 Serial ble(PTC4,PTC3);
nikitateggi 1:8316c23ec6b9 47
nikitateggi 4:6bd81bb1790d 48
nikitateggi 4:6bd81bb1790d 49
nikitateggi 1:8316c23ec6b9 50 void sample()
nikitateggi 1:8316c23ec6b9 51
nikitateggi 1:8316c23ec6b9 52 {
nikitateggi 1:8316c23ec6b9 53 data1n = Ain.read_u16();
nikitateggi 1:8316c23ec6b9 54 data2n = Ain2.read_u16();
nikitateggi 1:8316c23ec6b9 55 daata1 = beta*daata1+alpha*data1n;
nikitateggi 1:8316c23ec6b9 56 data2 = beta*data2+alpha*data2n;
nikitateggi 1:8316c23ec6b9 57
nikitateggi 1:8316c23ec6b9 58 if( ((daata1-data2) >=(data2/10) && (daata1 > data2)) || ((data2-daata1) >=(data2/10) && (data2 > daata1)) )
nikitateggi 1:8316c23ec6b9 59 {
nikitateggi 1:8316c23ec6b9 60
nikitateggi 1:8316c23ec6b9 61 err = 1;
nikitateggi 1:8316c23ec6b9 62 }
nikitateggi 1:8316c23ec6b9 63 else
nikitateggi 1:8316c23ec6b9 64 {
nikitateggi 1:8316c23ec6b9 65 err = 0;
nikitateggi 1:8316c23ec6b9 66 }
nikitateggi 1:8316c23ec6b9 67
nikitateggi 1:8316c23ec6b9 68 }
nikitateggi 1:8316c23ec6b9 69
nikitateggi 4:6bd81bb1790d 70
nikitateggi 4:6bd81bb1790d 71
nikitateggi 1:8316c23ec6b9 72 void Compute()
nikitateggi 1:8316c23ec6b9 73 {
nikitateggi 1:8316c23ec6b9 74
nikitateggi 4:6bd81bb1790d 75
nikitateggi 1:8316c23ec6b9 76 datafinal1 = (unsigned int) NUMB1*(data2*VREF/(TOTAL))-NUMB2;
nikitateggi 1:8316c23ec6b9 77 datafinal2 = (unsigned int) NUMB1*(daata1*VREF/(TOTAL))-NUMB2;
nikitateggi 1:8316c23ec6b9 78 mgdl = (unsigned int) NUMB1*(((daata1+data2)/2)*VREF/(TOTAL))-NUMB2;
nikitateggi 1:8316c23ec6b9 79
nikitateggi 1:8316c23ec6b9 80
nikitateggi 1:8316c23ec6b9 81 if (err == 0)
nikitateggi 1:8316c23ec6b9 82 {
nikitateggi 1:8316c23ec6b9 83
nikitateggi 1:8316c23ec6b9 84 glc_4(mgdl);
nikitateggi 4:6bd81bb1790d 85 sd_write(mgdl); // storing value into the sd card
nikitateggi 1:8316c23ec6b9 86 sd_close();
nikitateggi 7:11f926351d8f 87 // ble.printf("blood glucose is %d mg/dl", mgdl);
nikitateggi 1:8316c23ec6b9 88 flipper.detach();
nikitateggi 1:8316c23ec6b9 89 flipper1.detach();
nikitateggi 1:8316c23ec6b9 90 // return mgdl;
nikitateggi 1:8316c23ec6b9 91
nikitateggi 1:8316c23ec6b9 92 }
nikitateggi 4:6bd81bb1790d 93
nikitateggi 1:8316c23ec6b9 94 else
nikitateggi 1:8316c23ec6b9 95 {
nikitateggi 1:8316c23ec6b9 96 // lcd1.Print( " ERROR RESULT", 5,220,COLOR_RED,COLOR_BLACK, 0);
nikitateggi 1:8316c23ec6b9 97 // ble.printf("E:");
nikitateggi 1:8316c23ec6b9 98 }
nikitateggi 1:8316c23ec6b9 99
nikitateggi 1:8316c23ec6b9 100
nikitateggi 1:8316c23ec6b9 101 }
nikitateggi 1:8316c23ec6b9 102
nikitateggi 1:8316c23ec6b9 103
nikitateggi 1:8316c23ec6b9 104
nikitateggi 1:8316c23ec6b9 105 void glc(int pid){
nikitateggi 4:6bd81bb1790d 106 unsigned char GLC_START = 0;
nikitateggi 1:8316c23ec6b9 107 char t_s_d = 0;
nikitateggi 4:6bd81bb1790d 108 i2c_spec();
nikitateggi 4:6bd81bb1790d 109 GLC_START = 1;
nikitateggi 4:6bd81bb1790d 110 // ble.baud(115200);
nikitateggi 4:6bd81bb1790d 111 if(GLC_START == 1)
nikitateggi 1:8316c23ec6b9 112 {
nikitateggi 1:8316c23ec6b9 113
nikitateggi 1:8316c23ec6b9 114 //DisableTouch();
nikitateggi 1:8316c23ec6b9 115 //gpo_t = 0;
nikitateggi 1:8316c23ec6b9 116 //lcd1.FillRect(5,127,230,320,COLOR_BLACK);
nikitateggi 4:6bd81bb1790d 117 glc_1(); // displaying messages to insert the test strip
nikitateggi 1:8316c23ec6b9 118 err = 0;
nikitateggi 1:8316c23ec6b9 119 data1n = 0;
nikitateggi 1:8316c23ec6b9 120 data2n = 0;
nikitateggi 1:8316c23ec6b9 121 daata1 = 0;
nikitateggi 1:8316c23ec6b9 122 data2 = 0;
nikitateggi 4:6bd81bb1790d 123 sd_open_GLCfile(pid); // opening the glc file
nikitateggi 1:8316c23ec6b9 124
nikitateggi 1:8316c23ec6b9 125 while((test_strip));
nikitateggi 1:8316c23ec6b9 126
nikitateggi 1:8316c23ec6b9 127
nikitateggi 1:8316c23ec6b9 128 // wait(500);
nikitateggi 1:8316c23ec6b9 129 // Shutdown = 1;
nikitateggi 1:8316c23ec6b9 130
nikitateggi 4:6bd81bb1790d 131 if (!test_strip) // checks for the presence of test strip
nikitateggi 1:8316c23ec6b9 132 {
nikitateggi 1:8316c23ec6b9 133
nikitateggi 4:6bd81bb1790d 134 flipper.attach(&sample, 0.8);
nikitateggi 1:8316c23ec6b9 135 t_s_d = 0;
nikitateggi 4:6bd81bb1790d 136 glc_2(); // displaying message to insert blood
nikitateggi 4:6bd81bb1790d 137
nikitateggi 4:6bd81bb1790d 138 while((!t_s_d) && (!test_strip))
nikitateggi 1:8316c23ec6b9 139 {
nikitateggi 1:8316c23ec6b9 140
suhasini 5:a3ea7c82b7e1 141 gtc.printf("%d\n", data1n);
suhasini 5:a3ea7c82b7e1 142 gtc.printf("%d\n", data2n);
nikitateggi 1:8316c23ec6b9 143 if ((daata1 >= THRESHOLD) || (data2 >= THRESHOLD))
nikitateggi 1:8316c23ec6b9 144 {
nikitateggi 1:8316c23ec6b9 145 t_s_d = 1;
nikitateggi 4:6bd81bb1790d 146 flipper1.attach(&Compute, 2.25); //computing the glucose level
nikitateggi 1:8316c23ec6b9 147 glc_3();
nikitateggi 1:8316c23ec6b9 148
nikitateggi 1:8316c23ec6b9 149
nikitateggi 1:8316c23ec6b9 150 }
nikitateggi 1:8316c23ec6b9 151 else
nikitateggi 1:8316c23ec6b9 152 {
nikitateggi 1:8316c23ec6b9 153 //wait for insertion of blood;
nikitateggi 1:8316c23ec6b9 154 }
nikitateggi 1:8316c23ec6b9 155
nikitateggi 1:8316c23ec6b9 156 }
nikitateggi 1:8316c23ec6b9 157
nikitateggi 1:8316c23ec6b9 158
nikitateggi 1:8316c23ec6b9 159 // t_s_d = 0;
nikitateggi 1:8316c23ec6b9 160 wait_ms(800);
nikitateggi 1:8316c23ec6b9 161 //flipper.detach();
nikitateggi 1:8316c23ec6b9 162
nikitateggi 1:8316c23ec6b9 163 }
nikitateggi 1:8316c23ec6b9 164
nikitateggi 1:8316c23ec6b9 165
nikitateggi 1:8316c23ec6b9 166 }
nikitateggi 1:8316c23ec6b9 167
nikitateggi 1:8316c23ec6b9 168 }
nikitateggi 1:8316c23ec6b9 169
nidhinvarghese 15:208b146151ba 170 */
nidhinvarghese 15:208b146151ba 171
nidhinvarghese 15:208b146151ba 172 // Code Modified with Bluetooth Structure Nidhin 2/6/17
nidhinvarghese 15:208b146151ba 173 ///
nidhinvarghese 15:208b146151ba 174 #include "mbed.h"
nidhinvarghese 15:208b146151ba 175 #include "glc.h"
nidhinvarghese 15:208b146151ba 176 #include "i2c_dec.h"
nidhinvarghese 15:208b146151ba 177 //#include "ili9325.h"
nidhinvarghese 15:208b146151ba 178 //#include "lcd_base.h"
nidhinvarghese 15:208b146151ba 179 #include "display_modules.h"
nidhinvarghese 15:208b146151ba 180 //#include "touch_modules.h"
nidhinvarghese 15:208b146151ba 181 #include "rtc.h"
nidhinvarghese 15:208b146151ba 182 #include "sdcard.h"
nikitateggi 20:7c64e6ecad76 183 #include "eeprom_pgm.h" // Nidhin 12/6/17
nidhinvarghese 15:208b146151ba 184
nidhinvarghese 15:208b146151ba 185 #include "struct.h" //Nidhin 31/5/2017
nikitateggi 19:1650bbc923cc 186 //#include "test_type.h" //Nidhin 31/5/2017
nidhinvarghese 15:208b146151ba 187
nidhinvarghese 15:208b146151ba 188
nidhinvarghese 15:208b146151ba 189 void sample();
nidhinvarghese 15:208b146151ba 190 void Compute();
nidhinvarghese 15:208b146151ba 191 void i2c_spec();
nidhinvarghese 15:208b146151ba 192 Ticker flipper;
nidhinvarghese 15:208b146151ba 193 Ticker flipper1;
nikitateggi 16:8fa1d7fd7953 194 unsigned char GLC_START = 0;
nidhinvarghese 15:208b146151ba 195 //osTimerDef (sample_data, sample); // define timers
nidhinvarghese 15:208b146151ba 196 //osTimerDef (Compute_GLC, Compute);
nidhinvarghese 15:208b146151ba 197 DigitalIn test_strip(PTA12);
nidhinvarghese 15:208b146151ba 198
nidhinvarghese 15:208b146151ba 199 AnalogIn Ain(PTC1);//Electrode one
nidhinvarghese 15:208b146151ba 200 AnalogIn Ain2(PTE29); // Electrode two
nidhinvarghese 15:208b146151ba 201 AnalogOut DAC_signal(PTE30);
nidhinvarghese 15:208b146151ba 202 Serial gtc(USBTX, USBRX);
nidhinvarghese 15:208b146151ba 203 //unsigned char c;
nidhinvarghese 15:208b146151ba 204 //unsigned char HOME = 0;
nidhinvarghese 15:208b146151ba 205
nidhinvarghese 15:208b146151ba 206 //signed char test_strip = 0;
nidhinvarghese 15:208b146151ba 207 static uint16_t mgdl = 0;
nikitateggi 16:8fa1d7fd7953 208 static uint16_t mgdll = 0;
nikitateggi 16:8fa1d7fd7953 209 uint16_t daata1= 0;
nikitateggi 16:8fa1d7fd7953 210 uint16_t data2 = 0;
nidhinvarghese 15:208b146151ba 211
nikitateggi 16:8fa1d7fd7953 212 static uint16_t data1n= 0;
nikitateggi 16:8fa1d7fd7953 213 static uint16_t data2n = 0;
nikitateggi 16:8fa1d7fd7953 214 uint16_t datafinal1 = 0;
nikitateggi 16:8fa1d7fd7953 215 uint16_t datafinal2 = 0;
nidhinvarghese 15:208b146151ba 216 //unsigned int data_diff = 0;
nidhinvarghese 15:208b146151ba 217 unsigned char err = 0;
nidhinvarghese 15:208b146151ba 218
nidhinvarghese 17:22a87e12fb3a 219 uint32_t glcraw[2]; // Nidhin 31/5/2017
nidhinvarghese 15:208b146151ba 220 uint8_t chk_glc_data = 0;
nikitateggi 20:7c64e6ecad76 221 uint16_t glc_testtype; // Nidhin 12/6/2017
nidhinvarghese 15:208b146151ba 222
nidhinvarghese 15:208b146151ba 223 Serial ble(PTC4,PTC3);
nidhinvarghese 15:208b146151ba 224
nidhinvarghese 15:208b146151ba 225
nidhinvarghese 15:208b146151ba 226
nidhinvarghese 15:208b146151ba 227 void sample()
nidhinvarghese 15:208b146151ba 228
nidhinvarghese 15:208b146151ba 229 {
nidhinvarghese 15:208b146151ba 230 data1n = Ain.read_u16();
nidhinvarghese 15:208b146151ba 231 data2n = Ain2.read_u16();
nidhinvarghese 15:208b146151ba 232 daata1 = beta*daata1+alpha*data1n;
nidhinvarghese 15:208b146151ba 233 data2 = beta*data2+alpha*data2n;
nidhinvarghese 15:208b146151ba 234
nidhinvarghese 15:208b146151ba 235 if( ((daata1-data2) >=(data2/10) && (daata1 > data2)) || ((data2-daata1) >=(data2/10) && (data2 > daata1)) )
nidhinvarghese 15:208b146151ba 236 {
nidhinvarghese 15:208b146151ba 237
nidhinvarghese 15:208b146151ba 238 err = 1;
nidhinvarghese 15:208b146151ba 239
nidhinvarghese 15:208b146151ba 240 }
nidhinvarghese 15:208b146151ba 241 else
nidhinvarghese 15:208b146151ba 242 {
nidhinvarghese 15:208b146151ba 243 err = 0;
nidhinvarghese 15:208b146151ba 244 //gtc.printf("\n", data1n, data2n); only for testing added nidhin 5Jun17
nidhinvarghese 15:208b146151ba 245 }
nidhinvarghese 15:208b146151ba 246
nidhinvarghese 15:208b146151ba 247 }
nidhinvarghese 15:208b146151ba 248
nidhinvarghese 15:208b146151ba 249
nidhinvarghese 15:208b146151ba 250
nidhinvarghese 15:208b146151ba 251 void Compute()
nidhinvarghese 15:208b146151ba 252 {
nidhinvarghese 15:208b146151ba 253
nikitateggi 22:ffa88619551d 254 flipper.detach(); // ticker for sampling is disabled
nikitateggi 16:8fa1d7fd7953 255 datafinal1 = (uint16_t ) NUMB1*(data2*VREF/(TOTAL))-NUMB2;
nikitateggi 16:8fa1d7fd7953 256 datafinal2 = (uint16_t ) NUMB1*(daata1*VREF/(TOTAL))-NUMB2;
nikitateggi 16:8fa1d7fd7953 257 mgdl = (uint16_t) NUMB1*(((daata1+data2)/2)*VREF/(TOTAL))-NUMB2; // Nidhin 5/6/17 mgdl = (uint16_t) NUMB1*(((daata1+data2)/2)*VREF/(TOTAL))-NUMB2;
nidhinvarghese 15:208b146151ba 258
nidhinvarghese 15:208b146151ba 259
nidhinvarghese 15:208b146151ba 260
nidhinvarghese 15:208b146151ba 261 if (err == 0)
nidhinvarghese 15:208b146151ba 262 {
nidhinvarghese 15:208b146151ba 263
nidhinvarghese 15:208b146151ba 264 glc_4(mgdl);
nikitateggi 22:ffa88619551d 265
nidhinvarghese 15:208b146151ba 266 }
nidhinvarghese 15:208b146151ba 267
nidhinvarghese 15:208b146151ba 268 else
nikitateggi 22:ffa88619551d 269 {
nidhinvarghese 17:22a87e12fb3a 270 // gtc.printf("err=1\n"); Commented Nidhin 8/6/2017
nikitateggi 22:ffa88619551d 271
nikitateggi 22:ffa88619551d 272 }
nikitateggi 16:8fa1d7fd7953 273 GLC_START = 0;
nikitateggi 22:ffa88619551d 274 flipper1.detach();// ticker for computation is disabled
nidhinvarghese 15:208b146151ba 275 }
nidhinvarghese 15:208b146151ba 276
nidhinvarghese 15:208b146151ba 277
nikitateggi 22:ffa88619551d 278 void glc(int32_t pid){
nikitateggi 16:8fa1d7fd7953 279
nidhinvarghese 15:208b146151ba 280 char t_s_d = 0;
nikitateggi 22:ffa88619551d 281 i2c_spec(); // programming the i2c expander
nidhinvarghese 15:208b146151ba 282
nikitateggi 22:ffa88619551d 283 sd_open_GLCfilee(pid); // Opens GLC file in APPEND mode
nidhinvarghese 15:208b146151ba 284
nidhinvarghese 15:208b146151ba 285 // Bluetooth Structure created globally
nidhinvarghese 15:208b146151ba 286 BLEMsg_info *ptr_BLEMsg_info_glc, BLEMsg_info_glc; // A copy of master strcuture [ "BLEMsg_info" ] by name "BLEMsg_info_bp" is created
nidhinvarghese 15:208b146151ba 287 ptr_BLEMsg_info_glc = &BLEMsg_info_glc; // *ptr_BLEMsg_info_bp is the pointer to local copy;
nidhinvarghese 15:208b146151ba 288 // Cant declare this statement outside main. Causing conflicts
nidhinvarghese 15:208b146151ba 289
nidhinvarghese 15:208b146151ba 290 // Declaration of Date Structure
nidhinvarghese 15:208b146151ba 291 DateTime_info *ptr_DateTime_info_glc, DateTime_info_glc; // A copy of Master Structure "DateTime_info" created,
nidhinvarghese 15:208b146151ba 292 ptr_DateTime_info_glc = &DateTime_info_glc; // Structure pointer points to that copy.
nidhinvarghese 15:208b146151ba 293
nidhinvarghese 15:208b146151ba 294
nidhinvarghese 15:208b146151ba 295
nidhinvarghese 15:208b146151ba 296 // RTC operations
nidhinvarghese 15:208b146151ba 297 time_t epoch_time_glc; //A copy of time_t by name epoch_time_bp is created
nidhinvarghese 15:208b146151ba 298 epoch_time_glc = rtc_read(); // time is got from get epoch function.
nidhinvarghese 15:208b146151ba 299
nidhinvarghese 15:208b146151ba 300 struct tm * ptr_time_info_glc, time_info_glc; // Sturucture copy of tm is created
nidhinvarghese 15:208b146151ba 301 ptr_time_info_glc = localtime(&epoch_time_glc); // Structure accepts the time in local format from "time_t" type.
nidhinvarghese 15:208b146151ba 302 /*
nidhinvarghese 15:208b146151ba 303 //BELOW LINE IS TO CHECK Date and TIME
nidhinvarghese 15:208b146151ba 304 gtc.printf("Time is - %d:%d:%d\n", (*ptr_time_info_glc).tm_hour, (*ptr_time_info_glc).tm_min, (*ptr_time_info_glc).tm_sec);
nidhinvarghese 15:208b146151ba 305 gtc.printf("Date is - %d:%d:%d\n", (*ptr_time_info_glc).tm_mday, (*ptr_time_info_glc).tm_mon+1, (*ptr_time_info_glc).tm_year-100);
nidhinvarghese 15:208b146151ba 306 */
nidhinvarghese 15:208b146151ba 307 //Copying from one structure to the other using variables
nidhinvarghese 15:208b146151ba 308 DateTime_info_glc.hour = (uint8_t)(*ptr_time_info_glc).tm_hour;
nidhinvarghese 15:208b146151ba 309 DateTime_info_glc.mins = (uint8_t)(*ptr_time_info_glc).tm_min;
nidhinvarghese 15:208b146151ba 310 DateTime_info_glc.sec = (uint8_t)(*ptr_time_info_glc).tm_sec;
nidhinvarghese 15:208b146151ba 311
nidhinvarghese 15:208b146151ba 312 DateTime_info_glc.date = (uint8_t) (*ptr_time_info_glc).tm_mday;
nidhinvarghese 15:208b146151ba 313 DateTime_info_glc.month =(uint8_t)(*ptr_time_info_glc).tm_mon+1;
nidhinvarghese 15:208b146151ba 314 DateTime_info_glc.year = (uint8_t)(*ptr_time_info_glc).tm_year-100;
nidhinvarghese 15:208b146151ba 315
nidhinvarghese 15:208b146151ba 316 // Copying Time to Main structure
nidhinvarghese 15:208b146151ba 317 BLEMsg_info_glc.date_time.hour = DateTime_info_glc.hour;
nidhinvarghese 15:208b146151ba 318 BLEMsg_info_glc.date_time.mins = DateTime_info_glc.mins;
nidhinvarghese 15:208b146151ba 319 BLEMsg_info_glc.date_time.sec = DateTime_info_glc.sec;
nidhinvarghese 15:208b146151ba 320
nidhinvarghese 15:208b146151ba 321 BLEMsg_info_glc.date_time.date = DateTime_info_glc.date ;
nidhinvarghese 15:208b146151ba 322 BLEMsg_info_glc.date_time.month = DateTime_info_glc.month ;
nidhinvarghese 15:208b146151ba 323 BLEMsg_info_glc.date_time.year = DateTime_info_glc.year ;
nidhinvarghese 15:208b146151ba 324
nidhinvarghese 15:208b146151ba 325 /*
nidhinvarghese 15:208b146151ba 326 //Checking if the structure has these values
nidhinvarghese 15:208b146151ba 327 gtc.printf("\nTime 2 is - %d:%d:%d\n", DateTime_info_glc.hour, DateTime_info_glc.mins, DateTime_info_glc.sec);
nidhinvarghese 15:208b146151ba 328 gtc.printf("\nDate 2 is - %d:%d:%d\n",DateTime_info_glc.date, DateTime_info_glc.month, DateTime_info_glc.year);
nidhinvarghese 15:208b146151ba 329 */
nidhinvarghese 15:208b146151ba 330
nidhinvarghese 15:208b146151ba 331 //Loading values to of Test type
nidhinvarghese 15:208b146151ba 332 test_type_info test_type_info_glc; // copy of " test_type_info" created
nidhinvarghese 15:208b146151ba 333 test_type_info_glc = BG_Test; // Loaded value 00 to the test type
nidhinvarghese 15:208b146151ba 334
nidhinvarghese 15:208b146151ba 335 BLEMsg_info_glc.test_type = test_type_info_glc;
nidhinvarghese 15:208b146151ba 336 //Check if 01 is getting printed
nidhinvarghese 15:208b146151ba 337 //gtc.printf("\nTest Type for BG is 01 = %d\n", test_type_info_glc);
nidhinvarghese 15:208b146151ba 338
nidhinvarghese 15:208b146151ba 339
nidhinvarghese 15:208b146151ba 340 // Loading values of Length , PID, DID, sampling frequency, number of samples, calculated data.
nidhinvarghese 15:208b146151ba 341 BLEMsg_info_glc.device_id = 01; // Device ID fixed
nikitateggi 16:8fa1d7fd7953 342 BLEMsg_info_glc.patient_id = (uint16_t)pid; // Patient ID
nidhinvarghese 15:208b146151ba 343 BLEMsg_info_glc.sampling_freq = 0; // sampling frrquency
nidhinvarghese 15:208b146151ba 344 BLEMsg_info_glc.length = 30; //Total length of data in bytes 22 B+10752 B
nidhinvarghese 15:208b146151ba 345
nidhinvarghese 15:208b146151ba 346 BLEMsg_info_glc.num_samples.num_sample_ecg_OTtyp = 2;
nidhinvarghese 15:208b146151ba 347 BLEMsg_info_glc.num_samples.num_sample_ppg_dummy = 0;
nidhinvarghese 15:208b146151ba 348
nidhinvarghese 15:208b146151ba 349
nidhinvarghese 15:208b146151ba 350
nidhinvarghese 15:208b146151ba 351 GLC_START = 1;
nidhinvarghese 15:208b146151ba 352 // ble.baud(115200);
nidhinvarghese 15:208b146151ba 353 if(GLC_START == 1)
nidhinvarghese 15:208b146151ba 354 {
nidhinvarghese 15:208b146151ba 355 glc_1(); // displaying messages to insert the test strip
nidhinvarghese 15:208b146151ba 356 err = 0;
nidhinvarghese 15:208b146151ba 357 data1n = 0;
nidhinvarghese 15:208b146151ba 358 data2n = 0;
nidhinvarghese 15:208b146151ba 359 daata1 = 0;
nidhinvarghese 15:208b146151ba 360 data2 = 0;
nidhinvarghese 15:208b146151ba 361 //sd_open_GLCfile(pid); // opening the glc file Commented
nidhinvarghese 15:208b146151ba 362
nidhinvarghese 15:208b146151ba 363 while((test_strip));
nidhinvarghese 15:208b146151ba 364
nidhinvarghese 15:208b146151ba 365 if (!test_strip) // checks for the presence of test strip
nidhinvarghese 15:208b146151ba 366 {
nidhinvarghese 15:208b146151ba 367 flipper.attach(&sample, 0.8);
nidhinvarghese 15:208b146151ba 368 t_s_d = 0;
nidhinvarghese 15:208b146151ba 369 glc_2(); // displaying message to insert blood
nidhinvarghese 15:208b146151ba 370
nidhinvarghese 15:208b146151ba 371 while((!t_s_d) && (!test_strip))
nidhinvarghese 15:208b146151ba 372 {
nidhinvarghese 15:208b146151ba 373 //if(chk_glc_data == 0) //Nidhin 31/5/2017
nidhinvarghese 15:208b146151ba 374 //{
nidhinvarghese 15:208b146151ba 375 /*
nikitateggi 16:8fa1d7fd7953 376 glcraw[0] = (uint16_t) data1n; //Nidhin 31/5/2017
nikitateggi 16:8fa1d7fd7953 377 glcraw[1] = (uint16_t) data2n; // Nidhin 31/5/2017
nidhinvarghese 15:208b146151ba 378
nidhinvarghese 15:208b146151ba 379 gtc.printf("datain is =%d\n", data1n);
nidhinvarghese 15:208b146151ba 380 gtc.printf("data2n is = %d\n", data2n);
nidhinvarghese 15:208b146151ba 381
nidhinvarghese 15:208b146151ba 382 gtc.printf("datain is =%d\n", data1n);
nidhinvarghese 15:208b146151ba 383 gtc.printf("data2n is = %d\n", data2n);
nidhinvarghese 15:208b146151ba 384 */
nidhinvarghese 15:208b146151ba 385 //chk_glc_data = 1;
nidhinvarghese 15:208b146151ba 386 //}
nidhinvarghese 15:208b146151ba 387 //gtc.printf("Checking\n");
nidhinvarghese 15:208b146151ba 388
nidhinvarghese 15:208b146151ba 389 if ((daata1 >= THRESHOLD) || (data2 >= THRESHOLD))
nidhinvarghese 15:208b146151ba 390 {
nikitateggi 16:8fa1d7fd7953 391 //glcraw[0] = (uint16_t) data1n; //Nidhin 5/6/2017
nikitateggi 16:8fa1d7fd7953 392 //glcraw[1] = (uint16_t) data2n; // Nidhin 5/6/2017
nidhinvarghese 15:208b146151ba 393
nidhinvarghese 15:208b146151ba 394 //gtc.printf("data1n is =%d\n", data1n);
nidhinvarghese 15:208b146151ba 395 //gtc.printf("data2n is = %d\n", data2n);
nidhinvarghese 15:208b146151ba 396
nidhinvarghese 15:208b146151ba 397 // gtc.printf("glcraw[0] is =%d\n", glcraw[0]);
nidhinvarghese 15:208b146151ba 398 //gtc.printf("glcraw[1] is = %d\n", glcraw[1]);
nidhinvarghese 15:208b146151ba 399
nidhinvarghese 15:208b146151ba 400 t_s_d = 1;
nidhinvarghese 15:208b146151ba 401 flipper1.attach(&Compute, 2.25); //computing the glucose level
nidhinvarghese 15:208b146151ba 402 glc_3();
nidhinvarghese 15:208b146151ba 403 }
nidhinvarghese 15:208b146151ba 404 else
nidhinvarghese 15:208b146151ba 405 {
nidhinvarghese 15:208b146151ba 406 //wait for insertion of blood;
nidhinvarghese 15:208b146151ba 407 }
nidhinvarghese 15:208b146151ba 408 }
nidhinvarghese 15:208b146151ba 409 wait_ms(800);
nidhinvarghese 15:208b146151ba 410 }
nikitateggi 16:8fa1d7fd7953 411
nidhinvarghese 17:22a87e12fb3a 412 //gtc.printf("mgdl is - %d\n", mgdll);
nidhinvarghese 15:208b146151ba 413 }
nikitateggi 16:8fa1d7fd7953 414 wait(2.25);
nikitateggi 22:ffa88619551d 415
nikitateggi 22:ffa88619551d 416 if (err==0)
nikitateggi 22:ffa88619551d 417 {
nidhinvarghese 15:208b146151ba 418 gtc.printf("DATA1 is - %d\n", data1n);
nidhinvarghese 15:208b146151ba 419 gtc.printf("DATA2 is - %d\n", data2n);
nikitateggi 24:d992ee8369f4 420 gtc.printf("mgdl is - %d\n", mgdl);
nidhinvarghese 15:208b146151ba 421
nidhinvarghese 17:22a87e12fb3a 422 glcraw[0] = (uint32_t)data1n;
nidhinvarghese 17:22a87e12fb3a 423 glcraw[1] = (uint32_t)data2n;
nidhinvarghese 17:22a87e12fb3a 424
nidhinvarghese 17:22a87e12fb3a 425 sd_glcwrite(glcraw, pid); //Writes the raw data into GLC file
nidhinvarghese 15:208b146151ba 426
nikitateggi 20:7c64e6ecad76 427 //Results Stored to Bluetooth structure
nikitateggi 24:d992ee8369f4 428 glc_testtype = eprom_read_16(20); // Reads the test type (before meal = 0 / after meal = 1 OR Random = 2 from location 2 of the EEPROM) Nidhin 12/6/17
nikitateggi 20:7c64e6ecad76 429 BLEMsg_info_glc.cal_data.cal_sbp_dummy = (uint16_t) glc_testtype; // Data stored into structure
nikitateggi 24:d992ee8369f4 430 BLEMsg_info_glc.cal_data.cal_dbp_OTtyp = (uint16_t) mgdl; //To be checked for reliable results
nidhinvarghese 15:208b146151ba 431
nidhinvarghese 15:208b146151ba 432 structure_file(ptr_BLEMsg_info_glc, pid); // Copy the structure into the GLC file
nidhinvarghese 15:208b146151ba 433 glcfile_mainfile(pid);
nikitateggi 22:ffa88619551d 434 }
nikitateggi 31:0f67acfc6236 435 else if(err==1 || mgdl>200 || mgdl<40) // added threshold to check value out of range
nikitateggi 22:ffa88619551d 436 {
nikitateggi 22:ffa88619551d 437 gtc.printf("replace teststip");
nidhinvarghese 15:208b146151ba 438 }
nidhinvarghese 15:208b146151ba 439
nikitateggi 1:8316c23ec6b9 440
nikitateggi 22:ffa88619551d 441 }
nikitateggi 1:8316c23ec6b9 442
nikitateggi 1:8316c23ec6b9 443
nidhinvarghese 15:208b146151ba 444
nidhinvarghese 15:208b146151ba 445
nidhinvarghese 15:208b146151ba 446
nidhinvarghese 15:208b146151ba 447