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:
- 7:188bf08cfb44
- Parent:
- 3:a7396ed925e6
- Child:
- 12:2ad10c36f820
--- a/main.cpp Mon Oct 21 06:12:54 2019 +0000 +++ b/main.cpp Thu Oct 31 10:15:58 2019 +0000 @@ -7,7 +7,8 @@ #include "MAX30205.h" #include "System.h" #include "USBSerial.h" - +//#include "unistd.h" + /************************************************************************************************************************************/ // define the HVOUT Boost Voltage default for the MAX14720 PMIC #define HVOUT_VOLTAGE 4500 // set to 4500 mV @@ -28,7 +29,7 @@ #define Calp_sel 0x00 #define Caln_sel 0x00 #define E_fit 0x0F -#define Rate 0x02 +#define Rate 0x00 #define Gain 0x00 #define Dhpf 0x01 #define Dlpf 0x01 @@ -92,7 +93,7 @@ MAX30001 max30001(&spi); InterruptIn max30001_InterruptB(P3_6); InterruptIn max30001_Interrupt2B(P4_5); - + // PWM used as fclk for the MAX30001 PwmOut pwmout(P1_7); @@ -131,23 +132,15 @@ for (k = 0; k < number ; k++) { ECG_Raw = (int32_t)(buffer[k] << 8); ECG_Raw = ECG_Raw >> 14; - usbSerial.printf("ECG Raw: %d;%d\r\n", index, ECG_Raw); - usbSerial.printf("k is %d and number is %d\r\n", k, number); + //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++; } } - - //if(id == MAX30101_OXIMETER_DATA + 2) { - // for (k = 0; k < number; k++) - // SpO_Raw = (int32_t)(buffer[k]); - // usbSerial.printf("SpO Raw: %d\r\n", SpO_Raw); - //} } -//void MAX30101_OnInterrupt(void){ -// I2CM_Init_Reset(2, 1); -//} - int main() { // hold results for returning functions int result; @@ -159,28 +152,6 @@ max14720.boostEn = MAX14720::BOOST_ENABLED; max14720.boostSetVoltage(HVOUT_VOLTAGE); - // This is the SpO2 mode (IR&Red LED) - //max30101.SpO2mode_init(FIFO_WATERLEVEL_MARK, SAMPLE_AVG, SAMPLE_RATE, PULSE_WIDTH, RED_LED_CURRENT, IR_LED_CURRENT); - - // MAX30101 initialize interrupt - //max30101.onInterrupt(&MAX30101_OnInterrupt); - //max30101.onDataAvailable(&StreamPacketUint32_ex); - //max30101_Interrupt.fall(&MAX30101MidIntHandler); - - // LIS2DH initialize interrupt - //lis2dh.onInterrupt(&MAX30101_OnInterrupt); - //lis2dh.onDataAvailable(&StreamPacketUint32_ex); - //lis2dh_Interrupt.fall(&MAX30101MidIntHandler); - - // Initialise the BMP280 - //bmp280_pres.init(BMP280::OVERSAMPLING_X16_P, BMP280::OVERSAMPLING_X2_T, BMP280::FILT_4, BMP280::NORMAL_MODE, BMP280::T_62_5); - - // LIS2DH initialize interrupt - lis2dh.initStart(LIS2DH_DATARATE_50HZ, LIS2DH_FIFO_SIZE); - //lis2dh.init(); - //lis2dh_Interrupt.fall(&LIS2DHIntHandler); - //lis2dh_Interrupt.mode(PullUp); - // Interrupt priority NVIC_SetPriority(GPIO_P0_IRQn, 5); NVIC_SetPriority(GPIO_P1_IRQn, 5); @@ -229,43 +200,80 @@ MAX30001::MAX30001_INT_ODNR, // intb_Type MAX30001::MAX30001_INT_ODNR); // int2b_Type - - // MAX30001 initialize interrupt - /* + + 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_synch(); max30001.onDataAvailable(&StreamPacketUint32_ex); - */ - int a; + + while (1){ + // MAX30001 initialize interrupt + // ECG READING - while (1) { + // 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]); + 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]); + /* - wait(5); - a = usbSerial._getc(); - usbSerial.printf("WAIT 5 LIAO\n\n\n\r"); + int child_pid = fork(); + int status; - if (a == 98) { - max30001.max30001_Stop_ECG(); - index = 0; + + if (child_pid == 0) { + while (1){ + a = usbSerial._getc(); + if (a==97){ + max30001.max30001_Stop_ECG(); + lis2dh.stop(); + return 0; + } + } } - // if (a == 97) - // Read ECG - if (a == 97) - { - usbSerial.printf("-------------------------------------------------\n\n\n\r"); - 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); - usbSerial.printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\n\n\r"); - } + //LOOP-FOREVER READ ACCELEROTMETER + else { + pid_t result = waitpid(child_pid, &status, WNOHANG); + if (result == 0) { + while (1) { */ - lis2dh.int_handler(); - lis2dh.get_motion_fifo(&accel_value[0], &accel_value[1], &accel_value[2]); + /* + 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 *****\n\r"); - usbSerial.printf("X-Axis: %d\n\rY-Axis: %d\n\rZ-Axis: %d", accel_value[0], accel_value[1], accel_value[2]); - usbSerial.printf("-------------------------------------------------\n\n\n\r"); - wait(1); - } + //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; + } + } + } + } + */ + } }