Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of SS_SensePOC2P0_11Dec2017_USERPID by
Diff: bp.cpp
- Revision:
- 8:adf2ba7e6412
- Parent:
- 5:a3ea7c82b7e1
- Child:
- 10:aeff3309002a
--- a/bp.cpp Wed Apr 26 10:14:53 2017 +0000
+++ b/bp.cpp Fri Apr 28 10:05:29 2017 +0000
@@ -1,3 +1,4 @@
+
//BP Optimised Program for Averaging the received value from PPG and ECG & Check for SD card Storage//
@@ -5,7 +6,8 @@
ADS1291 is a single channel ECG chip
with a 24 bit Sigma-Delta ADC
*/
-
+
+/*
#include "mbed.h"
#include "MAX30102.h" // BP ADD
#include <string.h>
@@ -177,7 +179,7 @@
bc.printf( "DBP = %f\n", DBP);
screen_bp1(SBP,DBP);
-
+*/
//-----------------WRITE ECG &PPG
/*
@@ -202,4 +204,157 @@
- } // End of main function
+ //} // End of main function
+
+
+//-----------------------------------------------NEW BP code starts--------------------------------///
+
+#include "mbed.h"
+#include "MAX30102.h" // BP ADD
+#include <string.h>
+#include <stdio.h>
+//#include <iostream>
+#include "ds3231.h"
+#include "SDFileSystem.h"
+#include "rtc.h"
+#include "sdcard.h"
+#include "ec_bp.h"
+#include "bp.h"
+#include "display_modules.h"
+
+using namespace std;
+
+Serial bc(USBTX,USBRX);
+DigitalIn INTR(PTC7);
+
+Timer t;
+
+//FILE *ecg;
+//FILE *ppg;
+
+void bp(int pid) {
+ uint8_t uch_dummy;
+ uint32_t ppgdata;
+
+ //int dummyconcat = 700000;
+ int concatenate_value2 = 0;
+ unsigned char chk = 1;
+
+ int drum11[64];
+ uint32_t drum21[64];
+
+ // Variables for file operations
+ // uint32_t amax=0;
+ //uint32_t bmax = 0;
+ //uint32_t a;
+ //uint32_t b;
+
+ //int aloc = 0;
+ //int bloc = 0;
+ //int samples = 0;
+
+ bc.baud(baud_rate);
+
+ freqset(); // setting the frequency
+ setupfunc();
+ ecgsetupfunc();
+
+ maxim_max30102_reset(); // PPG reset
+ wait_ms(20);
+ maxim_max30102_init();
+
+ chk = 1;
+
+ wait(2);
+ //bc.printf("BP start\n");
+
+ for(int i=0; i<500; i++)
+ {
+
+ concatenate_value2= readvalue();
+
+ maxim_max30102_read_reg(0,&uch_dummy);
+ while(INTR.read()==1);
+ maxim_max30102_read_fifo(&ppgdata);
+
+ }
+
+
+ sd_open_BP_ECGfile(pid) ; // sd_open_BP_ECGfile(123) draft file for testing
+ sd_open_BP_PPGfile(pid) ; // sd_open_BP_PPGfile(123) draft file for testing
+
+ FILE *ecg = NULL;
+ FILE *ppg = NULL;
+ int *drum_ecg = NULL; // pointers to ecg buffer
+ uint32_t *drum_ppg = NULL; // pointer to ppg buffer
+
+ drum_ecg = drum11;
+ drum_ppg = drum21;
+
+ for(int j =0 ; j<16; j++) // changed to 16 from 8
+ {
+ for(int i=0; i<64; i++)
+ {
+ concatenate_value2 = readvalue();
+ drum11[i]=concatenate_value2; //drum11[i]=concatenate_value2; drum11[i]=dummyconcat;
+
+ maxim_max30102_read_reg(0,&uch_dummy);
+ while(INTR.read()==1);
+ maxim_max30102_read_fifo(&ppgdata);
+ drum21[i]=ppgdata;
+ }
+
+ ecg = sd_BP_ecgwrite(drum_ecg); //
+ ppg = sd_BP_ppgwrite(drum_ppg);
+
+
+ }
+
+ for(int j =0 ; j<10; j++) // changed to 16 from 8
+ {
+ for(int i=0; i<64; i++)
+ {
+ maxim_max30102_read_reg(0,&uch_dummy);
+ while(INTR.read()==1);
+ maxim_max30102_read_fifo(&ppgdata);
+ drum21[i]=ppgdata;
+ }
+
+ ppg = sd_BP_ppgwrite (drum_ppg);
+
+ }
+ fclose(ecg);
+ fclose(ppg);
+
+ maxim_max30102_reset();
+
+ //-----Reading from file starts //
+
+ //std::ifstream ec1("/sd/123_BP_ECG.csv");
+ //std::ifstream pp1("/sd/123_BP_PPG.csv");
+
+ int eloc = 0;
+ int ploc = 0;
+
+
+ eloc = sd_BP_ECGMAX(pid); // eloc = sd_BP_ECGMAX(123);
+ ploc = sd_BP_PPGMAX(pid); // ploc = sd_BP_PPGMAX(123);
+
+ //bc.printf("The ECG max is at : %d", eloc);
+ //bc.printf("The PPG Max is at : %d", ploc);
+
+ float PWV = 0;
+ int d = 210000;
+ int delta_t = 0;
+ float SBP = 0;
+ float DBP = 0;
+
+ delta_t = (2*(ploc - eloc));
+ PWV = d/delta_t;
+
+ SBP = 0.0508955*PWV+62.559;
+ DBP = (0.0494*PWV + 17.480)+10;
+
+ screen_bp1(SBP,DBP);
+
+ }
\ No newline at end of file
