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@15:208b146151ba, 2017-06-05 (annotated)
- Committer:
- nidhinvarghese
- Date:
- Mon Jun 05 09:14:44 2017 +0000
- Revision:
- 15:208b146151ba
- Parent:
- 7:11f926351d8f
- Child:
- 16:8fa1d7fd7953
Heart rate is calculated; GLC - Not working
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" |
nidhinvarghese | 15:208b146151ba | 183 | |
nidhinvarghese | 15:208b146151ba | 184 | #include "struct.h" //Nidhin 31/5/2017 |
nidhinvarghese | 15:208b146151ba | 185 | #include "test_type.h" //Nidhin 31/5/2017 |
nidhinvarghese | 15:208b146151ba | 186 | |
nidhinvarghese | 15:208b146151ba | 187 | |
nidhinvarghese | 15:208b146151ba | 188 | void sample(); |
nidhinvarghese | 15:208b146151ba | 189 | void Compute(); |
nidhinvarghese | 15:208b146151ba | 190 | void i2c_spec(); |
nidhinvarghese | 15:208b146151ba | 191 | Ticker flipper; |
nidhinvarghese | 15:208b146151ba | 192 | Ticker flipper1; |
nidhinvarghese | 15:208b146151ba | 193 | |
nidhinvarghese | 15:208b146151ba | 194 | //osTimerDef (sample_data, sample); // define timers |
nidhinvarghese | 15:208b146151ba | 195 | //osTimerDef (Compute_GLC, Compute); |
nidhinvarghese | 15:208b146151ba | 196 | DigitalIn test_strip(PTA12); |
nidhinvarghese | 15:208b146151ba | 197 | |
nidhinvarghese | 15:208b146151ba | 198 | AnalogIn Ain(PTC1);//Electrode one |
nidhinvarghese | 15:208b146151ba | 199 | AnalogIn Ain2(PTE29); // Electrode two |
nidhinvarghese | 15:208b146151ba | 200 | AnalogOut DAC_signal(PTE30); |
nidhinvarghese | 15:208b146151ba | 201 | Serial gtc(USBTX, USBRX); |
nidhinvarghese | 15:208b146151ba | 202 | //unsigned char c; |
nidhinvarghese | 15:208b146151ba | 203 | //unsigned char HOME = 0; |
nidhinvarghese | 15:208b146151ba | 204 | |
nidhinvarghese | 15:208b146151ba | 205 | //signed char test_strip = 0; |
nidhinvarghese | 15:208b146151ba | 206 | static uint16_t mgdl = 0; |
nidhinvarghese | 15:208b146151ba | 207 | uint16_t mgdll = 0; |
nidhinvarghese | 15:208b146151ba | 208 | uint32_t daata1= 0; |
nidhinvarghese | 15:208b146151ba | 209 | uint32_t data2 = 0; |
nidhinvarghese | 15:208b146151ba | 210 | |
nidhinvarghese | 15:208b146151ba | 211 | static uint32_t data1n= 0; |
nidhinvarghese | 15:208b146151ba | 212 | static uint32_t data2n = 0; |
nidhinvarghese | 15:208b146151ba | 213 | uint32_t datafinal1 = 0; |
nidhinvarghese | 15:208b146151ba | 214 | uint32_t datafinal2 = 0; |
nidhinvarghese | 15:208b146151ba | 215 | //unsigned int data_diff = 0; |
nidhinvarghese | 15:208b146151ba | 216 | unsigned char err = 0; |
nidhinvarghese | 15:208b146151ba | 217 | |
nidhinvarghese | 15:208b146151ba | 218 | uint32_t glcraw[2]; // Nidhin 31/5/2017 |
nidhinvarghese | 15:208b146151ba | 219 | uint8_t chk_glc_data = 0; |
nidhinvarghese | 15:208b146151ba | 220 | |
nidhinvarghese | 15:208b146151ba | 221 | Serial ble(PTC4,PTC3); |
nidhinvarghese | 15:208b146151ba | 222 | |
nidhinvarghese | 15:208b146151ba | 223 | |
nidhinvarghese | 15:208b146151ba | 224 | |
nidhinvarghese | 15:208b146151ba | 225 | void sample() |
nidhinvarghese | 15:208b146151ba | 226 | |
nidhinvarghese | 15:208b146151ba | 227 | { |
nidhinvarghese | 15:208b146151ba | 228 | data1n = Ain.read_u16(); |
nidhinvarghese | 15:208b146151ba | 229 | data2n = Ain2.read_u16(); |
nidhinvarghese | 15:208b146151ba | 230 | daata1 = beta*daata1+alpha*data1n; |
nidhinvarghese | 15:208b146151ba | 231 | data2 = beta*data2+alpha*data2n; |
nidhinvarghese | 15:208b146151ba | 232 | |
nidhinvarghese | 15:208b146151ba | 233 | if( ((daata1-data2) >=(data2/10) && (daata1 > data2)) || ((data2-daata1) >=(data2/10) && (data2 > daata1)) ) |
nidhinvarghese | 15:208b146151ba | 234 | { |
nidhinvarghese | 15:208b146151ba | 235 | |
nidhinvarghese | 15:208b146151ba | 236 | err = 1; |
nidhinvarghese | 15:208b146151ba | 237 | |
nidhinvarghese | 15:208b146151ba | 238 | } |
nidhinvarghese | 15:208b146151ba | 239 | else |
nidhinvarghese | 15:208b146151ba | 240 | { |
nidhinvarghese | 15:208b146151ba | 241 | err = 0; |
nidhinvarghese | 15:208b146151ba | 242 | //gtc.printf("\n", data1n, data2n); only for testing added nidhin 5Jun17 |
nidhinvarghese | 15:208b146151ba | 243 | } |
nidhinvarghese | 15:208b146151ba | 244 | |
nidhinvarghese | 15:208b146151ba | 245 | } |
nidhinvarghese | 15:208b146151ba | 246 | |
nidhinvarghese | 15:208b146151ba | 247 | |
nidhinvarghese | 15:208b146151ba | 248 | |
nidhinvarghese | 15:208b146151ba | 249 | void Compute() |
nidhinvarghese | 15:208b146151ba | 250 | { |
nidhinvarghese | 15:208b146151ba | 251 | |
nidhinvarghese | 15:208b146151ba | 252 | |
nidhinvarghese | 15:208b146151ba | 253 | datafinal1 = (uint32_t ) NUMB1*(data2*VREF/(TOTAL))-NUMB2; |
nidhinvarghese | 15:208b146151ba | 254 | datafinal2 = (uint32_t ) NUMB1*(daata1*VREF/(TOTAL))-NUMB2; |
nidhinvarghese | 15:208b146151ba | 255 | mgdl = (uint16_t) NUMB1*(((daata1+data2)/2)*VREF/(TOTAL))-NUMB2; // Nidhin 5/6/17 mgdl = (uint32_t) NUMB1*(((daata1+data2)/2)*VREF/(TOTAL))-NUMB2; |
nidhinvarghese | 15:208b146151ba | 256 | |
nidhinvarghese | 15:208b146151ba | 257 | |
nidhinvarghese | 15:208b146151ba | 258 | |
nidhinvarghese | 15:208b146151ba | 259 | if (err == 0) |
nidhinvarghese | 15:208b146151ba | 260 | { |
nidhinvarghese | 15:208b146151ba | 261 | |
nidhinvarghese | 15:208b146151ba | 262 | glc_4(mgdl); |
nidhinvarghese | 15:208b146151ba | 263 | mgdll = mgdl; // Nidhin 31/5/2017 |
nidhinvarghese | 15:208b146151ba | 264 | //gtc.printf("The Result is - %d", mgdll); |
nidhinvarghese | 15:208b146151ba | 265 | //sd_write(mgdl); // storing value into the sd card |
nidhinvarghese | 15:208b146151ba | 266 | //sd_close(); |
nidhinvarghese | 15:208b146151ba | 267 | // ble.printf("blood glucose is %d mg/dl", mgdl); |
nidhinvarghese | 15:208b146151ba | 268 | flipper.detach(); |
nidhinvarghese | 15:208b146151ba | 269 | flipper1.detach(); |
nidhinvarghese | 15:208b146151ba | 270 | // return mgdl; |
nidhinvarghese | 15:208b146151ba | 271 | |
nidhinvarghese | 15:208b146151ba | 272 | |
nidhinvarghese | 15:208b146151ba | 273 | } |
nidhinvarghese | 15:208b146151ba | 274 | |
nidhinvarghese | 15:208b146151ba | 275 | else |
nidhinvarghese | 15:208b146151ba | 276 | { |
nidhinvarghese | 15:208b146151ba | 277 | gtc.printf("err=1\n"); |
nidhinvarghese | 15:208b146151ba | 278 | |
nidhinvarghese | 15:208b146151ba | 279 | // lcd1.Print( " ERROR RESULT", 5,220,COLOR_RED,COLOR_BLACK, 0); |
nidhinvarghese | 15:208b146151ba | 280 | // ble.printf("E:"); |
nidhinvarghese | 15:208b146151ba | 281 | } |
nidhinvarghese | 15:208b146151ba | 282 | |
nidhinvarghese | 15:208b146151ba | 283 | |
nidhinvarghese | 15:208b146151ba | 284 | } |
nidhinvarghese | 15:208b146151ba | 285 | |
nidhinvarghese | 15:208b146151ba | 286 | |
nidhinvarghese | 15:208b146151ba | 287 | void glc(int pid){ |
nidhinvarghese | 15:208b146151ba | 288 | unsigned char GLC_START = 0; |
nidhinvarghese | 15:208b146151ba | 289 | char t_s_d = 0; |
nidhinvarghese | 15:208b146151ba | 290 | i2c_spec(); |
nidhinvarghese | 15:208b146151ba | 291 | |
nidhinvarghese | 15:208b146151ba | 292 | sd_open_GLCfilee(pid); // Opens GLC file in APPEND mode |
nidhinvarghese | 15:208b146151ba | 293 | |
nidhinvarghese | 15:208b146151ba | 294 | // Bluetooth Structure created globally |
nidhinvarghese | 15:208b146151ba | 295 | 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 | 296 | ptr_BLEMsg_info_glc = &BLEMsg_info_glc; // *ptr_BLEMsg_info_bp is the pointer to local copy; |
nidhinvarghese | 15:208b146151ba | 297 | // Cant declare this statement outside main. Causing conflicts |
nidhinvarghese | 15:208b146151ba | 298 | |
nidhinvarghese | 15:208b146151ba | 299 | // Declaration of Date Structure |
nidhinvarghese | 15:208b146151ba | 300 | DateTime_info *ptr_DateTime_info_glc, DateTime_info_glc; // A copy of Master Structure "DateTime_info" created, |
nidhinvarghese | 15:208b146151ba | 301 | ptr_DateTime_info_glc = &DateTime_info_glc; // Structure pointer points to that copy. |
nidhinvarghese | 15:208b146151ba | 302 | |
nidhinvarghese | 15:208b146151ba | 303 | |
nidhinvarghese | 15:208b146151ba | 304 | |
nidhinvarghese | 15:208b146151ba | 305 | // RTC operations |
nidhinvarghese | 15:208b146151ba | 306 | time_t epoch_time_glc; //A copy of time_t by name epoch_time_bp is created |
nidhinvarghese | 15:208b146151ba | 307 | epoch_time_glc = rtc_read(); // time is got from get epoch function. |
nidhinvarghese | 15:208b146151ba | 308 | |
nidhinvarghese | 15:208b146151ba | 309 | struct tm * ptr_time_info_glc, time_info_glc; // Sturucture copy of tm is created |
nidhinvarghese | 15:208b146151ba | 310 | ptr_time_info_glc = localtime(&epoch_time_glc); // Structure accepts the time in local format from "time_t" type. |
nidhinvarghese | 15:208b146151ba | 311 | /* |
nidhinvarghese | 15:208b146151ba | 312 | //BELOW LINE IS TO CHECK Date and TIME |
nidhinvarghese | 15:208b146151ba | 313 | 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 | 314 | 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 | 315 | */ |
nidhinvarghese | 15:208b146151ba | 316 | //Copying from one structure to the other using variables |
nidhinvarghese | 15:208b146151ba | 317 | DateTime_info_glc.hour = (uint8_t)(*ptr_time_info_glc).tm_hour; |
nidhinvarghese | 15:208b146151ba | 318 | DateTime_info_glc.mins = (uint8_t)(*ptr_time_info_glc).tm_min; |
nidhinvarghese | 15:208b146151ba | 319 | DateTime_info_glc.sec = (uint8_t)(*ptr_time_info_glc).tm_sec; |
nidhinvarghese | 15:208b146151ba | 320 | |
nidhinvarghese | 15:208b146151ba | 321 | DateTime_info_glc.date = (uint8_t) (*ptr_time_info_glc).tm_mday; |
nidhinvarghese | 15:208b146151ba | 322 | DateTime_info_glc.month =(uint8_t)(*ptr_time_info_glc).tm_mon+1; |
nidhinvarghese | 15:208b146151ba | 323 | DateTime_info_glc.year = (uint8_t)(*ptr_time_info_glc).tm_year-100; |
nidhinvarghese | 15:208b146151ba | 324 | |
nidhinvarghese | 15:208b146151ba | 325 | // Copying Time to Main structure |
nidhinvarghese | 15:208b146151ba | 326 | BLEMsg_info_glc.date_time.hour = DateTime_info_glc.hour; |
nidhinvarghese | 15:208b146151ba | 327 | BLEMsg_info_glc.date_time.mins = DateTime_info_glc.mins; |
nidhinvarghese | 15:208b146151ba | 328 | BLEMsg_info_glc.date_time.sec = DateTime_info_glc.sec; |
nidhinvarghese | 15:208b146151ba | 329 | |
nidhinvarghese | 15:208b146151ba | 330 | BLEMsg_info_glc.date_time.date = DateTime_info_glc.date ; |
nidhinvarghese | 15:208b146151ba | 331 | BLEMsg_info_glc.date_time.month = DateTime_info_glc.month ; |
nidhinvarghese | 15:208b146151ba | 332 | BLEMsg_info_glc.date_time.year = DateTime_info_glc.year ; |
nidhinvarghese | 15:208b146151ba | 333 | |
nidhinvarghese | 15:208b146151ba | 334 | /* |
nidhinvarghese | 15:208b146151ba | 335 | //Checking if the structure has these values |
nidhinvarghese | 15:208b146151ba | 336 | gtc.printf("\nTime 2 is - %d:%d:%d\n", DateTime_info_glc.hour, DateTime_info_glc.mins, DateTime_info_glc.sec); |
nidhinvarghese | 15:208b146151ba | 337 | gtc.printf("\nDate 2 is - %d:%d:%d\n",DateTime_info_glc.date, DateTime_info_glc.month, DateTime_info_glc.year); |
nidhinvarghese | 15:208b146151ba | 338 | */ |
nidhinvarghese | 15:208b146151ba | 339 | |
nidhinvarghese | 15:208b146151ba | 340 | //Loading values to of Test type |
nidhinvarghese | 15:208b146151ba | 341 | test_type_info test_type_info_glc; // copy of " test_type_info" created |
nidhinvarghese | 15:208b146151ba | 342 | test_type_info_glc = BG_Test; // Loaded value 00 to the test type |
nidhinvarghese | 15:208b146151ba | 343 | |
nidhinvarghese | 15:208b146151ba | 344 | BLEMsg_info_glc.test_type = test_type_info_glc; |
nidhinvarghese | 15:208b146151ba | 345 | //Check if 01 is getting printed |
nidhinvarghese | 15:208b146151ba | 346 | //gtc.printf("\nTest Type for BG is 01 = %d\n", test_type_info_glc); |
nidhinvarghese | 15:208b146151ba | 347 | |
nidhinvarghese | 15:208b146151ba | 348 | |
nidhinvarghese | 15:208b146151ba | 349 | // Loading values of Length , PID, DID, sampling frequency, number of samples, calculated data. |
nidhinvarghese | 15:208b146151ba | 350 | BLEMsg_info_glc.device_id = 01; // Device ID fixed |
nidhinvarghese | 15:208b146151ba | 351 | BLEMsg_info_glc.patient_id = (uint32_t)pid; // Patient ID |
nidhinvarghese | 15:208b146151ba | 352 | BLEMsg_info_glc.sampling_freq = 0; // sampling frrquency |
nidhinvarghese | 15:208b146151ba | 353 | BLEMsg_info_glc.length = 30; //Total length of data in bytes 22 B+10752 B |
nidhinvarghese | 15:208b146151ba | 354 | |
nidhinvarghese | 15:208b146151ba | 355 | BLEMsg_info_glc.num_samples.num_sample_ecg_OTtyp = 2; |
nidhinvarghese | 15:208b146151ba | 356 | BLEMsg_info_glc.num_samples.num_sample_ppg_dummy = 0; |
nidhinvarghese | 15:208b146151ba | 357 | |
nidhinvarghese | 15:208b146151ba | 358 | |
nidhinvarghese | 15:208b146151ba | 359 | |
nidhinvarghese | 15:208b146151ba | 360 | GLC_START = 1; |
nidhinvarghese | 15:208b146151ba | 361 | // ble.baud(115200); |
nidhinvarghese | 15:208b146151ba | 362 | if(GLC_START == 1) |
nidhinvarghese | 15:208b146151ba | 363 | { |
nidhinvarghese | 15:208b146151ba | 364 | glc_1(); // displaying messages to insert the test strip |
nidhinvarghese | 15:208b146151ba | 365 | err = 0; |
nidhinvarghese | 15:208b146151ba | 366 | data1n = 0; |
nidhinvarghese | 15:208b146151ba | 367 | data2n = 0; |
nidhinvarghese | 15:208b146151ba | 368 | daata1 = 0; |
nidhinvarghese | 15:208b146151ba | 369 | data2 = 0; |
nidhinvarghese | 15:208b146151ba | 370 | //sd_open_GLCfile(pid); // opening the glc file Commented |
nidhinvarghese | 15:208b146151ba | 371 | |
nidhinvarghese | 15:208b146151ba | 372 | while((test_strip)); |
nidhinvarghese | 15:208b146151ba | 373 | |
nidhinvarghese | 15:208b146151ba | 374 | if (!test_strip) // checks for the presence of test strip |
nidhinvarghese | 15:208b146151ba | 375 | { |
nidhinvarghese | 15:208b146151ba | 376 | flipper.attach(&sample, 0.8); |
nidhinvarghese | 15:208b146151ba | 377 | t_s_d = 0; |
nidhinvarghese | 15:208b146151ba | 378 | glc_2(); // displaying message to insert blood |
nidhinvarghese | 15:208b146151ba | 379 | |
nidhinvarghese | 15:208b146151ba | 380 | while((!t_s_d) && (!test_strip)) |
nidhinvarghese | 15:208b146151ba | 381 | { |
nidhinvarghese | 15:208b146151ba | 382 | //if(chk_glc_data == 0) //Nidhin 31/5/2017 |
nidhinvarghese | 15:208b146151ba | 383 | //{ |
nidhinvarghese | 15:208b146151ba | 384 | /* |
nidhinvarghese | 15:208b146151ba | 385 | glcraw[0] = (uint32_t) data1n; //Nidhin 31/5/2017 |
nidhinvarghese | 15:208b146151ba | 386 | glcraw[1] = (uint32_t) data2n; // Nidhin 31/5/2017 |
nidhinvarghese | 15:208b146151ba | 387 | |
nidhinvarghese | 15:208b146151ba | 388 | gtc.printf("datain is =%d\n", data1n); |
nidhinvarghese | 15:208b146151ba | 389 | gtc.printf("data2n is = %d\n", data2n); |
nidhinvarghese | 15:208b146151ba | 390 | |
nidhinvarghese | 15:208b146151ba | 391 | gtc.printf("datain is =%d\n", data1n); |
nidhinvarghese | 15:208b146151ba | 392 | gtc.printf("data2n is = %d\n", data2n); |
nidhinvarghese | 15:208b146151ba | 393 | */ |
nidhinvarghese | 15:208b146151ba | 394 | //chk_glc_data = 1; |
nidhinvarghese | 15:208b146151ba | 395 | //} |
nidhinvarghese | 15:208b146151ba | 396 | //gtc.printf("Checking\n"); |
nidhinvarghese | 15:208b146151ba | 397 | |
nidhinvarghese | 15:208b146151ba | 398 | if ((daata1 >= THRESHOLD) || (data2 >= THRESHOLD)) |
nidhinvarghese | 15:208b146151ba | 399 | { |
nidhinvarghese | 15:208b146151ba | 400 | //glcraw[0] = (uint32_t) data1n; //Nidhin 5/6/2017 |
nidhinvarghese | 15:208b146151ba | 401 | //glcraw[1] = (uint32_t) data2n; // Nidhin 5/6/2017 |
nidhinvarghese | 15:208b146151ba | 402 | |
nidhinvarghese | 15:208b146151ba | 403 | //gtc.printf("data1n is =%d\n", data1n); |
nidhinvarghese | 15:208b146151ba | 404 | //gtc.printf("data2n is = %d\n", data2n); |
nidhinvarghese | 15:208b146151ba | 405 | |
nidhinvarghese | 15:208b146151ba | 406 | // gtc.printf("glcraw[0] is =%d\n", glcraw[0]); |
nidhinvarghese | 15:208b146151ba | 407 | //gtc.printf("glcraw[1] is = %d\n", glcraw[1]); |
nidhinvarghese | 15:208b146151ba | 408 | |
nidhinvarghese | 15:208b146151ba | 409 | t_s_d = 1; |
nidhinvarghese | 15:208b146151ba | 410 | flipper1.attach(&Compute, 2.25); //computing the glucose level |
nidhinvarghese | 15:208b146151ba | 411 | glc_3(); |
nidhinvarghese | 15:208b146151ba | 412 | } |
nidhinvarghese | 15:208b146151ba | 413 | else |
nidhinvarghese | 15:208b146151ba | 414 | { |
nidhinvarghese | 15:208b146151ba | 415 | //wait for insertion of blood; |
nidhinvarghese | 15:208b146151ba | 416 | } |
nidhinvarghese | 15:208b146151ba | 417 | } |
nidhinvarghese | 15:208b146151ba | 418 | wait_ms(800); |
nidhinvarghese | 15:208b146151ba | 419 | } |
nidhinvarghese | 15:208b146151ba | 420 | } |
nidhinvarghese | 15:208b146151ba | 421 | |
nidhinvarghese | 15:208b146151ba | 422 | gtc.printf("DATA1 is - %d\n", data1n); |
nidhinvarghese | 15:208b146151ba | 423 | gtc.printf("DATA2 is - %d\n", data2n); |
nidhinvarghese | 15:208b146151ba | 424 | gtc.printf("mgdl is - %d\n", mgdl); |
nidhinvarghese | 15:208b146151ba | 425 | |
nidhinvarghese | 15:208b146151ba | 426 | sd_glcwrite(glcraw, pid); //Writes the raw data into GLC file |
nidhinvarghese | 15:208b146151ba | 427 | |
nidhinvarghese | 15:208b146151ba | 428 | //Results Stored to Bluetooth structure |
nidhinvarghese | 15:208b146151ba | 429 | BLEMsg_info_glc.cal_data.cal_sbp_dummy = 0; |
nidhinvarghese | 15:208b146151ba | 430 | BLEMsg_info_glc.cal_data.cal_dbp_OTtyp = (uint16_t) mgdll; //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); |
nidhinvarghese | 15:208b146151ba | 434 | |
nidhinvarghese | 15:208b146151ba | 435 | } |
nidhinvarghese | 15:208b146151ba | 436 | |
nikitateggi | 1:8316c23ec6b9 | 437 | |
nikitateggi | 1:8316c23ec6b9 | 438 | |
nikitateggi | 1:8316c23ec6b9 | 439 | |
nikitateggi | 1:8316c23ec6b9 | 440 | |
nidhinvarghese | 15:208b146151ba | 441 | |
nidhinvarghese | 15:208b146151ba | 442 | |
nidhinvarghese | 15:208b146151ba | 443 | |
nidhinvarghese | 15:208b146151ba | 444 |