Changes done in ECG and BT
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_20sept_2017_4th_oct_2017 by
bp.cpp@10:aeff3309002a, 2017-05-03 (annotated)
- Committer:
- nidhinvarghese
- Date:
- Wed May 03 05:32:37 2017 +0000
- Revision:
- 10:aeff3309002a
- Parent:
- 8:adf2ba7e6412
- Child:
- 14:f5c62d30c6fc
May2_2017(Nidhin); Stores 2 file data to 1 bp file and delete 2 Temp File.; BP value rounded Result displayed as int.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nidhinvarghese | 8:adf2ba7e6412 | 1 | |
nikitateggi | 3:9a06c2bed650 | 2 | //BP Optimised Program for Averaging the received value from PPG and ECG & Check for SD card Storage// |
nikitateggi | 3:9a06c2bed650 | 3 | |
nikitateggi | 3:9a06c2bed650 | 4 | |
nikitateggi | 3:9a06c2bed650 | 5 | /** ECG ADS1291 Test program. |
nikitateggi | 3:9a06c2bed650 | 6 | ADS1291 is a single channel ECG chip |
nikitateggi | 3:9a06c2bed650 | 7 | with a 24 bit Sigma-Delta ADC |
nikitateggi | 3:9a06c2bed650 | 8 | */ |
nidhinvarghese | 8:adf2ba7e6412 | 9 | |
nidhinvarghese | 8:adf2ba7e6412 | 10 | /* |
nikitateggi | 3:9a06c2bed650 | 11 | #include "mbed.h" |
nikitateggi | 3:9a06c2bed650 | 12 | #include "MAX30102.h" // BP ADD |
nikitateggi | 3:9a06c2bed650 | 13 | #include <string.h> |
nikitateggi | 3:9a06c2bed650 | 14 | #include <stdio.h> |
nikitateggi | 3:9a06c2bed650 | 15 | #include "ds3231.h" |
nikitateggi | 3:9a06c2bed650 | 16 | #include "SDFileSystem.h" |
nikitateggi | 3:9a06c2bed650 | 17 | #include "rtc.h" |
nikitateggi | 3:9a06c2bed650 | 18 | #include "sdcard.h" |
nikitateggi | 3:9a06c2bed650 | 19 | #include "ec_bp.h" |
nikitateggi | 3:9a06c2bed650 | 20 | #include "bp.h" |
nikitateggi | 3:9a06c2bed650 | 21 | #include "display_modules.h" |
nikitateggi | 3:9a06c2bed650 | 22 | |
nikitateggi | 3:9a06c2bed650 | 23 | |
nikitateggi | 3:9a06c2bed650 | 24 | Serial bc(USBTX,USBRX); |
nikitateggi | 3:9a06c2bed650 | 25 | DigitalIn INTR(PTC7); |
nikitateggi | 3:9a06c2bed650 | 26 | |
nikitateggi | 3:9a06c2bed650 | 27 | |
nikitateggi | 3:9a06c2bed650 | 28 | |
suhasini | 5:a3ea7c82b7e1 | 29 | void bp() { |
nikitateggi | 3:9a06c2bed650 | 30 | |
nikitateggi | 3:9a06c2bed650 | 31 | //------------------BP ADD------------------------------//{ |
suhasini | 5:a3ea7c82b7e1 | 32 | //int location; // BP ADD |
nikitateggi | 3:9a06c2bed650 | 33 | int32_t n_red_buffer_length = 1500; //data length |
nikitateggi | 3:9a06c2bed650 | 34 | uint32_t aun_red_buffer[1500]; //Red LED sensor data, set to 500 |
nikitateggi | 3:9a06c2bed650 | 35 | uint32_t red_value; |
nikitateggi | 3:9a06c2bed650 | 36 | uint32_t ecg_value; |
nikitateggi | 3:9a06c2bed650 | 37 | uint8_t uch_dummy; |
nikitateggi | 3:9a06c2bed650 | 38 | uint32_t ecg_buf[1000]; |
nikitateggi | 3:9a06c2bed650 | 39 | int32_t ecg_buffer_length = 1000; |
nikitateggi | 3:9a06c2bed650 | 40 | float SBP, DBP, PWV, delta_t; |
nikitateggi | 3:9a06c2bed650 | 41 | int d = 210; |
nikitateggi | 3:9a06c2bed650 | 42 | |
suhasini | 5:a3ea7c82b7e1 | 43 | uint32_t un_min, un_max, ecg_min, ecg_max ; //variables to calculate the on-board LED brightness that reflects the heartbeats |
suhasini | 5:a3ea7c82b7e1 | 44 | //int i, j; |
nikitateggi | 3:9a06c2bed650 | 45 | float ecg_location, ppg_location; |
suhasini | 5:a3ea7c82b7e1 | 46 | //int32_t n_brightness; |
nikitateggi | 3:9a06c2bed650 | 47 | |
suhasini | 5:a3ea7c82b7e1 | 48 | // n_brightness=0; |
nikitateggi | 3:9a06c2bed650 | 49 | un_min=0x3FFFF; |
nikitateggi | 3:9a06c2bed650 | 50 | un_max=0; |
nikitateggi | 3:9a06c2bed650 | 51 | ecg_min = 0xFFFFFF; |
nikitateggi | 3:9a06c2bed650 | 52 | ecg_max = 0; |
nikitateggi | 3:9a06c2bed650 | 53 | //---------------- BP ADD-----------------------------//} |
nikitateggi | 3:9a06c2bed650 | 54 | |
nikitateggi | 3:9a06c2bed650 | 55 | |
nikitateggi | 3:9a06c2bed650 | 56 | //time_t epoch_time; |
nikitateggi | 3:9a06c2bed650 | 57 | //int fp; |
nikitateggi | 3:9a06c2bed650 | 58 | int concatenate_value1 = 0; |
nikitateggi | 3:9a06c2bed650 | 59 | //uint32_t ecg_buf[1500]; |
nikitateggi | 3:9a06c2bed650 | 60 | //int32_t ecg_der[1500]; |
nikitateggi | 3:9a06c2bed650 | 61 | //int buff1[15]= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; |
suhasini | 5:a3ea7c82b7e1 | 62 | //int32_t sample_sum; // static int32_t avg[1500]; |
suhasini | 5:a3ea7c82b7e1 | 63 | //int32_t count = 0; int32_t fs = 500; int32_t w=0,w1=0; |
nikitateggi | 3:9a06c2bed650 | 64 | |
nikitateggi | 3:9a06c2bed650 | 65 | unsigned char chk = 1; |
nikitateggi | 3:9a06c2bed650 | 66 | bc.baud(baud_rate); |
nikitateggi | 3:9a06c2bed650 | 67 | // mySpi.frequency(freq) ; |
nikitateggi | 3:9a06c2bed650 | 68 | // mySpi.format(bits, mode) ; |
nikitateggi | 3:9a06c2bed650 | 69 | freqset(); |
nikitateggi | 3:9a06c2bed650 | 70 | // Ds3231 rtc(PTC11, PTC10); //sda,scl2yy |
nikitateggi | 3:9a06c2bed650 | 71 | |
nikitateggi | 3:9a06c2bed650 | 72 | //------------------BP ADD---------------------------// { |
nikitateggi | 3:9a06c2bed650 | 73 | while(bc.readable()==0) |
nikitateggi | 3:9a06c2bed650 | 74 | { |
nikitateggi | 3:9a06c2bed650 | 75 | bc.printf("\x1B[2J"); //clear terminal program screen |
nikitateggi | 3:9a06c2bed650 | 76 | bc.printf("Press any key to start conversion\n\r"); |
nikitateggi | 3:9a06c2bed650 | 77 | wait(1); |
nikitateggi | 3:9a06c2bed650 | 78 | } |
nikitateggi | 3:9a06c2bed650 | 79 | wait(5); |
nikitateggi | 3:9a06c2bed650 | 80 | bc.printf("Start of capture, Remain CALM and Donot MOVE\n"); |
nikitateggi | 3:9a06c2bed650 | 81 | wait(2); |
nikitateggi | 3:9a06c2bed650 | 82 | //-------------------BP ADD---------------------------//} |
nikitateggi | 3:9a06c2bed650 | 83 | |
nikitateggi | 3:9a06c2bed650 | 84 | setupfunc(); |
nikitateggi | 3:9a06c2bed650 | 85 | ecgsetupfunc(); |
nikitateggi | 3:9a06c2bed650 | 86 | //--------------- BP ADD------------------------------------//{ |
nikitateggi | 3:9a06c2bed650 | 87 | maxim_max30102_reset(); // PPG reset |
nikitateggi | 3:9a06c2bed650 | 88 | maxim_max30102_init(); // PPG ADC register Initialise |
nikitateggi | 3:9a06c2bed650 | 89 | //---------------BP ADD ----------------------------------// } |
nikitateggi | 3:9a06c2bed650 | 90 | |
nikitateggi | 3:9a06c2bed650 | 91 | |
nikitateggi | 3:9a06c2bed650 | 92 | chk = 1; |
nikitateggi | 3:9a06c2bed650 | 93 | bc.printf("rawecg......................\n"); |
nikitateggi | 3:9a06c2bed650 | 94 | for(int i=0; i<N_ECG; i++) |
nikitateggi | 3:9a06c2bed650 | 95 | { |
nikitateggi | 3:9a06c2bed650 | 96 | |
nikitateggi | 3:9a06c2bed650 | 97 | concatenate_value1=readvalue(); |
nikitateggi | 3:9a06c2bed650 | 98 | ecg_buf[i] = concatenate_value1; |
nikitateggi | 3:9a06c2bed650 | 99 | |
nikitateggi | 3:9a06c2bed650 | 100 | bc.printf( "%d\n", concatenate_value1); |
nikitateggi | 3:9a06c2bed650 | 101 | maxim_max30102_read_reg(0,&uch_dummy); |
nikitateggi | 3:9a06c2bed650 | 102 | while(INTR.read()==1); |
nikitateggi | 3:9a06c2bed650 | 103 | maxim_max30102_read_fifo((aun_red_buffer+i)); |
nikitateggi | 3:9a06c2bed650 | 104 | //bc.printf( "%d\n", concatenate_value1); |
nikitateggi | 3:9a06c2bed650 | 105 | // bc.printf("%d\n",aun_red_buffer[i]); |
nikitateggi | 3:9a06c2bed650 | 106 | //sd_write(concatenate_value); - -- BP ADD commented |
nikitateggi | 3:9a06c2bed650 | 107 | //printf( "%d\n", concatenate_value); -- BP ADD commented |
nikitateggi | 3:9a06c2bed650 | 108 | // bc.printf("loop2"); |
nikitateggi | 3:9a06c2bed650 | 109 | } |
nikitateggi | 3:9a06c2bed650 | 110 | |
nikitateggi | 3:9a06c2bed650 | 111 | for (int w=1000; w < n_red_buffer_length; w++) // for reading extra 500 PPG samples. |
nikitateggi | 3:9a06c2bed650 | 112 | { |
nikitateggi | 3:9a06c2bed650 | 113 | //bc.printf("loop2"); |
nikitateggi | 3:9a06c2bed650 | 114 | while(INTR.read()==1); |
nikitateggi | 3:9a06c2bed650 | 115 | maxim_max30102_read_fifo((aun_red_buffer+w)); |
nikitateggi | 3:9a06c2bed650 | 116 | } |
nikitateggi | 3:9a06c2bed650 | 117 | |
nikitateggi | 3:9a06c2bed650 | 118 | |
nikitateggi | 3:9a06c2bed650 | 119 | //sd_close(); -- BP ADD commented |
nikitateggi | 3:9a06c2bed650 | 120 | |
nikitateggi | 3:9a06c2bed650 | 121 | int32_t ecg_n_denom; |
nikitateggi | 3:9a06c2bed650 | 122 | |
nikitateggi | 3:9a06c2bed650 | 123 | // 4 pt Moving Average ECG |
nikitateggi | 3:9a06c2bed650 | 124 | bc.printf("PRINTING ECG 4 POINT IN DECIMAL........\n"); |
nikitateggi | 3:9a06c2bed650 | 125 | for(int y=0; y<996; y++){ |
nikitateggi | 3:9a06c2bed650 | 126 | ecg_n_denom= ( ecg_buf[y]+ ecg_buf[y+1]+ ecg_buf[y+2]+ ecg_buf[y+3]); |
nikitateggi | 3:9a06c2bed650 | 127 | ecg_buf[y]= ecg_n_denom/(int32_t)4; |
nikitateggi | 3:9a06c2bed650 | 128 | } |
nikitateggi | 3:9a06c2bed650 | 129 | for( int l= 0; l<1000; l++){ |
nikitateggi | 3:9a06c2bed650 | 130 | bc.printf("%d\n",ecg_buf[l]); //PRINTING ecg AFTER AVERAGING |
nikitateggi | 3:9a06c2bed650 | 131 | } |
nikitateggi | 3:9a06c2bed650 | 132 | bc.printf("PRINTING PPG IN DECIMAL (after averaging)........\n"); |
nikitateggi | 3:9a06c2bed650 | 133 | int32_t ppg_n_denom; |
nikitateggi | 3:9a06c2bed650 | 134 | // 4 pt Moving Average PPG |
nikitateggi | 3:9a06c2bed650 | 135 | for(int f=0; f<1496; f++){ |
nikitateggi | 3:9a06c2bed650 | 136 | ppg_n_denom= ( aun_red_buffer[f]+aun_red_buffer[f+1]+ aun_red_buffer[f+2]+ aun_red_buffer[f+3]); |
nikitateggi | 3:9a06c2bed650 | 137 | aun_red_buffer[f]= ppg_n_denom/(int32_t)4; |
nikitateggi | 3:9a06c2bed650 | 138 | } |
nikitateggi | 3:9a06c2bed650 | 139 | for( int b = 0; b<1500; b++){ |
nikitateggi | 3:9a06c2bed650 | 140 | bc.printf("%d\n",aun_red_buffer[b]); |
nikitateggi | 3:9a06c2bed650 | 141 | } |
nikitateggi | 3:9a06c2bed650 | 142 | |
nikitateggi | 3:9a06c2bed650 | 143 | |
nikitateggi | 3:9a06c2bed650 | 144 | for(int f=0; f<ecg_buffer_length; f++) |
nikitateggi | 3:9a06c2bed650 | 145 | { |
nikitateggi | 3:9a06c2bed650 | 146 | if(ecg_min > ecg_buf[f]) |
nikitateggi | 3:9a06c2bed650 | 147 | ecg_min = ecg_buf[f]; //update signal min |
nikitateggi | 3:9a06c2bed650 | 148 | if(ecg_max < ecg_buf[f]) |
nikitateggi | 3:9a06c2bed650 | 149 | { |
nikitateggi | 3:9a06c2bed650 | 150 | ecg_max=ecg_buf[f]; //update signal max |
nikitateggi | 3:9a06c2bed650 | 151 | ecg_location = f+1; |
nikitateggi | 3:9a06c2bed650 | 152 | } |
nikitateggi | 3:9a06c2bed650 | 153 | } |
nikitateggi | 3:9a06c2bed650 | 154 | bc.printf( "ecg_location = %f\n", ecg_location); |
nikitateggi | 3:9a06c2bed650 | 155 | |
nikitateggi | 3:9a06c2bed650 | 156 | for(int g = ecg_location; g < (ecg_location+400); g++) // Peak detect changed to 400 samples from 500 samples |
nikitateggi | 3:9a06c2bed650 | 157 | { |
nikitateggi | 3:9a06c2bed650 | 158 | if(un_min>aun_red_buffer[g]) |
nikitateggi | 3:9a06c2bed650 | 159 | un_min=aun_red_buffer[g]; //update signal min |
nikitateggi | 3:9a06c2bed650 | 160 | if(un_max<aun_red_buffer[g]) |
nikitateggi | 3:9a06c2bed650 | 161 | { |
nikitateggi | 3:9a06c2bed650 | 162 | un_max=aun_red_buffer[g]; //update signal max |
nikitateggi | 3:9a06c2bed650 | 163 | ppg_location = g+1; |
nikitateggi | 3:9a06c2bed650 | 164 | } |
nikitateggi | 3:9a06c2bed650 | 165 | } |
nikitateggi | 3:9a06c2bed650 | 166 | bc.printf( "ppg_location = %f\n", ppg_location); |
nikitateggi | 3:9a06c2bed650 | 167 | |
nikitateggi | 3:9a06c2bed650 | 168 | delta_t = (2*(ppg_location - ecg_location))/1000; |
nikitateggi | 3:9a06c2bed650 | 169 | bc.printf( "delta_t = %f\n", delta_t); |
nikitateggi | 3:9a06c2bed650 | 170 | |
nikitateggi | 3:9a06c2bed650 | 171 | PWV = d/delta_t; |
nikitateggi | 3:9a06c2bed650 | 172 | bc.printf( "PWV = %f\n", PWV); |
nikitateggi | 3:9a06c2bed650 | 173 | |
nikitateggi | 3:9a06c2bed650 | 174 | SBP = 0.0508955*PWV+62.559; |
nikitateggi | 3:9a06c2bed650 | 175 | DBP = 0.0494*PWV + 17.480; |
nikitateggi | 3:9a06c2bed650 | 176 | |
nikitateggi | 3:9a06c2bed650 | 177 | |
nikitateggi | 3:9a06c2bed650 | 178 | bc.printf( "SBP = %f\n", SBP); |
nikitateggi | 3:9a06c2bed650 | 179 | bc.printf( "DBP = %f\n", DBP); |
nikitateggi | 3:9a06c2bed650 | 180 | |
nikitateggi | 3:9a06c2bed650 | 181 | screen_bp1(SBP,DBP); |
nidhinvarghese | 8:adf2ba7e6412 | 182 | */ |
nikitateggi | 3:9a06c2bed650 | 183 | |
nikitateggi | 3:9a06c2bed650 | 184 | //-----------------WRITE ECG &PPG |
suhasini | 5:a3ea7c82b7e1 | 185 | /* |
nikitateggi | 3:9a06c2bed650 | 186 | sd_open_BPfile(1); |
nikitateggi | 3:9a06c2bed650 | 187 | for (int w=0; w < 1000; w++) |
nikitateggi | 3:9a06c2bed650 | 188 | { |
nikitateggi | 3:9a06c2bed650 | 189 | ecg_value = ecg_buf[w]; |
nikitateggi | 3:9a06c2bed650 | 190 | sd_write(ecg_value); |
nikitateggi | 3:9a06c2bed650 | 191 | } |
nikitateggi | 3:9a06c2bed650 | 192 | |
nikitateggi | 3:9a06c2bed650 | 193 | |
nikitateggi | 3:9a06c2bed650 | 194 | |
nikitateggi | 3:9a06c2bed650 | 195 | for (int w=0; w < n_red_buffer_length; w++) |
nikitateggi | 3:9a06c2bed650 | 196 | { |
nikitateggi | 3:9a06c2bed650 | 197 | red_value = aun_red_buffer[w]; |
nikitateggi | 3:9a06c2bed650 | 198 | sd_write(red_value); |
nikitateggi | 3:9a06c2bed650 | 199 | } |
suhasini | 5:a3ea7c82b7e1 | 200 | sd_close();*/ |
nikitateggi | 3:9a06c2bed650 | 201 | |
nikitateggi | 3:9a06c2bed650 | 202 | //----------- FINISHED WRITING ECG & PPG TO SD CARD |
nikitateggi | 3:9a06c2bed650 | 203 | |
nikitateggi | 3:9a06c2bed650 | 204 | |
nikitateggi | 3:9a06c2bed650 | 205 | |
nikitateggi | 3:9a06c2bed650 | 206 | |
nidhinvarghese | 8:adf2ba7e6412 | 207 | //} // End of main function |
nidhinvarghese | 8:adf2ba7e6412 | 208 | |
nidhinvarghese | 8:adf2ba7e6412 | 209 | |
nidhinvarghese | 8:adf2ba7e6412 | 210 | //-----------------------------------------------NEW BP code starts--------------------------------/// |
nidhinvarghese | 8:adf2ba7e6412 | 211 | |
nidhinvarghese | 8:adf2ba7e6412 | 212 | #include "mbed.h" |
nidhinvarghese | 8:adf2ba7e6412 | 213 | #include "MAX30102.h" // BP ADD |
nidhinvarghese | 8:adf2ba7e6412 | 214 | #include <string.h> |
nidhinvarghese | 8:adf2ba7e6412 | 215 | #include <stdio.h> |
nidhinvarghese | 8:adf2ba7e6412 | 216 | //#include <iostream> |
nidhinvarghese | 8:adf2ba7e6412 | 217 | #include "ds3231.h" |
nidhinvarghese | 8:adf2ba7e6412 | 218 | #include "SDFileSystem.h" |
nidhinvarghese | 8:adf2ba7e6412 | 219 | #include "rtc.h" |
nidhinvarghese | 8:adf2ba7e6412 | 220 | #include "sdcard.h" |
nidhinvarghese | 8:adf2ba7e6412 | 221 | #include "ec_bp.h" |
nidhinvarghese | 8:adf2ba7e6412 | 222 | #include "bp.h" |
nidhinvarghese | 8:adf2ba7e6412 | 223 | #include "display_modules.h" |
nidhinvarghese | 8:adf2ba7e6412 | 224 | |
nidhinvarghese | 8:adf2ba7e6412 | 225 | using namespace std; |
nidhinvarghese | 8:adf2ba7e6412 | 226 | |
nidhinvarghese | 8:adf2ba7e6412 | 227 | Serial bc(USBTX,USBRX); |
nidhinvarghese | 8:adf2ba7e6412 | 228 | DigitalIn INTR(PTC7); |
nidhinvarghese | 8:adf2ba7e6412 | 229 | |
nidhinvarghese | 8:adf2ba7e6412 | 230 | Timer t; |
nidhinvarghese | 8:adf2ba7e6412 | 231 | |
nidhinvarghese | 8:adf2ba7e6412 | 232 | //FILE *ecg; |
nidhinvarghese | 8:adf2ba7e6412 | 233 | //FILE *ppg; |
nidhinvarghese | 8:adf2ba7e6412 | 234 | |
nidhinvarghese | 8:adf2ba7e6412 | 235 | void bp(int pid) { |
nidhinvarghese | 8:adf2ba7e6412 | 236 | uint8_t uch_dummy; |
nidhinvarghese | 8:adf2ba7e6412 | 237 | uint32_t ppgdata; |
nidhinvarghese | 8:adf2ba7e6412 | 238 | |
nidhinvarghese | 8:adf2ba7e6412 | 239 | //int dummyconcat = 700000; |
nidhinvarghese | 8:adf2ba7e6412 | 240 | int concatenate_value2 = 0; |
nidhinvarghese | 8:adf2ba7e6412 | 241 | unsigned char chk = 1; |
nidhinvarghese | 8:adf2ba7e6412 | 242 | |
nidhinvarghese | 8:adf2ba7e6412 | 243 | int drum11[64]; |
nidhinvarghese | 8:adf2ba7e6412 | 244 | uint32_t drum21[64]; |
nidhinvarghese | 8:adf2ba7e6412 | 245 | |
nidhinvarghese | 8:adf2ba7e6412 | 246 | // Variables for file operations |
nidhinvarghese | 8:adf2ba7e6412 | 247 | // uint32_t amax=0; |
nidhinvarghese | 8:adf2ba7e6412 | 248 | //uint32_t bmax = 0; |
nidhinvarghese | 8:adf2ba7e6412 | 249 | //uint32_t a; |
nidhinvarghese | 8:adf2ba7e6412 | 250 | //uint32_t b; |
nidhinvarghese | 8:adf2ba7e6412 | 251 | |
nidhinvarghese | 8:adf2ba7e6412 | 252 | //int aloc = 0; |
nidhinvarghese | 8:adf2ba7e6412 | 253 | //int bloc = 0; |
nidhinvarghese | 8:adf2ba7e6412 | 254 | //int samples = 0; |
nidhinvarghese | 8:adf2ba7e6412 | 255 | |
nidhinvarghese | 8:adf2ba7e6412 | 256 | bc.baud(baud_rate); |
nidhinvarghese | 8:adf2ba7e6412 | 257 | |
nidhinvarghese | 8:adf2ba7e6412 | 258 | freqset(); // setting the frequency |
nidhinvarghese | 8:adf2ba7e6412 | 259 | setupfunc(); |
nidhinvarghese | 8:adf2ba7e6412 | 260 | ecgsetupfunc(); |
nidhinvarghese | 8:adf2ba7e6412 | 261 | |
nidhinvarghese | 8:adf2ba7e6412 | 262 | maxim_max30102_reset(); // PPG reset |
nidhinvarghese | 8:adf2ba7e6412 | 263 | wait_ms(20); |
nidhinvarghese | 8:adf2ba7e6412 | 264 | maxim_max30102_init(); |
nidhinvarghese | 8:adf2ba7e6412 | 265 | |
nidhinvarghese | 8:adf2ba7e6412 | 266 | chk = 1; |
nidhinvarghese | 8:adf2ba7e6412 | 267 | |
nidhinvarghese | 8:adf2ba7e6412 | 268 | wait(2); |
nidhinvarghese | 8:adf2ba7e6412 | 269 | //bc.printf("BP start\n"); |
nidhinvarghese | 8:adf2ba7e6412 | 270 | |
nidhinvarghese | 8:adf2ba7e6412 | 271 | for(int i=0; i<500; i++) |
nidhinvarghese | 8:adf2ba7e6412 | 272 | { |
nidhinvarghese | 8:adf2ba7e6412 | 273 | |
nidhinvarghese | 8:adf2ba7e6412 | 274 | concatenate_value2= readvalue(); |
nidhinvarghese | 8:adf2ba7e6412 | 275 | |
nidhinvarghese | 8:adf2ba7e6412 | 276 | maxim_max30102_read_reg(0,&uch_dummy); |
nidhinvarghese | 8:adf2ba7e6412 | 277 | while(INTR.read()==1); |
nidhinvarghese | 8:adf2ba7e6412 | 278 | maxim_max30102_read_fifo(&ppgdata); |
nidhinvarghese | 8:adf2ba7e6412 | 279 | |
nidhinvarghese | 8:adf2ba7e6412 | 280 | } |
nidhinvarghese | 8:adf2ba7e6412 | 281 | |
nidhinvarghese | 8:adf2ba7e6412 | 282 | |
nidhinvarghese | 8:adf2ba7e6412 | 283 | sd_open_BP_ECGfile(pid) ; // sd_open_BP_ECGfile(123) draft file for testing |
nidhinvarghese | 8:adf2ba7e6412 | 284 | sd_open_BP_PPGfile(pid) ; // sd_open_BP_PPGfile(123) draft file for testing |
nidhinvarghese | 8:adf2ba7e6412 | 285 | |
nidhinvarghese | 8:adf2ba7e6412 | 286 | FILE *ecg = NULL; |
nidhinvarghese | 8:adf2ba7e6412 | 287 | FILE *ppg = NULL; |
nidhinvarghese | 8:adf2ba7e6412 | 288 | int *drum_ecg = NULL; // pointers to ecg buffer |
nidhinvarghese | 8:adf2ba7e6412 | 289 | uint32_t *drum_ppg = NULL; // pointer to ppg buffer |
nidhinvarghese | 8:adf2ba7e6412 | 290 | |
nidhinvarghese | 8:adf2ba7e6412 | 291 | drum_ecg = drum11; |
nidhinvarghese | 8:adf2ba7e6412 | 292 | drum_ppg = drum21; |
nidhinvarghese | 8:adf2ba7e6412 | 293 | |
nidhinvarghese | 8:adf2ba7e6412 | 294 | for(int j =0 ; j<16; j++) // changed to 16 from 8 |
nidhinvarghese | 8:adf2ba7e6412 | 295 | { |
nidhinvarghese | 8:adf2ba7e6412 | 296 | for(int i=0; i<64; i++) |
nidhinvarghese | 8:adf2ba7e6412 | 297 | { |
nidhinvarghese | 8:adf2ba7e6412 | 298 | concatenate_value2 = readvalue(); |
nidhinvarghese | 8:adf2ba7e6412 | 299 | drum11[i]=concatenate_value2; //drum11[i]=concatenate_value2; drum11[i]=dummyconcat; |
nidhinvarghese | 8:adf2ba7e6412 | 300 | |
nidhinvarghese | 8:adf2ba7e6412 | 301 | maxim_max30102_read_reg(0,&uch_dummy); |
nidhinvarghese | 8:adf2ba7e6412 | 302 | while(INTR.read()==1); |
nidhinvarghese | 8:adf2ba7e6412 | 303 | maxim_max30102_read_fifo(&ppgdata); |
nidhinvarghese | 8:adf2ba7e6412 | 304 | drum21[i]=ppgdata; |
nidhinvarghese | 8:adf2ba7e6412 | 305 | } |
nidhinvarghese | 8:adf2ba7e6412 | 306 | |
nidhinvarghese | 8:adf2ba7e6412 | 307 | ecg = sd_BP_ecgwrite(drum_ecg); // |
nidhinvarghese | 8:adf2ba7e6412 | 308 | ppg = sd_BP_ppgwrite(drum_ppg); |
nidhinvarghese | 8:adf2ba7e6412 | 309 | |
nidhinvarghese | 8:adf2ba7e6412 | 310 | |
nidhinvarghese | 8:adf2ba7e6412 | 311 | } |
nidhinvarghese | 8:adf2ba7e6412 | 312 | |
nidhinvarghese | 8:adf2ba7e6412 | 313 | for(int j =0 ; j<10; j++) // changed to 16 from 8 |
nidhinvarghese | 8:adf2ba7e6412 | 314 | { |
nidhinvarghese | 8:adf2ba7e6412 | 315 | for(int i=0; i<64; i++) |
nidhinvarghese | 8:adf2ba7e6412 | 316 | { |
nidhinvarghese | 8:adf2ba7e6412 | 317 | maxim_max30102_read_reg(0,&uch_dummy); |
nidhinvarghese | 8:adf2ba7e6412 | 318 | while(INTR.read()==1); |
nidhinvarghese | 8:adf2ba7e6412 | 319 | maxim_max30102_read_fifo(&ppgdata); |
nidhinvarghese | 8:adf2ba7e6412 | 320 | drum21[i]=ppgdata; |
nidhinvarghese | 8:adf2ba7e6412 | 321 | } |
nidhinvarghese | 8:adf2ba7e6412 | 322 | |
nidhinvarghese | 8:adf2ba7e6412 | 323 | ppg = sd_BP_ppgwrite (drum_ppg); |
nidhinvarghese | 8:adf2ba7e6412 | 324 | |
nidhinvarghese | 8:adf2ba7e6412 | 325 | } |
nidhinvarghese | 8:adf2ba7e6412 | 326 | fclose(ecg); |
nidhinvarghese | 8:adf2ba7e6412 | 327 | fclose(ppg); |
nidhinvarghese | 8:adf2ba7e6412 | 328 | |
nidhinvarghese | 8:adf2ba7e6412 | 329 | maxim_max30102_reset(); |
nidhinvarghese | 8:adf2ba7e6412 | 330 | |
nidhinvarghese | 8:adf2ba7e6412 | 331 | //-----Reading from file starts // |
nidhinvarghese | 8:adf2ba7e6412 | 332 | |
nidhinvarghese | 8:adf2ba7e6412 | 333 | //std::ifstream ec1("/sd/123_BP_ECG.csv"); |
nidhinvarghese | 8:adf2ba7e6412 | 334 | //std::ifstream pp1("/sd/123_BP_PPG.csv"); |
nidhinvarghese | 8:adf2ba7e6412 | 335 | |
nidhinvarghese | 8:adf2ba7e6412 | 336 | int eloc = 0; |
nidhinvarghese | 8:adf2ba7e6412 | 337 | int ploc = 0; |
nidhinvarghese | 8:adf2ba7e6412 | 338 | |
nidhinvarghese | 8:adf2ba7e6412 | 339 | |
nidhinvarghese | 8:adf2ba7e6412 | 340 | eloc = sd_BP_ECGMAX(pid); // eloc = sd_BP_ECGMAX(123); |
nidhinvarghese | 8:adf2ba7e6412 | 341 | ploc = sd_BP_PPGMAX(pid); // ploc = sd_BP_PPGMAX(123); |
nidhinvarghese | 8:adf2ba7e6412 | 342 | |
nidhinvarghese | 8:adf2ba7e6412 | 343 | //bc.printf("The ECG max is at : %d", eloc); |
nidhinvarghese | 8:adf2ba7e6412 | 344 | //bc.printf("The PPG Max is at : %d", ploc); |
nidhinvarghese | 8:adf2ba7e6412 | 345 | |
nidhinvarghese | 8:adf2ba7e6412 | 346 | float PWV = 0; |
nidhinvarghese | 8:adf2ba7e6412 | 347 | int d = 210000; |
nidhinvarghese | 8:adf2ba7e6412 | 348 | int delta_t = 0; |
nidhinvarghese | 8:adf2ba7e6412 | 349 | float SBP = 0; |
nidhinvarghese | 8:adf2ba7e6412 | 350 | float DBP = 0; |
nidhinvarghese | 8:adf2ba7e6412 | 351 | |
nidhinvarghese | 8:adf2ba7e6412 | 352 | delta_t = (2*(ploc - eloc)); |
nidhinvarghese | 8:adf2ba7e6412 | 353 | PWV = d/delta_t; |
nidhinvarghese | 8:adf2ba7e6412 | 354 | |
nidhinvarghese | 8:adf2ba7e6412 | 355 | SBP = 0.0508955*PWV+62.559; |
nidhinvarghese | 8:adf2ba7e6412 | 356 | DBP = (0.0494*PWV + 17.480)+10; |
nidhinvarghese | 8:adf2ba7e6412 | 357 | |
nidhinvarghese | 8:adf2ba7e6412 | 358 | screen_bp1(SBP,DBP); |
nidhinvarghese | 10:aeff3309002a | 359 | |
nidhinvarghese | 10:aeff3309002a | 360 | create_single_BPfile(pid); |
nidhinvarghese | 8:adf2ba7e6412 | 361 | |
nidhinvarghese | 8:adf2ba7e6412 | 362 | } |