HRV -> Mood
Dependencies: MAX30101 Hexi_KW40Z Hexi_OLED_SSD1351
8cee5929f4d8/main.cpp@17:611a14bc8afd, 2019-03-18 (annotated)
- Committer:
- jeannie9809
- Date:
- Mon Mar 18 01:03:38 2019 +0000
- Revision:
- 17:611a14bc8afd
- Parent:
- 16:8b4f1abd8acc
- Child:
- 18:0d1ef7ea9d4b
better connection
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jeannie9809 | 0:338c50c9c8cd | 1 | #include "mbed.h" |
| jeannie9809 | 0:338c50c9c8cd | 2 | #include "mbed_events.h" |
| jeannie9809 | 0:338c50c9c8cd | 3 | #include "MAX30101.h" |
| jeannie9809 | 0:338c50c9c8cd | 4 | #include "string.h" |
| jeannie9809 | 0:338c50c9c8cd | 5 | #include "Hexi_OLED_SSD1351.h" |
| jeannie9809 | 0:338c50c9c8cd | 6 | #include "Hexi_KW40Z.h" |
| jeannie9809 | 14:0258b126d726 | 7 | |
| jeannie9809 | 14:0258b126d726 | 8 | #include "OLED_types.h" |
| jeannie9809 | 14:0258b126d726 | 9 | #include "OpenSans_Font.h" |
| jeannie9809 | 14:0258b126d726 | 10 | |
| jeannie9809 | 0:338c50c9c8cd | 11 | #include <math.h> |
| jeannie9809 | 6:ff1c3560db84 | 12 | #include <vector> |
| jeannie9809 | 6:ff1c3560db84 | 13 | using namespace std; |
| jeannie9809 | 11:58a443cf3f7c | 14 | |
| jeannie9809 | 0:338c50c9c8cd | 15 | #define FIFO_DATA_MAX 288 |
| jeannie9809 | 11:58a443cf3f7c | 16 | //#define M_PI 3.14159265358979323846 |
| jeannie9809 | 11:58a443cf3f7c | 17 | #define M_PI 3.14159 |
| jeannie9809 | 11:58a443cf3f7c | 18 | |
| jeannie9809 | 0:338c50c9c8cd | 19 | void UpdateSensorData(void); |
| jeannie9809 | 0:338c50c9c8cd | 20 | void StartHaptic(void); |
| jeannie9809 | 0:338c50c9c8cd | 21 | void StopHaptic(void const *n); |
| jeannie9809 | 0:338c50c9c8cd | 22 | void txTask(void); |
| jeannie9809 | 0:338c50c9c8cd | 23 | |
| jeannie9809 | 14:0258b126d726 | 24 | DigitalOut blueLed(LED3,1); // i added this |
| jeannie9809 | 14:0258b126d726 | 25 | |
| jeannie9809 | 0:338c50c9c8cd | 26 | DigitalOut pwr1v8(PTA29); |
| jeannie9809 | 0:338c50c9c8cd | 27 | DigitalOut pwr3v3b(PTC13); |
| jeannie9809 | 0:338c50c9c8cd | 28 | DigitalOut pwr15v(PTB12); |
| jeannie9809 | 0:338c50c9c8cd | 29 | I2C i2c0(PTB1, PTB0); |
| jeannie9809 | 0:338c50c9c8cd | 30 | InterruptIn maximInterrupt(PTB18); |
| jeannie9809 | 0:338c50c9c8cd | 31 | Serial pc(USBTX, USBRX); |
| jeannie9809 | 0:338c50c9c8cd | 32 | SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); |
| jeannie9809 | 0:338c50c9c8cd | 33 | KW40Z kw40z_device(PTE24, PTE25); |
| jeannie9809 | 0:338c50c9c8cd | 34 | DigitalOut haptic(PTB9); |
| jeannie9809 | 0:338c50c9c8cd | 35 | EventQueue evqueue(32 * EVENTS_EVENT_SIZE); |
| jeannie9809 | 0:338c50c9c8cd | 36 | Thread t; |
| jeannie9809 | 0:338c50c9c8cd | 37 | /* Define timer for haptic feedback */ |
| jeannie9809 | 0:338c50c9c8cd | 38 | RtosTimer hapticTimer(StopHaptic, osTimerOnce); |
| jeannie9809 | 0:338c50c9c8cd | 39 | |
| jeannie9809 | 3:0da9235c9069 | 40 | /*Create a Thread to handle sending BLE Sensor Data */ |
| jeannie9809 | 0:338c50c9c8cd | 41 | Thread txThread; |
| jeannie9809 | 0:338c50c9c8cd | 42 | MAX30101 hr(i2c0); |
| jeannie9809 | 1:eabf219849ab | 43 | int ppg_single_sample; |
| jeannie9809 | 0:338c50c9c8cd | 44 | int mask_ppg = 0; |
| jeannie9809 | 0:338c50c9c8cd | 45 | uint32_t count = 0; |
| jeannie9809 | 0:338c50c9c8cd | 46 | uint32_t num; |
| jeannie9809 | 14:0258b126d726 | 47 | // uint8_t testsignal = 60; |
| jeannie9809 | 14:0258b126d726 | 48 | |
| jeannie9809 | 14:0258b126d726 | 49 | uint8_t battery = 0; |
| jeannie9809 | 14:0258b126d726 | 50 | |
| jeannie9809 | 14:0258b126d726 | 51 | char text[20]; /* Text Buffer */ |
| jeannie9809 | 0:338c50c9c8cd | 52 | |
| jeannie9809 | 2:3389bdfd9afa | 53 | // I added this |
| jeannie9809 | 11:58a443cf3f7c | 54 | const int num_samples = 500; // for 30 sec |
| jeannie9809 | 0:338c50c9c8cd | 55 | int ppg[num_samples]; |
| jeannie9809 | 13:45c2837ab056 | 56 | int SDNN, valence_arousal; |
| jeannie9809 | 12:95d141421e18 | 57 | double HF_LF = 0.0; |
| jeannie9809 | 13:45c2837ab056 | 58 | double HF_LF_n; |
| jeannie9809 | 13:45c2837ab056 | 59 | int SDNN_n = 0; |
| jeannie9809 | 9:83dcb7382516 | 60 | bool ready = false; |
| jeannie9809 | 14:0258b126d726 | 61 | bool ready_to_send = false; |
| jeannie9809 | 0:338c50c9c8cd | 62 | |
| jeannie9809 | 3:0da9235c9069 | 63 | void StartHaptic(void) |
| jeannie9809 | 3:0da9235c9069 | 64 | { |
| jeannie9809 | 0:338c50c9c8cd | 65 | hapticTimer.start(50); |
| jeannie9809 | 0:338c50c9c8cd | 66 | haptic = 1; |
| jeannie9809 | 0:338c50c9c8cd | 67 | } |
| jeannie9809 | 0:338c50c9c8cd | 68 | void ButtonRight(void) |
| jeannie9809 | 0:338c50c9c8cd | 69 | { |
| jeannie9809 | 0:338c50c9c8cd | 70 | StartHaptic(); |
| jeannie9809 | 0:338c50c9c8cd | 71 | kw40z_device.ToggleAdvertisementMode(); |
| jeannie9809 | 0:338c50c9c8cd | 72 | } |
| jeannie9809 | 0:338c50c9c8cd | 73 | |
| jeannie9809 | 0:338c50c9c8cd | 74 | void ButtonLeft(void) |
| jeannie9809 | 0:338c50c9c8cd | 75 | { |
| jeannie9809 | 0:338c50c9c8cd | 76 | StartHaptic(); |
| jeannie9809 | 0:338c50c9c8cd | 77 | kw40z_device.ToggleAdvertisementMode(); |
| jeannie9809 | 0:338c50c9c8cd | 78 | } |
| jeannie9809 | 0:338c50c9c8cd | 79 | |
| jeannie9809 | 3:0da9235c9069 | 80 | void StopHaptic(void const *n) |
| jeannie9809 | 3:0da9235c9069 | 81 | { |
| jeannie9809 | 0:338c50c9c8cd | 82 | haptic = 0; |
| jeannie9809 | 0:338c50c9c8cd | 83 | hapticTimer.stop(); |
| jeannie9809 | 0:338c50c9c8cd | 84 | } |
| jeannie9809 | 3:0da9235c9069 | 85 | void txTask(void) |
| jeannie9809 | 3:0da9235c9069 | 86 | { |
| jeannie9809 | 3:0da9235c9069 | 87 | |
| jeannie9809 | 3:0da9235c9069 | 88 | while (true) { |
| jeannie9809 | 17:611a14bc8afd | 89 | /* |
| jeannie9809 | 14:0258b126d726 | 90 | while(ready_to_send == false) { |
| jeannie9809 | 16:8b4f1abd8acc | 91 | Thread::wait(1000); // wait until has something to send |
| jeannie9809 | 14:0258b126d726 | 92 | } |
| jeannie9809 | 17:611a14bc8afd | 93 | */ |
| jeannie9809 | 14:0258b126d726 | 94 | |
| jeannie9809 | 17:611a14bc8afd | 95 | if(ready_to_send) { |
| jeannie9809 | 17:611a14bc8afd | 96 | UpdateSensorData(); |
| jeannie9809 | 17:611a14bc8afd | 97 | |
| jeannie9809 | 17:611a14bc8afd | 98 | printf("Sending!"); |
| jeannie9809 | 17:611a14bc8afd | 99 | kw40z_device.SendBatteryLevel(battery); |
| jeannie9809 | 17:611a14bc8afd | 100 | |
| jeannie9809 | 17:611a14bc8afd | 101 | ready_to_send = false; |
| jeannie9809 | 17:611a14bc8afd | 102 | } |
| jeannie9809 | 0:338c50c9c8cd | 103 | /*Notify Hexiwear App that it is running Sensor Tag mode*/ |
| jeannie9809 | 0:338c50c9c8cd | 104 | kw40z_device.SendSetApplicationMode(GUI_CURRENT_APP_SENSOR_TAG); |
| jeannie9809 | 14:0258b126d726 | 105 | |
| jeannie9809 | 14:0258b126d726 | 106 | |
| jeannie9809 | 0:338c50c9c8cd | 107 | //send heartrate |
| jeannie9809 | 14:0258b126d726 | 108 | // kw40z_device.SendHeartRate(testsignal); |
| jeannie9809 | 0:338c50c9c8cd | 109 | /*The following is sending dummy data over BLE. Replace with real data*/ |
| jeannie9809 | 3:0da9235c9069 | 110 | |
| jeannie9809 | 3:0da9235c9069 | 111 | /*Send Battery Level for 20% |
| jeannie9809 | 0:338c50c9c8cd | 112 | kw40z_device.SendBatteryLevel(battery); |
| jeannie9809 | 3:0da9235c9069 | 113 | |
| jeannie9809 | 3:0da9235c9069 | 114 | Send Ambient Light Level at 50% |
| jeannie9809 | 0:338c50c9c8cd | 115 | kw40z_device.SendAmbientLight(light);*/ |
| jeannie9809 | 3:0da9235c9069 | 116 | |
| jeannie9809 | 0:338c50c9c8cd | 117 | /*Send Humidity at 90% */ |
| jeannie9809 | 0:338c50c9c8cd | 118 | //kw40z_device.SendHumidity(humidity); |
| jeannie9809 | 3:0da9235c9069 | 119 | |
| jeannie9809 | 3:0da9235c9069 | 120 | /*Send Temperature at 25 degrees Celsius |
| jeannie9809 | 0:338c50c9c8cd | 121 | kw40z_device.SendTemperature(temperature); |
| jeannie9809 | 0:338c50c9c8cd | 122 | |
| jeannie9809 | 11:58a443cf3f7c | 123 | //Send Pressure at 100kPA |
| jeannie9809 | 11:58a443cf3f7c | 124 | //kw40z_device.SendPressure(pressure); */ |
| jeannie9809 | 3:0da9235c9069 | 125 | |
| jeannie9809 | 3:0da9235c9069 | 126 | /*Send Mag,Accel,Gyro Data. |
| jeannie9809 | 0:338c50c9c8cd | 127 | kw40z_device.SendGyro(x,y,z); |
| jeannie9809 | 0:338c50c9c8cd | 128 | kw40z_device.SendAccel(z,x,y); |
| jeannie9809 | 0:338c50c9c8cd | 129 | kw40z_device.SendMag(y,z,x);*/ |
| jeannie9809 | 0:338c50c9c8cd | 130 | |
| jeannie9809 | 3:0da9235c9069 | 131 | Thread::wait(1000); |
| jeannie9809 | 0:338c50c9c8cd | 132 | } |
| jeannie9809 | 0:338c50c9c8cd | 133 | } |
| jeannie9809 | 0:338c50c9c8cd | 134 | void UpdateSensorData(void) |
| jeannie9809 | 3:0da9235c9069 | 135 | { |
| jeannie9809 | 14:0258b126d726 | 136 | // testsignal+=1; |
| jeannie9809 | 14:0258b126d726 | 137 | battery = valence_arousal; |
| jeannie9809 | 0:338c50c9c8cd | 138 | /*battery -= 5; |
| jeannie9809 | 0:338c50c9c8cd | 139 | if(battery < 5) battery = 100; |
| jeannie9809 | 3:0da9235c9069 | 140 | |
| jeannie9809 | 0:338c50c9c8cd | 141 | light += 20; |
| jeannie9809 | 0:338c50c9c8cd | 142 | if(light > 100) light = 0; |
| jeannie9809 | 3:0da9235c9069 | 143 | |
| jeannie9809 | 0:338c50c9c8cd | 144 | humidity += 500; |
| jeannie9809 | 0:338c50c9c8cd | 145 | if(humidity > 8000) humidity = 2000; |
| jeannie9809 | 3:0da9235c9069 | 146 | |
| jeannie9809 | 0:338c50c9c8cd | 147 | temperature -= 200; |
| jeannie9809 | 0:338c50c9c8cd | 148 | if(temperature < 200) temperature = 4200; |
| jeannie9809 | 3:0da9235c9069 | 149 | |
| jeannie9809 | 0:338c50c9c8cd | 150 | pressure += 300; |
| jeannie9809 | 0:338c50c9c8cd | 151 | if(pressure > 10300) pressure = 7500; |
| jeannie9809 | 3:0da9235c9069 | 152 | |
| jeannie9809 | 0:338c50c9c8cd | 153 | x += 1400; |
| jeannie9809 | 0:338c50c9c8cd | 154 | y -= 2300; |
| jeannie9809 | 0:338c50c9c8cd | 155 | z += 1700;*/ |
| jeannie9809 | 0:338c50c9c8cd | 156 | } |
| jeannie9809 | 0:338c50c9c8cd | 157 | |
| jeannie9809 | 3:0da9235c9069 | 158 | void interruptHandlerQueued() |
| jeannie9809 | 3:0da9235c9069 | 159 | { |
| jeannie9809 | 4:94190624967a | 160 | // int temp_ppg[num_samples]; |
| jeannie9809 | 3:0da9235c9069 | 161 | for(int iter = 0; iter < num_samples; iter+=0) { |
| jeannie9809 | 0:338c50c9c8cd | 162 | |
| jeannie9809 | 3:0da9235c9069 | 163 | MAX30101::InterruptBitField_u interruptStatus; |
| jeannie9809 | 3:0da9235c9069 | 164 | hr.getInterruptStatus(interruptStatus); |
| jeannie9809 | 3:0da9235c9069 | 165 | // printf("Interrupt Status: 0x%02x\r\n", interruptStatus.all); |
| jeannie9809 | 3:0da9235c9069 | 166 | |
| jeannie9809 | 3:0da9235c9069 | 167 | if (interruptStatus.bits.pwr_rdy == 0x1) { |
| jeannie9809 | 3:0da9235c9069 | 168 | // printf("Powered on\r\n"); |
| jeannie9809 | 3:0da9235c9069 | 169 | |
| jeannie9809 | 3:0da9235c9069 | 170 | // Soft reset |
| jeannie9809 | 3:0da9235c9069 | 171 | MAX30101::ModeConfiguration_u modeConf; |
| jeannie9809 | 3:0da9235c9069 | 172 | modeConf.all = 0; |
| jeannie9809 | 3:0da9235c9069 | 173 | modeConf.bits.reset = 1; |
| jeannie9809 | 3:0da9235c9069 | 174 | hr.setModeConfiguration(modeConf); |
| jeannie9809 | 3:0da9235c9069 | 175 | wait(0.01); |
| jeannie9809 | 3:0da9235c9069 | 176 | |
| jeannie9809 | 3:0da9235c9069 | 177 | // Configure FIFO |
| jeannie9809 | 3:0da9235c9069 | 178 | MAX30101::FIFO_Configuration_u fifoConf; |
| jeannie9809 | 3:0da9235c9069 | 179 | hr.getFIFOConfiguration(fifoConf); |
| jeannie9809 | 0:338c50c9c8cd | 180 | // pc.printf("FIFO Configuration: 0x%02x\r\n", fifoConf.all); |
| jeannie9809 | 3:0da9235c9069 | 181 | |
| jeannie9809 | 3:0da9235c9069 | 182 | // Set LED power |
| jeannie9809 | 3:0da9235c9069 | 183 | hr.setLEDPulseAmplitude(MAX30101::LED1_PA, 0x0C); |
| jeannie9809 | 3:0da9235c9069 | 184 | hr.setLEDPulseAmplitude(MAX30101::ProxModeLED_PA, 0x19); |
| jeannie9809 | 0:338c50c9c8cd | 185 | // pc.printf("LED set\r\n"); |
| jeannie9809 | 3:0da9235c9069 | 186 | |
| jeannie9809 | 3:0da9235c9069 | 187 | MAX30101::SpO2Configuration_u spo2Conf; |
| jeannie9809 | 3:0da9235c9069 | 188 | hr.getSpO2Configuration(spo2Conf); |
| jeannie9809 | 3:0da9235c9069 | 189 | spo2Conf.bits.led_pw = MAX30101::PW_1; |
| jeannie9809 | 3:0da9235c9069 | 190 | spo2Conf.bits.spo2_sr = MAX30101::SR_100_Hz; |
| jeannie9809 | 3:0da9235c9069 | 191 | hr.setSpO2Configuration(spo2Conf); |
| jeannie9809 | 3:0da9235c9069 | 192 | hr.getSpO2Configuration(spo2Conf); |
| jeannie9809 | 0:338c50c9c8cd | 193 | // pc.printf("SpO2 Configuration: 0x%02x\r\n", spo2Conf.all); |
| jeannie9809 | 3:0da9235c9069 | 194 | |
| jeannie9809 | 3:0da9235c9069 | 195 | // Proximity settings |
| jeannie9809 | 3:0da9235c9069 | 196 | hr.setProxIntThreshold(0x14); |
| jeannie9809 | 3:0da9235c9069 | 197 | |
| jeannie9809 | 3:0da9235c9069 | 198 | // Enable HR mode |
| jeannie9809 | 3:0da9235c9069 | 199 | modeConf.all = 0; |
| jeannie9809 | 3:0da9235c9069 | 200 | modeConf.bits.mode = MAX30101::HeartRateMode; |
| jeannie9809 | 3:0da9235c9069 | 201 | hr.setModeConfiguration(modeConf); |
| jeannie9809 | 0:338c50c9c8cd | 202 | // printf("Mode set\r\n"); |
| jeannie9809 | 3:0da9235c9069 | 203 | } |
| jeannie9809 | 3:0da9235c9069 | 204 | |
| jeannie9809 | 3:0da9235c9069 | 205 | if (interruptStatus.bits.prox_int == 0x1) { |
| jeannie9809 | 0:338c50c9c8cd | 206 | // printf("Proximity Triggered, entered HR Mode."); |
| jeannie9809 | 3:0da9235c9069 | 207 | } |
| jeannie9809 | 3:0da9235c9069 | 208 | |
| jeannie9809 | 3:0da9235c9069 | 209 | if (interruptStatus.bits.ppg_rdy == 0x1) { |
| jeannie9809 | 0:338c50c9c8cd | 210 | // printf("PPG Ready.\r\n"); |
| jeannie9809 | 3:0da9235c9069 | 211 | mask_ppg = 1; |
| jeannie9809 | 3:0da9235c9069 | 212 | } |
| jeannie9809 | 3:0da9235c9069 | 213 | |
| jeannie9809 | 3:0da9235c9069 | 214 | if (interruptStatus.bits.a_full == 0x1) { |
| jeannie9809 | 0:338c50c9c8cd | 215 | // printf("FIFO Almost Full.\r\n"); |
| jeannie9809 | 3:0da9235c9069 | 216 | uint8_t data[FIFO_DATA_MAX]; |
| jeannie9809 | 3:0da9235c9069 | 217 | uint16_t readBytes = 0; |
| jeannie9809 | 3:0da9235c9069 | 218 | |
| jeannie9809 | 3:0da9235c9069 | 219 | hr.readFIFO(MAX30101::OneLedChannel, data, readBytes); |
| jeannie9809 | 9:83dcb7382516 | 220 | // printf("data length: %u \r\n",readBytes); |
| jeannie9809 | 3:0da9235c9069 | 221 | //printf("data length: %u \r\n",data); |
| jeannie9809 | 3:0da9235c9069 | 222 | for (uint16_t i = 0; i < readBytes; i += 3) { |
| jeannie9809 | 3:0da9235c9069 | 223 | uint8_t sample[4] = {0}; |
| jeannie9809 | 3:0da9235c9069 | 224 | sample[0] = data[i + 2]; |
| jeannie9809 | 3:0da9235c9069 | 225 | sample[1] = data[i + 1]; |
| jeannie9809 | 3:0da9235c9069 | 226 | sample[2] = data[i]; |
| jeannie9809 | 3:0da9235c9069 | 227 | |
| jeannie9809 | 3:0da9235c9069 | 228 | num = *(uint32_t *) sample; |
| jeannie9809 | 9:83dcb7382516 | 229 | |
| jeannie9809 | 11:58a443cf3f7c | 230 | if (num < 0) { |
| jeannie9809 | 3:0da9235c9069 | 231 | ppg_single_sample = 0; |
| jeannie9809 | 9:83dcb7382516 | 232 | // printf("keep closer to your hand \r\n"); |
| jeannie9809 | 3:0da9235c9069 | 233 | } else { |
| jeannie9809 | 3:0da9235c9069 | 234 | |
| jeannie9809 | 3:0da9235c9069 | 235 | //ppg_single_sample = 65; |
| jeannie9809 | 6:ff1c3560db84 | 236 | ppg_single_sample = num; |
| jeannie9809 | 9:83dcb7382516 | 237 | if(iter < num_samples && !ready) { |
| jeannie9809 | 9:83dcb7382516 | 238 | ppg[iter] = num; |
| jeannie9809 | 9:83dcb7382516 | 239 | // printf("%d \n", ppg[iter]); |
| jeannie9809 | 9:83dcb7382516 | 240 | if(iter == num_samples-1) |
| jeannie9809 | 9:83dcb7382516 | 241 | ready = true; |
| jeannie9809 | 9:83dcb7382516 | 242 | } |
| jeannie9809 | 9:83dcb7382516 | 243 | |
| jeannie9809 | 9:83dcb7382516 | 244 | // printf("%d ", ppg_single_sample); // I commented this out |
| jeannie9809 | 3:0da9235c9069 | 245 | iter++; |
| jeannie9809 | 3:0da9235c9069 | 246 | } |
| jeannie9809 | 9:83dcb7382516 | 247 | // printf("%d; %d\r\n", iter, ppg[iter-1]); |
| jeannie9809 | 3:0da9235c9069 | 248 | |
| jeannie9809 | 3:0da9235c9069 | 249 | |
| jeannie9809 | 0:338c50c9c8cd | 250 | } |
| jeannie9809 | 0:338c50c9c8cd | 251 | } |
| jeannie9809 | 3:0da9235c9069 | 252 | |
| jeannie9809 | 3:0da9235c9069 | 253 | interruptStatus.all = 0xFF; |
| jeannie9809 | 11:58a443cf3f7c | 254 | |
| jeannie9809 | 3:0da9235c9069 | 255 | if (mask_ppg == 1) { |
| jeannie9809 | 3:0da9235c9069 | 256 | interruptStatus.bits.ppg_rdy = 0; |
| jeannie9809 | 3:0da9235c9069 | 257 | } |
| jeannie9809 | 3:0da9235c9069 | 258 | hr.enableInterrupts(interruptStatus); |
| jeannie9809 | 0:338c50c9c8cd | 259 | } |
| jeannie9809 | 4:94190624967a | 260 | /* |
| jeannie9809 | 4:94190624967a | 261 | for(int i = 0; i < num_samples; i++) { |
| jeannie9809 | 4:94190624967a | 262 | ppg[i] = temp_ppg[i]; |
| jeannie9809 | 4:94190624967a | 263 | } |
| jeannie9809 | 4:94190624967a | 264 | */ |
| jeannie9809 | 4:94190624967a | 265 | //ppg = temp_ppg; |
| jeannie9809 | 11:58a443cf3f7c | 266 | |
| jeannie9809 | 0:338c50c9c8cd | 267 | } |
| jeannie9809 | 0:338c50c9c8cd | 268 | |
| jeannie9809 | 3:0da9235c9069 | 269 | void interruptHandler() |
| jeannie9809 | 3:0da9235c9069 | 270 | { |
| jeannie9809 | 0:338c50c9c8cd | 271 | evqueue.call(interruptHandlerQueued); |
| jeannie9809 | 9:83dcb7382516 | 272 | // interruptHandlerQueued(); |
| jeannie9809 | 11:58a443cf3f7c | 273 | // printf("\nLezzgo\n"); |
| jeannie9809 | 9:83dcb7382516 | 274 | if(ready) { |
| jeannie9809 | 11:58a443cf3f7c | 275 | printf("\nStarting... "); |
| jeannie9809 | 11:58a443cf3f7c | 276 | |
| jeannie9809 | 11:58a443cf3f7c | 277 | int i = 0; |
| jeannie9809 | 11:58a443cf3f7c | 278 | int j = 0; |
| jeannie9809 | 11:58a443cf3f7c | 279 | |
| jeannie9809 | 11:58a443cf3f7c | 280 | double TIME[num_samples]; |
| jeannie9809 | 11:58a443cf3f7c | 281 | for(int i = 0; i < num_samples; i++) { |
| jeannie9809 | 11:58a443cf3f7c | 282 | TIME[i] = (double)i*(5.0/(double)num_samples); // change to 30.0 later |
| jeannie9809 | 11:58a443cf3f7c | 283 | } |
| jeannie9809 | 11:58a443cf3f7c | 284 | |
| jeannie9809 | 11:58a443cf3f7c | 285 | // moving average |
| jeannie9809 | 11:58a443cf3f7c | 286 | double movave[num_samples]; |
| jeannie9809 | 11:58a443cf3f7c | 287 | int avecap = 25; |
| jeannie9809 | 11:58a443cf3f7c | 288 | for(i = 0; i < (avecap-1)/2; i++) { |
| jeannie9809 | 11:58a443cf3f7c | 289 | movave[i] = (double)ppg[0]; |
| jeannie9809 | 11:58a443cf3f7c | 290 | for(j = 1; j < 1+(avecap-1)/2; j++) { |
| jeannie9809 | 11:58a443cf3f7c | 291 | movave[i] = movave[i] + (double)ppg[j]; |
| jeannie9809 | 11:58a443cf3f7c | 292 | } |
| jeannie9809 | 11:58a443cf3f7c | 293 | movave[i] = (double)(movave[i]/(i+(avecap-1)/2-1)); |
| jeannie9809 | 11:58a443cf3f7c | 294 | } |
| jeannie9809 | 11:58a443cf3f7c | 295 | for(i = (num_samples-(avecap-1)/2); i < num_samples; i++) { |
| jeannie9809 | 11:58a443cf3f7c | 296 | movave[i] = (double)ppg[i-(avecap-1)/2-1]; |
| jeannie9809 | 11:58a443cf3f7c | 297 | for(j = (i-(avecap-1)/2); j < num_samples; j++) { |
| jeannie9809 | 11:58a443cf3f7c | 298 | movave[i] = movave[i] + (double)ppg[j]; |
| jeannie9809 | 11:58a443cf3f7c | 299 | } |
| jeannie9809 | 11:58a443cf3f7c | 300 | movave[i] = movave[i]/(double)(num_samples-i+(avecap-1)/2); |
| jeannie9809 | 11:58a443cf3f7c | 301 | } |
| jeannie9809 | 11:58a443cf3f7c | 302 | for(i = (avecap-1)/2; i < (num_samples-(avecap-1)/2); i++) { |
| jeannie9809 | 11:58a443cf3f7c | 303 | movave[i] = (double)ppg[i-(avecap-1)/2-1]; |
| jeannie9809 | 11:58a443cf3f7c | 304 | for(j = i-(avecap-1)/2; j < i+(avecap-1)/2; j++) { |
| jeannie9809 | 11:58a443cf3f7c | 305 | movave[i] = movave[i] + (double)ppg[j]; |
| jeannie9809 | 11:58a443cf3f7c | 306 | } |
| jeannie9809 | 11:58a443cf3f7c | 307 | movave[i] = movave[i]/(double)avecap; |
| jeannie9809 | 4:94190624967a | 308 | } |
| jeannie9809 | 11:58a443cf3f7c | 309 | |
| jeannie9809 | 11:58a443cf3f7c | 310 | // normalize ppg |
| jeannie9809 | 11:58a443cf3f7c | 311 | for(i = 0; i < num_samples; i++) { |
| jeannie9809 | 11:58a443cf3f7c | 312 | ppg[i] = ppg[i] - (int)movave[i]; |
| jeannie9809 | 11:58a443cf3f7c | 313 | if(ppg[i] > 1000 || ppg[i] < -1000) |
| jeannie9809 | 11:58a443cf3f7c | 314 | ppg[i] = 0; |
| jeannie9809 | 11:58a443cf3f7c | 315 | } |
| jeannie9809 | 11:58a443cf3f7c | 316 | |
| jeannie9809 | 11:58a443cf3f7c | 317 | // smoothing curve |
| jeannie9809 | 11:58a443cf3f7c | 318 | for(i = 1; i < num_samples; i++) { |
| jeannie9809 | 11:58a443cf3f7c | 319 | ppg[i] = ppg[i] + ppg[i-1]; |
| jeannie9809 | 11:58a443cf3f7c | 320 | //printf("%d ", ppg[i]); |
| jeannie9809 | 4:94190624967a | 321 | } |
| jeannie9809 | 11:58a443cf3f7c | 322 | |
| jeannie9809 | 11:58a443cf3f7c | 323 | // AMPD Algorithm |
| jeannie9809 | 11:58a443cf3f7c | 324 | const int kcap = 25; |
| jeannie9809 | 11:58a443cf3f7c | 325 | int m[kcap][num_samples]; |
| jeannie9809 | 11:58a443cf3f7c | 326 | for(int k = 1; k <= kcap; k++) { |
| jeannie9809 | 11:58a443cf3f7c | 327 | for(i = 1; i < num_samples; i++) { |
| jeannie9809 | 11:58a443cf3f7c | 328 | if(i-1 < 0 || i-k-1 < 0 || i+k-1 >= num_samples) |
| jeannie9809 | 11:58a443cf3f7c | 329 | m[k-1][i] = 0; |
| jeannie9809 | 11:58a443cf3f7c | 330 | else if(ppg[i-1] > ppg[i-k-1] && ppg[i-1] > ppg[i+k-1]) |
| jeannie9809 | 11:58a443cf3f7c | 331 | m[k-1][i] = 1; |
| jeannie9809 | 11:58a443cf3f7c | 332 | else |
| jeannie9809 | 11:58a443cf3f7c | 333 | m[k-1][i] = 0; |
| jeannie9809 | 11:58a443cf3f7c | 334 | } |
| jeannie9809 | 11:58a443cf3f7c | 335 | } |
| jeannie9809 | 11:58a443cf3f7c | 336 | |
| jeannie9809 | 11:58a443cf3f7c | 337 | int max_mult[num_samples]; |
| jeannie9809 | 11:58a443cf3f7c | 338 | for(i = 0; i < num_samples; i++) { // max_mult = m(1,:)'; |
| jeannie9809 | 11:58a443cf3f7c | 339 | max_mult[i] = m[0][i]; |
| jeannie9809 | 11:58a443cf3f7c | 340 | } |
| jeannie9809 | 11:58a443cf3f7c | 341 | |
| jeannie9809 | 11:58a443cf3f7c | 342 | for(int k = 1; k < kcap; k++) { |
| jeannie9809 | 11:58a443cf3f7c | 343 | for(i = 0; i < num_samples; i++) { |
| jeannie9809 | 11:58a443cf3f7c | 344 | max_mult[i] = max_mult[i]*m[k][i]; |
| jeannie9809 | 11:58a443cf3f7c | 345 | } |
| jeannie9809 | 11:58a443cf3f7c | 346 | } |
| jeannie9809 | 11:58a443cf3f7c | 347 | |
| jeannie9809 | 11:58a443cf3f7c | 348 | int num_max = 0; |
| jeannie9809 | 11:58a443cf3f7c | 349 | // extract times that are max |
| jeannie9809 | 11:58a443cf3f7c | 350 | for(i = 0; i < num_samples; i++) { |
| jeannie9809 | 11:58a443cf3f7c | 351 | num_max = num_max + max_mult[i]; |
| jeannie9809 | 4:94190624967a | 352 | } |
| jeannie9809 | 11:58a443cf3f7c | 353 | |
| jeannie9809 | 11:58a443cf3f7c | 354 | // printf("num_max = %d ", num_max); |
| jeannie9809 | 11:58a443cf3f7c | 355 | |
| jeannie9809 | 11:58a443cf3f7c | 356 | vector<double> time_of_max; |
| jeannie9809 | 11:58a443cf3f7c | 357 | vector<int> index_of_max; |
| jeannie9809 | 11:58a443cf3f7c | 358 | vector<int> max_points; |
| jeannie9809 | 11:58a443cf3f7c | 359 | for(i = 0; i < num_samples; i++) { |
| jeannie9809 | 11:58a443cf3f7c | 360 | if(max_mult[i] == 1) { |
| jeannie9809 | 11:58a443cf3f7c | 361 | time_of_max.push_back(TIME[i-1]); |
| jeannie9809 | 11:58a443cf3f7c | 362 | index_of_max.push_back(i-1); |
| jeannie9809 | 11:58a443cf3f7c | 363 | max_points.push_back(ppg[i-1]); |
| jeannie9809 | 11:58a443cf3f7c | 364 | } |
| jeannie9809 | 11:58a443cf3f7c | 365 | } |
| jeannie9809 | 11:58a443cf3f7c | 366 | |
| jeannie9809 | 11:58a443cf3f7c | 367 | // calculating HRV |
| jeannie9809 | 11:58a443cf3f7c | 368 | vector<double> r; |
| jeannie9809 | 11:58a443cf3f7c | 369 | vector<int> index_r; |
| jeannie9809 | 11:58a443cf3f7c | 370 | double mean_inter_time = 0; |
| jeannie9809 | 11:58a443cf3f7c | 371 | for(i = 0; i < num_max-1; i++) { |
| jeannie9809 | 11:58a443cf3f7c | 372 | r.push_back(time_of_max.at(i+1)-time_of_max.at(i)); |
| jeannie9809 | 11:58a443cf3f7c | 373 | index_r.push_back(index_of_max.at(i+1) - index_of_max.at(i)); |
| jeannie9809 | 11:58a443cf3f7c | 374 | mean_inter_time = mean_inter_time + r.at(i); |
| jeannie9809 | 11:58a443cf3f7c | 375 | } |
| jeannie9809 | 11:58a443cf3f7c | 376 | |
| jeannie9809 | 11:58a443cf3f7c | 377 | //printf("r: %.2f %.2f %.2f ", r.at(0), r.at(1), r.at(2)); |
| jeannie9809 | 11:58a443cf3f7c | 378 | mean_inter_time = mean_inter_time/(double)(num_max-1); |
| jeannie9809 | 11:58a443cf3f7c | 379 | |
| jeannie9809 | 11:58a443cf3f7c | 380 | // getting rid of outlier points in r |
| jeannie9809 | 11:58a443cf3f7c | 381 | for(i = 0; i < num_max-1; i++) { |
| jeannie9809 | 11:58a443cf3f7c | 382 | if(r.at(i) > mean_inter_time + 0.11) |
| jeannie9809 | 11:58a443cf3f7c | 383 | r.at(i) = mean_inter_time + 0.11; |
| jeannie9809 | 11:58a443cf3f7c | 384 | else if(r.at(i) < mean_inter_time - 0.11) |
| jeannie9809 | 11:58a443cf3f7c | 385 | r.at(i) = mean_inter_time - 0.11; |
| jeannie9809 | 11:58a443cf3f7c | 386 | } |
| jeannie9809 | 11:58a443cf3f7c | 387 | |
| jeannie9809 | 11:58a443cf3f7c | 388 | // SDNN -- std of normal to normal R-R intervals |
| jeannie9809 | 11:58a443cf3f7c | 389 | mean_inter_time = 0; |
| jeannie9809 | 11:58a443cf3f7c | 390 | for(i = 0; i < num_max-1; i++) { |
| jeannie9809 | 11:58a443cf3f7c | 391 | mean_inter_time = mean_inter_time + r.at(i); |
| jeannie9809 | 5:a6b6d0e5a69f | 392 | } |
| jeannie9809 | 11:58a443cf3f7c | 393 | mean_inter_time = double(mean_inter_time/(num_max-1)); |
| jeannie9809 | 11:58a443cf3f7c | 394 | double SDNN_doub = 0.0; |
| jeannie9809 | 11:58a443cf3f7c | 395 | for(i = 0; i < num_max-1; i++) { |
| jeannie9809 | 11:58a443cf3f7c | 396 | SDNN_doub = SDNN_doub + (r.at(i)-mean_inter_time)*(r.at(i)-mean_inter_time); |
| jeannie9809 | 11:58a443cf3f7c | 397 | } |
| jeannie9809 | 11:58a443cf3f7c | 398 | SDNN = (int)(sqrt(SDNN_doub/(num_max-1))*1000); |
| jeannie9809 | 11:58a443cf3f7c | 399 | printf("SDNN = %d ", SDNN); |
| jeannie9809 | 11:58a443cf3f7c | 400 | |
| jeannie9809 | 11:58a443cf3f7c | 401 | // TIME TO CALCULATE HF/LF |
| jeannie9809 | 11:58a443cf3f7c | 402 | // FFT: use movave as fftppg |
| jeannie9809 | 5:a6b6d0e5a69f | 403 | for(i = 0; i < num_samples; i++) { |
| jeannie9809 | 11:58a443cf3f7c | 404 | double real = 0; |
| jeannie9809 | 11:58a443cf3f7c | 405 | double im = 0; |
| jeannie9809 | 11:58a443cf3f7c | 406 | double dum_ppg; |
| jeannie9809 | 11:58a443cf3f7c | 407 | for(j = 0; j < num_samples; j++) { |
| jeannie9809 | 11:58a443cf3f7c | 408 | dum_ppg = (double) ppg[j]; |
| jeannie9809 | 11:58a443cf3f7c | 409 | real = real + dum_ppg * cos(2.0*M_PI*(double)(j*i)/(double)num_samples); |
| jeannie9809 | 11:58a443cf3f7c | 410 | im = im + dum_ppg * sin(2.0*M_PI*(double)(j*i)/(double)num_samples); |
| jeannie9809 | 11:58a443cf3f7c | 411 | } |
| jeannie9809 | 11:58a443cf3f7c | 412 | movave[i] = sqrt(real*real + im*im)/(double)num_samples; |
| jeannie9809 | 11:58a443cf3f7c | 413 | } |
| jeannie9809 | 11:58a443cf3f7c | 414 | |
| jeannie9809 | 11:58a443cf3f7c | 415 | |
| jeannie9809 | 11:58a443cf3f7c | 416 | // make frequency array: use TIME |
| jeannie9809 | 11:58a443cf3f7c | 417 | double sampling_freq = (double)(1/TIME[1]); |
| jeannie9809 | 11:58a443cf3f7c | 418 | for(i = 0; i < num_samples; i++) { |
| jeannie9809 | 11:58a443cf3f7c | 419 | TIME[i] = sampling_freq*(double)(i)/(double)(num_samples); |
| jeannie9809 | 5:a6b6d0e5a69f | 420 | } |
| jeannie9809 | 11:58a443cf3f7c | 421 | |
| jeannie9809 | 11:58a443cf3f7c | 422 | double LF = 0.0; |
| jeannie9809 | 11:58a443cf3f7c | 423 | i = 0; |
| jeannie9809 | 11:58a443cf3f7c | 424 | while(TIME[i] < 0.15) { |
| jeannie9809 | 11:58a443cf3f7c | 425 | LF = LF + movave[i]; |
| jeannie9809 | 11:58a443cf3f7c | 426 | i++; |
| jeannie9809 | 11:58a443cf3f7c | 427 | } |
| jeannie9809 | 11:58a443cf3f7c | 428 | |
| jeannie9809 | 11:58a443cf3f7c | 429 | double HF = 0.0; |
| jeannie9809 | 11:58a443cf3f7c | 430 | while(TIME[i] < 0.4) { |
| jeannie9809 | 11:58a443cf3f7c | 431 | HF = HF + movave[i]; |
| jeannie9809 | 11:58a443cf3f7c | 432 | i++; |
| jeannie9809 | 11:58a443cf3f7c | 433 | } |
| jeannie9809 | 11:58a443cf3f7c | 434 | HF_LF = HF/LF; |
| jeannie9809 | 11:58a443cf3f7c | 435 | printf("HF/LF = %.2f \n", HF_LF); |
| jeannie9809 | 11:58a443cf3f7c | 436 | |
| jeannie9809 | 14:0258b126d726 | 437 | if(SDNN_n < 1) { |
| jeannie9809 | 12:95d141421e18 | 438 | SDNN_n = SDNN; |
| jeannie9809 | 12:95d141421e18 | 439 | HF_LF_n = HF_LF; |
| jeannie9809 | 12:95d141421e18 | 440 | valence_arousal = 0; |
| jeannie9809 | 12:95d141421e18 | 441 | } |
| jeannie9809 | 12:95d141421e18 | 442 | else { |
| jeannie9809 | 14:0258b126d726 | 443 | // mapping SDNN, HF/LF to valence, arousal |
| jeannie9809 | 14:0258b126d726 | 444 | int comp_sdnn = SDNN-SDNN_n; |
| jeannie9809 | 14:0258b126d726 | 445 | if(comp_sdnn > 20) |
| jeannie9809 | 15:5d291cd60879 | 446 | valence_arousal = 5; |
| jeannie9809 | 14:0258b126d726 | 447 | else if(comp_sdnn > 5) |
| jeannie9809 | 15:5d291cd60879 | 448 | valence_arousal = 4; |
| jeannie9809 | 14:0258b126d726 | 449 | else if(comp_sdnn > -5) |
| jeannie9809 | 15:5d291cd60879 | 450 | valence_arousal = 3; |
| jeannie9809 | 14:0258b126d726 | 451 | else if(comp_sdnn > -20) |
| jeannie9809 | 15:5d291cd60879 | 452 | valence_arousal = 2; |
| jeannie9809 | 14:0258b126d726 | 453 | else |
| jeannie9809 | 15:5d291cd60879 | 454 | valence_arousal = 1; |
| jeannie9809 | 14:0258b126d726 | 455 | |
| jeannie9809 | 14:0258b126d726 | 456 | double comp_hf_lf = HF_LF/HF_LF_n; |
| jeannie9809 | 14:0258b126d726 | 457 | if(comp_hf_lf > 5.0) |
| jeannie9809 | 15:5d291cd60879 | 458 | valence_arousal += 50; |
| jeannie9809 | 14:0258b126d726 | 459 | else if(comp_hf_lf > 1.5) |
| jeannie9809 | 15:5d291cd60879 | 460 | valence_arousal += 40; |
| jeannie9809 | 14:0258b126d726 | 461 | else if(comp_hf_lf > 0.9) |
| jeannie9809 | 15:5d291cd60879 | 462 | valence_arousal += 30; |
| jeannie9809 | 14:0258b126d726 | 463 | else if(comp_hf_lf > 0.7) |
| jeannie9809 | 15:5d291cd60879 | 464 | valence_arousal += 20; |
| jeannie9809 | 14:0258b126d726 | 465 | else |
| jeannie9809 | 15:5d291cd60879 | 466 | valence_arousal += 10; |
| jeannie9809 | 14:0258b126d726 | 467 | printf("valence_arousal = %d ", valence_arousal); |
| jeannie9809 | 14:0258b126d726 | 468 | ready_to_send = true; |
| jeannie9809 | 12:95d141421e18 | 469 | } |
| jeannie9809 | 12:95d141421e18 | 470 | |
| jeannie9809 | 11:58a443cf3f7c | 471 | ready = false; // last line |
| jeannie9809 | 11:58a443cf3f7c | 472 | |
| jeannie9809 | 5:a6b6d0e5a69f | 473 | } |
| jeannie9809 | 11:58a443cf3f7c | 474 | |
| jeannie9809 | 0:338c50c9c8cd | 475 | } |
| jeannie9809 | 0:338c50c9c8cd | 476 | |
| jeannie9809 | 0:338c50c9c8cd | 477 | // main() runs in its own thread in the OS |
| jeannie9809 | 3:0da9235c9069 | 478 | int main() |
| jeannie9809 | 3:0da9235c9069 | 479 | { |
| jeannie9809 | 0:338c50c9c8cd | 480 | // printf("Hello world.\r\n"); |
| jeannie9809 | 4:94190624967a | 481 | |
| jeannie9809 | 0:338c50c9c8cd | 482 | t.start(callback(&evqueue, &EventQueue::dispatch_forever)); |
| jeannie9809 | 0:338c50c9c8cd | 483 | kw40z_device.attach_buttonLeft(&ButtonLeft); |
| jeannie9809 | 0:338c50c9c8cd | 484 | kw40z_device.attach_buttonRight(&ButtonRight); |
| jeannie9809 | 3:0da9235c9069 | 485 | |
| jeannie9809 | 0:338c50c9c8cd | 486 | pwr1v8 = 1; |
| jeannie9809 | 0:338c50c9c8cd | 487 | pwr3v3b = 1; |
| jeannie9809 | 0:338c50c9c8cd | 488 | pwr15v = 0; |
| jeannie9809 | 3:0da9235c9069 | 489 | |
| jeannie9809 | 0:338c50c9c8cd | 490 | maximInterrupt.fall(interruptHandler); |
| jeannie9809 | 0:338c50c9c8cd | 491 | maximInterrupt.enable_irq(); |
| jeannie9809 | 3:0da9235c9069 | 492 | |
| jeannie9809 | 0:338c50c9c8cd | 493 | MAX30101::InterruptBitField_u interruptStatus; |
| jeannie9809 | 0:338c50c9c8cd | 494 | interruptStatus.all = 0xFF; |
| jeannie9809 | 0:338c50c9c8cd | 495 | hr.enableInterrupts(interruptStatus); |
| jeannie9809 | 3:0da9235c9069 | 496 | |
| jeannie9809 | 14:0258b126d726 | 497 | |
| jeannie9809 | 0:338c50c9c8cd | 498 | oled_text_properties_t textProperties = {0}; |
| jeannie9809 | 3:0da9235c9069 | 499 | oled.GetTextProperties(&textProperties); |
| jeannie9809 | 0:338c50c9c8cd | 500 | /* Turn on the backlight of the OLED Display */ |
| jeannie9809 | 0:338c50c9c8cd | 501 | oled.DimScreenON(); |
| jeannie9809 | 3:0da9235c9069 | 502 | |
| jeannie9809 | 3:0da9235c9069 | 503 | /* Fills the screen with solid black */ |
| jeannie9809 | 0:338c50c9c8cd | 504 | oled.FillScreen(COLOR_BLACK); |
| jeannie9809 | 1:eabf219849ab | 505 | strcpy((char *) text, "Raw PPG:"); |
| jeannie9809 | 0:338c50c9c8cd | 506 | oled.Label((uint8_t *)text,7,0); |
| jeannie9809 | 3:0da9235c9069 | 507 | |
| jeannie9809 | 11:58a443cf3f7c | 508 | strcpy((char *) text, " LOFI"); |
| jeannie9809 | 0:338c50c9c8cd | 509 | oled.Label((uint8_t *)text,7,40); |
| jeannie9809 | 0:338c50c9c8cd | 510 | //dynamic text setup |
| jeannie9809 | 0:338c50c9c8cd | 511 | textProperties.fontColor = COLOR_WHITE; |
| jeannie9809 | 0:338c50c9c8cd | 512 | textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; |
| jeannie9809 | 3:0da9235c9069 | 513 | oled.SetTextProperties(&textProperties); |
| jeannie9809 | 3:0da9235c9069 | 514 | |
| jeannie9809 | 0:338c50c9c8cd | 515 | txThread.start(txTask); |
| jeannie9809 | 11:58a443cf3f7c | 516 | |
| jeannie9809 | 12:95d141421e18 | 517 | |
| jeannie9809 | 0:338c50c9c8cd | 518 | while (true) { |
| jeannie9809 | 3:0da9235c9069 | 519 | |
| jeannie9809 | 11:58a443cf3f7c | 520 | // Format the time reading |
| jeannie9809 | 1:eabf219849ab | 521 | sprintf(text,"%d",ppg_single_sample); |
| jeannie9809 | 0:338c50c9c8cd | 522 | oled.TextBox((uint8_t *)text,55,15,35,15); //Increase textbox for more digits |
| jeannie9809 | 11:58a443cf3f7c | 523 | |
| jeannie9809 | 11:58a443cf3f7c | 524 | /* |
| jeannie9809 | 11:58a443cf3f7c | 525 | // Display time reading in 35px by 15px textbox at(x=55, y=40) |
| jeannie9809 | 3:0da9235c9069 | 526 | if (ppg_single_sample > 45) { |
| jeannie9809 | 1:eabf219849ab | 527 | sprintf(text,"%d; %.2f",SDNN, HF_LF); |
| jeannie9809 | 3:0da9235c9069 | 528 | |
| jeannie9809 | 11:58a443cf3f7c | 529 | // Display time reading in 35px by 15px textbox at(x=55, y=40) |
| jeannie9809 | 0:338c50c9c8cd | 530 | oled.TextBox((uint8_t *)text,55,55,35,15); //Increase textbox for more digits |
| jeannie9809 | 3:0da9235c9069 | 531 | } else { |
| jeannie9809 | 0:338c50c9c8cd | 532 | sprintf(text,"wait HR"); |
| jeannie9809 | 3:0da9235c9069 | 533 | |
| jeannie9809 | 11:58a443cf3f7c | 534 | // Display time reading in 35px by 15px textbox at(x=55, y=40) |
| jeannie9809 | 0:338c50c9c8cd | 535 | oled.TextBox((uint8_t *)text,55,55,35,15); |
| jeannie9809 | 11:58a443cf3f7c | 536 | }*/ |
| jeannie9809 | 0:338c50c9c8cd | 537 | Thread::wait(1000); |
| jeannie9809 | 3:0da9235c9069 | 538 | } |
| jeannie9809 | 0:338c50c9c8cd | 539 | return 0; |
| jeannie9809 | 0:338c50c9c8cd | 540 | } |
| jeannie9809 | 0:338c50c9c8cd | 541 |