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.
Diff: main.cpp
- Revision:
- 13:0f663ca63342
- Parent:
- 12:2ad10c36f820
--- a/main.cpp Mon Nov 11 17:38:48 2019 +0000 +++ b/main.cpp Wed Nov 13 11:10:03 2019 +0000 @@ -1,23 +1,11 @@ #include "mbed.h" #include "LIS2DH.h" -#include "MAX14720.h" #include "MAX30001.h" -#include "MAX30205.h" #include "System.h" -#include "USBSerial.h" -//#include "unistd.h" +#include "USBSerial.h" -/************************************************************************************************************************************/ -// define the HVOUT Boost Voltage default for the MAX14720 PMIC -#define HVOUT_VOLTAGE 4500 // set to 4500 mV - -// define all I2C addresses -#define LIS2DH_I2C_SLAVE_ADDR (0x32) -#define MAX14720_I2C_SLAVE_ADDR (0x54) -#define MAX30101_I2C_SLAVE_ADDR (0xAE) -#define MAX30205_I2C_SLAVE_ADDR_BOTTOM (0x90) -#define MAX30205_I2C_SLAVE_ADDR_TOP (0x92) -#define BMP280_I2C_SLAVE_ADDR (0xEC) +/******************************************************************************/ +#define LIS2DH_I2C_SLAVE_ADDR (0x32) // Settings for ECG Initialization #define En_ecg 0x01 @@ -43,42 +31,19 @@ #define Rhsf 0x04 #define Clr_rrint 0x01 -// Settings for Lead Detection -#define En_dcloff 0x01 -#define Ipol 0x00 -#define Imag 0x00 -#define Vth 0x00 - -// Settings for the HR initialization -#define FIFO_WATERLEVEL_MARK 15 -#define SAMPLE_AVG 2 -#define SAMPLE_RATE 1 -#define PULSE_WIDTH 2 -#define RED_LED_CURRENT 0x1F -#define IR_LED_CURRENT 0X1F - -// Define with Maxim VID and a Maxim assigned PID, set to version 0x0001 and non-blocking +// Define with Maxim VID and a Maxim assigned PID, set to version 0x0001 and +// non-blocking USBSerial usbSerial(0x0b6a, 0x0100, 0x0001, false); -// I2C Masters -I2C i2c1(I2C1_SDA, I2C1_SCL); // used by MAX30205 -I2C i2c2(I2C2_SDA, I2C2_SCL); // used by MAX14720, LIS2DH +// LIS2DH I2C Master +I2C i2c2(I2C2_SDA, I2C2_SCL); // SPI Master 0 with SPI0_SS for use with MAX30001 SPI spi(SPI0_MOSI, SPI0_MISO, SPI0_SCK, SPI0_SS); -// PMIC -MAX14720 max14720(&i2c2, MAX14720_I2C_SLAVE_ADDR); - // Accelerometer LIS2DH lis2dh(&i2c2, LIS2DH_I2C_SLAVE_ADDR); InterruptIn lis2dh_Interrupt(P4_7); - -// Top Temperature Sensor -MAX30205 MAX30205_top(&i2c1, MAX30205_I2C_SLAVE_ADDR_TOP); - -// Botttom Temperature Sensor -MAX30205 MAX30205_bottom(&i2c1, MAX30205_I2C_SLAVE_ADDR_BOTTOM); // ECG device MAX30001 max30001(&spi); @@ -91,54 +56,35 @@ DigitalOut led(LED1); // Data of sensors -int32_t ECG_Raw, ECG_cumul, SpO_Raw; +int16_t Acc[3]; +int32_t ECG_Raw, ECG_cumul; double ECG_converted = 0; uint32_t index = 0; - -//Temperature sensor variables -uint16_t rawTemp_top, rawTemp_bottom; -float celsius_top, celsius_bottom, fahrenheit_top, fahrenheit_bottom; - -// Accelerometer sensor variables -int16_t accel_value[3]; - -//write the power down command to PMIC -void turnOff() { - max14720.shutdown(); -} -//@brief Creates a packet that will be streamed via USB Serial -//@brief the packet created will be inserted into a fifo to be streamed at a later time -//@param id Streaming ID -//@param buffer Pointer to a uint32 array that contains the data to include in the packet +//@brief Creates a packet that will be streamed via USB Serial, the packet +// created will be inserted into a fifo to be streamed at a later time +//@param id Streaming ID +//@param buffer Pointer to a uint32 array that contains the data to include in +// the packet //@param number Number of elements in the buffer void StreamPacketUint32_ex(uint32_t id, uint32_t *buffer, uint32_t number) { int k; if(id == MAX30001_DATA_ECG) { - for (k = 0; k < number ; k++) { + for (k = 0; k < number; k++) { ECG_Raw = (int32_t)(buffer[k] << 8); ECG_Raw = ECG_Raw >> 14; - //usbSerial.printf("%s ECG", datetime.datetime.utcnow().strftime("%H:%M:%S")); usbSerial.printf("ECG\r\n"); usbSerial.printf("%d\r\n", ECG_Raw); - //usbSerial.printf("k is %d and number is %d\r\n", k, number); index++; } } } int main() { - // hold results for returning functions + // Hold results for returning functions int result; - // initialize HVOUT on the MAX14720 PMIC - result = max14720.init(); - if (result == MAX14720_ERROR) - printf("Error initializing MAX14720"); - max14720.boostEn = MAX14720::BOOST_ENABLED; - max14720.boostSetVoltage(HVOUT_VOLTAGE); - // Interrupt priority NVIC_SetPriority(GPIO_P0_IRQn, 5); NVIC_SetPriority(GPIO_P1_IRQn, 5); @@ -189,78 +135,15 @@ MAX30001::MAX30001_INT_ODNR); // int2b_Type lis2dh.initStart(LIS2DH_DATARATE_50HZ, LIS2DH_FIFO_SIZE); - - max30001.max30001_ECG_InitStart(En_ecg, Openp, Openn, Pol, Calp_sel, Caln_sel, E_fit, Rate, Gain, Dhpf, Dlpf); + max30001.max30001_ECG_InitStart(En_ecg, Openp, Openn, Pol, Calp_sel, + Caln_sel, E_fit, Rate, Gain, Dhpf, Dlpf); max30001.max30001_synch(); max30001.onDataAvailable(&StreamPacketUint32_ex); while (1){ - // MAX30001 initialize interrupt - // ECG READING - - // LIS2DH initialize interrupt - //lis2dh.init(); - //lis2dh_Interrupt.fall(&LIS2DHIntHandler); - //lis2dh_Interrupt.mode(PullUp); - int a; - lis2dh.get_motion_fifo(&accel_value[0], &accel_value[1], &accel_value[2]); + lis2dh.get_motion_fifo(&Acc[0], &Acc[1], &Acc[2]); usbSerial.printf("ACC\r\n"); - - usbSerial.printf("X %d\r\nY %d\r\nZ %d\r\n", accel_value[0], accel_value[1], accel_value[2]); - - /* - int child_pid = fork(); - int status; - - - if (child_pid == 0) { - while (1){ - a = usbSerial._getc(); - if (a==97){ - max30001.max30001_Stop_ECG(); - lis2dh.stop(); - return 0; - } - } - } - //LOOP-FOREVER READ ACCELEROTMETER - else { - pid_t result = waitpid(child_pid, &status, WNOHANG); - if (result == 0) { - while (1) { - */ - - /* - wait(5); - a = usbSerial._getc(); - usbSerial.printf("WAIT 5 LIAO\r\n"); - - if (a == 98) { - max30001.max30001_Stop_ECG(); - index = 0; - } - */ - /* - lis2dh.int_handler(); - - lis2dh.get_motion_fifo(&accel_value[0], &accel_value[1], &accel_value[2]); - - //usbSerial.printf("***** LIS2DH Acclerometer Sensor Reading *****\r\n"); - usbSerial.printf("X %d\r\nY %d\r\nZ %d\r\n", accel_value[0], accel_value[1], accel_value[2]); - //usbSerial.printf("-------------------------------------------------\r\n"); - wait(1); - } - } else { - while(1){ - usbSerial.printf("Press c to continue\r\n"); - a = usbSerial._getc(); - if (a==99){ - break; - } - } - } - } - */ + usbSerial.printf("X %d\r\nY %d\r\nZ %d\r\n", Acc[0], Acc[1], Acc[2]); } }