/**
* @file main.c
* @brief 低功耗设计,程序实现舒眠科技智眠传感带信号采集和呼吸,心跳提取功能,实现和上位设备的通信功能
*/
//作者:Justice
//版本:V1.0.0
//日期:2017-05-25
//工具:Keil MDK 5.23
//修改日期:2017-06-28
//修改内容:不修改底层源代码,把需要改的函数放在相应的自定义文件中
//修改日期:2017-06-29
//修改内容:增加了BootLoader程序,支持IAP升级
/***** Includes *****/
#include "Com.h"
#define REPORTING_PERIOD_MS 1000
const uint8_t Test_Buff[10] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A};
uint32_t aun_ir_buffer[500]; //IR LED sensor data
int32_t n_ir_buffer_length; //data length
uint32_t aun_red_buffer[500]; //Red LED sensor data
int32_t n_sp02; //SPO2 value
int8_t ch_spo2_valid; //indicator to show if the SP02 calculation is valid
int32_t n_heart_rate; //heart rate value
int8_t ch_hr_valid; //indicator to show if the heart rate calculation is valid
uint8_t uch_dummy;
#define MAX_BRIGHTNESS 255
#define false 0
#define true 1
int main(void)
{
uint32_t un_min, un_max, un_prev_data; //variables to calculate the on-board LED brightness that reflects the heartbeats
int i;
int32_t n_brightness;
float f_temp;
USART2_Configuration(115200);
I2CM_Init(MAX14690_I2CM, &max14690_sys_cfg, I2CM_SPEED_100KHZ);
I2CM_Init(MXC_I2CM1, &max30102_sys_cfg, I2CM_SPEED_100KHZ);
//Device_Hardware_Init();
maxim_max30102_reset(); //resets the MAX30102
//read and clear status register
maxim_max30102_read_reg(0,&uch_dummy);
maxim_max30102_init(); //initializes the MAX30102
n_brightness=0;
un_min=0x3FFFF;
un_max=0;
n_ir_buffer_length=500; //buffer length of 100 stores 5 seconds of samples running at 100sps
//read the first 500 samples, and determine the signal range
for(i=0;i<n_ir_buffer_length;i++)
{
//while(INT.read()==1); //wait until the interrupt pin asserts
maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i)); //read from MAX30102 FIFO
if(un_min>aun_red_buffer[i])[/i]
[i] un_min=aun_red_buffer; //update signal min[/i]
[i] if(un_max<aun_red_buffer)[/i]
[i] un_max=aun_red_buffer; //update signal max[/i]
[i] printf("red=");[/i]
[i] printf("%i", aun_red_buffer);[/i]
[i] printf(", ir=");[/i]
[i] printf("%i\n\r", aun_ir_buffer);[/i]
[i] }[/i]
[i] un_prev_data=aun_red_buffer;[/i]
[i] //calculate heart rate and SpO2 after first 500 samples (first 5 seconds of samples)[/i]
[i] maxim_heart_rate_and_oxygen_saturation(aun_ir_buffer, n_ir_buffer_length, aun_red_buffer, &n_sp02, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid); [/i]
[i] //Continuously taking samples from MAX30102. Heart rate and SpO2 are calculated every 1 second[/i]
[i] while(1)[/i]
[i] {[/i]
[i] i=0;[/i]
[i] un_min=0x3FFFF;//???[/i]
[i] un_max=0;[/i]
[i] //dumping the first 100 sets of samples in the memory and shift the last 400 sets of samples to the top[/i]
[i] for(i=100;i<500;i++)[/i]
[i] {[/i]
[i] aun_red_buffer[i-100]=aun_red_buffer;[/i]
[i] aun_ir_buffer[i-100]=aun_ir_buffer;[/i]
[i] //update the signal min and max[/i]
[i] if(un_min>aun_red_buffer)[/i]
[i] un_min=aun_red_buffer;[/i]
[i] if(un_max<aun_red_buffer)[/i]
[i] un_max=aun_red_buffer;[/i]
[i] }[/i]
[i] //take 100 sets of samples before calculating the heart rate.[/i]
[i] for(i=400;i<500;i++)[/i]
[i] {[/i]
[i] un_prev_data=aun_red_buffer[i-1];[/i]
[i] // while(INT.read()==1);[/i]
[i] maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i));[/i]
[i] if(aun_red_buffer>un_prev_data)//just to determine the brightness of LED according to the deviation of adjacent two AD data[/i]
[i] {[/i]
[i] f_temp=aun_red_buffer-un_prev_data;[/i]
[i] f_temp/=(un_max-un_min);[/i]
[i] f_temp*=MAX_BRIGHTNESS;[/i]
[i] n_brightness-=(int)f_temp;[/i]
[i] if(n_brightness<0)[/i]
[i] n_brightness=0;[/i]
[i] }[/i]
[i] else[/i]
[i] {[/i]
[i] f_temp=un_prev_data-aun_red_buffer;[/i]
[i] f_temp/=(un_max-un_min);[/i]
[i] f_temp*=MAX_BRIGHTNESS;[/i]
[i] n_brightness+=(int)f_temp;[/i]
[i] if(n_brightness>MAX_BRIGHTNESS)[/i]
[i] n_brightness=MAX_BRIGHTNESS;[/i]
[i] }[/i]
[i] //led.write(1-(float)n_brightness/256);//pwm control led brightness[/i]
[i] //send samples and calculation result to terminal program through UART[/i]
[i] printf("red=");[/i]
[i] printf("%i", aun_red_buffer);[/i]
[i] printf(", ir=");[/i]
[i] printf("%i", aun_ir_buffer);[/i]
[i] printf(", HR=%i, ", n_heart_rate); [/i]
[i] printf("HRvalid=%i, ", ch_hr_valid);[/i]
[i] printf("SpO2=%i, ", n_sp02);[/i]
[i] printf("SPO2Valid=%i\n\r", ch_spo2_valid);[/i]
[i] }[/i]
[i] maxim_heart_rate_and_oxygen_saturation(aun_ir_buffer, n_ir_buffer_length, aun_red_buffer, &n_sp02, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid); [/i]
[i] }[/i]
[i]}[/i]1223334444tk
[i]
评论0