Changes done in ECG and BT
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_20sept_2017_4th_oct_2017 by
glc.cpp@20:7c64e6ecad76, 2017-06-17 (annotated)
- Committer:
- nikitateggi
- Date:
- Sat Jun 17 09:36:18 2017 +0000
- Revision:
- 20:7c64e6ecad76
- Parent:
- 19:1650bbc923cc
- Child:
- 22:ffa88619551d
poc code with finger detect and leadoff
Who changed what in which revision?
User | Revision | Line number | New 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 | |
nidhinvarghese | 15:208b146151ba | 254 | |
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); |
nidhinvarghese | 15:208b146151ba | 265 | mgdll = mgdl; // Nidhin 31/5/2017 |
nidhinvarghese | 15:208b146151ba | 266 | //gtc.printf("The Result is - %d", mgdll); |
nidhinvarghese | 15:208b146151ba | 267 | //sd_write(mgdl); // storing value into the sd card |
nidhinvarghese | 15:208b146151ba | 268 | //sd_close(); |
nidhinvarghese | 15:208b146151ba | 269 | // ble.printf("blood glucose is %d mg/dl", mgdl); |
nidhinvarghese | 15:208b146151ba | 270 | flipper.detach(); |
nidhinvarghese | 15:208b146151ba | 271 | flipper1.detach(); |
nidhinvarghese | 15:208b146151ba | 272 | // return mgdl; |
nidhinvarghese | 15:208b146151ba | 273 | |
nidhinvarghese | 15:208b146151ba | 274 | |
nidhinvarghese | 15:208b146151ba | 275 | } |
nidhinvarghese | 15:208b146151ba | 276 | |
nidhinvarghese | 15:208b146151ba | 277 | else |
nidhinvarghese | 15:208b146151ba | 278 | { |
nidhinvarghese | 17:22a87e12fb3a | 279 | // gtc.printf("err=1\n"); Commented Nidhin 8/6/2017 |
nidhinvarghese | 15:208b146151ba | 280 | |
nidhinvarghese | 15:208b146151ba | 281 | // lcd1.Print( " ERROR RESULT", 5,220,COLOR_RED,COLOR_BLACK, 0); |
nidhinvarghese | 15:208b146151ba | 282 | // ble.printf("E:"); |
nidhinvarghese | 15:208b146151ba | 283 | } |
nikitateggi | 16:8fa1d7fd7953 | 284 | GLC_START = 0; |
nidhinvarghese | 15:208b146151ba | 285 | } |
nidhinvarghese | 15:208b146151ba | 286 | |
nidhinvarghese | 15:208b146151ba | 287 | |
nidhinvarghese | 15:208b146151ba | 288 | void glc(int pid){ |
nikitateggi | 16:8fa1d7fd7953 | 289 | |
nidhinvarghese | 15:208b146151ba | 290 | char t_s_d = 0; |
nidhinvarghese | 15:208b146151ba | 291 | i2c_spec(); |
nidhinvarghese | 15:208b146151ba | 292 | |
nidhinvarghese | 15:208b146151ba | 293 | sd_open_GLCfilee(pid); // Opens GLC file in APPEND mode |
nidhinvarghese | 15:208b146151ba | 294 | |
nidhinvarghese | 15:208b146151ba | 295 | // Bluetooth Structure created globally |
nidhinvarghese | 15:208b146151ba | 296 | 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 | 297 | ptr_BLEMsg_info_glc = &BLEMsg_info_glc; // *ptr_BLEMsg_info_bp is the pointer to local copy; |
nidhinvarghese | 15:208b146151ba | 298 | // Cant declare this statement outside main. Causing conflicts |
nidhinvarghese | 15:208b146151ba | 299 | |
nidhinvarghese | 15:208b146151ba | 300 | // Declaration of Date Structure |
nidhinvarghese | 15:208b146151ba | 301 | DateTime_info *ptr_DateTime_info_glc, DateTime_info_glc; // A copy of Master Structure "DateTime_info" created, |
nidhinvarghese | 15:208b146151ba | 302 | ptr_DateTime_info_glc = &DateTime_info_glc; // Structure pointer points to that copy. |
nidhinvarghese | 15:208b146151ba | 303 | |
nidhinvarghese | 15:208b146151ba | 304 | |
nidhinvarghese | 15:208b146151ba | 305 | |
nidhinvarghese | 15:208b146151ba | 306 | // RTC operations |
nidhinvarghese | 15:208b146151ba | 307 | time_t epoch_time_glc; //A copy of time_t by name epoch_time_bp is created |
nidhinvarghese | 15:208b146151ba | 308 | epoch_time_glc = rtc_read(); // time is got from get epoch function. |
nidhinvarghese | 15:208b146151ba | 309 | |
nidhinvarghese | 15:208b146151ba | 310 | struct tm * ptr_time_info_glc, time_info_glc; // Sturucture copy of tm is created |
nidhinvarghese | 15:208b146151ba | 311 | ptr_time_info_glc = localtime(&epoch_time_glc); // Structure accepts the time in local format from "time_t" type. |
nidhinvarghese | 15:208b146151ba | 312 | /* |
nidhinvarghese | 15:208b146151ba | 313 | //BELOW LINE IS TO CHECK Date and TIME |
nidhinvarghese | 15:208b146151ba | 314 | 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 | 315 | 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 | 316 | */ |
nidhinvarghese | 15:208b146151ba | 317 | //Copying from one structure to the other using variables |
nidhinvarghese | 15:208b146151ba | 318 | DateTime_info_glc.hour = (uint8_t)(*ptr_time_info_glc).tm_hour; |
nidhinvarghese | 15:208b146151ba | 319 | DateTime_info_glc.mins = (uint8_t)(*ptr_time_info_glc).tm_min; |
nidhinvarghese | 15:208b146151ba | 320 | DateTime_info_glc.sec = (uint8_t)(*ptr_time_info_glc).tm_sec; |
nidhinvarghese | 15:208b146151ba | 321 | |
nidhinvarghese | 15:208b146151ba | 322 | DateTime_info_glc.date = (uint8_t) (*ptr_time_info_glc).tm_mday; |
nidhinvarghese | 15:208b146151ba | 323 | DateTime_info_glc.month =(uint8_t)(*ptr_time_info_glc).tm_mon+1; |
nidhinvarghese | 15:208b146151ba | 324 | DateTime_info_glc.year = (uint8_t)(*ptr_time_info_glc).tm_year-100; |
nidhinvarghese | 15:208b146151ba | 325 | |
nidhinvarghese | 15:208b146151ba | 326 | // Copying Time to Main structure |
nidhinvarghese | 15:208b146151ba | 327 | BLEMsg_info_glc.date_time.hour = DateTime_info_glc.hour; |
nidhinvarghese | 15:208b146151ba | 328 | BLEMsg_info_glc.date_time.mins = DateTime_info_glc.mins; |
nidhinvarghese | 15:208b146151ba | 329 | BLEMsg_info_glc.date_time.sec = DateTime_info_glc.sec; |
nidhinvarghese | 15:208b146151ba | 330 | |
nidhinvarghese | 15:208b146151ba | 331 | BLEMsg_info_glc.date_time.date = DateTime_info_glc.date ; |
nidhinvarghese | 15:208b146151ba | 332 | BLEMsg_info_glc.date_time.month = DateTime_info_glc.month ; |
nidhinvarghese | 15:208b146151ba | 333 | BLEMsg_info_glc.date_time.year = DateTime_info_glc.year ; |
nidhinvarghese | 15:208b146151ba | 334 | |
nidhinvarghese | 15:208b146151ba | 335 | /* |
nidhinvarghese | 15:208b146151ba | 336 | //Checking if the structure has these values |
nidhinvarghese | 15:208b146151ba | 337 | gtc.printf("\nTime 2 is - %d:%d:%d\n", DateTime_info_glc.hour, DateTime_info_glc.mins, DateTime_info_glc.sec); |
nidhinvarghese | 15:208b146151ba | 338 | gtc.printf("\nDate 2 is - %d:%d:%d\n",DateTime_info_glc.date, DateTime_info_glc.month, DateTime_info_glc.year); |
nidhinvarghese | 15:208b146151ba | 339 | */ |
nidhinvarghese | 15:208b146151ba | 340 | |
nidhinvarghese | 15:208b146151ba | 341 | //Loading values to of Test type |
nidhinvarghese | 15:208b146151ba | 342 | test_type_info test_type_info_glc; // copy of " test_type_info" created |
nidhinvarghese | 15:208b146151ba | 343 | test_type_info_glc = BG_Test; // Loaded value 00 to the test type |
nidhinvarghese | 15:208b146151ba | 344 | |
nidhinvarghese | 15:208b146151ba | 345 | BLEMsg_info_glc.test_type = test_type_info_glc; |
nidhinvarghese | 15:208b146151ba | 346 | //Check if 01 is getting printed |
nidhinvarghese | 15:208b146151ba | 347 | //gtc.printf("\nTest Type for BG is 01 = %d\n", test_type_info_glc); |
nidhinvarghese | 15:208b146151ba | 348 | |
nidhinvarghese | 15:208b146151ba | 349 | |
nidhinvarghese | 15:208b146151ba | 350 | // Loading values of Length , PID, DID, sampling frequency, number of samples, calculated data. |
nidhinvarghese | 15:208b146151ba | 351 | BLEMsg_info_glc.device_id = 01; // Device ID fixed |
nikitateggi | 16:8fa1d7fd7953 | 352 | BLEMsg_info_glc.patient_id = (uint16_t)pid; // Patient ID |
nidhinvarghese | 15:208b146151ba | 353 | BLEMsg_info_glc.sampling_freq = 0; // sampling frrquency |
nidhinvarghese | 15:208b146151ba | 354 | BLEMsg_info_glc.length = 30; //Total length of data in bytes 22 B+10752 B |
nidhinvarghese | 15:208b146151ba | 355 | |
nidhinvarghese | 15:208b146151ba | 356 | BLEMsg_info_glc.num_samples.num_sample_ecg_OTtyp = 2; |
nidhinvarghese | 15:208b146151ba | 357 | BLEMsg_info_glc.num_samples.num_sample_ppg_dummy = 0; |
nidhinvarghese | 15:208b146151ba | 358 | |
nidhinvarghese | 15:208b146151ba | 359 | |
nidhinvarghese | 15:208b146151ba | 360 | |
nidhinvarghese | 15:208b146151ba | 361 | GLC_START = 1; |
nidhinvarghese | 15:208b146151ba | 362 | // ble.baud(115200); |
nidhinvarghese | 15:208b146151ba | 363 | if(GLC_START == 1) |
nidhinvarghese | 15:208b146151ba | 364 | { |
nidhinvarghese | 15:208b146151ba | 365 | glc_1(); // displaying messages to insert the test strip |
nidhinvarghese | 15:208b146151ba | 366 | err = 0; |
nidhinvarghese | 15:208b146151ba | 367 | data1n = 0; |
nidhinvarghese | 15:208b146151ba | 368 | data2n = 0; |
nidhinvarghese | 15:208b146151ba | 369 | daata1 = 0; |
nidhinvarghese | 15:208b146151ba | 370 | data2 = 0; |
nidhinvarghese | 15:208b146151ba | 371 | //sd_open_GLCfile(pid); // opening the glc file Commented |
nidhinvarghese | 15:208b146151ba | 372 | |
nidhinvarghese | 15:208b146151ba | 373 | while((test_strip)); |
nidhinvarghese | 15:208b146151ba | 374 | |
nidhinvarghese | 15:208b146151ba | 375 | if (!test_strip) // checks for the presence of test strip |
nidhinvarghese | 15:208b146151ba | 376 | { |
nidhinvarghese | 15:208b146151ba | 377 | flipper.attach(&sample, 0.8); |
nidhinvarghese | 15:208b146151ba | 378 | t_s_d = 0; |
nidhinvarghese | 15:208b146151ba | 379 | glc_2(); // displaying message to insert blood |
nidhinvarghese | 15:208b146151ba | 380 | |
nidhinvarghese | 15:208b146151ba | 381 | while((!t_s_d) && (!test_strip)) |
nidhinvarghese | 15:208b146151ba | 382 | { |
nidhinvarghese | 15:208b146151ba | 383 | //if(chk_glc_data == 0) //Nidhin 31/5/2017 |
nidhinvarghese | 15:208b146151ba | 384 | //{ |
nidhinvarghese | 15:208b146151ba | 385 | /* |
nikitateggi | 16:8fa1d7fd7953 | 386 | glcraw[0] = (uint16_t) data1n; //Nidhin 31/5/2017 |
nikitateggi | 16:8fa1d7fd7953 | 387 | glcraw[1] = (uint16_t) data2n; // Nidhin 31/5/2017 |
nidhinvarghese | 15:208b146151ba | 388 | |
nidhinvarghese | 15:208b146151ba | 389 | gtc.printf("datain is =%d\n", data1n); |
nidhinvarghese | 15:208b146151ba | 390 | gtc.printf("data2n is = %d\n", data2n); |
nidhinvarghese | 15:208b146151ba | 391 | |
nidhinvarghese | 15:208b146151ba | 392 | gtc.printf("datain is =%d\n", data1n); |
nidhinvarghese | 15:208b146151ba | 393 | gtc.printf("data2n is = %d\n", data2n); |
nidhinvarghese | 15:208b146151ba | 394 | */ |
nidhinvarghese | 15:208b146151ba | 395 | //chk_glc_data = 1; |
nidhinvarghese | 15:208b146151ba | 396 | //} |
nidhinvarghese | 15:208b146151ba | 397 | //gtc.printf("Checking\n"); |
nidhinvarghese | 15:208b146151ba | 398 | |
nidhinvarghese | 15:208b146151ba | 399 | if ((daata1 >= THRESHOLD) || (data2 >= THRESHOLD)) |
nidhinvarghese | 15:208b146151ba | 400 | { |
nikitateggi | 16:8fa1d7fd7953 | 401 | //glcraw[0] = (uint16_t) data1n; //Nidhin 5/6/2017 |
nikitateggi | 16:8fa1d7fd7953 | 402 | //glcraw[1] = (uint16_t) data2n; // Nidhin 5/6/2017 |
nidhinvarghese | 15:208b146151ba | 403 | |
nidhinvarghese | 15:208b146151ba | 404 | //gtc.printf("data1n is =%d\n", data1n); |
nidhinvarghese | 15:208b146151ba | 405 | //gtc.printf("data2n is = %d\n", data2n); |
nidhinvarghese | 15:208b146151ba | 406 | |
nidhinvarghese | 15:208b146151ba | 407 | // gtc.printf("glcraw[0] is =%d\n", glcraw[0]); |
nidhinvarghese | 15:208b146151ba | 408 | //gtc.printf("glcraw[1] is = %d\n", glcraw[1]); |
nidhinvarghese | 15:208b146151ba | 409 | |
nidhinvarghese | 15:208b146151ba | 410 | t_s_d = 1; |
nidhinvarghese | 15:208b146151ba | 411 | flipper1.attach(&Compute, 2.25); //computing the glucose level |
nidhinvarghese | 15:208b146151ba | 412 | glc_3(); |
nidhinvarghese | 15:208b146151ba | 413 | } |
nidhinvarghese | 15:208b146151ba | 414 | else |
nidhinvarghese | 15:208b146151ba | 415 | { |
nidhinvarghese | 15:208b146151ba | 416 | //wait for insertion of blood; |
nidhinvarghese | 15:208b146151ba | 417 | } |
nidhinvarghese | 15:208b146151ba | 418 | } |
nidhinvarghese | 15:208b146151ba | 419 | wait_ms(800); |
nidhinvarghese | 15:208b146151ba | 420 | } |
nikitateggi | 16:8fa1d7fd7953 | 421 | |
nidhinvarghese | 17:22a87e12fb3a | 422 | //gtc.printf("mgdl is - %d\n", mgdll); |
nidhinvarghese | 15:208b146151ba | 423 | } |
nikitateggi | 16:8fa1d7fd7953 | 424 | wait(2.25); |
nidhinvarghese | 15:208b146151ba | 425 | gtc.printf("DATA1 is - %d\n", data1n); |
nidhinvarghese | 15:208b146151ba | 426 | gtc.printf("DATA2 is - %d\n", data2n); |
nikitateggi | 16:8fa1d7fd7953 | 427 | gtc.printf("mgdl is - %d\n", mgdll); |
nidhinvarghese | 15:208b146151ba | 428 | |
nidhinvarghese | 17:22a87e12fb3a | 429 | glcraw[0] = (uint32_t)data1n; |
nidhinvarghese | 17:22a87e12fb3a | 430 | glcraw[1] = (uint32_t)data2n; |
nidhinvarghese | 17:22a87e12fb3a | 431 | |
nidhinvarghese | 17:22a87e12fb3a | 432 | sd_glcwrite(glcraw, pid); //Writes the raw data into GLC file |
nidhinvarghese | 15:208b146151ba | 433 | |
nikitateggi | 20:7c64e6ecad76 | 434 | //Results Stored to Bluetooth structure |
nikitateggi | 20:7c64e6ecad76 | 435 | 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 |
nikitateggi | 20:7c64e6ecad76 | 436 | BLEMsg_info_glc.cal_data.cal_sbp_dummy = (uint16_t) glc_testtype; // Data stored into structure |
nidhinvarghese | 15:208b146151ba | 437 | BLEMsg_info_glc.cal_data.cal_dbp_OTtyp = (uint16_t) mgdll; //To be checked for reliable results |
nidhinvarghese | 15:208b146151ba | 438 | |
nidhinvarghese | 15:208b146151ba | 439 | structure_file(ptr_BLEMsg_info_glc, pid); // Copy the structure into the GLC file |
nidhinvarghese | 15:208b146151ba | 440 | glcfile_mainfile(pid); |
nidhinvarghese | 15:208b146151ba | 441 | |
nidhinvarghese | 15:208b146151ba | 442 | } |
nidhinvarghese | 15:208b146151ba | 443 | |
nikitateggi | 1:8316c23ec6b9 | 444 | |
nikitateggi | 1:8316c23ec6b9 | 445 | |
nikitateggi | 1:8316c23ec6b9 | 446 | |
nikitateggi | 1:8316c23ec6b9 | 447 | |
nidhinvarghese | 15:208b146151ba | 448 | |
nidhinvarghese | 15:208b146151ba | 449 | |
nidhinvarghese | 15:208b146151ba | 450 | |
nidhinvarghese | 15:208b146151ba | 451 |