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.
Fork of RD117_MBED by
main.cpp@5:27d600e46926, 2018-04-10 (annotated)
- Committer:
- denizdosluoglu
- Date:
- Tue Apr 10 03:36:39 2018 +0000
- Revision:
- 5:27d600e46926
- Parent:
- 4:5273ab1085ab
- Child:
- 6:519bdb0ec306
Changed algorithm
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MaximGordon | 0:346a7fa07998 | 1 | /** \file main.cpp ****************************************************** |
MaximGordon | 0:346a7fa07998 | 2 | * |
MaximGordon | 0:346a7fa07998 | 3 | * Project: MAXREFDES117# |
MaximGordon | 0:346a7fa07998 | 4 | * Filename: main.cpp |
MaximGordon | 0:346a7fa07998 | 5 | * Description: This module contains the Main application for the MAXREFDES117 example program. |
MaximGordon | 0:346a7fa07998 | 6 | * |
MaximGordon | 0:346a7fa07998 | 7 | * |
MaximGordon | 0:346a7fa07998 | 8 | * -------------------------------------------------------------------- |
MaximGordon | 0:346a7fa07998 | 9 | * |
MaximGordon | 0:346a7fa07998 | 10 | * This code follows the following naming conventions: |
MaximGordon | 0:346a7fa07998 | 11 | * |
MaximGordon | 4:5273ab1085ab | 12 | * char ch_pmod_value |
MaximGordon | 4:5273ab1085ab | 13 | * char (array) s_pmod_s_string[16] |
MaximGordon | 4:5273ab1085ab | 14 | * float f_pmod_value |
MaximGordon | 4:5273ab1085ab | 15 | * int32_t n_pmod_value |
MaximGordon | 4:5273ab1085ab | 16 | * int32_t (array) an_pmod_value[16] |
MaximGordon | 4:5273ab1085ab | 17 | * int16_t w_pmod_value |
MaximGordon | 4:5273ab1085ab | 18 | * int16_t (array) aw_pmod_value[16] |
MaximGordon | 4:5273ab1085ab | 19 | * uint16_t uw_pmod_value |
MaximGordon | 4:5273ab1085ab | 20 | * uint16_t (array) auw_pmod_value[16] |
MaximGordon | 4:5273ab1085ab | 21 | * uint8_t uch_pmod_value |
MaximGordon | 4:5273ab1085ab | 22 | * uint8_t (array) auch_pmod_buffer[16] |
MaximGordon | 4:5273ab1085ab | 23 | * uint32_t un_pmod_value |
MaximGordon | 4:5273ab1085ab | 24 | * int32_t * pn_pmod_value |
MaximGordon | 0:346a7fa07998 | 25 | * |
MaximGordon | 0:346a7fa07998 | 26 | * ------------------------------------------------------------------------- */ |
MaximGordon | 0:346a7fa07998 | 27 | /******************************************************************************* |
MaximGordon | 4:5273ab1085ab | 28 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
MaximGordon | 0:346a7fa07998 | 29 | * |
MaximGordon | 0:346a7fa07998 | 30 | * Permission is hereby granted, free of charge, to any person obtaining a |
MaximGordon | 0:346a7fa07998 | 31 | * copy of this software and associated documentation files (the "Software"), |
MaximGordon | 0:346a7fa07998 | 32 | * to deal in the Software without restriction, including without limitation |
MaximGordon | 0:346a7fa07998 | 33 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
MaximGordon | 0:346a7fa07998 | 34 | * and/or sell copies of the Software, and to permit persons to whom the |
MaximGordon | 0:346a7fa07998 | 35 | * Software is furnished to do so, subject to the following conditions: |
MaximGordon | 0:346a7fa07998 | 36 | * |
MaximGordon | 0:346a7fa07998 | 37 | * The above copyright notice and this permission notice shall be included |
MaximGordon | 0:346a7fa07998 | 38 | * in all copies or substantial portions of the Software. |
MaximGordon | 0:346a7fa07998 | 39 | * |
MaximGordon | 0:346a7fa07998 | 40 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
MaximGordon | 0:346a7fa07998 | 41 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
MaximGordon | 0:346a7fa07998 | 42 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
MaximGordon | 0:346a7fa07998 | 43 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
MaximGordon | 0:346a7fa07998 | 44 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
MaximGordon | 0:346a7fa07998 | 45 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
MaximGordon | 0:346a7fa07998 | 46 | * OTHER DEALINGS IN THE SOFTWARE. |
MaximGordon | 0:346a7fa07998 | 47 | * |
MaximGordon | 0:346a7fa07998 | 48 | * Except as contained in this notice, the name of Maxim Integrated |
MaximGordon | 0:346a7fa07998 | 49 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
MaximGordon | 0:346a7fa07998 | 50 | * Products, Inc. Branding Policy. |
MaximGordon | 0:346a7fa07998 | 51 | * |
MaximGordon | 0:346a7fa07998 | 52 | * The mere transfer of this software does not imply any licenses |
MaximGordon | 0:346a7fa07998 | 53 | * of trade secrets, proprietary technology, copyrights, patents, |
MaximGordon | 0:346a7fa07998 | 54 | * trademarks, maskwork rights, or any other form of intellectual |
MaximGordon | 0:346a7fa07998 | 55 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
MaximGordon | 0:346a7fa07998 | 56 | * ownership rights. |
MaximGordon | 0:346a7fa07998 | 57 | ******************************************************************************* |
MaximGordon | 0:346a7fa07998 | 58 | */ |
MaximGordon | 0:346a7fa07998 | 59 | /*!\mainpage Main Page |
MaximGordon | 0:346a7fa07998 | 60 | * |
MaximGordon | 0:346a7fa07998 | 61 | * \section intro_sec Introduction |
MaximGordon | 0:346a7fa07998 | 62 | * |
MaximGordon | 0:346a7fa07998 | 63 | * This is the code documentation for the MAXREFDES117# subsystem reference design. |
MaximGordon | 4:5273ab1085ab | 64 | * |
MaximGordon | 4:5273ab1085ab | 65 | * The Files page contains the File List page and the Globals page. |
MaximGordon | 4:5273ab1085ab | 66 | * |
MaximGordon | 4:5273ab1085ab | 67 | * The Globals page contains the Functions, Variables, and Macros sub-pages. |
MaximGordon | 0:346a7fa07998 | 68 | * |
MaximGordon | 0:346a7fa07998 | 69 | * \image html MAXREFDES117_Block_Diagram.png "MAXREFDES117# System Block Diagram" |
MaximGordon | 4:5273ab1085ab | 70 | * |
MaximGordon | 0:346a7fa07998 | 71 | * \image html MAXREFDES117_firmware_Flowchart.png "MAXREFDES117# Firmware Flowchart" |
MaximGordon | 0:346a7fa07998 | 72 | * |
MaximGordon | 0:346a7fa07998 | 73 | */ |
MaximGordon | 0:346a7fa07998 | 74 | #include "mbed.h" |
denizdosluoglu | 5:27d600e46926 | 75 | //#include "algorithm.h" |
denizdosluoglu | 5:27d600e46926 | 76 | #include "algorithm_by_RF.h" |
MaximGordon | 0:346a7fa07998 | 77 | #include "MAX30102.h" |
denizdosluoglu | 5:27d600e46926 | 78 | #include "C12832.h" |
MaximGordon | 0:346a7fa07998 | 79 | #define MAX_BRIGHTNESS 255 |
denizdosluoglu | 5:27d600e46926 | 80 | /* |
denizdosluoglu | 5:27d600e46926 | 81 | #ifndef PLATFORM_H_ |
denizdosluoglu | 5:27d600e46926 | 82 | #define PLATFORM_H_ |
denizdosluoglu | 5:27d600e46926 | 83 | //disable application functions |
denizdosluoglu | 5:27d600e46926 | 84 | #define PL_BOARD_IS_FRDM 1 |
denizdosluoglu | 5:27d600e46926 | 85 | #define PL_HAS_LOW_POWER 1 |
denizdosluoglu | 5:27d600e46926 | 86 | #define PL_HAS_SHELL 0 |
denizdosluoglu | 5:27d600e46926 | 87 | #define PL_HAS_LED 1 |
denizdosluoglu | 5:27d600e46926 | 88 | #define PL_HAS_RTOS 0 |
denizdosluoglu | 5:27d600e46926 | 89 | |
denizdosluoglu | 5:27d600e46926 | 90 | #endif PLATFORM_H_ */ |
MaximGordon | 0:346a7fa07998 | 91 | |
MaximGordon | 3:7c0fb55eb3ff | 92 | uint32_t aun_ir_buffer[500]; //IR LED sensor data |
denizdosluoglu | 5:27d600e46926 | 93 | //int32_t n_ir_buffer_length; //data length |
denizdosluoglu | 5:27d600e46926 | 94 | float n_ir_buffer_length; //data length |
MaximGordon | 3:7c0fb55eb3ff | 95 | uint32_t aun_red_buffer[500]; //Red LED sensor data |
denizdosluoglu | 5:27d600e46926 | 96 | //int32_t n_sp02; //SPO2 value |
denizdosluoglu | 5:27d600e46926 | 97 | float n_sp02;//SPO2 value |
MaximGordon | 0:346a7fa07998 | 98 | int8_t ch_spo2_valid; //indicator to show if the SP02 calculation is valid |
MaximGordon | 0:346a7fa07998 | 99 | int32_t n_heart_rate; //heart rate value |
MaximGordon | 0:346a7fa07998 | 100 | int8_t ch_hr_valid; //indicator to show if the heart rate calculation is valid |
MaximGordon | 0:346a7fa07998 | 101 | uint8_t uch_dummy; |
denizdosluoglu | 5:27d600e46926 | 102 | Timer t; |
MaximGordon | 0:346a7fa07998 | 103 | |
MaximGordon | 0:346a7fa07998 | 104 | Serial pc(USBTX, USBRX); //initializes the serial port |
MaximGordon | 0:346a7fa07998 | 105 | #ifdef TARGET_KL25Z |
MaximGordon | 0:346a7fa07998 | 106 | PwmOut led(PTB18); //initializes the pwm output that connects to the on board LED |
denizdosluoglu | 5:27d600e46926 | 107 | DigitalIn INT(PTD0); //pin PTD0 connects to the interrupt output pin of the MAX30102 |
MaximGordon | 0:346a7fa07998 | 108 | #endif |
MaximGordon | 0:346a7fa07998 | 109 | #ifdef TARGET_K64F |
MaximGordon | 0:346a7fa07998 | 110 | DigitalIn INT(PTD1); //pin PTD1 connects to the interrupt output pin of the MAX30102 |
MaximGordon | 0:346a7fa07998 | 111 | #endif |
MaximGordon | 0:346a7fa07998 | 112 | #ifdef TARGET_MAX32600MBED |
MaximGordon | 0:346a7fa07998 | 113 | PwmOut led(LED_RED); //initializes the pwm output that connects to the on board LED |
MaximGordon | 0:346a7fa07998 | 114 | DigitalIn INT(P2_0); //pin P20 connects to the interrupt output pin of the MAX30102 |
MaximGordon | 0:346a7fa07998 | 115 | #endif |
MaximGordon | 0:346a7fa07998 | 116 | |
denizdosluoglu | 5:27d600e46926 | 117 | //C12832 lcd(PTD2,PTD1,PTA20,PTD5, PTD4); |
denizdosluoglu | 5:27d600e46926 | 118 | |
MaximGordon | 0:346a7fa07998 | 119 | // the setup routine runs once when you press reset: |
MaximGordon | 0:346a7fa07998 | 120 | int main() { |
denizdosluoglu | 5:27d600e46926 | 121 | t.start(); |
denizdosluoglu | 5:27d600e46926 | 122 | //lcd.cls(); |
denizdosluoglu | 5:27d600e46926 | 123 | // wait(100); |
denizdosluoglu | 5:27d600e46926 | 124 | // lcd.printf("Hello world"); |
denizdosluoglu | 5:27d600e46926 | 125 | /* |
denizdosluoglu | 5:27d600e46926 | 126 | wait(100); |
denizdosluoglu | 5:27d600e46926 | 127 | |
denizdosluoglu | 5:27d600e46926 | 128 | for (int i = 20; i < 30; i++) |
denizdosluoglu | 5:27d600e46926 | 129 | { |
denizdosluoglu | 5:27d600e46926 | 130 | for (int j = 20; j <30; j++) |
denizdosluoglu | 5:27d600e46926 | 131 | { |
denizdosluoglu | 5:27d600e46926 | 132 | lcd.clearpixel(i,j); |
denizdosluoglu | 5:27d600e46926 | 133 | } |
denizdosluoglu | 5:27d600e46926 | 134 | } |
denizdosluoglu | 5:27d600e46926 | 135 | */ |
denizdosluoglu | 5:27d600e46926 | 136 | |
MaximGordon | 0:346a7fa07998 | 137 | uint32_t un_min, un_max, un_prev_data; //variables to calculate the on-board LED brightness that reflects the heartbeats |
MaximGordon | 0:346a7fa07998 | 138 | int i; |
MaximGordon | 0:346a7fa07998 | 139 | int32_t n_brightness; |
denizdosluoglu | 5:27d600e46926 | 140 | float f_temp, ratio, correl; |
MaximGordon | 0:346a7fa07998 | 141 | |
MaximGordon | 0:346a7fa07998 | 142 | maxim_max30102_reset(); //resets the MAX30102 |
MaximGordon | 0:346a7fa07998 | 143 | // initialize serial communication at 115200 bits per second: |
MaximGordon | 0:346a7fa07998 | 144 | pc.baud(115200); |
MaximGordon | 0:346a7fa07998 | 145 | pc.format(8,SerialBase::None,1); |
MaximGordon | 0:346a7fa07998 | 146 | wait(1); |
MaximGordon | 0:346a7fa07998 | 147 | |
MaximGordon | 0:346a7fa07998 | 148 | //read and clear status register |
MaximGordon | 0:346a7fa07998 | 149 | maxim_max30102_read_reg(0,&uch_dummy); |
MaximGordon | 0:346a7fa07998 | 150 | |
MaximGordon | 0:346a7fa07998 | 151 | //wait until the user presses a key |
MaximGordon | 0:346a7fa07998 | 152 | while(pc.readable()==0) |
MaximGordon | 0:346a7fa07998 | 153 | { |
MaximGordon | 4:5273ab1085ab | 154 | pc.printf("\x1B[2J"); //clear terminal program screen |
MaximGordon | 0:346a7fa07998 | 155 | pc.printf("Press any key to start conversion\n\r"); |
MaximGordon | 0:346a7fa07998 | 156 | wait(1); |
MaximGordon | 0:346a7fa07998 | 157 | } |
MaximGordon | 0:346a7fa07998 | 158 | uch_dummy=getchar(); |
MaximGordon | 0:346a7fa07998 | 159 | |
MaximGordon | 0:346a7fa07998 | 160 | maxim_max30102_init(); //initializes the MAX30102 |
MaximGordon | 0:346a7fa07998 | 161 | |
MaximGordon | 0:346a7fa07998 | 162 | |
MaximGordon | 0:346a7fa07998 | 163 | n_brightness=0; |
MaximGordon | 0:346a7fa07998 | 164 | un_min=0x3FFFF; |
MaximGordon | 0:346a7fa07998 | 165 | un_max=0; |
MaximGordon | 0:346a7fa07998 | 166 | |
denizdosluoglu | 5:27d600e46926 | 167 | //n_ir_buffer_length=500; //buffer length of 500 stores 5 seconds of samples running at 100sps |
MaximGordon | 0:346a7fa07998 | 168 | |
MaximGordon | 0:346a7fa07998 | 169 | //read the first 500 samples, and determine the signal range |
denizdosluoglu | 5:27d600e46926 | 170 | //READ 100 SAMPLES |
denizdosluoglu | 5:27d600e46926 | 171 | for(i=0;i<BUFFER_SIZE;i++) |
MaximGordon | 0:346a7fa07998 | 172 | { |
MaximGordon | 0:346a7fa07998 | 173 | while(INT.read()==1); //wait until the interrupt pin asserts |
MaximGordon | 0:346a7fa07998 | 174 | |
MaximGordon | 3:7c0fb55eb3ff | 175 | maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i)); //read from MAX30102 FIFO |
MaximGordon | 0:346a7fa07998 | 176 | |
MaximGordon | 3:7c0fb55eb3ff | 177 | if(un_min>aun_red_buffer[i]) |
MaximGordon | 3:7c0fb55eb3ff | 178 | un_min=aun_red_buffer[i]; //update signal min |
MaximGordon | 3:7c0fb55eb3ff | 179 | if(un_max<aun_red_buffer[i]) |
MaximGordon | 3:7c0fb55eb3ff | 180 | un_max=aun_red_buffer[i]; //update signal max |
MaximGordon | 0:346a7fa07998 | 181 | pc.printf("red="); |
MaximGordon | 3:7c0fb55eb3ff | 182 | pc.printf("%i", aun_red_buffer[i]); |
MaximGordon | 0:346a7fa07998 | 183 | pc.printf(", ir="); |
MaximGordon | 3:7c0fb55eb3ff | 184 | pc.printf("%i\n\r", aun_ir_buffer[i]); |
MaximGordon | 0:346a7fa07998 | 185 | } |
denizdosluoglu | 5:27d600e46926 | 186 | rf_heart_rate_and_oxygen_saturation(aun_ir_buffer, BUFFER_SIZE, aun_red_buffer, &n_sp02, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid, &ratio, &correl); |
denizdosluoglu | 5:27d600e46926 | 187 | pc.printf("%i ", t.read_ms()); |
denizdosluoglu | 5:27d600e46926 | 188 | pc.printf("%i ", aun_red_buffer[i]); |
denizdosluoglu | 5:27d600e46926 | 189 | //pc.printf(", ir="); |
denizdosluoglu | 5:27d600e46926 | 190 | pc.printf("%i ", aun_ir_buffer[i]); |
denizdosluoglu | 5:27d600e46926 | 191 | //pc.printf(", HR=%i, ", n_heart_rate); |
denizdosluoglu | 5:27d600e46926 | 192 | pc.printf("%i ", n_heart_rate); |
denizdosluoglu | 5:27d600e46926 | 193 | //pc.printf("HRvalid=%i, ", ch_hr_valid); |
denizdosluoglu | 5:27d600e46926 | 194 | pc.printf("%i ", ch_hr_valid); |
denizdosluoglu | 5:27d600e46926 | 195 | //pc.printf("SpO2=%i, ", n_sp02); |
denizdosluoglu | 5:27d600e46926 | 196 | pc.printf("%i ", n_sp02); |
denizdosluoglu | 5:27d600e46926 | 197 | //pc.printf("SPO2Valid=%i\n\r", ch_spo2_valid); |
denizdosluoglu | 5:27d600e46926 | 198 | pc.printf("%i\n\r", ch_spo2_valid); |
denizdosluoglu | 5:27d600e46926 | 199 | |
MaximGordon | 3:7c0fb55eb3ff | 200 | un_prev_data=aun_red_buffer[i]; |
MaximGordon | 0:346a7fa07998 | 201 | |
MaximGordon | 0:346a7fa07998 | 202 | |
MaximGordon | 0:346a7fa07998 | 203 | //calculate heart rate and SpO2 after first 500 samples (first 5 seconds of samples) |
denizdosluoglu | 5:27d600e46926 | 204 | //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); |
denizdosluoglu | 5:27d600e46926 | 205 | rf_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, &ratio, &correl); |
MaximGordon | 0:346a7fa07998 | 206 | //Continuously taking samples from MAX30102. Heart rate and SpO2 are calculated every 1 second |
denizdosluoglu | 5:27d600e46926 | 207 | //while(1) //infinite loop |
denizdosluoglu | 5:27d600e46926 | 208 | for (int a = 0; a<20; a++)//acquire finite amount of data |
MaximGordon | 0:346a7fa07998 | 209 | { |
MaximGordon | 0:346a7fa07998 | 210 | i=0; |
MaximGordon | 0:346a7fa07998 | 211 | un_min=0x3FFFF; |
MaximGordon | 0:346a7fa07998 | 212 | un_max=0; |
MaximGordon | 0:346a7fa07998 | 213 | |
MaximGordon | 0:346a7fa07998 | 214 | //dumping the first 100 sets of samples in the memory and shift the last 400 sets of samples to the top |
denizdosluoglu | 5:27d600e46926 | 215 | //revision, dump first 25 |
denizdosluoglu | 5:27d600e46926 | 216 | //for(i=100;i<500;i++) |
denizdosluoglu | 5:27d600e46926 | 217 | for(i=20;i<100;i++) |
MaximGordon | 0:346a7fa07998 | 218 | { |
denizdosluoglu | 5:27d600e46926 | 219 | aun_red_buffer[i-20]=aun_red_buffer[i]; |
denizdosluoglu | 5:27d600e46926 | 220 | aun_ir_buffer[i-20]=aun_ir_buffer[i]; |
denizdosluoglu | 5:27d600e46926 | 221 | //aun_red_buffer[i-25]=aun_red_buffer[i]; |
denizdosluoglu | 5:27d600e46926 | 222 | //aun_ir_buffer[i-25]=aun_ir_buffer[i]; |
MaximGordon | 0:346a7fa07998 | 223 | //update the signal min and max |
MaximGordon | 3:7c0fb55eb3ff | 224 | if(un_min>aun_red_buffer[i]) |
MaximGordon | 3:7c0fb55eb3ff | 225 | un_min=aun_red_buffer[i]; |
MaximGordon | 3:7c0fb55eb3ff | 226 | if(un_max<aun_red_buffer[i]) |
MaximGordon | 3:7c0fb55eb3ff | 227 | un_max=aun_red_buffer[i]; |
MaximGordon | 0:346a7fa07998 | 228 | } |
MaximGordon | 0:346a7fa07998 | 229 | |
MaximGordon | 0:346a7fa07998 | 230 | //take 100 sets of samples before calculating the heart rate. |
denizdosluoglu | 5:27d600e46926 | 231 | //take |
denizdosluoglu | 5:27d600e46926 | 232 | //for(i=400;i<500;i++) |
denizdosluoglu | 5:27d600e46926 | 233 | for(i=80;i<100;i++) |
MaximGordon | 0:346a7fa07998 | 234 | { |
MaximGordon | 3:7c0fb55eb3ff | 235 | un_prev_data=aun_red_buffer[i-1]; |
MaximGordon | 0:346a7fa07998 | 236 | while(INT.read()==1); |
MaximGordon | 3:7c0fb55eb3ff | 237 | maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i)); |
MaximGordon | 0:346a7fa07998 | 238 | |
MaximGordon | 3:7c0fb55eb3ff | 239 | if(aun_red_buffer[i]>un_prev_data) |
MaximGordon | 0:346a7fa07998 | 240 | { |
MaximGordon | 3:7c0fb55eb3ff | 241 | f_temp=aun_red_buffer[i]-un_prev_data; |
MaximGordon | 0:346a7fa07998 | 242 | f_temp/=(un_max-un_min); |
MaximGordon | 0:346a7fa07998 | 243 | f_temp*=MAX_BRIGHTNESS; |
MaximGordon | 0:346a7fa07998 | 244 | n_brightness-=(int)f_temp; |
MaximGordon | 0:346a7fa07998 | 245 | if(n_brightness<0) |
MaximGordon | 0:346a7fa07998 | 246 | n_brightness=0; |
MaximGordon | 0:346a7fa07998 | 247 | } |
MaximGordon | 0:346a7fa07998 | 248 | else |
MaximGordon | 0:346a7fa07998 | 249 | { |
MaximGordon | 3:7c0fb55eb3ff | 250 | f_temp=un_prev_data-aun_red_buffer[i]; |
MaximGordon | 0:346a7fa07998 | 251 | f_temp/=(un_max-un_min); |
MaximGordon | 0:346a7fa07998 | 252 | f_temp*=MAX_BRIGHTNESS; |
MaximGordon | 0:346a7fa07998 | 253 | n_brightness+=(int)f_temp; |
MaximGordon | 0:346a7fa07998 | 254 | if(n_brightness>MAX_BRIGHTNESS) |
MaximGordon | 0:346a7fa07998 | 255 | n_brightness=MAX_BRIGHTNESS; |
MaximGordon | 0:346a7fa07998 | 256 | } |
MaximGordon | 0:346a7fa07998 | 257 | #if defined(TARGET_KL25Z) || defined(TARGET_MAX32600MBED) |
MaximGordon | 0:346a7fa07998 | 258 | led.write(1-(float)n_brightness/256); |
MaximGordon | 0:346a7fa07998 | 259 | #endif |
MaximGordon | 0:346a7fa07998 | 260 | //send samples and calculation result to terminal program through UART |
denizdosluoglu | 5:27d600e46926 | 261 | // pc.printf("red="); // remove heading to make compatible with MATLAB |
denizdosluoglu | 5:27d600e46926 | 262 | |
denizdosluoglu | 5:27d600e46926 | 263 | //write seconds to create seventh column for martins code |
denizdosluoglu | 5:27d600e46926 | 264 | pc.printf("%i ", t.read_ms()); |
denizdosluoglu | 5:27d600e46926 | 265 | pc.printf("%i ", aun_red_buffer[i]); |
denizdosluoglu | 5:27d600e46926 | 266 | //pc.printf(", ir="); |
denizdosluoglu | 5:27d600e46926 | 267 | pc.printf("%i ", aun_ir_buffer[i]); |
denizdosluoglu | 5:27d600e46926 | 268 | //pc.printf(", HR=%i, ", n_heart_rate); |
denizdosluoglu | 5:27d600e46926 | 269 | pc.printf("%i ", n_heart_rate); |
denizdosluoglu | 5:27d600e46926 | 270 | //pc.printf("HRvalid=%i, ", ch_hr_valid); |
denizdosluoglu | 5:27d600e46926 | 271 | pc.printf("%i ", ch_hr_valid); |
denizdosluoglu | 5:27d600e46926 | 272 | //pc.printf("SpO2=%i, ", n_sp02); |
denizdosluoglu | 5:27d600e46926 | 273 | pc.printf("%i ", n_sp02); |
denizdosluoglu | 5:27d600e46926 | 274 | //pc.printf("SPO2Valid=%i\n\r", ch_spo2_valid); |
denizdosluoglu | 5:27d600e46926 | 275 | pc.printf("%i\n\r", ch_spo2_valid); |
MaximGordon | 0:346a7fa07998 | 276 | } |
denizdosluoglu | 5:27d600e46926 | 277 | //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); |
denizdosluoglu | 5:27d600e46926 | 278 | rf_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, &ratio, &correl); |
MaximGordon | 0:346a7fa07998 | 279 | } |
denizdosluoglu | 5:27d600e46926 | 280 | |
MaximGordon | 0:346a7fa07998 | 281 | } |
MaximGordon | 0:346a7fa07998 | 282 |