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@5:a3ea7c82b7e1, 2017-03-30 (annotated)
- Committer:
- suhasini
- Date:
- Thu Mar 30 11:34:04 2017 +0000
- Revision:
- 5:a3ea7c82b7e1
- Parent:
- 4:6bd81bb1790d
- Child:
- 7:11f926351d8f
PID updation possible, Proper screen navigation enabled, Return functionality from BP to main screen-done, date-time format modified, BP data not saved into SD card
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nikitateggi | 1:8316c23ec6b9 | 1 | #include "mbed.h" |
nikitateggi | 1:8316c23ec6b9 | 2 | #include "glc.h" |
nikitateggi | 1:8316c23ec6b9 | 3 | #include "i2c_dec.h" |
nikitateggi | 1:8316c23ec6b9 | 4 | #include "ili9325.h" |
nikitateggi | 1:8316c23ec6b9 | 5 | #include "lcd_base.h" |
nikitateggi | 1:8316c23ec6b9 | 6 | #include "display_modules.h" |
nikitateggi | 1:8316c23ec6b9 | 7 | //#include "touch_modules.h" |
nikitateggi | 1:8316c23ec6b9 | 8 | #include "rtc.h" |
nikitateggi | 1:8316c23ec6b9 | 9 | #include "sdcard.h" |
nikitateggi | 1:8316c23ec6b9 | 10 | |
nikitateggi | 1:8316c23ec6b9 | 11 | |
nikitateggi | 1:8316c23ec6b9 | 12 | void sample(); |
nikitateggi | 1:8316c23ec6b9 | 13 | void Compute(); |
nikitateggi | 1:8316c23ec6b9 | 14 | void i2c_spec(); |
nikitateggi | 1:8316c23ec6b9 | 15 | Ticker flipper; |
nikitateggi | 1:8316c23ec6b9 | 16 | Ticker flipper1; |
nikitateggi | 1:8316c23ec6b9 | 17 | |
nikitateggi | 1:8316c23ec6b9 | 18 | //osTimerDef (sample_data, sample); // define timers |
nikitateggi | 1:8316c23ec6b9 | 19 | //osTimerDef (Compute_GLC, Compute); |
nikitateggi | 1:8316c23ec6b9 | 20 | DigitalIn test_strip(PTA12); |
nikitateggi | 1:8316c23ec6b9 | 21 | |
nikitateggi | 1:8316c23ec6b9 | 22 | AnalogIn Ain(PTC1);//Electrode one |
nikitateggi | 1:8316c23ec6b9 | 23 | AnalogIn Ain2(PTE29); // Electrode two |
nikitateggi | 1:8316c23ec6b9 | 24 | AnalogOut DAC_signal(PTE30); |
nikitateggi | 4:6bd81bb1790d | 25 | Serial gtc(USBTX, USBRX); |
nikitateggi | 1:8316c23ec6b9 | 26 | //unsigned char c; |
nikitateggi | 1:8316c23ec6b9 | 27 | //unsigned char HOME = 0; |
nikitateggi | 4:6bd81bb1790d | 28 | |
nikitateggi | 1:8316c23ec6b9 | 29 | //signed char test_strip = 0; |
nikitateggi | 1:8316c23ec6b9 | 30 | unsigned int mgdl = 0; |
nikitateggi | 1:8316c23ec6b9 | 31 | unsigned int mgdll = 0; |
nikitateggi | 1:8316c23ec6b9 | 32 | unsigned int daata1= 0; |
nikitateggi | 1:8316c23ec6b9 | 33 | unsigned int data2 = 0; |
nikitateggi | 1:8316c23ec6b9 | 34 | |
nikitateggi | 1:8316c23ec6b9 | 35 | unsigned int data1n= 0; |
nikitateggi | 1:8316c23ec6b9 | 36 | unsigned int data2n = 0; |
nikitateggi | 1:8316c23ec6b9 | 37 | unsigned int datafinal1 = 0; |
nikitateggi | 1:8316c23ec6b9 | 38 | unsigned int datafinal2 = 0; |
nikitateggi | 1:8316c23ec6b9 | 39 | //unsigned int data_diff = 0; |
nikitateggi | 1:8316c23ec6b9 | 40 | unsigned char err = 0; |
nikitateggi | 1:8316c23ec6b9 | 41 | |
nikitateggi | 1:8316c23ec6b9 | 42 | Serial ble(PTC4,PTC3); |
nikitateggi | 1:8316c23ec6b9 | 43 | |
nikitateggi | 4:6bd81bb1790d | 44 | |
nikitateggi | 4:6bd81bb1790d | 45 | |
nikitateggi | 1:8316c23ec6b9 | 46 | void sample() |
nikitateggi | 1:8316c23ec6b9 | 47 | |
nikitateggi | 1:8316c23ec6b9 | 48 | { |
nikitateggi | 1:8316c23ec6b9 | 49 | data1n = Ain.read_u16(); |
nikitateggi | 1:8316c23ec6b9 | 50 | data2n = Ain2.read_u16(); |
nikitateggi | 1:8316c23ec6b9 | 51 | daata1 = beta*daata1+alpha*data1n; |
nikitateggi | 1:8316c23ec6b9 | 52 | data2 = beta*data2+alpha*data2n; |
nikitateggi | 1:8316c23ec6b9 | 53 | |
nikitateggi | 1:8316c23ec6b9 | 54 | if( ((daata1-data2) >=(data2/10) && (daata1 > data2)) || ((data2-daata1) >=(data2/10) && (data2 > daata1)) ) |
nikitateggi | 1:8316c23ec6b9 | 55 | { |
nikitateggi | 1:8316c23ec6b9 | 56 | |
nikitateggi | 1:8316c23ec6b9 | 57 | err = 1; |
nikitateggi | 1:8316c23ec6b9 | 58 | } |
nikitateggi | 1:8316c23ec6b9 | 59 | else |
nikitateggi | 1:8316c23ec6b9 | 60 | { |
nikitateggi | 1:8316c23ec6b9 | 61 | err = 0; |
nikitateggi | 1:8316c23ec6b9 | 62 | } |
nikitateggi | 1:8316c23ec6b9 | 63 | |
nikitateggi | 1:8316c23ec6b9 | 64 | } |
nikitateggi | 1:8316c23ec6b9 | 65 | |
nikitateggi | 4:6bd81bb1790d | 66 | |
nikitateggi | 4:6bd81bb1790d | 67 | |
nikitateggi | 1:8316c23ec6b9 | 68 | void Compute() |
nikitateggi | 1:8316c23ec6b9 | 69 | { |
nikitateggi | 1:8316c23ec6b9 | 70 | |
nikitateggi | 4:6bd81bb1790d | 71 | |
nikitateggi | 1:8316c23ec6b9 | 72 | datafinal1 = (unsigned int) NUMB1*(data2*VREF/(TOTAL))-NUMB2; |
nikitateggi | 1:8316c23ec6b9 | 73 | datafinal2 = (unsigned int) NUMB1*(daata1*VREF/(TOTAL))-NUMB2; |
nikitateggi | 1:8316c23ec6b9 | 74 | mgdl = (unsigned int) NUMB1*(((daata1+data2)/2)*VREF/(TOTAL))-NUMB2; |
nikitateggi | 1:8316c23ec6b9 | 75 | |
nikitateggi | 1:8316c23ec6b9 | 76 | |
nikitateggi | 1:8316c23ec6b9 | 77 | if (err == 0) |
nikitateggi | 1:8316c23ec6b9 | 78 | { |
nikitateggi | 1:8316c23ec6b9 | 79 | |
nikitateggi | 1:8316c23ec6b9 | 80 | glc_4(mgdl); |
nikitateggi | 4:6bd81bb1790d | 81 | sd_write(mgdl); // storing value into the sd card |
nikitateggi | 1:8316c23ec6b9 | 82 | sd_close(); |
nikitateggi | 2:3b7b71bfc941 | 83 | ble.printf("blood glucose is %d mg/dl", mgdl); |
nikitateggi | 1:8316c23ec6b9 | 84 | flipper.detach(); |
nikitateggi | 1:8316c23ec6b9 | 85 | flipper1.detach(); |
nikitateggi | 1:8316c23ec6b9 | 86 | // return mgdl; |
nikitateggi | 1:8316c23ec6b9 | 87 | |
nikitateggi | 1:8316c23ec6b9 | 88 | } |
nikitateggi | 4:6bd81bb1790d | 89 | |
nikitateggi | 1:8316c23ec6b9 | 90 | else |
nikitateggi | 1:8316c23ec6b9 | 91 | { |
nikitateggi | 1:8316c23ec6b9 | 92 | // lcd1.Print( " ERROR RESULT", 5,220,COLOR_RED,COLOR_BLACK, 0); |
nikitateggi | 1:8316c23ec6b9 | 93 | // ble.printf("E:"); |
nikitateggi | 1:8316c23ec6b9 | 94 | } |
nikitateggi | 1:8316c23ec6b9 | 95 | |
nikitateggi | 1:8316c23ec6b9 | 96 | |
nikitateggi | 1:8316c23ec6b9 | 97 | } |
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 | |
nikitateggi | 1:8316c23ec6b9 | 106 | |
nikitateggi | 1:8316c23ec6b9 | 107 | |
nikitateggi | 1:8316c23ec6b9 | 108 | |
nikitateggi | 1:8316c23ec6b9 | 109 | |
nikitateggi | 1:8316c23ec6b9 | 110 | |
nikitateggi | 1:8316c23ec6b9 | 111 | |
nikitateggi | 1:8316c23ec6b9 | 112 | |
nikitateggi | 1:8316c23ec6b9 | 113 | |
nikitateggi | 1:8316c23ec6b9 | 114 | |
nikitateggi | 1:8316c23ec6b9 | 115 | |
nikitateggi | 1:8316c23ec6b9 | 116 | void glc(int pid){ |
nikitateggi | 4:6bd81bb1790d | 117 | unsigned char GLC_START = 0; |
nikitateggi | 1:8316c23ec6b9 | 118 | char t_s_d = 0; |
nikitateggi | 4:6bd81bb1790d | 119 | i2c_spec(); |
nikitateggi | 4:6bd81bb1790d | 120 | GLC_START = 1; |
nikitateggi | 4:6bd81bb1790d | 121 | // ble.baud(115200); |
nikitateggi | 4:6bd81bb1790d | 122 | if(GLC_START == 1) |
nikitateggi | 1:8316c23ec6b9 | 123 | { |
nikitateggi | 1:8316c23ec6b9 | 124 | |
nikitateggi | 1:8316c23ec6b9 | 125 | //DisableTouch(); |
nikitateggi | 1:8316c23ec6b9 | 126 | //gpo_t = 0; |
nikitateggi | 1:8316c23ec6b9 | 127 | //lcd1.FillRect(5,127,230,320,COLOR_BLACK); |
nikitateggi | 4:6bd81bb1790d | 128 | glc_1(); // displaying messages to insert the test strip |
nikitateggi | 1:8316c23ec6b9 | 129 | err = 0; |
nikitateggi | 1:8316c23ec6b9 | 130 | data1n = 0; |
nikitateggi | 1:8316c23ec6b9 | 131 | data2n = 0; |
nikitateggi | 1:8316c23ec6b9 | 132 | daata1 = 0; |
nikitateggi | 1:8316c23ec6b9 | 133 | data2 = 0; |
nikitateggi | 4:6bd81bb1790d | 134 | sd_open_GLCfile(pid); // opening the glc file |
nikitateggi | 1:8316c23ec6b9 | 135 | |
nikitateggi | 1:8316c23ec6b9 | 136 | while((test_strip)); |
nikitateggi | 1:8316c23ec6b9 | 137 | |
nikitateggi | 1:8316c23ec6b9 | 138 | |
nikitateggi | 1:8316c23ec6b9 | 139 | // wait(500); |
nikitateggi | 1:8316c23ec6b9 | 140 | // Shutdown = 1; |
nikitateggi | 1:8316c23ec6b9 | 141 | |
nikitateggi | 4:6bd81bb1790d | 142 | if (!test_strip) // checks for the presence of test strip |
nikitateggi | 1:8316c23ec6b9 | 143 | { |
nikitateggi | 1:8316c23ec6b9 | 144 | |
nikitateggi | 4:6bd81bb1790d | 145 | flipper.attach(&sample, 0.8); |
nikitateggi | 1:8316c23ec6b9 | 146 | t_s_d = 0; |
nikitateggi | 4:6bd81bb1790d | 147 | glc_2(); // displaying message to insert blood |
nikitateggi | 4:6bd81bb1790d | 148 | |
nikitateggi | 4:6bd81bb1790d | 149 | while((!t_s_d) && (!test_strip)) |
nikitateggi | 1:8316c23ec6b9 | 150 | { |
nikitateggi | 1:8316c23ec6b9 | 151 | |
suhasini | 5:a3ea7c82b7e1 | 152 | gtc.printf("%d\n", data1n); |
suhasini | 5:a3ea7c82b7e1 | 153 | gtc.printf("%d\n", data2n); |
nikitateggi | 1:8316c23ec6b9 | 154 | if ((daata1 >= THRESHOLD) || (data2 >= THRESHOLD)) |
nikitateggi | 1:8316c23ec6b9 | 155 | { |
nikitateggi | 1:8316c23ec6b9 | 156 | t_s_d = 1; |
nikitateggi | 4:6bd81bb1790d | 157 | flipper1.attach(&Compute, 2.25); //computing the glucose level |
nikitateggi | 1:8316c23ec6b9 | 158 | glc_3(); |
nikitateggi | 1:8316c23ec6b9 | 159 | |
nikitateggi | 1:8316c23ec6b9 | 160 | |
nikitateggi | 1:8316c23ec6b9 | 161 | } |
nikitateggi | 1:8316c23ec6b9 | 162 | else |
nikitateggi | 1:8316c23ec6b9 | 163 | { |
nikitateggi | 1:8316c23ec6b9 | 164 | //wait for insertion of blood; |
nikitateggi | 1:8316c23ec6b9 | 165 | } |
nikitateggi | 1:8316c23ec6b9 | 166 | |
nikitateggi | 1:8316c23ec6b9 | 167 | } |
nikitateggi | 1:8316c23ec6b9 | 168 | |
nikitateggi | 1:8316c23ec6b9 | 169 | |
nikitateggi | 1:8316c23ec6b9 | 170 | // t_s_d = 0; |
nikitateggi | 1:8316c23ec6b9 | 171 | wait_ms(800); |
nikitateggi | 1:8316c23ec6b9 | 172 | //flipper.detach(); |
nikitateggi | 1:8316c23ec6b9 | 173 | |
nikitateggi | 1:8316c23ec6b9 | 174 | } |
nikitateggi | 1:8316c23ec6b9 | 175 | |
nikitateggi | 1:8316c23ec6b9 | 176 | |
nikitateggi | 1:8316c23ec6b9 | 177 | } |
nikitateggi | 1:8316c23ec6b9 | 178 | |
nikitateggi | 1:8316c23ec6b9 | 179 | } |
nikitateggi | 1:8316c23ec6b9 | 180 | |
nikitateggi | 1:8316c23ec6b9 | 181 | |
nikitateggi | 1:8316c23ec6b9 | 182 | |
nikitateggi | 1:8316c23ec6b9 | 183 | |
nikitateggi | 1:8316c23ec6b9 | 184 |