You are on page 1of 6

// Ensure this library description is only included once

//#ifndef eHealthClass_h
//#define eHealthClass_h
// Library interface description
class eHealthClass {
public:
// Constructor of the class
//! Class constructor.
eHealthClass(void);

// Public Methods
*
//! Initializes the position sensor and configure some values.
/*!
//! Initializes the BloodPressureSensor sensor and configure some values
/*!
\param float parameter with correction value
\return void
*/ void readBloodPressureSensor(void);
//! Returns the heart beats per minute.
/*!
\param void
\return int : The beats per minute.
*/ int getBPM(void);
//! Returns the value of the systolic pressure.
/*!
\param void
\return int : The systolic pressure.
*/ int getSystolicPressure(int i);
//! Returns the value of the diastolic pressure.
/*!
\param void
\return int : The diastolic pressure.
*/ int getDiastolicPressure(int i);
//!Returns the number of data stored in the blood pressure sensor.
/*!
\param void
\return int : length of data
*/ uint8_t getBloodPressureLength(void);
//! Convert month variable from numeric to character.
/*!
\param int month in numerical format.
\return String with the month characters (January, February...).
*/ String numberToMonth(int month);
//!Struct to store data of the blood pressure sensor.
struct bloodPressureData {
uint8_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minutes;
uint8_t systolic;
uint8_t diastolic;

uint8_t pulse;
};
//!Vector to store the blood pressure measures and dates.
bloodPressureData bloodPressureDataVector[8];
private:
// Private Variables
*
//! It stores the systolic pressure value
int systolic;
//! It stores the diastolic pressure value
int diastolic;
//! It stores the beats per minute value.
int BPM;
};
extern eHealthClass eHealth;
//////////////////
// Constructor of the class
*
//! Function that handles the creation and setup of instances
eHealthClass::eHealthClass(void) { /*void constructor*/ }
// Public Methods

//!***************************************************************************
***
//! Name: readBloodPressureSensor()
*
//! Description: Initializes the BloodPressureSensor sensor.
*
//! Param : void
*
//! Returns: void
*
//! Example: eHealth.initBloodPressureSensor();
*
//!***************************************************************************
***
void eHealthClass::readBloodPressureSensor(void)
{
unsigned char _data;
int ia=0;
length=0;
Serial.begin(19200);
Serial.write(0xAA);
delayMicroseconds(1);
Serial.write(0x55);
delayMicroseconds(1);
Serial.write(0x88);
delay(2500);
Serial.print("\n");
if (Serial.available() > 0) { // The protocol sends the measures
for (int i = 0; i<4; i++){ // Read four dummy data
Serial.read();
}

while(_data != 0xD1){
if (ia==0){
_data = Serial.read();
}
bloodPressureDataVector[length].year = swap(_data);
bloodPressureDataVector[length].month = swap(Serial.read());
bloodPressureDataVector[length].day = swap(Serial.read());
bloodPressureDataVector[length].hour = swap(Serial.read());
bloodPressureDataVector[length].minutes = swap(Serial.read());
bloodPressureDataVector[length].systolic = swap(Serial.read());
bloodPressureDataVector[length].diastolic = swap(Serial.read());
bloodPressureDataVector[length].pulse = swap(Serial.read());
length++;
ia=1;
for (int i = 0; i<4; i++){ // CheckSum 1
Serial.read();
}
_data = Serial.read();
}
for (int i = 0; i<3; i++){ // CheckSum 2
Serial.read();
}
}
}
//!***************************************************************************
***
//! Name: getBPM()
*
//! Description: Returns the heart beats per minute.
*
//! Param : void
*
//! Returns: int with the beats per minute
*
//! Example: int BPM = eHealth.getBPM();
*
//!***************************************************************************
***
int eHealthClass::getBPM(void)
{
return BPM;
}
//!***************************************************************************
***
//! Name: getSystolicPressure()
*
//! Description: Returns the value of the systolic pressure.
*
//! Param : void
*
//! Returns: int with the systolic pressure.
*
//! Example: int systolic = eHealth.getSystolicPressure();
*
//!***************************************************************************
***
int eHealthClass::getSystolicPressure(int i)
{
return bloodPressureDataVector[i].systolic;
}

//!***************************************************************************
***
//! Name: getDiastolicPressure()
*
//! Description: Returns the value of the diastolic pressure.
*
//! Param : void
*
//! Returns: int with the diastolic pressure.
*
//! Example: int diastolic = eHealth.getDiastolicPressure();
*
//!***************************************************************************
***
int eHealthClass::getDiastolicPressure(int i)
{
return bloodPressureDataVector[i].diastolic;
}
//!***************************************************************************
***
//! Name: getBloodPressureLength()
*
//! Description: it returns the number of data stored in
*
//! the blood pressure sensor
*
//! Param : void
*
//! Returns: uint8_t with length
*
//! Example: int length = eHealth.getBloodPressureLength();
*
//!***************************************************************************
***
uint8_t eHealthClass::getBloodPressureLength(void)
{
return length;
}
//!***************************************************************************
***
//! Name: numberToMonth()
*
//! Description: Convert month variable from numeric to character.
*
//! Param : int month in numerical format
*
//! Returns: String with the month characters (January, February...). *
//! Example: Serial.print(eHealth.numberToMonth(month));
*
//!***************************************************************************
***
String eHealthClass::numberToMonth(int month)
{
if (month == 1) return "January";
else if (month == 2) return "February";
else if (month == 3) return "March";
else if (month == 4) return "April";
else if (month == 5) return "May";
else if (month == 6) return "June";
else if (month == 7) return "July";
else if (month == 8) return "August";
else if (month == 9) return "September";
else if (month == 10) return "October";
else if (month == 11) return "November";
else return "December";
}
// Private Methods

//! Swap data for blood pressure mesure


char eHealthClass::swap(char _data)
{
char highBits = (_data & 0xF0) / 16;
char lowBits = (_data & 0x0F) * 16;
return ~(highBits + lowBits);
}
// Preinstantiate Objects
eHealthClass eHealth = eHealthClass();

void setup() {
eHealth.readBloodPressureSensor();
Serial.begin(115200);
delay(100);
}
void loop() {
uint8_t numberOfData = eHealth.getBloodPressureLength();
Serial.print(F("Number of measures : "));
Serial.println(numberOfData, DEC);
delay(100);
for (int i = 0; i<numberOfData; i++) {
// The protocol sends data in this order
Serial.println(F("=========================================="));
Serial.print(F("Measure number "));
Serial.println(i + 1);
Serial.print(F("Date -> "));
Serial.print(eHealth.bloodPressureDataVector[i].day);
Serial.print(F(" of "));
Serial.print(eHealth.numberToMonth(eHealth.bloodPressureDataVector[i].month)
);
Serial.print(F(" of "));
Serial.print(2000 + eHealth.bloodPressureDataVector[i].year);
Serial.print(F(" at "));
if (eHealth.bloodPressureDataVector[i].hour < 10) {
Serial.print(0); // Only for best representation.
}
Serial.print(eHealth.bloodPressureDataVector[i].hour);
Serial.print(F(":"));
if (eHealth.bloodPressureDataVector[i].minutes < 10) {
Serial.print(0);// Only for best representation.
}
Serial.println(eHealth.bloodPressureDataVector[i].minutes);
Serial.print(F("Systolic value : "));
Serial.print(30+eHealth.bloodPressureDataVector[i].systolic);
Serial.println(F(" mmHg"));
Serial.print(F("Diastolic value : "));

Serial.print(eHealth.bloodPressureDataVector[i].diastolic);
Serial.println(F(" mmHg"));
Serial.print(F("Pulse value : "));
Serial.print(eHealth.bloodPressureDataVector[i].pulse);
Serial.println(F(" bpm"));
}
delay(20000);
}

You might also like