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