HRV -> Mood
Dependencies: MAX30101 Hexi_KW40Z Hexi_OLED_SSD1351
8cee5929f4d8/main.cpp@3:0da9235c9069, 2019-03-16 (annotated)
- Committer:
- jeannie9809
- Date:
- Sat Mar 16 03:03:34 2019 +0000
- Revision:
- 3:0da9235c9069
- Parent:
- 2:3389bdfd9afa
- Child:
- 4:94190624967a
stored into array
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 | 0:338c50c9c8cd | 7 | #include <math.h> |
| jeannie9809 | 0:338c50c9c8cd | 8 | #define FIFO_DATA_MAX 288 |
| jeannie9809 | 0:338c50c9c8cd | 9 | void UpdateSensorData(void); |
| jeannie9809 | 0:338c50c9c8cd | 10 | void StartHaptic(void); |
| jeannie9809 | 0:338c50c9c8cd | 11 | void StopHaptic(void const *n); |
| jeannie9809 | 0:338c50c9c8cd | 12 | void txTask(void); |
| jeannie9809 | 0:338c50c9c8cd | 13 | |
| jeannie9809 | 0:338c50c9c8cd | 14 | DigitalOut pwr1v8(PTA29); |
| jeannie9809 | 0:338c50c9c8cd | 15 | DigitalOut pwr3v3b(PTC13); |
| jeannie9809 | 0:338c50c9c8cd | 16 | DigitalOut pwr15v(PTB12); |
| jeannie9809 | 0:338c50c9c8cd | 17 | I2C i2c0(PTB1, PTB0); |
| jeannie9809 | 0:338c50c9c8cd | 18 | InterruptIn maximInterrupt(PTB18); |
| jeannie9809 | 0:338c50c9c8cd | 19 | Serial pc(USBTX, USBRX); |
| jeannie9809 | 0:338c50c9c8cd | 20 | SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); |
| jeannie9809 | 0:338c50c9c8cd | 21 | KW40Z kw40z_device(PTE24, PTE25); |
| jeannie9809 | 0:338c50c9c8cd | 22 | DigitalOut haptic(PTB9); |
| jeannie9809 | 0:338c50c9c8cd | 23 | EventQueue evqueue(32 * EVENTS_EVENT_SIZE); |
| jeannie9809 | 0:338c50c9c8cd | 24 | Thread t; |
| jeannie9809 | 0:338c50c9c8cd | 25 | /* Define timer for haptic feedback */ |
| jeannie9809 | 0:338c50c9c8cd | 26 | RtosTimer hapticTimer(StopHaptic, osTimerOnce); |
| jeannie9809 | 0:338c50c9c8cd | 27 | |
| jeannie9809 | 3:0da9235c9069 | 28 | /*Create a Thread to handle sending BLE Sensor Data */ |
| jeannie9809 | 0:338c50c9c8cd | 29 | Thread txThread; |
| jeannie9809 | 0:338c50c9c8cd | 30 | MAX30101 hr(i2c0); |
| jeannie9809 | 1:eabf219849ab | 31 | int ppg_single_sample; |
| jeannie9809 | 0:338c50c9c8cd | 32 | int mask_ppg = 0; |
| jeannie9809 | 0:338c50c9c8cd | 33 | uint32_t count = 0; |
| jeannie9809 | 0:338c50c9c8cd | 34 | uint32_t num; |
| jeannie9809 | 0:338c50c9c8cd | 35 | uint8_t testsignal = 60; |
| jeannie9809 | 0:338c50c9c8cd | 36 | |
| jeannie9809 | 2:3389bdfd9afa | 37 | // I added this |
| jeannie9809 | 0:338c50c9c8cd | 38 | const int num_samples = 2129; |
| jeannie9809 | 0:338c50c9c8cd | 39 | int index = 0; |
| jeannie9809 | 0:338c50c9c8cd | 40 | int ppg[num_samples]; |
| jeannie9809 | 1:eabf219849ab | 41 | int SDNN_n, SDNN; |
| jeannie9809 | 0:338c50c9c8cd | 42 | bool first_sample_set = true; |
| jeannie9809 | 1:eabf219849ab | 43 | double arousal, valence, HF_LF, HF_LF_n; |
| jeannie9809 | 0:338c50c9c8cd | 44 | |
| jeannie9809 | 3:0da9235c9069 | 45 | void StartHaptic(void) |
| jeannie9809 | 3:0da9235c9069 | 46 | { |
| jeannie9809 | 0:338c50c9c8cd | 47 | hapticTimer.start(50); |
| jeannie9809 | 0:338c50c9c8cd | 48 | haptic = 1; |
| jeannie9809 | 0:338c50c9c8cd | 49 | } |
| jeannie9809 | 0:338c50c9c8cd | 50 | void ButtonRight(void) |
| jeannie9809 | 0:338c50c9c8cd | 51 | { |
| jeannie9809 | 0:338c50c9c8cd | 52 | StartHaptic(); |
| jeannie9809 | 0:338c50c9c8cd | 53 | kw40z_device.ToggleAdvertisementMode(); |
| jeannie9809 | 0:338c50c9c8cd | 54 | } |
| jeannie9809 | 0:338c50c9c8cd | 55 | |
| jeannie9809 | 0:338c50c9c8cd | 56 | void ButtonLeft(void) |
| jeannie9809 | 0:338c50c9c8cd | 57 | { |
| jeannie9809 | 0:338c50c9c8cd | 58 | StartHaptic(); |
| jeannie9809 | 0:338c50c9c8cd | 59 | kw40z_device.ToggleAdvertisementMode(); |
| jeannie9809 | 0:338c50c9c8cd | 60 | } |
| jeannie9809 | 0:338c50c9c8cd | 61 | |
| jeannie9809 | 3:0da9235c9069 | 62 | void StopHaptic(void const *n) |
| jeannie9809 | 3:0da9235c9069 | 63 | { |
| jeannie9809 | 0:338c50c9c8cd | 64 | haptic = 0; |
| jeannie9809 | 0:338c50c9c8cd | 65 | hapticTimer.stop(); |
| jeannie9809 | 0:338c50c9c8cd | 66 | } |
| jeannie9809 | 3:0da9235c9069 | 67 | void txTask(void) |
| jeannie9809 | 3:0da9235c9069 | 68 | { |
| jeannie9809 | 3:0da9235c9069 | 69 | |
| jeannie9809 | 3:0da9235c9069 | 70 | while (true) { |
| jeannie9809 | 0:338c50c9c8cd | 71 | UpdateSensorData(); |
| jeannie9809 | 3:0da9235c9069 | 72 | |
| jeannie9809 | 0:338c50c9c8cd | 73 | /*Notify Hexiwear App that it is running Sensor Tag mode*/ |
| jeannie9809 | 0:338c50c9c8cd | 74 | kw40z_device.SendSetApplicationMode(GUI_CURRENT_APP_SENSOR_TAG); |
| jeannie9809 | 0:338c50c9c8cd | 75 | //send heartrate |
| jeannie9809 | 3:0da9235c9069 | 76 | kw40z_device.SendHeartRate(testsignal); |
| jeannie9809 | 0:338c50c9c8cd | 77 | /*The following is sending dummy data over BLE. Replace with real data*/ |
| jeannie9809 | 3:0da9235c9069 | 78 | |
| jeannie9809 | 3:0da9235c9069 | 79 | /*Send Battery Level for 20% |
| jeannie9809 | 0:338c50c9c8cd | 80 | kw40z_device.SendBatteryLevel(battery); |
| jeannie9809 | 3:0da9235c9069 | 81 | |
| jeannie9809 | 3:0da9235c9069 | 82 | Send Ambient Light Level at 50% |
| jeannie9809 | 0:338c50c9c8cd | 83 | kw40z_device.SendAmbientLight(light);*/ |
| jeannie9809 | 3:0da9235c9069 | 84 | |
| jeannie9809 | 0:338c50c9c8cd | 85 | /*Send Humidity at 90% */ |
| jeannie9809 | 0:338c50c9c8cd | 86 | //kw40z_device.SendHumidity(humidity); |
| jeannie9809 | 3:0da9235c9069 | 87 | |
| jeannie9809 | 3:0da9235c9069 | 88 | /*Send Temperature at 25 degrees Celsius |
| jeannie9809 | 0:338c50c9c8cd | 89 | kw40z_device.SendTemperature(temperature); |
| jeannie9809 | 0:338c50c9c8cd | 90 | |
| jeannie9809 | 3:0da9235c9069 | 91 | /*Send Pressure at 100kPA */ |
| jeannie9809 | 0:338c50c9c8cd | 92 | //kw40z_device.SendPressure(pressure); |
| jeannie9809 | 3:0da9235c9069 | 93 | |
| jeannie9809 | 3:0da9235c9069 | 94 | /*Send Mag,Accel,Gyro Data. |
| jeannie9809 | 0:338c50c9c8cd | 95 | kw40z_device.SendGyro(x,y,z); |
| jeannie9809 | 0:338c50c9c8cd | 96 | kw40z_device.SendAccel(z,x,y); |
| jeannie9809 | 0:338c50c9c8cd | 97 | kw40z_device.SendMag(y,z,x);*/ |
| jeannie9809 | 0:338c50c9c8cd | 98 | |
| jeannie9809 | 3:0da9235c9069 | 99 | Thread::wait(1000); |
| jeannie9809 | 0:338c50c9c8cd | 100 | } |
| jeannie9809 | 0:338c50c9c8cd | 101 | } |
| jeannie9809 | 0:338c50c9c8cd | 102 | void UpdateSensorData(void) |
| jeannie9809 | 3:0da9235c9069 | 103 | { |
| jeannie9809 | 3:0da9235c9069 | 104 | testsignal+=1; |
| jeannie9809 | 0:338c50c9c8cd | 105 | /*battery -= 5; |
| jeannie9809 | 0:338c50c9c8cd | 106 | if(battery < 5) battery = 100; |
| jeannie9809 | 3:0da9235c9069 | 107 | |
| jeannie9809 | 0:338c50c9c8cd | 108 | light += 20; |
| jeannie9809 | 0:338c50c9c8cd | 109 | if(light > 100) light = 0; |
| jeannie9809 | 3:0da9235c9069 | 110 | |
| jeannie9809 | 0:338c50c9c8cd | 111 | humidity += 500; |
| jeannie9809 | 0:338c50c9c8cd | 112 | if(humidity > 8000) humidity = 2000; |
| jeannie9809 | 3:0da9235c9069 | 113 | |
| jeannie9809 | 0:338c50c9c8cd | 114 | temperature -= 200; |
| jeannie9809 | 0:338c50c9c8cd | 115 | if(temperature < 200) temperature = 4200; |
| jeannie9809 | 3:0da9235c9069 | 116 | |
| jeannie9809 | 0:338c50c9c8cd | 117 | pressure += 300; |
| jeannie9809 | 0:338c50c9c8cd | 118 | if(pressure > 10300) pressure = 7500; |
| jeannie9809 | 3:0da9235c9069 | 119 | |
| jeannie9809 | 0:338c50c9c8cd | 120 | x += 1400; |
| jeannie9809 | 0:338c50c9c8cd | 121 | y -= 2300; |
| jeannie9809 | 0:338c50c9c8cd | 122 | z += 1700;*/ |
| jeannie9809 | 0:338c50c9c8cd | 123 | } |
| jeannie9809 | 0:338c50c9c8cd | 124 | |
| jeannie9809 | 3:0da9235c9069 | 125 | void interruptHandlerQueued() |
| jeannie9809 | 3:0da9235c9069 | 126 | { |
| jeannie9809 | 3:0da9235c9069 | 127 | |
| jeannie9809 | 3:0da9235c9069 | 128 | for(int iter = 0; iter < num_samples; iter+=0) { |
| jeannie9809 | 0:338c50c9c8cd | 129 | |
| jeannie9809 | 3:0da9235c9069 | 130 | MAX30101::InterruptBitField_u interruptStatus; |
| jeannie9809 | 3:0da9235c9069 | 131 | hr.getInterruptStatus(interruptStatus); |
| jeannie9809 | 3:0da9235c9069 | 132 | // printf("Interrupt Status: 0x%02x\r\n", interruptStatus.all); |
| jeannie9809 | 3:0da9235c9069 | 133 | |
| jeannie9809 | 3:0da9235c9069 | 134 | if (interruptStatus.bits.pwr_rdy == 0x1) { |
| jeannie9809 | 3:0da9235c9069 | 135 | // printf("Powered on\r\n"); |
| jeannie9809 | 3:0da9235c9069 | 136 | |
| jeannie9809 | 3:0da9235c9069 | 137 | // Soft reset |
| jeannie9809 | 3:0da9235c9069 | 138 | MAX30101::ModeConfiguration_u modeConf; |
| jeannie9809 | 3:0da9235c9069 | 139 | modeConf.all = 0; |
| jeannie9809 | 3:0da9235c9069 | 140 | modeConf.bits.reset = 1; |
| jeannie9809 | 3:0da9235c9069 | 141 | hr.setModeConfiguration(modeConf); |
| jeannie9809 | 3:0da9235c9069 | 142 | wait(0.01); |
| jeannie9809 | 3:0da9235c9069 | 143 | |
| jeannie9809 | 3:0da9235c9069 | 144 | // Configure FIFO |
| jeannie9809 | 3:0da9235c9069 | 145 | MAX30101::FIFO_Configuration_u fifoConf; |
| jeannie9809 | 3:0da9235c9069 | 146 | hr.getFIFOConfiguration(fifoConf); |
| jeannie9809 | 0:338c50c9c8cd | 147 | // pc.printf("FIFO Configuration: 0x%02x\r\n", fifoConf.all); |
| jeannie9809 | 3:0da9235c9069 | 148 | |
| jeannie9809 | 3:0da9235c9069 | 149 | // Set LED power |
| jeannie9809 | 3:0da9235c9069 | 150 | hr.setLEDPulseAmplitude(MAX30101::LED1_PA, 0x0C); |
| jeannie9809 | 3:0da9235c9069 | 151 | hr.setLEDPulseAmplitude(MAX30101::ProxModeLED_PA, 0x19); |
| jeannie9809 | 0:338c50c9c8cd | 152 | // pc.printf("LED set\r\n"); |
| jeannie9809 | 3:0da9235c9069 | 153 | |
| jeannie9809 | 3:0da9235c9069 | 154 | MAX30101::SpO2Configuration_u spo2Conf; |
| jeannie9809 | 3:0da9235c9069 | 155 | hr.getSpO2Configuration(spo2Conf); |
| jeannie9809 | 3:0da9235c9069 | 156 | spo2Conf.bits.led_pw = MAX30101::PW_1; |
| jeannie9809 | 3:0da9235c9069 | 157 | spo2Conf.bits.spo2_sr = MAX30101::SR_100_Hz; |
| jeannie9809 | 3:0da9235c9069 | 158 | hr.setSpO2Configuration(spo2Conf); |
| jeannie9809 | 3:0da9235c9069 | 159 | hr.getSpO2Configuration(spo2Conf); |
| jeannie9809 | 0:338c50c9c8cd | 160 | // pc.printf("SpO2 Configuration: 0x%02x\r\n", spo2Conf.all); |
| jeannie9809 | 3:0da9235c9069 | 161 | |
| jeannie9809 | 3:0da9235c9069 | 162 | // Proximity settings |
| jeannie9809 | 3:0da9235c9069 | 163 | hr.setProxIntThreshold(0x14); |
| jeannie9809 | 3:0da9235c9069 | 164 | |
| jeannie9809 | 3:0da9235c9069 | 165 | // Enable HR mode |
| jeannie9809 | 3:0da9235c9069 | 166 | modeConf.all = 0; |
| jeannie9809 | 3:0da9235c9069 | 167 | modeConf.bits.mode = MAX30101::HeartRateMode; |
| jeannie9809 | 3:0da9235c9069 | 168 | hr.setModeConfiguration(modeConf); |
| jeannie9809 | 0:338c50c9c8cd | 169 | // printf("Mode set\r\n"); |
| jeannie9809 | 3:0da9235c9069 | 170 | } |
| jeannie9809 | 3:0da9235c9069 | 171 | |
| jeannie9809 | 3:0da9235c9069 | 172 | if (interruptStatus.bits.prox_int == 0x1) { |
| jeannie9809 | 0:338c50c9c8cd | 173 | // printf("Proximity Triggered, entered HR Mode."); |
| jeannie9809 | 3:0da9235c9069 | 174 | } |
| jeannie9809 | 3:0da9235c9069 | 175 | |
| jeannie9809 | 3:0da9235c9069 | 176 | if (interruptStatus.bits.ppg_rdy == 0x1) { |
| jeannie9809 | 0:338c50c9c8cd | 177 | // printf("PPG Ready.\r\n"); |
| jeannie9809 | 3:0da9235c9069 | 178 | mask_ppg = 1; |
| jeannie9809 | 3:0da9235c9069 | 179 | } |
| jeannie9809 | 3:0da9235c9069 | 180 | |
| jeannie9809 | 3:0da9235c9069 | 181 | if (interruptStatus.bits.a_full == 0x1) { |
| jeannie9809 | 0:338c50c9c8cd | 182 | // printf("FIFO Almost Full.\r\n"); |
| jeannie9809 | 3:0da9235c9069 | 183 | uint8_t data[FIFO_DATA_MAX]; |
| jeannie9809 | 3:0da9235c9069 | 184 | uint16_t readBytes = 0; |
| jeannie9809 | 3:0da9235c9069 | 185 | |
| jeannie9809 | 3:0da9235c9069 | 186 | hr.readFIFO(MAX30101::OneLedChannel, data, readBytes); |
| jeannie9809 | 3:0da9235c9069 | 187 | printf("data length: %u \r\n",readBytes); |
| jeannie9809 | 3:0da9235c9069 | 188 | //printf("data length: %u \r\n",data); |
| jeannie9809 | 3:0da9235c9069 | 189 | for (uint16_t i = 0; i < readBytes; i += 3) { |
| jeannie9809 | 3:0da9235c9069 | 190 | uint8_t sample[4] = {0}; |
| jeannie9809 | 3:0da9235c9069 | 191 | sample[0] = data[i + 2]; |
| jeannie9809 | 3:0da9235c9069 | 192 | sample[1] = data[i + 1]; |
| jeannie9809 | 3:0da9235c9069 | 193 | sample[2] = data[i]; |
| jeannie9809 | 3:0da9235c9069 | 194 | |
| jeannie9809 | 3:0da9235c9069 | 195 | num = *(uint32_t *) sample; |
| jeannie9809 | 3:0da9235c9069 | 196 | if (num < 310000) { |
| jeannie9809 | 3:0da9235c9069 | 197 | ppg_single_sample = 0; |
| jeannie9809 | 3:0da9235c9069 | 198 | printf("keep closer to your hand \r\n"); |
| jeannie9809 | 3:0da9235c9069 | 199 | } else { |
| jeannie9809 | 3:0da9235c9069 | 200 | |
| jeannie9809 | 3:0da9235c9069 | 201 | //ppg_single_sample = 65; |
| jeannie9809 | 3:0da9235c9069 | 202 | ppg_single_sample = num; |
| jeannie9809 | 3:0da9235c9069 | 203 | if(iter < num_samples) |
| jeannie9809 | 3:0da9235c9069 | 204 | ppg[iter] = num; |
| jeannie9809 | 3:0da9235c9069 | 205 | // printf("%d\r\n", ppg_single_sample); // I commented this out |
| jeannie9809 | 3:0da9235c9069 | 206 | iter++; |
| jeannie9809 | 3:0da9235c9069 | 207 | } |
| jeannie9809 | 3:0da9235c9069 | 208 | //printf("%u\r\n", num); |
| jeannie9809 | 3:0da9235c9069 | 209 | |
| jeannie9809 | 3:0da9235c9069 | 210 | |
| jeannie9809 | 0:338c50c9c8cd | 211 | } |
| jeannie9809 | 0:338c50c9c8cd | 212 | } |
| jeannie9809 | 3:0da9235c9069 | 213 | |
| jeannie9809 | 3:0da9235c9069 | 214 | interruptStatus.all = 0xFF; |
| jeannie9809 | 3:0da9235c9069 | 215 | if (mask_ppg == 1) { |
| jeannie9809 | 3:0da9235c9069 | 216 | interruptStatus.bits.ppg_rdy = 0; |
| jeannie9809 | 3:0da9235c9069 | 217 | } |
| jeannie9809 | 3:0da9235c9069 | 218 | hr.enableInterrupts(interruptStatus); |
| jeannie9809 | 0:338c50c9c8cd | 219 | } |
| jeannie9809 | 0:338c50c9c8cd | 220 | } |
| jeannie9809 | 0:338c50c9c8cd | 221 | |
| jeannie9809 | 3:0da9235c9069 | 222 | void interruptHandler() |
| jeannie9809 | 3:0da9235c9069 | 223 | { |
| jeannie9809 | 0:338c50c9c8cd | 224 | evqueue.call(interruptHandlerQueued); |
| jeannie9809 | 3:0da9235c9069 | 225 | |
| jeannie9809 | 0:338c50c9c8cd | 226 | } |
| jeannie9809 | 0:338c50c9c8cd | 227 | |
| jeannie9809 | 0:338c50c9c8cd | 228 | // main() runs in its own thread in the OS |
| jeannie9809 | 3:0da9235c9069 | 229 | int main() |
| jeannie9809 | 3:0da9235c9069 | 230 | { |
| jeannie9809 | 0:338c50c9c8cd | 231 | // printf("Hello world.\r\n"); |
| jeannie9809 | 0:338c50c9c8cd | 232 | |
| jeannie9809 | 0:338c50c9c8cd | 233 | t.start(callback(&evqueue, &EventQueue::dispatch_forever)); |
| jeannie9809 | 0:338c50c9c8cd | 234 | kw40z_device.attach_buttonLeft(&ButtonLeft); |
| jeannie9809 | 0:338c50c9c8cd | 235 | kw40z_device.attach_buttonRight(&ButtonRight); |
| jeannie9809 | 3:0da9235c9069 | 236 | |
| jeannie9809 | 0:338c50c9c8cd | 237 | pwr1v8 = 1; |
| jeannie9809 | 0:338c50c9c8cd | 238 | pwr3v3b = 1; |
| jeannie9809 | 0:338c50c9c8cd | 239 | pwr15v = 0; |
| jeannie9809 | 3:0da9235c9069 | 240 | |
| jeannie9809 | 0:338c50c9c8cd | 241 | maximInterrupt.fall(interruptHandler); |
| jeannie9809 | 0:338c50c9c8cd | 242 | maximInterrupt.enable_irq(); |
| jeannie9809 | 3:0da9235c9069 | 243 | |
| jeannie9809 | 0:338c50c9c8cd | 244 | MAX30101::InterruptBitField_u interruptStatus; |
| jeannie9809 | 0:338c50c9c8cd | 245 | interruptStatus.all = 0xFF; |
| jeannie9809 | 0:338c50c9c8cd | 246 | hr.enableInterrupts(interruptStatus); |
| jeannie9809 | 3:0da9235c9069 | 247 | |
| jeannie9809 | 3:0da9235c9069 | 248 | char text[20]; /* Text Buffer */ |
| jeannie9809 | 0:338c50c9c8cd | 249 | oled_text_properties_t textProperties = {0}; |
| jeannie9809 | 3:0da9235c9069 | 250 | oled.GetTextProperties(&textProperties); |
| jeannie9809 | 0:338c50c9c8cd | 251 | /* Turn on the backlight of the OLED Display */ |
| jeannie9809 | 0:338c50c9c8cd | 252 | oled.DimScreenON(); |
| jeannie9809 | 3:0da9235c9069 | 253 | |
| jeannie9809 | 3:0da9235c9069 | 254 | /* Fills the screen with solid black */ |
| jeannie9809 | 0:338c50c9c8cd | 255 | oled.FillScreen(COLOR_BLACK); |
| jeannie9809 | 1:eabf219849ab | 256 | strcpy((char *) text, "Raw PPG:"); |
| jeannie9809 | 0:338c50c9c8cd | 257 | oled.Label((uint8_t *)text,7,0); |
| jeannie9809 | 3:0da9235c9069 | 258 | |
| jeannie9809 | 1:eabf219849ab | 259 | strcpy((char *) text, "SDNN; LF/HF:"); |
| jeannie9809 | 0:338c50c9c8cd | 260 | oled.Label((uint8_t *)text,7,40); |
| jeannie9809 | 0:338c50c9c8cd | 261 | //dynamic text setup |
| jeannie9809 | 0:338c50c9c8cd | 262 | textProperties.fontColor = COLOR_WHITE; |
| jeannie9809 | 0:338c50c9c8cd | 263 | textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; |
| jeannie9809 | 3:0da9235c9069 | 264 | oled.SetTextProperties(&textProperties); |
| jeannie9809 | 3:0da9235c9069 | 265 | |
| jeannie9809 | 0:338c50c9c8cd | 266 | txThread.start(txTask); |
| jeannie9809 | 0:338c50c9c8cd | 267 | while (true) { |
| jeannie9809 | 3:0da9235c9069 | 268 | |
| jeannie9809 | 0:338c50c9c8cd | 269 | /* Format the time reading */ |
| jeannie9809 | 1:eabf219849ab | 270 | sprintf(text,"%d",ppg_single_sample); |
| jeannie9809 | 3:0da9235c9069 | 271 | |
| jeannie9809 | 0:338c50c9c8cd | 272 | /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ |
| jeannie9809 | 0:338c50c9c8cd | 273 | oled.TextBox((uint8_t *)text,55,15,35,15); //Increase textbox for more digits |
| jeannie9809 | 3:0da9235c9069 | 274 | if (ppg_single_sample > 45) { |
| jeannie9809 | 1:eabf219849ab | 275 | sprintf(text,"%d; %.2f",SDNN, HF_LF); |
| jeannie9809 | 3:0da9235c9069 | 276 | |
| jeannie9809 | 0:338c50c9c8cd | 277 | /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ |
| jeannie9809 | 0:338c50c9c8cd | 278 | oled.TextBox((uint8_t *)text,55,55,35,15); //Increase textbox for more digits |
| jeannie9809 | 3:0da9235c9069 | 279 | } else { |
| jeannie9809 | 0:338c50c9c8cd | 280 | sprintf(text,"wait HR"); |
| jeannie9809 | 3:0da9235c9069 | 281 | |
| jeannie9809 | 0:338c50c9c8cd | 282 | /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ |
| jeannie9809 | 0:338c50c9c8cd | 283 | oled.TextBox((uint8_t *)text,55,55,35,15); |
| jeannie9809 | 0:338c50c9c8cd | 284 | } |
| jeannie9809 | 3:0da9235c9069 | 285 | |
| jeannie9809 | 0:338c50c9c8cd | 286 | Thread::wait(1000); |
| jeannie9809 | 3:0da9235c9069 | 287 | } |
| jeannie9809 | 0:338c50c9c8cd | 288 | return 0; |
| jeannie9809 | 0:338c50c9c8cd | 289 | } |
| jeannie9809 | 0:338c50c9c8cd | 290 |