code with new display driver ili9341
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of Int_Demo_09May2017_Suhasini_HRavg_Nik_BT_ba_update4thJuly17_nikita7july by
Diff: sdcard.cpp
- Revision:
- 22:ffa88619551d
- Parent:
- 20:7c64e6ecad76
- Child:
- 24:d992ee8369f4
diff -r 7ef1b0b40841 -r ffa88619551d sdcard.cpp --- a/sdcard.cpp Wed Jun 21 08:39:10 2017 +0000 +++ b/sdcard.cpp Fri Jun 23 07:25:24 2017 +0000 @@ -34,7 +34,7 @@ int pbp = 0; //Function Added on 16/5/2017 by Nidhin - void sd_open_mainfile(int pid) + void sd_open_mainfile(int32_t pid) { char buffer1[32]; sprintf(buffer1,"/sd/%d.csv",pid); @@ -60,7 +60,7 @@ } */ - void sd_open_GLCfilee(int pid) // only opening the glc file after entering TEST screen + void sd_open_GLCfilee(int32_t pid) // only opening the glc file after entering TEST screen { char buffer1[32]; sprintf(buffer1,"/sd/%d_GLC.csv",pid); @@ -85,7 +85,7 @@ } */ - void sd_open_ECGfilee(int pid) // only opening the ECG file after entering TEST screen + void sd_open_ECGfilee(int32_t pid) // only opening the ECG file after entering TEST screen { char buffer1[32]; @@ -110,7 +110,7 @@ fprintf(fp,"%s\n",ctime(&epoch_time1) ); } */ -void sd_open_BPfilee(int pid) // only opening the BP file after entering TEST screen +void sd_open_BPfilee(int32_t pid) // only opening the BP file after entering TEST screen { @@ -218,7 +218,7 @@ } //-----------------------------------------------SD Read - void sd_reopen_BPfilee(int pid) // only opening the BP file after entering TEST screen + void sd_reopen_BPfilee(int32_t pid) // only opening the BP file after entering TEST screen { @@ -235,7 +235,7 @@ //--------------------------------------- - void sd_open_BP_ECGfile(int pid) + void sd_open_BP_ECGfile(int32_t pid) { //char buffer[32]; @@ -255,7 +255,7 @@ } - void sd_open_BP_PPGfile(int pid) + void sd_open_BP_PPGfile(int32_t pid) { char buffer1[32]; @@ -307,7 +307,7 @@ //------------------------------------------ //REOPEN FUNCTIONs for reading data Nidhin - int sd_BP_ECGMAX(int pid) + int sd_BP_ECGMAX(int32_t pid) { char buffer1[32]; @@ -346,7 +346,7 @@ // Function to calculate PPG MAx and location - int sd_BP_PPGMAX(int pid) + int sd_BP_PPGMAX(int32_t pid) { char buffer1[32]; @@ -394,7 +394,7 @@ //------- FUNCTION TO CREATE SINGLE BP FILE --------2/5/2017 (NIDHIN)---------------// - void create_single_BPfile(int pid) + void create_single_BPfile(int32_t pid) { //int ecgbuf[64] = {0}; @@ -455,7 +455,7 @@ } //Creating strcuture file Common to All Functions -void structure_file(BLEMsg_info *ptr, int pid) +void structure_file(BLEMsg_info *ptr, int32_t pid) { char buffer3[32]; sprintf(buffer3, "/sd/%d.csv", pid); //Printing file path to the buffer @@ -466,7 +466,7 @@ //Copy Data into file. -void bpfile_mainfile(int pid) //Copy data of bp file to main +void bpfile_mainfile(int32_t pid) //Copy data of bp file to main { char buffer3[32]; sprintf(buffer3, "/sd/%d.csv", pid); @@ -498,7 +498,7 @@ //------------ Function to write ECG data to main file -void ecgfile_mainfile(int pid) +void ecgfile_mainfile(int32_t pid) { char buffer3[32]; sprintf(buffer3, "/sd/%d.csv", pid); @@ -528,7 +528,7 @@ //---------------------- Function to write GLC data to GLC file -void sd_glcwrite(uint32_t *glc_ptr, int pid) +void sd_glcwrite(uint32_t *glc_ptr, int32_t pid) { char buffer3[32]; sprintf(buffer3, "/sd/%d_GLC.csv", pid); @@ -541,7 +541,7 @@ // --------------------------Fuinction to write GLC data to Main file -void glcfile_mainfile(int pid) +void glcfile_mainfile(int32_t pid) { char buffer3[32]; sprintf(buffer3, "/sd/%d.csv", pid); @@ -565,7 +565,7 @@ } -void delete_subfiles(int pid) +void delete_subfiles(int32_t pid) { char buffer3[32]; int success1 , success2, success3; @@ -596,4 +596,149 @@ else snd.printf("\nECG file delete : UnSuccessful"); +} + + +uint16_t heart_cal(int pid) // Function created on 10/6/17, Function modified on 13/6/17 Nidhin +// Objective ti understand how file pointers work +{ + //FILE *fpeecg2; // Secondary File + + char buffer3[32]; + + + int32_t buff1[1] ; int32_t buff2[2]; int32_t buff3[1]; // Buff 12 &3 Stores sample 1, 2 & 10th sample + int32_t fppos; // Variable to hold pointer position + + int32_t val1_val10; // VARIABLE holding difference of sample 1 and 10 + + int32_t peakpos[10]; //array taht holds the peak position //Changed to 10 (ORG 4) Nidhin 20/6/17 + int32_t peakval[10]; // Array holding peak values ////Changed to 10 (ORG 4) Nidhin 20/6/17 + int32_t pk = 0; // Variable to access array + + int32_t no_of_peaks =0; // Variable holding toatl number of peaks ; increments on each peak + + float hrt_rate; // Heart rate in float varoable + uint16_t heart_rate; // Heart rate to be type casted to int + + sprintf(buffer3, "/sd/%d_ECG.csv", pid); // For opening a specific file + fpeecg = fopen(buffer3, "r"); + + /* + fppos = ftell(fpeecg); + snd.printf("Main pointer is at Position : %d \n", fppos); + */ + int32_t m =0; // Variable to move the file pointer in fseek function Org Static Nidhin 22/6/17 + int32_t i =0; // Variable to count sample number, ORG Static Nidhin 22/6/17 + + for ( i = 0; i < 1000; i++) // for 1024 samples in file + { + rewind(fpeecg); // Go to satrt of file each time + fseek(fpeecg, m, SEEK_CUR); // Update the count value according to move pointer + + fread(buff1, sizeof(int32_t), 1, fpeecg); // Read sample 1 + //fpeecg2 = fpeecg; + fread(buff2, sizeof(int32_t), 1, fpeecg); // Read Sample 2 + + int32_t n = 28; // Variable to move to 10th sampple from current + + + fseek(fpeecg, n, SEEK_CUR); // Moving to tenth sample + fread(buff3, sizeof(int32_t), 1, fpeecg); // Read 3rd sample + + snd.printf("buff1 = %d , buff2 = %d, buff3 = %d\n",buff1[0],buff2[0],buff3[0] ); //Test Value heald by buffer each round + + val1_val10 = buff1[0] - buff3[0]; // Difference of sample 1 and 10 + + if(buff1[0] > buff2[0] && val1_val10 > 10000) // Condition for -ve gradient and difference of 10000 + { + peakpos[pk] = i; // Peak detected sample number updated in array + peakval[pk] = buff1[0]; // Peak value updated in array + pk++; // Array pointer incremented + i = i+120; // i incremented to 120 for next 120 samples + no_of_peaks = no_of_peaks + 1; // no. of peaks incremented + //fseek(fpeecg, 480, SEEK_CUR); // push the pointer to + //fppos = ftell(fpeecg); Commenetd Nidhin 20/6/17 + //snd.printf("in if : The Pointer is moved to positon %d\n", fppos); + m = m + 480; + + } + + else + { + m = m+4; + //fpeecg = fpeecg2; + //i = i+1; + //fppos = ftell(fpeecg); COMMENTED NIDHIN 20/6/17 + //snd.printf("in Else : The Pointer is moved to positon %d\n", fppos); + } + } + + snd.printf("The No: of Peaks is %d\n", no_of_peaks); + + for(int j=0; j<no_of_peaks; j++) + { + snd.printf("The Peak %d, is at %d & value is %d\n",j, peakpos[j], peakval[j]); + } + + // Heart rate calculation + //Testing + int32_t t_diff; + t_diff = peakpos[1] - peakpos[0]; + snd.printf("t_diff is %d\n", t_diff); + + hrt_rate = 60.0/(t_diff*2); + //snd.printf("Hear rate in float is %f\n", hrt_rate); COMMENETD NIDHIN 20/6/17 + + hrt_rate = float (hrt_rate*1000); + snd.printf("Hear rate in float is %f\n", hrt_rate); + + heart_rate = uint16_t(hrt_rate + 0.5); + snd.printf("The heart rate after type casting is %d\n", heart_rate); + + /* + fppos = ftell(fpeecg); + snd.printf("The first data is = %d\n", buff1); + snd.printf("The Position after reading first data is = %d\n\n", fppos); + + fread(buff2, sizeof(int32_t), 1, fpeecg); + fppos = ftell(fpeecg); + snd.printf("The Second data is = %d\n", buff2); + snd.printf("The Position after reading Second data is = %d\n\n", fppos); + + fseek(fpeecg, 32,SEEK_CUR); + + fread(buff3, sizeof(int32_t), 1, fpeecg); + fppos = ftell(fpeecg); + snd.printf("The third data is = %d\n", buff3); + snd.printf("The Position after reading Second data is = %d\n\n", fppos); + + fseek(fpeecg, -24,SEEK_CUR); + + fread(buff3, sizeof(int32_t), 1, fpeecg); + fppos = ftell(fpeecg); + snd.printf("The fourth data is = %d\n", buff3); + snd.printf("The Position after reading fourth data is = %d\n", fppos); + + } + /* + snd.printf("Printing from 500-999\n\n"); + fread(ecgbufnew, sizeof(int), 500, fpeecg); + for(int i=0; i<500; i++) + { + //snd.printf("%d\n", ecgbufnew[i]); + } + + rewind(fpeecg); + fseek(fpeecg, 996, SEEK_SET); // Try modifying with 996 = 249*4 if not working + + snd.printf("Printing from 250-749\n\n"); + fread(ecgbufnew, sizeof(int), 500, fpeecg); + for(int i=0; i<500; i++) + { + //snd.printf("%d\n", ecgbufnew[i]); + } + */ + fclose(fpeecg); + return heart_rate; } \ No newline at end of file