Updated with option to return from BP screen to main screen, resolved screen navigation issues
Dependencies: SDFileSystem TFTLCD_8bit ds3231 program mbed
Fork of poc_dis_5 by
glc.cpp@1:8316c23ec6b9, 2017-01-30 (annotated)
- Committer:
- nikitateggi
- Date:
- Mon Jan 30 07:45:41 2017 +0000
- Revision:
- 1:8316c23ec6b9
- Child:
- 2:3b7b71bfc941
POC code
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 | 1:8316c23ec6b9 | 25 | //Serial gc(USBTX, USBRX); |
nikitateggi | 1:8316c23ec6b9 | 26 | //unsigned char c; |
nikitateggi | 1:8316c23ec6b9 | 27 | //unsigned char HOME = 0; |
nikitateggi | 1:8316c23ec6b9 | 28 | unsigned char GLC_START = 0; |
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 | 1:8316c23ec6b9 | 44 | void sample() |
nikitateggi | 1:8316c23ec6b9 | 45 | |
nikitateggi | 1:8316c23ec6b9 | 46 | { |
nikitateggi | 1:8316c23ec6b9 | 47 | data1n = Ain.read_u16(); |
nikitateggi | 1:8316c23ec6b9 | 48 | data2n = Ain2.read_u16(); |
nikitateggi | 1:8316c23ec6b9 | 49 | daata1 = beta*daata1+alpha*data1n; |
nikitateggi | 1:8316c23ec6b9 | 50 | data2 = beta*data2+alpha*data2n; |
nikitateggi | 1:8316c23ec6b9 | 51 | |
nikitateggi | 1:8316c23ec6b9 | 52 | if( ((daata1-data2) >=(data2/10) && (daata1 > data2)) || ((data2-daata1) >=(data2/10) && (data2 > daata1)) ) |
nikitateggi | 1:8316c23ec6b9 | 53 | { |
nikitateggi | 1:8316c23ec6b9 | 54 | |
nikitateggi | 1:8316c23ec6b9 | 55 | err = 1; |
nikitateggi | 1:8316c23ec6b9 | 56 | } |
nikitateggi | 1:8316c23ec6b9 | 57 | else |
nikitateggi | 1:8316c23ec6b9 | 58 | { |
nikitateggi | 1:8316c23ec6b9 | 59 | err = 0; |
nikitateggi | 1:8316c23ec6b9 | 60 | } |
nikitateggi | 1:8316c23ec6b9 | 61 | |
nikitateggi | 1:8316c23ec6b9 | 62 | } |
nikitateggi | 1:8316c23ec6b9 | 63 | |
nikitateggi | 1:8316c23ec6b9 | 64 | void Compute() |
nikitateggi | 1:8316c23ec6b9 | 65 | { |
nikitateggi | 1:8316c23ec6b9 | 66 | |
nikitateggi | 1:8316c23ec6b9 | 67 | //datafinal1 = data1; |
nikitateggi | 1:8316c23ec6b9 | 68 | // unsigned char check; |
nikitateggi | 1:8316c23ec6b9 | 69 | //osTimerStop(id2); |
nikitateggi | 1:8316c23ec6b9 | 70 | //osTimerStop(id1); |
nikitateggi | 1:8316c23ec6b9 | 71 | datafinal1 = (unsigned int) NUMB1*(data2*VREF/(TOTAL))-NUMB2; |
nikitateggi | 1:8316c23ec6b9 | 72 | datafinal2 = (unsigned int) NUMB1*(daata1*VREF/(TOTAL))-NUMB2; |
nikitateggi | 1:8316c23ec6b9 | 73 | mgdl = (unsigned int) NUMB1*(((daata1+data2)/2)*VREF/(TOTAL))-NUMB2; |
nikitateggi | 1:8316c23ec6b9 | 74 | |
nikitateggi | 1:8316c23ec6b9 | 75 | |
nikitateggi | 1:8316c23ec6b9 | 76 | if (err == 0) |
nikitateggi | 1:8316c23ec6b9 | 77 | { |
nikitateggi | 1:8316c23ec6b9 | 78 | |
nikitateggi | 1:8316c23ec6b9 | 79 | glc_4(mgdl); |
nikitateggi | 1:8316c23ec6b9 | 80 | |
nikitateggi | 1:8316c23ec6b9 | 81 | sd_write(mgdl); |
nikitateggi | 1:8316c23ec6b9 | 82 | sd_close(); |
nikitateggi | 1:8316c23ec6b9 | 83 | ble.printf("blood glucose is %d", 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 | 1:8316c23ec6b9 | 89 | else |
nikitateggi | 1:8316c23ec6b9 | 90 | { |
nikitateggi | 1:8316c23ec6b9 | 91 | // lcd1.Print( " ERROR RESULT", 5,220,COLOR_RED,COLOR_BLACK, 0); |
nikitateggi | 1:8316c23ec6b9 | 92 | // ble.printf("E:"); |
nikitateggi | 1:8316c23ec6b9 | 93 | } |
nikitateggi | 1:8316c23ec6b9 | 94 | |
nikitateggi | 1:8316c23ec6b9 | 95 | |
nikitateggi | 1:8316c23ec6b9 | 96 | } |
nikitateggi | 1:8316c23ec6b9 | 97 | |
nikitateggi | 1:8316c23ec6b9 | 98 | |
nikitateggi | 1:8316c23ec6b9 | 99 | void T_S_detect(void) |
nikitateggi | 1:8316c23ec6b9 | 100 | { |
nikitateggi | 1:8316c23ec6b9 | 101 | GLC_START = 1; |
nikitateggi | 1:8316c23ec6b9 | 102 | //st_strip=1; |
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 | |
nikitateggi | 1:8316c23ec6b9 | 117 | |
nikitateggi | 1:8316c23ec6b9 | 118 | |
nikitateggi | 1:8316c23ec6b9 | 119 | |
nikitateggi | 1:8316c23ec6b9 | 120 | void glc(int pid){ |
nikitateggi | 1:8316c23ec6b9 | 121 | char t_s_d = 0; |
nikitateggi | 1:8316c23ec6b9 | 122 | i2c_spec(); |
nikitateggi | 1:8316c23ec6b9 | 123 | GLC_START = 1; |
nikitateggi | 1:8316c23ec6b9 | 124 | ble.baud(115200); |
nikitateggi | 1:8316c23ec6b9 | 125 | if(GLC_START == 1) |
nikitateggi | 1:8316c23ec6b9 | 126 | { |
nikitateggi | 1:8316c23ec6b9 | 127 | |
nikitateggi | 1:8316c23ec6b9 | 128 | //DisableTouch(); |
nikitateggi | 1:8316c23ec6b9 | 129 | //gpo_t = 0; |
nikitateggi | 1:8316c23ec6b9 | 130 | //lcd1.FillRect(5,127,230,320,COLOR_BLACK); |
nikitateggi | 1:8316c23ec6b9 | 131 | glc_1(); |
nikitateggi | 1:8316c23ec6b9 | 132 | err = 0; |
nikitateggi | 1:8316c23ec6b9 | 133 | data1n = 0; |
nikitateggi | 1:8316c23ec6b9 | 134 | data2n = 0; |
nikitateggi | 1:8316c23ec6b9 | 135 | daata1 = 0; |
nikitateggi | 1:8316c23ec6b9 | 136 | data2 = 0; |
nikitateggi | 1:8316c23ec6b9 | 137 | sd_open_GLCfile(pid); |
nikitateggi | 1:8316c23ec6b9 | 138 | |
nikitateggi | 1:8316c23ec6b9 | 139 | while((test_strip)); |
nikitateggi | 1:8316c23ec6b9 | 140 | |
nikitateggi | 1:8316c23ec6b9 | 141 | |
nikitateggi | 1:8316c23ec6b9 | 142 | // wait(500); |
nikitateggi | 1:8316c23ec6b9 | 143 | // Shutdown = 1; |
nikitateggi | 1:8316c23ec6b9 | 144 | |
nikitateggi | 1:8316c23ec6b9 | 145 | if (!test_strip) |
nikitateggi | 1:8316c23ec6b9 | 146 | { |
nikitateggi | 1:8316c23ec6b9 | 147 | |
nikitateggi | 1:8316c23ec6b9 | 148 | flipper.attach(&sample, 0.8); |
nikitateggi | 1:8316c23ec6b9 | 149 | t_s_d = 0; |
nikitateggi | 1:8316c23ec6b9 | 150 | glc_2(); |
nikitateggi | 1:8316c23ec6b9 | 151 | //gc.printf("%d\n", data1n); |
nikitateggi | 1:8316c23ec6b9 | 152 | |
nikitateggi | 1:8316c23ec6b9 | 153 | while((!t_s_d) && (!test_strip)) |
nikitateggi | 1:8316c23ec6b9 | 154 | { |
nikitateggi | 1:8316c23ec6b9 | 155 | |
nikitateggi | 1:8316c23ec6b9 | 156 | |
nikitateggi | 1:8316c23ec6b9 | 157 | if ((daata1 >= THRESHOLD) || (data2 >= THRESHOLD)) |
nikitateggi | 1:8316c23ec6b9 | 158 | { |
nikitateggi | 1:8316c23ec6b9 | 159 | t_s_d = 1; |
nikitateggi | 1:8316c23ec6b9 | 160 | flipper1.attach(&Compute, 2.25); |
nikitateggi | 1:8316c23ec6b9 | 161 | glc_3(); |
nikitateggi | 1:8316c23ec6b9 | 162 | |
nikitateggi | 1:8316c23ec6b9 | 163 | |
nikitateggi | 1:8316c23ec6b9 | 164 | } |
nikitateggi | 1:8316c23ec6b9 | 165 | else |
nikitateggi | 1:8316c23ec6b9 | 166 | { |
nikitateggi | 1:8316c23ec6b9 | 167 | //wait for insertion of blood; |
nikitateggi | 1:8316c23ec6b9 | 168 | } |
nikitateggi | 1:8316c23ec6b9 | 169 | |
nikitateggi | 1:8316c23ec6b9 | 170 | } |
nikitateggi | 1:8316c23ec6b9 | 171 | |
nikitateggi | 1:8316c23ec6b9 | 172 | |
nikitateggi | 1:8316c23ec6b9 | 173 | // t_s_d = 0; |
nikitateggi | 1:8316c23ec6b9 | 174 | wait_ms(800); |
nikitateggi | 1:8316c23ec6b9 | 175 | //flipper.detach(); |
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 | |
nikitateggi | 1:8316c23ec6b9 | 185 | |
nikitateggi | 1:8316c23ec6b9 | 186 | |
nikitateggi | 1:8316c23ec6b9 | 187 |